#include <stdio.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>

/** "sys_archnum" options */
struct sys_archnum_options {};

/** "sys_archnum" option list */
static struct option_descriptor sys_archnum_opts[] = {};

/** "sys_archnum" command descriptor */
static struct command_descriptor sys_archnum_cmd =
	COMMAND_DESC ( struct sys_archnum_options, sys_archnum_opts, 0, 0, "" );

static int sys_archnum_exec ( int argc, char **argv ) {
	struct sys_archnum_options opts;
	const char *num;
	int rc;

	if ( ( rc = parse_options ( argc, argv, &sys_archnum_cmd, &opts ) ) != 0 )
		return rc;

#if defined(__x86_64__) || defined(_M_X64)
	num = "64";
#elif defined(__i386) || defined(_M_IX86)
	num = "32";
#elif defined(__aarch64__)
	num = "64";
#elif defined(__arm__)
	num = "32";
#elif defined(__riscv) && __riscv_xlen == 64
	num = "64";
#elif defined(__riscv) && __riscv_xlen == 32
	num = "32";
#elif defined(__loongarch64) || defined(__loongarch__)
	num = "64";
#else
	num = "unknown";
#endif

	printf ( "%s\n", num );
	return 0;
}

/** "sys_archnum" command */
COMMAND ( sys_archnum, sys_archnum_exec );