// File: /workspace/github_c_makefile_star2_O1/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
cmpl $0x2, %edi
movq %rsi, 0x8(%rsp)
jl 0xc4e4
movl %edi, %r8d
xorl %edx, %edx
movl $0x1, %r15d
leaq 0x73c2(%rip), %r12      # 0x13734
movl $0x1, %ebx
xorl %ecx, %ecx
xorl %edi, %edi
movq %r8, 0x18(%rsp)
movq (%rsi,%r15,8), %rax
cmpb $0x2d, (%rax)
jne 0xc4ae
movl %edi, 0x14(%rsp)
movl %edx, %r14d
movq %rax, %r13
movl %ecx, %ebp
incq %rax
movzbl 0x1(%r13), %esi
cmpl $0x72, %esi
jg 0xc3c6
leal -0x61(%rsi), %ecx
cmpl $0x7, %ecx
ja 0xc3e0
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movl $0x1, 0x10b3b(%rip)     # 0x1cefc
jmp 0xc4a4
cmpl $0x73, %esi
je 0xc45d
movl $0x1, %edx
movl %ebp, %ecx
cmpl $0x76, %esi
je 0xc391
jmp 0xc48a
cmpl $0x34, %esi
jne 0xc486
movl $0x1, 0x10b05(%rip)     # 0x1cef8
jmp 0xc4a4
leaq 0x2(%r13), %rdi
callq 0x9190
movl %eax, 0xd6fd(%rip)      # 0x19b04
movb 0x2(%r13), %al
addb $-0x3a, %al
incq %r13
cmpb $-0xa, %al
jae 0xc407
jmp 0xc479
leaq 0x2(%r13), %rax
movl $0x1, %ecx
cmpb $0x28, 0x2(%r13)
movl %r14d, %edx
jne 0xc391
addq $0x3, %r13
movq %r13, %rax
leaq 0x10ad5(%rip), %rcx     # 0x1cf10
movzbl (%rax), %edx
testl %edx, %edx
je 0xc49c
cmpl $0x29, %edx
je 0xc497
movb %dl, (%rcx)
incq %rcx
incq %rax
jmp 0xc43b
movl $0x1, 0x10aa5(%rip)     # 0x1cf00
jmp 0xc4a4
leaq 0x2(%r13), %rdi
callq 0x9190
movl %eax, 0xd698(%rip)      # 0x19b04
movb 0x2(%r13), %al
addb $-0x3a, %al
incq %r13
cmpb $-0xa, %al
jae 0xc46c
movl %ebp, %ecx
movq %r13, %rax
movl %r14d, %edx
jmp 0xc391
testl %esi, %esi
je 0xc4b9
movl $0x1, %ecx
movl %r14d, %edx
jmp 0xc391
movb $0x0, (%rcx)
jmp 0xc49f
decq %rax
testb %dl, %dl
cmovel %ebx, %ebp
movl %ebp, %ecx
movl %r14d, %edx
jmp 0xc391
testl %edi, %edi
cmovel %r15d, %edi
cmovnel %ebx, %ecx
jmp 0xc4cc
movl %ebp, %ecx
movl %r14d, %edx
movq 0x8(%rsp), %rsi
movl 0x14(%rsp), %edi
movq 0x18(%rsp), %r8
incq %r15
cmpq %r8, %r15
jne 0xc380
testl %ecx, %ecx
sete %cl
testl %edx, %edx
sete %al
jmp 0xc4ea
movb $0x1, %cl
xorl %edi, %edi
movb $0x1, %al
testl %edi, %edi
je 0xc88d
testb %cl, %cl
je 0xc88d
movl 0x109f8(%rip), %ecx     # 0x1cef8
cmpl $0x1, %ecx
je 0xc5bc
testl %ecx, %ecx
jne 0xc5d1
testb %al, %al
jne 0xc5d1
leaq 0x7613(%rip), %rax      # 0x13b33
leaq 0xf039(%rip), %rcx      # 0x1b560
movq %rax, 0xd0(%rcx)
leaq 0x75fc(%rip), %rax      # 0x13b31
movq %rax, 0xe8(%rcx)
leaq 0x75f5(%rip), %rax      # 0x13b38
leaq 0xce86(%rip), %rdx      # 0x193d0
movq %rax, 0x1b8(%rdx)
leaq 0x75e7(%rip), %rax      # 0x13b3f
movq %rax, 0xfa0(%rcx)
movq %rax, 0xfb8(%rcx)
leaq 0x75da(%rip), %rax      # 0x13b47
movq %rax, 0x1210(%rcx)
movq %rax, 0x1228(%rcx)
leaq 0x75ca(%rip), %rax      # 0x13b4c
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 0xc5d1
leaq 0x758f(%rip), %rax      # 0x13b52
leaq 0xd596(%rip), %rcx      # 0x19b60
movq %rax, 0x1318(%rcx)
movslq %edi, %rax
movq (%rsi,%rax,8), %rsi
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x9070
movq %r14, %rdi
movl $0x2e, %esi
callq 0x90c0
testq %rax, %rax
jne 0xc60e
leaq 0x20(%rsp), %rdi
callq 0x90b0
movl $0x6a626f2e, 0x20(%rsp,%rax) # imm = 0x6A626F2E
movb $0x0, 0x24(%rsp,%rax)
leaq 0x754f(%rip), %rsi      # 0x13b64
leaq 0x20(%rsp), %rdi
callq 0x9180
movq %rax, 0x10932(%rip)     # 0x1cf58
testq %rax, %rax
je 0xc895
leaq 0x755e(%rip), %rdi      # 0x13b94
callq 0x9080
leaq 0x757f(%rip), %rdi      # 0x13bc1
callq 0x9080
callq 0x12173
leaq 0x4(%rsp), %r14
leaq 0x7518(%rip), %rbx      # 0x13b70
leaq 0x70f5(%rip), %rbp      # 0x13754
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x108ec(%rip), %rdi     # 0x1cf58
movq %r12, %rsi
xorl %edx, %edx
callq 0x9160
movq 0x108db(%rip), %rdi     # 0x1cf58
callq 0x90e0
cmpl $-0x1, %eax
je 0xc6d1
movl %eax, %r13d
movq 0x108c7(%rip), %rcx     # 0x1cf58
movl $0x1, %esi
movl $0x2, %edx
movq %r14, %rdi
callq 0x9090
leaq 0x3(%r12), %rax
movq %rax, 0x108b1(%rip)     # 0x1cf60
leal -0x80(%r13), %eax
cmpl $0x38, %eax
ja 0xc7f0
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
movl 0x4(%rsp), %edi
movl $0x1, %esi
jmp 0xc6e2
movl $0x1, %r15d
jmp 0xc80e
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x11bfc
jmp 0xc804
callq 0x11d53
jmp 0xc804
movl 0x4(%rsp), %edi
movl $0x1, %esi
jmp 0xc7cc
movl 0x4(%rsp), %edi
xorl %esi, %esi
jmp 0xc775
movl 0x4(%rsp), %edi
xorl %esi, %esi
jmp 0xc74a
movl 0x4(%rsp), %edi
callq 0x114d6
jmp 0xc804
leaq 0x743e(%rip), %rdi      # 0x13b67
movq %r12, %rsi
xorl %eax, %eax
callq 0x90d0
movl 0x4(%rsp), %edi
callq 0x104d2
jmp 0xc804
movl 0x4(%rsp), %edi
movl $0x1, %esi
callq 0x103f6
jmp 0xc804
movl 0x4(%rsp), %edi
movl $0x1, %esi
jmp 0xc7e9
callq 0x120fc
jmp 0xc804
movl 0x4(%rsp), %edi
movl $0x1, %esi
callq 0x113c0
jmp 0xc804
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x11b1c
movl $0x1, %r15d
jmp 0xc804
movl 0x4(%rsp), %edi
xorl %esi, %esi
jmp 0xc7dc
movl 0x4(%rsp), %edi
movl $0x1, %r15d
movl $0x1, %esi
callq 0x11b1c
jmp 0xc804
movl 0x4(%rsp), %edi
callq 0x11ae1
jmp 0xc804
movl 0x4(%rsp), %edi
callq 0x119ae
jmp 0xc804
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x118cc
jmp 0xc804
movl 0x4(%rsp), %edi
movl $0x1, %esi
callq 0x117c7
jmp 0xc804
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x1110e
jmp 0xc804
movl 0x4(%rsp), %ecx
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x90d0
movl 0x4(%rsp), %eax
addl $0x3, %eax
addq %rax, %r12
testl %r15d, %r15d
je 0xc665
cmpb $0x0, 0x106f2(%rip)     # 0x1cf10
je 0xc834
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x106e1(%rip), %rsi     # 0x1cf10
callq 0xbced
movl $0x1, 0x1072a(%rip)     # 0x1cf68
callq 0xe8e1
movl $0x2, 0x1071b(%rip)     # 0x1cf68
callq 0xe8e1
callq 0xecd7
callq 0xedd3
callq 0xeea5
movl $0x3, 0x106fd(%rip)     # 0x1cf68
callq 0xe8e1
movq 0x106e1(%rip), %rdi     # 0x1cf58
callq 0x90a0
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %rdi
callq 0x9237
leaq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x93b1