// File: /workspace/github_c_makefile_star2_O2/Nico01[P]obj2asm/oextra.c
// Function: load_extra
void load_extra( exename, filename )
    char            *exename;
    char            *filename;
{
    FILE            *e_file;
    char            temp_name[50];
    char            e_line[LINE_SIZE+1];
    int             line_num;
    char            *pc;
    char            *semicolon;
    char            *equal;
    char            *colon;
    char            seg_text[NAMESIZE+1];
    char            lab_text[NAMESIZE+1];
    int             segment_type;
    dword   disp;
    int             count;

#ifdef DEBUG
    printf("Loading from extra file %s\n", filename );
#endif

    strcpy( temp_name, filename );
    if ( strchr(temp_name,'.') == NULL ) {  /* Append ".add" if not extension */
        strcat( temp_name, ".add" );        /* is supplied                    */
    }
    e_file = fopen( temp_name, "r" );
    if ( e_file == NULL ) {
        fprintf( stderr, "%s: Cannot open %s\n", exename, temp_name );
        exit(6);
    }

    line_num = 1;

    /*
    ** Process lines of format:
    **
    **  SEG segname CODE/DATA                 Pick segment type
    **  labname = segname : offset            Create label
    **  segname : offset : DB/DW/DD/DF/DQ/DT  Control dis-assembly
    */

    while ( fgets(e_line,LINE_SIZE,e_file) != NULL ) {
        semicolon = strchr( e_line, ';' );
        if ( semicolon ) {
            *semicolon = '\0';
        }
        pc = ignore_whitespace( e_line );
#ifdef DEBUG
fprintf(stderr, "%s", pc );
#endif
        if ( strnicmp(pc,"SEG ",4) == 0 ) {
            pc = ignore_whitespace( pc+4 );
            pc = get_text( seg_text, pc );
            pc = ignore_whitespace( pc );
            segment_type = 0;
            if ( strnicmp(pc,"CODE",4) == 0 ) {
                pc += 4;
                segment_type = 1;
            }
            if ( strnicmp(pc,"DATA",4) == 0 ) {
                pc += 4;
                segment_type = 2;
            }
            if ( segment_type == 0 ) {
                fprintf( stderr,
                  "%s: Syntax error on line %d of %s (should be CODE/DATA).\n",
                  exename, line_num, temp_name );
                exit(7);
            }
            seg_rec = find_seg_by_name( seg_text );
            if ( !seg_rec ) {
                fprintf( stderr,
            "%s: Syntax error on line %d of %s (segment '%s' not found)\n",
                    exename, line_num, temp_name, seg_text );
                exit(7);
            }
            if ( segment_type == 1 ) {
                seg_rec->code = TRUE;
            } else {
                seg_rec->code = FALSE;
            }
        }
        equal = strchr(pc, '=' );
        if ( equal ) {
            pc = get_text(lab_text, pc );
            pc = ignore_whitespace(pc);
            if ( strnicmp(pc,"=",1) != 0 ) {
                fprintf( stderr,
            "%s: Syntax error on line %d of %s (expecting '=' after label)\n",
                    exename, line_num, temp_name );
                exit(7);
            }
            pc=ignore_whitespace(pc+1);
            colon=strchr(pc,':');
            if ( colon == NULL ) {
                fprintf( stderr,
            "%s: Syntax error on line %d of %s (expecting ':')\n",
                    exename, line_num, temp_name );
                exit(7);
            }
            pc = get_text( seg_text, pc );
            pc = ignore_whitespace( colon+1 );
            pc = get_num( pc, &disp );
            seg_rec = find_seg_by_name( seg_text );
            if ( !seg_rec ) {
                fprintf( stderr,
            "%s: Syntax error on line %d of %s (segment '%s' not found)\n",
                    exename, line_num, temp_name, seg_text );
                exit(7);
            }
            pub_insert( seg_rec->index, disp, lab_text, LOCAL, FALSE );
        }
        colon = strchr(pc,':');
        if ( colon ) {
            pc = get_text( seg_text, pc );
            seg_rec = find_seg_by_name( seg_text );
            if ( !seg_rec ) {
                fprintf( stderr,
            "%s: Syntax error on line %d of %s (segment '%s' not found)\n",
                    exename, line_num, temp_name, seg_text );
                exit(7);
            }
            pc = ignore_whitespace( pc );
            if ( strnicmp(pc,":",1) != 0 ) {
                fprintf( stderr,
            "%s: Syntax error on line %d of %s (expecting ':' seperator)\n",
                    exename, line_num, temp_name );
                exit(7);
            }
            pc = get_num( pc+1, &disp );
            pc = ignore_whitespace( pc );
            if ( strnicmp(pc,":",1) != 0 ) {
                fprintf( stderr,
            "%s: Syntax error on line %d of %s (expecting ':' seperator)\n",
                    exename, line_num, temp_name );
                exit(7);
            }
            pc = ignore_whitespace( pc+1 );
            pc = get_text( lab_text, pc );  /* Is really data type text */
            count = 0;
            while ( count < hint_nwords ) {
                if ( stricmp(lab_text,hint_words[count].text) == 0 ) {
                    break;
                }
                count++;
            }
            if ( count == hint_nwords ) {
                fprintf( stderr,
            "%s: Syntax error on line %d of %s (expecting DB/DW/DD/DF/DQ/DT)\n",
                    exename, line_num, temp_name );
                exit(7);
            }
            hint_insert(seg_rec->index,disp,hint_words[count].type,1);
        }
        pc = ignore_whitespace( pc );
        if ( strlen(pc) != 0 ) {
                fprintf( stderr,
       "%s: Syntax error on line %d of %s (too many characters on line '%s')\n",
                    exename, line_num, temp_name, pc );
                exit(7);
        }
        line_num++;
    }

#ifdef DEBUG
fprintf(stderr, "\n", e_line );
#endif

    fclose( e_file );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x10(%rsp)
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x9070
pushq $0x2e
popq %rsi
movq %rbx, %rdi
callq 0x90c0
testq %rax, %rax
jne 0xb86a
leaq 0x30(%rsp), %rdi
callq 0x90b0
movl $0x6464612e, 0x30(%rsp,%rax) # imm = 0x6464612E
movb $0x0, 0x34(%rsp,%rax)
leaq 0x8127(%rip), %rsi      # 0x13998
leaq 0x30(%rsp), %rdi
callq 0x9180
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0xbcec
pushq $0x1
popq %r13
leaq 0xd0(%rsp), %rbx
leaq 0x70(%rsp), %r12
pushq $0x1
popq %rbp
movq %rbx, %rdi
pushq $0x50
popq %rsi
movq 0x28(%rsp), %rdx
callq 0x9100
testq %rax, %rax
je 0xbbcb
movq %rbx, %rdi
pushq $0x3b
popq %rsi
callq 0x90c0
testq %rax, %rax
je 0xb8c9
movb $0x0, (%rax)
movq %rbx, %rdi
callq 0xb70c
movq %rax, %r14
movq %rax, %rdi
leaq 0x6c97(%rip), %rsi      # 0x12575
pushq $0x4
popq %rdx
callq 0x9150
testl %eax, %eax
jne 0xb9b5
movl %r13d, 0x1c(%rsp)
addq $0x4, %r14
movq %r14, %rdi
callq 0xb70c
movq %r12, %rdi
movq %rax, %rsi
callq 0xb72e
movq %rax, %rdi
callq 0xb70c
movq %rax, %r14
movq %rax, %rdi
leaq 0x6c5b(%rip), %rsi      # 0x1257a
pushq $0x4
popq %rbx
movq %rbx, %rdx
callq 0x9150
movl %eax, %r13d
xorl %eax, %eax
testl %r13d, %r13d
setne 0xf(%rsp)
sete %al
leaq (%r14,%rax,4), %r14
movq %r14, %rdi
leaq 0x6c37(%rip), %rsi      # 0x1257f
movq %rbx, %rdx
callq 0x9150
movl %eax, %r15d
xorl %ebx, %ebx
testl %eax, %eax
sete %bpl
setne %al
andb 0xf(%rsp), %al
cmpb $0x1, %al
je 0xbc98
movq %r12, %rdi
callq 0xb65f
leaq 0x10677(%rip), %rcx     # 0x1bff0
movq %rax, (%rcx)
testq %rax, %rax
je 0xbcb9
movb %bpl, %bl
leaq (%r14,%rbx,4), %r14
testl %r15d, %r15d
setne %cl
testl %r13d, %r13d
sete %dl
andb %cl, %dl
movzbl %dl, %ecx
movl %ecx, 0x14(%rax)
movl 0x1c(%rsp), %r13d
leaq 0xd0(%rsp), %rbx
leaq 0x70(%rsp), %r12
pushq $0x1
popq %rbp
movq %r14, %rdi
pushq $0x3d
popq %rsi
callq 0x90c0
testq %rax, %rax
je 0xba7d
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0xb72e
movq %rax, %rdi
callq 0xb70c
movq %rax, %r14
movq %rax, %rdi
leaq 0x6c0c(%rip), %rsi      # 0x125fa
movq %rbp, %rdx
callq 0x9150
testl %eax, %eax
jne 0xbc71
incq %r14
movq %r14, %rdi
callq 0xb70c
movq %rax, %r14
movq %rax, %rdi
pushq $0x3a
popq %rsi
callq 0x90c0
testq %rax, %rax
je 0xbc4b
movq %rax, %r15
movq %r12, %rdi
movq %r14, %rsi
callq 0xb72e
incq %r15
movq %r15, %rdi
callq 0xb70c
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0xb763
movq %rax, %r14
movq %r12, %rdi
callq 0xb65f
leaq 0x10598(%rip), %rcx     # 0x1bff0
movq %rax, (%rcx)
testq %rax, %rax
je 0xbbfd
movl (%rax), %edi
movq 0x20(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x113e0
movq %r14, %rdi
pushq $0x3a
popq %rsi
callq 0x90c0
testq %rax, %rax
je 0xbbb6
movq %r12, %rdi
movq %r14, %rsi
callq 0xb72e
movq %rax, %r14
movq %r12, %rdi
callq 0xb65f
leaq 0x10542(%rip), %rcx     # 0x1bff0
movq %rax, (%rcx)
testq %rax, %rax
je 0xbbfd
movq %r14, %rdi
callq 0xb70c
movq %rax, %r14
movq %rax, %rdi
leaq 0x7aeb(%rip), %rbx      # 0x135ba
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x9150
testl %eax, %eax
jne 0xbbe7
incq %r14
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0xb763
movq %rax, %rdi
callq 0xb70c
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x9150
testl %eax, %eax
jne 0xbbe7
incq %r14
movq %r14, %rdi
callq 0xb70c
leaq 0xa0(%rsp), %rdi
movq %rax, %rsi
callq 0xb72e
movq %rax, %r14
movl 0xcfc8(%rip), %r12d     # 0x18b00
testl %r12d, %r12d
movl $0x0, %ebp
cmovgl %r12d, %ebp
leaq 0xcf55(%rip), %rbx      # 0x18aa0
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0xbb73
movq (%rbx), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x9050
testl %eax, %eax
je 0xbb70
incq %r15
addq $0x10, %rbx
jmp 0xbb4e
movl %r15d, %ebp
cmpl %r12d, %ebp
je 0xbc5e
leaq 0x1046d(%rip), %rax     # 0x1bff0
movq (%rax), %rax
movl (%rax), %edi
movq 0x20(%rsp), %rsi
movl %ebp, %eax
shlq $0x4, %rax
leaq 0xcf06(%rip), %rcx      # 0x18aa0
movl 0x8(%rax,%rcx), %edx
pushq $0x1
popq %rbp
movq %rbp, %rcx
callq 0xb614
leaq 0xd0(%rsp), %rbx
leaq 0x70(%rsp), %r12
movq %r14, %rdi
callq 0xb70c
cmpb $0x0, (%rax)
jne 0xbc25
incl %r13d
jmp 0xb89d
movq 0x28(%rsp), %rdi
callq 0x90a0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc40a(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq 0x6a76(%rip), %rsi      # 0x1266e
jmp 0xbc82
movq 0xc3f4(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq 0x69b0(%rip), %rsi      # 0x125be
leaq 0x30(%rsp), %r8
leaq 0x70(%rsp), %r9
movq 0x10(%rsp), %rdx
movl %r13d, %ecx
jmp 0xbcdd
movq 0xc3cc(%rip), %rcx      # 0x17ff8
movq (%rcx), %rdi
leaq 0x6ab6(%rip), %rsi      # 0x126ec
leaq 0x30(%rsp), %r8
movq 0x10(%rsp), %rdx
movl %r13d, %ecx
movq %rax, %r9
jmp 0xbcdd
movq 0xc3a6(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq 0x69df(%rip), %rsi      # 0x1263b
jmp 0xbc82
movq 0xc393(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq 0x6a3c(%rip), %rsi      # 0x126ab
jmp 0xbc82
movq 0xc380(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq 0x697a(%rip), %rsi      # 0x125fc
leaq 0x30(%rsp), %r8
movq 0x10(%rsp), %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x9140
jmp 0xbce4
movq 0xc359(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq 0x68db(%rip), %rsi      # 0x12584
leaq 0x30(%rsp), %r8
movq 0x10(%rsp), %rdx
movl 0x1c(%rsp), %ecx
jmp 0xbc8f
movq 0xc338(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq 0x68f4(%rip), %rsi      # 0x125be
leaq 0x30(%rsp), %r8
leaq 0x70(%rsp), %r9
movq 0x10(%rsp), %rdx
movl 0x1c(%rsp), %ecx
xorl %eax, %eax
callq 0x9140
pushq $0x7
popq %rdi
callq 0x91c0
movq 0xc305(%rip), %rax      # 0x17ff8
movq (%rax), %rdi
leaq 0x6864(%rip), %rsi      # 0x12561
leaq 0x30(%rsp), %rcx
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x9140
pushq $0x6
jmp 0xbce6
nop