// File: /workspace/github_c_makefile_star2_O3/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
jl 0xc902
movl %edi, %r8d
xorl %edx, %edx
movl $0x1, %r15d
leaq 0x7337(%rip), %r12      # 0x13734
movl $0x1, %ebx
xorl %ecx, %ecx
xorl %edi, %edi
movq %rsi, 0x8(%rsp)
movq %r8, 0x18(%rsp)
movq (%rsi,%r15,8), %rax
cmpb $0x2d, (%rax)
jne 0xc53e
movl %edi, 0x14(%rsp)
movl %edx, %r14d
movq %rax, %r13
movl %ecx, %ebp
incq %rax
movzbl 0x1(%r13), %esi
cmpl $0x72, %esi
jg 0xc456
leal -0x61(%rsi), %ecx
cmpl $0x7, %ecx
ja 0xc470
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movl $0x1, 0x10aab(%rip)     # 0x1cefc
jmp 0xc534
cmpl $0x73, %esi
je 0xc4ed
movl $0x1, %edx
movl %ebp, %ecx
cmpl $0x76, %esi
je 0xc421
jmp 0xc51a
cmpl $0x34, %esi
jne 0xc516
movl $0x1, 0x10a75(%rip)     # 0x1cef8
jmp 0xc534
leaq 0x2(%r13), %rdi
callq 0x9190
movl %eax, 0xd66d(%rip)      # 0x19b04
movb 0x2(%r13), %al
addb $-0x3a, %al
incq %r13
cmpb $-0xa, %al
jae 0xc497
jmp 0xc509
leaq 0x2(%r13), %rax
movl $0x1, %ecx
cmpb $0x28, 0x2(%r13)
movl %r14d, %edx
jne 0xc421
addq $0x3, %r13
movq %r13, %rax
leaq 0x10a45(%rip), %rcx     # 0x1cf10
movzbl (%rax), %edx
testl %edx, %edx
je 0xc52c
cmpl $0x29, %edx
je 0xc527
movb %dl, (%rcx)
incq %rcx
incq %rax
jmp 0xc4cb
movl $0x1, 0x10a15(%rip)     # 0x1cf00
jmp 0xc534
leaq 0x2(%r13), %rdi
callq 0x9190
movl %eax, 0xd608(%rip)      # 0x19b04
movb 0x2(%r13), %al
addb $-0x3a, %al
incq %r13
cmpb $-0xa, %al
jae 0xc4fc
movl %ebp, %ecx
movq %r13, %rax
movl %r14d, %edx
jmp 0xc421
testl %esi, %esi
je 0xc549
movl $0x1, %ecx
movl %r14d, %edx
jmp 0xc421
movb $0x0, (%rcx)
jmp 0xc52f
decq %rax
testb %dl, %dl
cmovel %ebx, %ebp
movl %ebp, %ecx
movl %r14d, %edx
jmp 0xc421
testl %edi, %edi
cmovel %r15d, %edi
cmovnel %ebx, %ecx
jmp 0xc55c
movl %ebp, %ecx
movl %r14d, %edx
movq 0x8(%rsp), %rsi
movl 0x14(%rsp), %edi
movq 0x18(%rsp), %r8
incq %r15
cmpq %r8, %r15
jne 0xc410
testl %edi, %edi
je 0xc902
testl %ecx, %ecx
jne 0xc902
movl 0x1097a(%rip), %eax     # 0x1cef8
cmpl $0x1, %eax
je 0xc63a
testl %eax, %eax
jne 0xc64f
testl %edx, %edx
je 0xc64f
leaq 0x7595(%rip), %rax      # 0x13b33
leaq 0xefbb(%rip), %rcx      # 0x1b560
movq %rax, 0xd0(%rcx)
leaq 0x757e(%rip), %rax      # 0x13b31
movq %rax, 0xe8(%rcx)
leaq 0x7577(%rip), %rax      # 0x13b38
leaq 0xce08(%rip), %rdx      # 0x193d0
movq %rax, 0x1b8(%rdx)
leaq 0x7569(%rip), %rax      # 0x13b3f
movq %rax, 0xfa0(%rcx)
movq %rax, 0xfb8(%rcx)
leaq 0x755c(%rip), %rax      # 0x13b47
movq %rax, 0x1210(%rcx)
movq %rax, 0x1228(%rcx)
leaq 0x754c(%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 0xc64f
leaq 0x7511(%rip), %rax      # 0x13b52
leaq 0xd518(%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 0xc68c
leaq 0x20(%rsp), %rdi
callq 0x90b0
movl $0x6a626f2e, 0x20(%rsp,%rax) # imm = 0x6A626F2E
movb $0x0, 0x24(%rsp,%rax)
leaq 0x74d1(%rip), %rsi      # 0x13b64
leaq 0x20(%rsp), %rdi
callq 0x9180
movq %rax, 0x108b4(%rip)     # 0x1cf58
testq %rax, %rax
je 0xc90a
leaq 0x74e0(%rip), %rdi      # 0x13b94
callq 0x9080
leaq 0x7501(%rip), %rdi      # 0x13bc1
callq 0x9080
callq 0x12223
movq 0x10887(%rip), %rdi     # 0x1cf58
xorl %esi, %esi
xorl %edx, %edx
callq 0x9160
movq 0x10877(%rip), %rdi     # 0x1cf58
callq 0x90e0
cmpl $-0x1, %eax
je 0xc875
movl %eax, %r13d
leaq 0x4(%rsp), %r14
leaq 0x7472(%rip), %r15      # 0x13b70
leaq 0x704f(%rip), %rbp      # 0x13754
xorl %r12d, %r12d
movq 0x10849(%rip), %rcx     # 0x1cf58
movl $0x1, %esi
movl $0x2, %edx
movq %r14, %rdi
callq 0x9090
leaq 0x3(%r12), %rax
movq %rax, 0x10833(%rip)     # 0x1cf60
leal -0x80(%r13), %eax
cmpl $0x38, %eax
ja 0xc82e
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
movl 0x4(%rsp), %edi
movl $0x1, %esi
jmp 0xc75f
callq 0x11ddf
jmp 0xc842
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x11c88
jmp 0xc842
movl 0x4(%rsp), %edi
xorl %esi, %esi
jmp 0xc7d6
movl 0x4(%rsp), %edi
movl $0x1, %esi
jmp 0xc79b
movl 0x4(%rsp), %edi
movl $0x1, %esi
jmp 0xc827
movl 0x4(%rsp), %edi
movl $0x1, %esi
jmp 0xc7b6
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x11958
jmp 0xc842
movl 0x4(%rsp), %edi
movl $0x1, %esi
jmp 0xc7c6
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x11853
jmp 0xc842
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x11450
jmp 0xc842
movl 0x4(%rsp), %edi
movl $0x1, %esi
callq 0x1119a
jmp 0xc842
leaq 0x7383(%rip), %rdi      # 0x13b67
movq %r12, %rsi
xorl %eax, %eax
callq 0x90d0
movl 0x4(%rsp), %edi
callq 0x1054e
jmp 0xc842
movl 0x4(%rsp), %edi
callq 0x11b6d
jmp 0xc842
movl 0x4(%rsp), %edi
callq 0x11566
jmp 0xc842
movl 0x4(%rsp), %edi
callq 0x11a3a
jmp 0xc842
callq 0x121ac
jmp 0xc842
movl 0x4(%rsp), %edi
xorl %esi, %esi
callq 0x1046e
jmp 0xc842
movl 0x4(%rsp), %ecx
movq %r15, %rdi
movq %r12, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x90d0
movl 0x4(%rsp), %eax
addl $0x3, %eax
addq %rax, %r12
movq 0x10705(%rip), %rdi     # 0x1cf58
movq %r12, %rsi
xorl %edx, %edx
callq 0x9160
movq 0x106f4(%rip), %rdi     # 0x1cf58
callq 0x90e0
movl %eax, %r13d
cmpl $-0x1, %eax
jne 0xc708
cmpb $0x0, 0x10694(%rip)     # 0x1cf10
je 0xc892
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x10683(%rip), %rsi     # 0x1cf10
callq 0xbd49
movl $0x1, 0x106cc(%rip)     # 0x1cf68
callq 0xe90c
movl $0x2, 0x106bd(%rip)     # 0x1cf68
callq 0xe90c
callq 0xed11
callq 0xee0d
callq 0xeedf
movl $0x3, 0x1069f(%rip)     # 0x1cf68
callq 0xe90c
movq 0x10683(%rip), %rdi     # 0x1cf58
callq 0x90a0
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %esi, %esi
jmp 0xc8f4
movl $0x1, %esi
movl 0x4(%rsp), %edi
callq 0x11ba8
jmp 0xc875
movq %rsi, %rdi
callq 0x9237
leaq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x93b1
nopl (%rax)