// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movq 0x365ae(%rip), %rax     # 0x3bff0
movl $0x0, (%rax)
leaq 0x1cfe2(%rip), %r12     # 0x22a31
leaq 0x1cfe2(%rip), %r15     # 0x22a38
movq 0x36573(%rip), %r14     # 0x3bfd0
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x41c0
cmpl $0x6e, %eax
jle 0x5a8e
cmpl $0x72, %eax
je 0x5a9c
cmpl $0x6f, %eax
jne 0x5fa1
movq (%r14), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x4160
jmp 0x5a5d
cmpl $0x41, %eax
jne 0x5aa6
movb $0x1, 0x376c2(%rip)     # 0x3d15c
jmp 0x5a5d
movq (%r14), %rdi
callq 0x216ff
jmp 0x5a5d
cmpl $-0x1, %eax
je 0x5ab9
cmpl $0x61, %eax
jne 0x5fa1
movq (%r14), %r12
jmp 0x5a5d
movq 0x36508(%rip), %r14     # 0x3bfc8
movslq (%r14), %rax
movq (%rbx,%rax,8), %rdi
testq %rdi, %rdi
je 0x5fb9
cmpb $0x2d, (%rdi)
je 0x5fb9
xorl %esi, %esi
xorl %eax, %eax
callq 0x4180
cmpl $-0x1, %eax
je 0x5f7b
movl %eax, %ebp
movl $0x1, %edi
movl $0x100000, %esi         # imm = 0x100000
callq 0x4120
testq %rax, %rax
je 0x5f84
movq %rax, %r15
movl $0x100000, %edx         # imm = 0x100000
movl %ebp, %edi
movq %rax, %rsi
callq 0x40f0
testl %eax, %eax
jle 0x5f8d
movl %ebp, 0x1c(%rsp)
movq %r12, 0x10(%rsp)
movslq (%r14), %rcx
movq (%rbx,%rcx,8), %rdx
leaq 0x1cf1a(%rip), %rdi     # 0x22a50
xorl %r12d, %r12d
movl %eax, %esi
xorl %eax, %eax
callq 0x40b0
callq 0x2164d
movslq (%r14), %rcx
movq 0x8(%rbx,%rcx,8), %rax
testq %rax, %rax
je 0x5f60
leaq (%rbx,%rcx,8), %r13
leaq (%rbx,%rcx,8), %r14
addq $0x8, %r14
cmpb $0x0, (%rax)
je 0x5f60
movl %r12d, 0x375e0(%rip)    # 0x3d154
movl %r12d, 0x375dd(%rip)    # 0x3d158
movl %r12d, 0x3757e(%rip)    # 0x3d100
cmpb $0x0, 0x1(%rax)
jne 0x5fa9
movzbl (%rax), %eax
cmpl $0x62, %eax
jle 0x5c1c
leal -0x63(%rax), %ecx
cmpl $0x9, %ecx
ja 0x5c41
leaq 0x1c465(%rip), %rdx     # 0x22010
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x10(%r13), %rdi
testq %rdi, %rdi
je 0x5fd1
addq $0x10, %r13
xorl %esi, %esi
movl $0x10, %edx
callq 0x4160
movq %rax, %r14
movq %r15, %rdi
callq 0x4d1b
movq 0x3755d(%rip), %rdi     # 0x3d140
movl %r14d, %esi
callq 0x4d89
movl %eax, %ebp
movq %r15, %rdi
movl %eax, %esi
movl $0x1, %edx
movl %r14d, %ecx
callq 0x5380
testl %ebp, %ebp
setne %cl
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x5dd0
movslq %ebp, %rdi
jmp 0x5dbc
cmpl $0x43, %eax
je 0x5d84
cmpl $0x46, %eax
je 0x5dd8
cmpl $0x54, %eax
jne 0x5fc1
callq 0x58d1
jmp 0x5f4c
cmpl $0x78, %eax
jne 0x5fc1
movq 0x10(%r13), %rdi
testq %rdi, %rdi
je 0x5fb1
cmpq $0x0, 0x18(%r13)
je 0x5fb1
addq $0x18, %r13
xorl %esi, %esi
movl $0x10, %edx
callq 0x4160
movq %rax, %r14
movq (%r13), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x4160
leal (%rax,%r14), %edx
movq %r15, %rdi
movl %r14d, %esi
callq 0x54ed
jmp 0x5dd0
movq 0x10(%r13), %rdi
testq %rdi, %rdi
je 0x5fc9
addq $0x10, %r13
xorl %esi, %esi
movl $0x10, %edx
callq 0x4160
movq %rax, %rbp
movq %r15, %rdi
callq 0x4d1b
movq 0x37480(%rip), %rdi     # 0x3d148
movl %ebp, %esi
callq 0x4d89
movl %eax, %r14d
movq %r15, %rdi
movl %eax, %esi
movl $0x2, %edx
movl %ebp, %ecx
callq 0x5380
testl %r14d, %r14d
setne %cl
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x5dd0
movslq %r14d, %r14
addq %r15, %r14
movq %r14, %rdi
movl $0x4, %esi
movl %eax, %edx
callq 0x54ed
movq %r14, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x562e
jmp 0x5dd0
movq %r15, %rdi
callq 0x4d1b
leaq 0x37402(%rip), %rdi     # 0x3d130
callq 0x51ad
jmp 0x5f4c
movq %r15, %rdi
callq 0x4d1b
movq 0x36279(%rip), %rax     # 0x3bfc0
movq (%rax), %rdi
movq 0x373e7(%rip), %rax     # 0x3d138
movzbl 0x2(%rax), %edx
movzbl 0x3(%rax), %ecx
movzwl 0x10(%rax), %r8d
addq 0x373cb(%rip), %r8      # 0x3d130
movzwl 0x18(%rax), %r9d
movzwl 0x1a(%rax), %eax
movl %eax, (%rsp)
leaq 0x1c64a(%rip), %rsi     # 0x223c2
xorl %eax, %eax
callq 0x4150
jmp 0x5f4c
movq 0x10(%r13), %rdi
testq %rdi, %rdi
je 0x5fd9
addq $0x10, %r13
xorl %esi, %esi
movl $0x10, %edx
callq 0x4160
movq %rax, %r14
movq %r15, %rdi
movl %r14d, %esi
movl $0x1, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x5380
movslq %r14d, %rdi
addq %r15, %rdi
movl $0x6, %esi
movl %eax, %edx
movq 0x10(%rsp), %rcx
callq 0x5759
movq %r13, %r14
jmp 0x5f4c
movq %r14, 0x20(%rsp)
movq %r15, %rdi
callq 0x4d1b
movq 0x361d4(%rip), %r14     # 0x3bfc0
movq (%r14), %rdi
movq 0x37342(%rip), %rax     # 0x3d138
movzbl 0x2(%rax), %edx
movzbl 0x3(%rax), %ecx
movzwl 0x10(%rax), %r8d
addq 0x37326(%rip), %r8      # 0x3d130
movzwl 0x18(%rax), %r9d
movzwl 0x1a(%rax), %eax
movl %eax, (%rsp)
xorl %ebp, %ebp
leaq 0x1c5a3(%rip), %rsi     # 0x223c2
xorl %eax, %eax
callq 0x4150
leaq 0x37303(%rip), %rdi     # 0x3d130
callq 0x51ad
movq (%r14), %rsi
leaq 0x1cc34(%rip), %rdi     # 0x22a70
callq 0x40c0
movq 0x10(%rsp), %r13
movl %r12d, 0x37307(%rip)    # 0x3d154
movl %r12d, 0x37304(%rip)    # 0x3d158
movq 0x372e5(%rip), %rdi     # 0x3d140
movl %ebp, %esi
callq 0x4d89
movl %eax, %r14d
movq %r15, %rdi
movl %eax, %esi
movl $0x1, %edx
movl %ebp, %ecx
callq 0x5380
testl %r14d, %r14d
setne %cl
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x5eb3
movslq %r14d, %rdi
addq %r15, %rdi
movl $0x6, %esi
movl %eax, %edx
movq %r13, %rcx
callq 0x5759
movq 0x3611c(%rip), %rax     # 0x3bfc0
movq (%rax), %rsi
leaq 0x1cbeb(%rip), %rdi     # 0x22a99
callq 0x40c0
incl %ebp
cmpl $0x50, %ebp
jne 0x5e46
movq 0x360ff(%rip), %rax     # 0x3bfc0
movq (%rax), %rsi
leaq 0x1cbbc(%rip), %rdi     # 0x22a87
callq 0x40c0
movl $0x1, %ebp
movq 0x3726c(%rip), %rdi     # 0x3d148
movl %ebp, %esi
callq 0x4d89
movl %eax, %r14d
movq %r15, %rdi
movl %eax, %esi
movl $0x2, %edx
movl %ebp, %ecx
callq 0x5380
testl %r14d, %r14d
setne %cl
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x5f40
movslq %r14d, %r14
addq %r15, %r14
movq %r14, %rdi
movl $0x4, %esi
movl %eax, %edx
callq 0x54ed
movq %r14, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x562e
movq 0x3608f(%rip), %rax     # 0x3bfc0
movq (%rax), %rsi
leaq 0x1cb5e(%rip), %rdi     # 0x22a99
callq 0x40c0
incl %ebp
cmpl $0x22, %ebp
jne 0x5ed5
movq 0x20(%rsp), %r14
movq %r14, %r13
addq $0x8, %r14
movq 0x8(%r13), %rax
testq %rax, %rax
jne 0x5b64
movl 0x1c(%rsp), %edi
callq 0x40e0
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq (%r14), %rax
movq (%rbx,%rax,8), %rdi
jmp 0x5f94
leaq 0x1cab5(%rip), %rdi     # 0x22a40
jmp 0x5f94
leaq 0x1cab5(%rip), %rdi     # 0x22a49
callq 0x41a0
movl $0x1, %r12d
jmp 0x5f69
movq %rbx, %rdi
callq 0x4366
movq %rbx, %rdi
callq 0x4255
movq %rbx, %rdi
callq 0x42f1
movq %rbx, %rdi
callq 0x433f
movq %rbx, %rdi
callq 0x4318
movq %rbx, %rdi
callq 0x42ca
movq %rbx, %rdi
callq 0x42a3
movq %rbx, %rdi
callq 0x427c
nopl (%rax)