// File: /workspace/github_c_makefile_star2_O2/Nico01[P]obj2asm/omain.c
// Function: main
int main(int argc, char *argv[])
{
    char            *argp;
    int             name_arg;
    int             argi;
    int             bad_args;
    char            *fnamep;
    dword   position;
    int             at_eof;
    int             rec_type;
    word    rec_length;
    char            temp_name[50];
    char            ch;
    int             i486;

    bad_args = FALSE;
    argi = 1;
    name_arg = 0;
    i486 = FALSE;

    while ( argi < argc ) {
        argp = argv[argi];
        if ( *argp++ == '-' ) {
            while ( *argp ) {
                switch ( *argp ) {
                    case 'a':
                        add_labels = TRUE;
                        break;
                    case '4':
                        compatibility = 1;
                        break;
                    case 'h':
                        hex_output = TRUE;
                        break;
                    case 'v':
                        i486 = TRUE;
                        break;
                    case 'c':
                        code_string = atoi(argp+1);
                        while ( (ch = *(argp+1)) != '\0' ) {
                            if ( ch < '0' || ch > '9' ) {
                                break;
                            }
                            argp++;
                        }
                        break;
                    case 's':
                        code_string = atoi(argp+1);
                        while ( (ch = *(argp+1)) != '\0' ) {
                            if ( ch < '0' || ch > '9' ) {
                                break;
                            }
                            argp++;
                        }
                        break;
                    case 'f':
                        argp++;
                        if ( *argp != '(' ) {
                            bad_args = TRUE;
                            break;
                        }
                        fnamep = extra_filename;
                        while ( (ch = *(argp+1)) != '\0' ) {
                            argp++;
                            if ( ch == ')' ) {
                                *fnamep = '\0';
                                break;
                            }
                            *fnamep++ = ch;
                        }
                        if ( ch == '\0' ) {
                            bad_args = TRUE;
                        }
                        break;
                    default:
                        bad_args = TRUE;
                        break;
                }
                argp++;
            }
        } else {
            if ( name_arg == 0 ) {
                name_arg = argi;
            } else {
                bad_args = TRUE;
            }
        }
        argi++;
    }

    if ( name_arg == 0 ) {
        bad_args = TRUE;
    }

    if ( bad_args ) {
        fprintf( stderr, "Usage:  %s [-options] [objfilename]\n", argv[0] );
        fprintf( stderr, "where -options are:\n" );
        fprintf( stderr, "           -4 Make MASM 4.0 compatible (no RETF)\n" );
        fprintf( stderr, "           -a Add labels for un-named data references\n");
        fprintf( stderr, "           -h Hex output in comments\n");
        fprintf( stderr, "           -v Include 486 instructions\n" );
        fprintf( stderr, "          -c# Minimum string size in a code segment (default=40)\n");
        fprintf( stderr, "          -s# Mimimum string size in a data segment (default=3)\n");
        fprintf( stderr, " -f(filename) Additional information filename (w/paren.)\n");
        fprintf( stderr, "\n" );
        fprintf( stderr, "Additional information file lines:\n");
        fprintf( stderr, "SEG sname CODE                named segment is a code segment\n");
        fprintf( stderr, "SEG sname DATA                named segment is a data segment\n");
        fprintf( stderr, "var=sname:####                creates a local label in segment name\n");
        fprintf( stderr, "sname:####:DB/DW/DD/DF/DQ/DT  directs dis-assembly into data\n");
        fprintf( stderr, "... (for more info, read OBJASM.DOC)\n");
        exit(1);
    }

    switch( compatibility ) {
        case 0:             /* MASM 5.0+ */
            if ( i486 ) {
                ex_instr[0x08].text = "invd";
                ex_instr[0x09].text = "wbinvd";
                op_grp[6][7] = "invlpg";
                ex_instr[0xA6].text = "cmpxchg";
                ex_instr[0xA7].text = "cmpxchg";
                ex_instr[0xC0].text = "xadd";
                ex_instr[0xC1].text = "xadd";
                ex_instr[0xC8].text = "bswap";
                ex_instr[0xC9].text = "bswap";
                ex_instr[0xCA].text = "bswap";
                ex_instr[0xCB].text = "bswap";
                ex_instr[0xCC].text = "bswap";
                ex_instr[0xCD].text = "bswap";
                ex_instr[0xCE].text = "bswap";
                ex_instr[0xCF].text = "bswap";

            }
            break;
        case 1:             /* MASM 4.0  */
            /*
            ** Make far return only a comment
            */
            instr[0xCB].text = "ret\t; (retf)";
            break;
    }

    strcpy( temp_name, argv[name_arg] );
    if ( strchr(temp_name,'.') == NULL ) {  /* Append ".obj" if no extension */
        strcat( temp_name, ".obj" );        /* is supplied                   */
    }

    o_file = fopen( temp_name, "rb" );
    if ( o_file == NULL ) {
        fprintf( stderr, "%s: Cannot open %s\n", argv[0], temp_name );
        exit(2);
    }

    /* Print copyright message */
    printf("; OBJASM version 2.0 released on Jan 3, 1991\n");
    printf("; (C) Copyright 1988,1989,1990,1991 by Robert F. Day.  All rights reserved\n\n");

    init_trees();                   /* Initialize all trees */

    at_eof = FALSE;
    position = 0;

    while ( !at_eof ) {
        fseek( o_file, position, L_SET );

        rec_type = fgetc( o_file );

        if ( rec_type == EOF ) {
            at_eof = TRUE;
        } else {
            //size_t rec_length = getw( o_file );
            fread(&rec_length, 1, 2, o_file);

            o_position = position + 3;      /* (1 rec_type) + (2 rec_length) */

#ifdef DEBUG
            printf("PROCESSING rec_type [%02X] rec_length [%04X]\n",
                                                    rec_type, rec_length );
#endif

            switch( rec_type ) {
              case THEADR:  theadr();                       break;
              case LNAMES:  lnames( rec_length );           break;
              case GRPDEF:  grpdef( rec_length );           break;
              case SEGDEF:  segdef();                       break;
              case SEGDEFL: segdef();                       break;
              case PUBDEF:  pubdef( rec_length, TRUE );     break;
              case PUBDEFL: pubdef( rec_length, TRUE );     break;
              case LPUBDEF: pubdef( rec_length, FALSE );    break;
              case LPUBDF2: pubdef( rec_length, FALSE );    break;
              case EXTDEF:  extdef( rec_length, TRUE );     break;
              case LEXTDEF: extdef( rec_length, FALSE );    break;
              case LEDATA:  ledata( rec_length, REGULAR );  break;
              case LEDATAL: ledata( rec_length, LARGER );   break;
              case LIDATA:  lidata( rec_length, REGULAR );  break;
              case LIDATAL: lidata( rec_length, LARGER );   break;
              case FIXUPP:  fixupp( rec_length, REGULAR );  break;
              case FIXUPPL: fixupp( rec_length, LARGER );   break;
              case COMDEF:  comdef( rec_length, TRUE );     break;
              case LCOMDEF: comdef( rec_length, FALSE );    break;
              case MODEND:  modend( rec_length, REGULAR );
                            at_eof = TRUE;                  break;
              case MODENDL: modend( rec_length, LARGER );
                            at_eof = TRUE;                  break;
              case TYPDEF:                                  break;
              case COMENT:  printf("; [%04X]",position);
                            coment( rec_length );           break;
              case LINNUM:  linnum( rec_length );           break;
              default:  printf( "Bad record type: [%08lX:%02X:%04X]\n",
                                position, rec_type, rec_length          );
                        break;
            }
            position += 3 + rec_length;
        }
    }

#ifdef DEBUG
    printf("PROCESSING dis-assembly, pass 1\n");
#endif

    if ( strlen(extra_filename) != 0 ) {
        load_extra( argv[0], extra_filename );
    }

    pass = 1;
    process();                      /* First pass: Processing */

    pass = 2;
    process();                      /* Second pass: Figure out labels */

#ifdef DEBUG
    printf("PROCESSING listing externals\n");
#endif

    list_ext();                     /* Show EXTERNAL's */

#ifdef DEBUG
    printf("PROCESSING listing publics and communal definitions\n");
#endif

    list_pub();                     /* Show PUBLIC's */

    list_struc();                   /* Show STRUC's */

#ifdef DEBUG
    printf("PROCESSING dis-assembly, pass 2 (last)\n");
#endif

    pass = 3;
    process();                      /* Third pass: Output */

    fclose( o_file );

#ifdef DEBUG
    printf("END OF RUN\n");
#endif

    return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r15
movslq %edi, %rdi
xorl %esi, %esi
pushq $0x1
popq %r8
pushq $0x1
popq %r12
leaq 0x6adf(%rip), %r13      # 0x12818
leaq 0x101d0(%rip), %rbx     # 0x1bf10
xorl %ecx, %ecx
xorl %edx, %edx
movq %r15, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
cmpq %rdi, %r8
jge 0xbe9e
movq (%r15,%r8,8), %rax
cmpb $0x2d, (%rax)
jne 0xbe72
movq %r8, 0x18(%rsp)
movl %esi, 0x4(%rsp)
movl %edx, %r14d
movq %rax, %r15
movl %ecx, %ebp
incq %rax
movzbl 0x1(%r15), %esi
leal -0x61(%rsi), %ecx
cmpl $0x7, %ecx
ja 0xbd9e
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
movl $0x1, 0x10163(%rip)     # 0x1befc
jmp 0xbe68
cmpl $0x34, %esi
je 0xbe4e
cmpl $0x73, %esi
je 0xbe25
movl %ebp, %ecx
movl %r12d, %edx
cmpl $0x76, %esi
je 0xbd6d
testl %esi, %esi
je 0xbe7e
movl %r12d, %ecx
movl %r14d, %edx
jmp 0xbd6d
leaq 0x2(%r15), %rdi
callq 0x9190
movl %eax, 0xcd2f(%rip)      # 0x18b04
movb 0x2(%r15), %al
addb $-0x3a, %al
incq %r15
cmpb $-0xa, %al
jae 0xbdd5
jmp 0xbe41
movl $0x1, 0x10112(%rip)     # 0x1bf00
jmp 0xbe68
leaq 0x2(%r15), %rax
cmpb $0x28, 0x2(%r15)
movl %r12d, %ecx
movl %r14d, %edx
jne 0xbd6d
addq $0x3, %r15
movq %r15, %rax
movq %rbx, %rcx
movzbl (%rax), %edx
testl %edx, %edx
je 0xbe5f
cmpl $0x29, %edx
je 0xbe5a
movb %dl, (%rcx)
incq %rcx
incq %rax
jmp 0xbe0f
leaq 0x2(%r15), %rdi
callq 0x9190
movl %eax, 0xccd0(%rip)      # 0x18b04
movb 0x2(%r15), %al
addb $-0x3a, %al
incq %r15
cmpb $-0xa, %al
jae 0xbe34
movl %ebp, %ecx
movq %r15, %rax
movl %r14d, %edx
jmp 0xbd6d
movl $0x1, 0x100a0(%rip)     # 0x1bef8
jmp 0xbe68
movb $0x0, (%rcx)
jmp 0xbe62
decq %rax
testb %dl, %dl
cmovel %r12d, %ebp
movl %ebp, %ecx
movl %r14d, %edx
jmp 0xbd6d
testl %esi, %esi
cmovel %r8d, %esi
cmovnel %r12d, %ecx
jmp 0xbe96
movl %r14d, %edx
movl %ebp, %ecx
movq 0x10(%rsp), %r15
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %r8
incq %r8
jmp 0xbd4e
testl %esi, %esi
je 0xc212
testl %ecx, %ecx
jne 0xc212
movl 0x10044(%rip), %eax     # 0x1bef8
cmpl $0x1, %eax
je 0xbf70
testl %eax, %eax
jne 0xbf85
testl %edx, %edx
je 0xbf85
leaq 0x6c5f(%rip), %rax      # 0x12b33
leaq 0xe685(%rip), %rcx      # 0x1a560
movq %rax, 0xd0(%rcx)
leaq 0x6c48(%rip), %rax      # 0x12b31
movq %rax, 0xe8(%rcx)
leaq 0x6c41(%rip), %rax      # 0x12b38
leaq 0xc4d2(%rip), %rdx      # 0x183d0
movq %rax, 0x1b8(%rdx)
leaq 0x6c33(%rip), %rax      # 0x12b3f
movq %rax, 0xfa0(%rcx)
movq %rax, 0xfb8(%rcx)
leaq 0x6c26(%rip), %rax      # 0x12b47
movq %rax, 0x1210(%rcx)
movq %rax, 0x1228(%rcx)
leaq 0x6c16(%rip), %rax      # 0x12b4c
movq %rax, 0x12d0(%rcx)
movq %rax, 0x12e8(%rcx)
movq %rax, 0x1300(%rcx)
movq %rax, 0x1318(%rcx)
movq %rax, 0x1330(%rcx)
movq %rax, 0x1348(%rcx)
movq %rax, 0x1360(%rcx)
movq %rax, 0x1378(%rcx)
jmp 0xbf85
leaq 0x6bdb(%rip), %rax      # 0x12b52
leaq 0xcbe2(%rip), %rcx      # 0x18b60
movq %rax, 0x1318(%rcx)
movslq %esi, %rax
movq (%r15,%rax,8), %rsi
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x9070
pushq $0x2e
popq %rsi
movq %r14, %rdi
callq 0x90c0
testq %rax, %rax
jne 0xbfc0
leaq 0x20(%rsp), %rdi
callq 0x90b0
movl $0x6a626f2e, 0x20(%rsp,%rax) # imm = 0x6A626F2E
movb $0x0, 0x24(%rsp,%rax)
leaq 0x6b9d(%rip), %rsi      # 0x12b64
leaq 0x20(%rsp), %rdi
callq 0x9180
movq %rax, 0xff80(%rip)      # 0x1bf58
testq %rax, %rax
je 0xc37d
movq %r15, %rbx
leaq 0x6ba9(%rip), %rdi      # 0x12b94
callq 0x9080
leaq 0x6bca(%rip), %rdi      # 0x12bc1
callq 0x9080
callq 0x119ce
xorl %r14d, %r14d
pushq $0x2
popq %r13
leaq 0x6725(%rip), %r12      # 0x12734
xorl %ebp, %ebp
testl %ebp, %ebp
jne 0xc1a1
movq 0xff38(%rip), %rdi      # 0x1bf58
movq %r14, %rsi
xorl %edx, %edx
callq 0x9160
movq 0xff27(%rip), %rdi      # 0x1bf58
callq 0x90e0
cmpl $-0x1, %eax
je 0xc1a1
movl %eax, %r15d
movq 0xff0f(%rip), %rcx      # 0x1bf58
movq %rsp, %rdi
pushq $0x1
popq %rsi
movq %r13, %rdx
callq 0x9090
leaq 0x3(%r14), %rax
movq %rax, 0xfefe(%rip)      # 0x1bf60
leal -0x80(%r15), %eax
cmpl $0x38, %eax
ja 0xc17a
xorl %ebp, %ebp
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl (%rsp), %edi
pushq $0x1
popq %rsi
jmp 0xc089
movl (%rsp), %edi
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x1144d
jmp 0xc193
callq 0x115ac
jmp 0xc193
movl (%rsp), %edi
pushq $0x1
popq %rsi
jmp 0xc158
movl (%rsp), %edi
xorl %ebp, %ebp
xorl %esi, %esi
jmp 0xc10f
movl (%rsp), %edi
xorl %ebp, %ebp
xorl %esi, %esi
jmp 0xc0ed
movl (%rsp), %edi
callq 0x10d48
jmp 0xc193
leaq 0x6a99(%rip), %rdi      # 0x12b67
xorl %ebp, %ebp
movq %r14, %rsi
xorl %eax, %eax
callq 0x90d0
movl (%rsp), %edi
callq 0xfda6
jmp 0xc193
movl (%rsp), %edi
pushq $0x1
popq %rsi
callq 0xfcc3
jmp 0xc193
movl (%rsp), %edi
pushq $0x1
popq %rsi
jmp 0xc173
callq 0x1195c
jmp 0xc193
movl (%rsp), %edi
pushq $0x1
popq %rsi
callq 0x10c36
jmp 0xc193
movl (%rsp), %edi
xorl %esi, %esi
callq 0x11388
pushq $0x1
popq %rbp
jmp 0xc193
movl (%rsp), %edi
xorl %ebp, %ebp
xorl %esi, %esi
jmp 0xc165
movl (%rsp), %edi
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0x11388
jmp 0xc193
movl (%rsp), %edi
callq 0x1134f
jmp 0xc193
movl (%rsp), %edi
callq 0x11222
jmp 0xc193
movl (%rsp), %edi
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x1114c
jmp 0xc193
movl (%rsp), %edi
pushq $0x1
popq %rsi
callq 0x11093
jmp 0xc193
movl (%rsp), %edi
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x10985
jmp 0xc193
movl (%rsp), %ecx
xorl %ebp, %ebp
leaq 0x69ea(%rip), %rdi      # 0x12b70
movq %r14, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x90d0
movl (%rsp), %eax
addl $0x3, %eax
addq %rax, %r14
jmp 0xc011
cmpb $0x0, 0xfd68(%rip)      # 0x1bf10
je 0xc1b9
movq (%rbx), %rdi
leaq 0xfd5c(%rip), %rsi      # 0x1bf10
callq 0xb820
movl $0x1, 0xfda5(%rip)      # 0x1bf68
callq 0xe22c
movl $0x2, 0xfd96(%rip)      # 0x1bf68
callq 0xe22c
callq 0xe5f0
callq 0xe6e1
callq 0xe7a8
movl $0x3, 0xfd78(%rip)      # 0x1bf68
callq 0xe22c
movq 0xfd5c(%rip), %rdi      # 0x1bf58
callq 0x90a0
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbddf(%rip), %r12      # 0x17ff8
movq (%r12), %rdi
movq (%r15), %rdx
leaq 0x6611(%rip), %rsi      # 0x12838
xorl %eax, %eax
callq 0x9140
movq (%r12), %rcx
leaq 0x6624(%rip), %rdi      # 0x1285d
pushq $0x14
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x6620(%rip), %rdi      # 0x12872
pushq $0x31
popq %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x663c(%rip), %rdi      # 0x128a4
pushq $0x36
popq %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x665d(%rip), %rdi      # 0x128db
pushq $0x25
popq %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x6669(%rip), %rdi      # 0x12901
pushq $0x27
popq %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x667b(%rip), %rdi      # 0x12929
pushq $0x41
popq %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x66a7(%rip), %rdi      # 0x1296b
pushq $0x40
popq %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x66d2(%rip), %rdi      # 0x129ac
pushq $0x39
popq %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rsi
pushq $0xa
popq %rdi
callq 0x90f0
movq (%r12), %rcx
leaq 0x66ea(%rip), %rdi      # 0x129e6
pushq $0x23
popq %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x66f8(%rip), %rdi      # 0x12a0a
pushq $0x3e
popq %r15
movq %r15, %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x671d(%rip), %rdi      # 0x12a49
movq %r15, %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x6746(%rip), %rdi      # 0x12a88
pushq $0x44
popq %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x6775(%rip), %rdi      # 0x12acd
pushq $0x3d
popq %rsi
movq %rbx, %rdx
callq 0x91d0
movq (%r12), %rcx
leaq 0x679d(%rip), %rdi      # 0x12b0b
movq %r14, %rsi
movq %rbx, %rdx
callq 0x91d0
pushq $0x1
jmp 0xc39f
movq 0xbc74(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
movq (%r15), %rdx
leaq 0x61d0(%rip), %rsi      # 0x12561
leaq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x9140
pushq $0x2
popq %rdi
callq 0x91c0
nopl (%rax)