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

/** "sys_arch" options */
struct sys_arch_options {};

/** "sys_arch" option list */
static struct option_descriptor sys_arch_opts[] = {};

/** "sys_arch" command descriptor */
static struct command_descriptor sys_arch_cmd =
	COMMAND_DESC ( struct sys_arch_options, sys_arch_opts, 0, 0, "" );

static int sys_arch_exec ( int argc, char **argv ) {
	struct sys_arch_options opts;
	const char *arch;
	int rc;

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

#if defined(__x86_64__) || defined(_M_X64)
	arch = "amd64";
#elif defined(__i386) || defined(_M_IX86)
	arch = "i386";
#elif defined(__aarch64__)
	arch = "arm64";
#elif defined(__arm__)
	arch = "arm32";
#elif defined(__riscv) && __riscv_xlen == 64
	arch = "riscv64";
#elif defined(__riscv) && __riscv_xlen == 32
	arch = "riscv32";
#elif defined(__loongarch64) || defined(__loongarch__)
	arch = "loong64";
#else
	arch = "unknown";
#endif

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

/** "sys_arch" command */
COMMAND ( sys_arch, sys_arch_exec );