// File: /workspace/github_c_makefile_star2_O0/mikebdp2[P]AtomDis/main.c
// Function: main
int main (int argc, char *argv[])
{
    int            c;
    int            opt_off = 0;
    const char    *opt_addrformat = "%04x: ";
    char         **arg;
    int            fdmem;
    uint8_t       *data;
    bios_tables_t *tabs;
    int            off, start, len, last;

    opterr = 0;
    while ( (c = getopt (argc, argv, "o:r:a:A")) != -1)
	switch (c) {
	case 'o':
	    opt_off = strtol (optarg, NULL, 16);
	    break;
	case 'r':
	    index_load_registers (optarg);
	    break;
	case 'a':
	    opt_addrformat = optarg;
	    break;
	case 'A':
	    opt_reg_addresses = 1;
	    break;
	default:
	    usage (argv);
	}

    if (! argv[optind] || argv[optind][0] == '-')
	usage (argv);

    if ( (fdmem = open (argv[optind], O_RDONLY)) == -1) {
	perror (argv[optind]);
	return 1;
    }
    
#if USE_MMAP 
    if ( (data = mmap (NULL, MMAP_SIZE, PROT_READ, MAP_PRIVATE, fdmem, opt_off))
	 == (void *) -1) {
	perror ("mmap()");
	return 1;
    }
#else
    if (! (data = calloc (1, MMAP_SIZE)) ) {
	perror ("calloc()");
	return 1;
    }
    if ( (len = read (fdmem, data, MMAP_SIZE)) <= 0) {
	perror ("read()");
	return 1;
    }
    printf ("Read %x bytes of data from %s\n\n", len, argv[optind]);
    init_data_dumpers ();
#endif

    for (arg = &argv[optind+1]; *arg && **arg; arg++) {
	last_reg_index  = INDEX_NONE;
	last_reg_offset = 0;
	addrtypes_shift[D_REG] = 0;
	if (arg[0][1])
	    usage (argv);
	switch (arg[0][0]) {
	case 'i':
	    tabs = get_pointers (data);
	    do_info (tabs);
	    break;
	case 'l':
	    tabs = get_pointers (data);
	    do_list (tabs);
	    break;
	case 'x':
	    if (!arg[1] || !arg[2])
		usage (argv);
	    start = strtol (arg[1], NULL, 16);
	    len   = strtol (arg[2], NULL, 16);
	    arg  += 2;
	    do_dump (data, start, start+len);
	    break;
	case 'd':
	    if (!arg[1])
		usage (argv);
	    start = strtol (arg[1], NULL, 16);
	    arg++;
	    tabs  = get_pointers (data);
	    off   = get_table_offset(tabs->MasterDataTables, start);
	    len   = do_tableinfo (data, off, INDEX_DATA_TABLE, start);
	    if (off && len) {
		do_dump (data + off, 4, len);
		do_data (data + off, 0, start);
	    }
	    break;
	case 'c':
	    if (!arg[1])
		usage (argv);
	    start = strtol (arg[1], NULL, 16);
	    arg++;
	    tabs  = get_pointers (data);
	    off   = get_table_offset(tabs->MasterCommandTables, start);
	    len   = do_tableinfo (data, off, INDEX_COMMAND_TABLE, start);
	    if (off && len)
		do_diss (data + off, 6, len, opt_addrformat);
	    break;
	case 'C':
	    if (!arg[1])
		usage (argv);
	    off   = strtol (arg[1], NULL, 16);
	    arg++;
	    len   = do_tableinfo (data, off, INDEX_COMMAND_TABLE, -1);
	    do_diss (data + off, 6, len, opt_addrformat);
	    break;
	case 'T':
	    do_test (data);
	    break;
	case 'F':
	    tabs = get_pointers (data);
	    do_info (tabs);
	    do_list (tabs);
	    fputs ("\n*** Command Tables:\n\n", stdout);
	    last = 0;
	    for (start = 0; start < sizeof (ATOM_MASTER_LIST_OF_COMMAND_TABLES)
		 / sizeof (uint16_t); start++) {
		last_reg_index  = INDEX_NONE;
		last_reg_offset = 0;
		off   = get_table_offset(tabs->MasterCommandTables, start);
		len   = do_tableinfo (data, off, INDEX_COMMAND_TABLE, start);
		if (off && len) {
		    do_diss (data + off, 6, len, opt_addrformat);
		    fputs ("\n", stdout);
		}
	    }
	    fputs ("\n*** Data Tables:\n\n", stdout);
	    last = 0;
	    /* Data table #0 is reseverd (SET_DATA_BLOCK 0 == BIOS start */
	    for (start = 1; start < sizeof (ATOM_MASTER_LIST_OF_DATA_TABLES)
		 / sizeof (uint16_t); start++) {
		off   = get_table_offset(tabs->MasterDataTables, start);
		len   = do_tableinfo (data, off, INDEX_DATA_TABLE, start);
		if (off && len) {
		    do_dump (data + off, 4, len);
		    do_data (data + off, 0, start);
		    fputs ("\n", stdout);
		}
	    }
	    break;
	default:
	    usage (argv);
	}
    }

#if USE_MMAP
    munmap (data, MMAP_SIZE);
#endif
    close  (fdmem);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
leaq 0x466c0(%rip), %rax     # 0x4cb14
movq %rax, -0x20(%rbp)
movq 0x5db91(%rip), %rax     # 0x63ff0
movl $0x0, (%rax)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x466a8(%rip), %rdx     # 0x4cb1b
callq 0x41a0
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x6507
movl -0x14(%rbp), %eax
movl %eax, -0x54(%rbp)
subl $0x41, %eax
je 0x64ed
jmp 0x6491
movl -0x54(%rbp), %eax
subl $0x61, %eax
je 0x64dd
jmp 0x649b
movl -0x54(%rbp), %eax
subl $0x6f, %eax
je 0x64af
jmp 0x64a5
movl -0x54(%rbp), %eax
subl $0x72, %eax
je 0x64cc
jmp 0x64f9
movq 0x5db1a(%rip), %rax     # 0x63fd0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0x4140
movl %eax, -0x18(%rbp)
jmp 0x6502
movq 0x5dafd(%rip), %rax     # 0x63fd0
movq (%rax), %rdi
callq 0x4b740
jmp 0x6502
movq 0x5daec(%rip), %rax     # 0x63fd0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x6502
movl $0x1, 0x5ec55(%rip)     # 0x6514c
jmp 0x6502
movq -0x10(%rbp), %rdi
callq 0x63f0
jmp 0x6465
movq -0x10(%rbp), %rax
movq 0x5dab6(%rip), %rcx     # 0x63fc8
movslq (%rcx), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x6536
movq -0x10(%rbp), %rax
movq 0x5daa1(%rip), %rcx     # 0x63fc8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x653f
movq -0x10(%rbp), %rdi
callq 0x63f0
movq -0x10(%rbp), %rax
movq 0x5da7e(%rip), %rcx     # 0x63fc8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x4160
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
jne 0x6585
movq -0x10(%rbp), %rax
movq 0x5da5b(%rip), %rcx     # 0x63fc8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x4180
movl $0x1, -0x4(%rbp)
jmp 0x6afa
movl $0x1, %edi
movl $0x100000, %esi         # imm = 0x100000
callq 0x4100
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x65b6
leaq 0x4657e(%rip), %rdi     # 0x4cb23
callq 0x4180
movl $0x1, -0x4(%rbp)
jmp 0x6afa
movl -0x2c(%rbp), %edi
movq -0x38(%rbp), %rsi
movl $0x100000, %edx         # imm = 0x100000
callq 0x40d0
movl %eax, -0x4c(%rbp)
cmpl $0x0, %eax
jg 0x65e7
leaq 0x46556(%rip), %rdi     # 0x4cb2c
callq 0x4180
movl $0x1, -0x4(%rbp)
jmp 0x6afa
movl -0x4c(%rbp), %esi
movq -0x10(%rbp), %rax
movq 0x5d9d3(%rip), %rcx     # 0x63fc8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x46530(%rip), %rdi     # 0x4cb33
movb $0x0, %al
callq 0x4090
callq 0x4b5b0
movq -0x10(%rbp), %rax
movq 0x5d9ae(%rip), %rcx     # 0x63fc8
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx)
movb %al, -0x55(%rbp)
je 0x664f
movq -0x28(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x665b
jmp 0x6aeb
movl $0x0, 0x5eadf(%rip)     # 0x65144
movl $0x0, 0x5ead9(%rip)     # 0x65148
movl $0x0, 0x5ea77(%rip)     # 0x650f0
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpb $0x0, 0x1(%rax)
je 0x668f
movq -0x10(%rbp), %rdi
callq 0x63f0
movq -0x28(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
addl $-0x43, %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x35, %eax
ja 0x6acf
movq -0x60(%rbp), %rax
leaq 0x4595a(%rip), %rcx     # 0x4c010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x38(%rbp), %rdi
callq 0x50d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x5750
jmp 0x6ad8
movq -0x38(%rbp), %rdi
callq 0x50d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x57d0
jmp 0x6ad8
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x670b
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x6714
movq -0x10(%rbp), %rdi
callq 0x63f0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0x4140
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0x4140
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rdi
movl -0x48(%rbp), %esi
movl -0x48(%rbp), %edx
addl -0x4c(%rbp), %edx
callq 0x5c20
jmp 0x6ad8
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x677d
movq -0x10(%rbp), %rdi
callq 0x63f0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0x4140
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rdi
callq 0x50d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x48(%rbp), %esi
callq 0x5190
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rdi
movl -0x44(%rbp), %esi
movl -0x48(%rbp), %ecx
movl $0x2, %edx
callq 0x5a50
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x6812
cmpl $0x0, -0x4c(%rbp)
je 0x6812
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rax
addq %rax, %rdi
movl -0x4c(%rbp), %edx
movl $0x4, %esi
callq 0x5c20
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rax
addq %rax, %rdi
movl -0x48(%rbp), %edx
xorl %esi, %esi
callq 0x5e10
jmp 0x6ad8
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x682b
movq -0x10(%rbp), %rdi
callq 0x63f0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0x4140
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rdi
callq 0x50d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x48(%rbp), %esi
callq 0x5190
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rdi
movl -0x44(%rbp), %esi
movl -0x48(%rbp), %ecx
movl $0x1, %edx
callq 0x5a50
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x68af
cmpl $0x0, -0x4c(%rbp)
je 0x68af
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rax
addq %rax, %rdi
movl -0x4c(%rbp), %edx
movq -0x20(%rbp), %rcx
movl $0x6, %esi
callq 0x5fb0
jmp 0x6ad8
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x68c8
movq -0x10(%rbp), %rdi
callq 0x63f0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0x4140
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rdi
movl -0x44(%rbp), %esi
movl $0x1, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x5a50
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rax
addq %rax, %rdi
movl -0x4c(%rbp), %edx
movq -0x20(%rbp), %rcx
movl $0x6, %esi
callq 0x5fb0
jmp 0x6ad8
movq -0x38(%rbp), %rdi
callq 0x61a0
jmp 0x6ad8
movq -0x38(%rbp), %rdi
callq 0x50d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x5750
movq -0x40(%rbp), %rdi
callq 0x57d0
movq 0x5d665(%rip), %rax     # 0x63fc0
movq (%rax), %rsi
leaq 0x461ee(%rip), %rdi     # 0x4cb53
callq 0x40a0
movl $0x0, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
movslq -0x48(%rbp), %rax
cmpq $0x50, %rax
jae 0x6a12
movl $0x0, 0x5e7b4(%rip)     # 0x65144
movl $0x0, 0x5e7ae(%rip)     # 0x65148
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x48(%rbp), %esi
callq 0x5190
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rdi
movl -0x44(%rbp), %esi
movl -0x48(%rbp), %ecx
movl $0x1, %edx
callq 0x5a50
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x6a02
cmpl $0x0, -0x4c(%rbp)
je 0x6a02
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rax
addq %rax, %rdi
movl -0x4c(%rbp), %edx
movq -0x20(%rbp), %rcx
movl $0x6, %esi
callq 0x5fb0
movq 0x5d5cd(%rip), %rax     # 0x63fc0
movq (%rax), %rsi
leaq 0x4617f(%rip), %rdi     # 0x4cb7c
callq 0x40a0
jmp 0x6a04
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6978
movq 0x5d5a7(%rip), %rax     # 0x63fc0
movq (%rax), %rsi
leaq 0x46147(%rip), %rdi     # 0x4cb6a
callq 0x40a0
movl $0x0, -0x50(%rbp)
movl $0x1, -0x48(%rbp)
movslq -0x48(%rbp), %rax
cmpq $0x22, %rax
jae 0x6acd
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x48(%rbp), %esi
callq 0x5190
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rdi
movl -0x44(%rbp), %esi
movl -0x48(%rbp), %ecx
movl $0x2, %edx
callq 0x5a50
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x6abd
cmpl $0x0, -0x4c(%rbp)
je 0x6abd
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rax
addq %rax, %rdi
movl -0x4c(%rbp), %edx
movl $0x4, %esi
callq 0x5c20
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rax
addq %rax, %rdi
movl -0x48(%rbp), %edx
xorl %esi, %esi
callq 0x5e10
movq 0x5d512(%rip), %rax     # 0x63fc0
movq (%rax), %rsi
leaq 0x460c4(%rip), %rdi     # 0x4cb7c
callq 0x40a0
jmp 0x6abf
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6a36
jmp 0x6ad8
movq -0x10(%rbp), %rdi
callq 0x63f0
jmp 0x6ada
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
jmp 0x662d
movl -0x2c(%rbp), %edi
callq 0x40c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)