// File: /workspace/github_c_makefile_star2_O0/Nico01[P]obj2asm/oprocess.c
// Function: process_segment
void process_segment(void)
{
    NAME_T          *name_rec;
    DAT_T           *next_rec;
    int             inst_proc;
    int             seg_reg;

    segment = seg_rec->index;

    /*
    ** Skip segments which have no data, no external definitions,
    ** and no public symbols
    */
    if ( seg_rec->length == 0
  && (sex_node == sex_tree || ((SEX_T *)sex_node->data)->seg_index > segment)
  && (pub_node == public_tree || ((PUB_T *)pub_node->data)->seg_idx > segment)
        ) {
        return;
    }

    for ( seg_reg = 0; seg_reg < MAX_SEG_REGS; seg_reg++ ) {
        seg_rec->new_mode [seg_reg] = 0;
        seg_rec->new_index[seg_reg] = 0;
        seg_rec->prv_mode [seg_reg] = 0;
        seg_rec->prv_index[seg_reg] = 0;
    }

    /* Move to the hint records for this segment */
    while ( hint_node != hint_tree && hint_rec->seg_idx < segment ) {
        hint_node = traverse( hint_node, RIGHT );
    }

    name_search.index = seg_rec->name;      /* Look up segment name */
    name_rec = find( &name_search, name_tree, TC name_compare, NULL );
    if ( name_rec == NULL ) fmt_error( "Lost Code Segment Name (Oops!)" );
    cseg_name = name_rec->name;

#ifdef DEBUG
    printf("DIS-ASSEMBLY pass %d: segment %s\n", pass, cseg_name);
#endif

    if ( seg_rec->bit32 ) {
        segment_mode = 386;
    } else {
        segment_mode = 286;
    }

    if ( segment_mode == 386 ) {
        segment_bytes = 4;
    } else {
        segment_bytes = 2;
    }

    if ( pass == 3 ) {
        out_newline();
        if ( seg_rec->code ) {
            if ( compatibility == 2 ) {
                out_line( cseg_name, "CSEG", "", "" );
            } else {
                out_line( cseg_name, "SEGMENT", "", "" );
                seg_rec->new_mode[1] = SEGMENT;     /* Default assume for CS: */
                seg_rec->new_index[1] = segment;
                adjust_assumes();
            }
        } else {
            if ( compatibility == 2 ) {
                if ( stricmp(seg_rec->class->name,"CODE") == 0 ) {
                    out_line( cseg_name, "CSEG", "", "" );
                } else
                if ( stricmp(seg_rec->class->name,"DATA") == 0 ) {
                    out_line( cseg_name, "DSEG", "", "" );
                } else
                if ( stricmp(seg_rec->class->name,"STACK") == 0 ) {
                    out_line( cseg_name, "SSEG", "", "" );
                } else
                if ( stricmp(seg_rec->class->name,"EXTRA") == 0 ) {
                    out_line( cseg_name, "ESEG", "", "" );
                } else {
                    out_line( cseg_name, seg_rec->class->name, "", "" );
                }
            } else {
                out_line( cseg_name, "SEGMENT", "", "" );
            }
        }
        sex_node = list_sex( sex_node, segment );   /* List local extrns */
    }

#if 0
    sprintf( operand, "; Segment mode is %d\n", segment_mode );
    if ( pass == 3 ) {
        out_line( "", operand, "", "" );
    }
#endif

    inst_proc = seg_rec->code;

    last_pub_rec = NULL;
    inst_offset = 0;                        /* Start at beginning of seg */

    inst_init();

    /*
    ** Loop through all data records for this segment
    */
    if ( data_node != data_tree ) {
        while ( data_rec->seg_idx == segment ) {
            /*
            ** Advance to next data record
            */
            data_node = traverse( data_node, RIGHT );
            /*
            ** Check if we can process this record with extra bytes from
            ** the next record.  This is to catch any instructions which
            ** span the record edges. (Only for ENUMERATED records)
            */
            next_rec = (DAT_T *)data_node->data;
            if ( data_node != data_tree && data_rec->type == ENUMERATED &&
                    next_rec->type == ENUMERATED &&
                    next_rec->seg_idx == segment && 
                    data_rec->offset + data_rec->length == next_rec->offset ) {
                proc_drec( data_rec, next_rec, inst_proc );
            } else {
                proc_drec( data_rec, NULL, inst_proc );
            }
            data_rec = next_rec;
        }
    }

    if ( pass == 3 && pub_rec->seg_idx == segment ) {
        out_newline();                  /* Blank line before trailings */
    }
    while ( pub_rec->seg_idx == segment ) {
        pre_dups( pub_rec->offset - inst_offset, FALSE );
        proc_label();
    }

    pre_dups( seg_rec->length - inst_offset, FALSE );
        
    if ( pass == 3 ) {
        out_newline();
        if ( compatibility == 2 ) {
        } else {
            out_line( cseg_name, "ENDS", "", "" );
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
leaq 0xfba1(%rip), %rax      # 0x201c0
movq (%rax), %rax
movl (%rax), %ecx
leaq 0xfd35(%rip), %rax      # 0x20360
movl %ecx, (%rax)
leaq 0xfb8c(%rip), %rax      # 0x201c0
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
jne 0x1069e
movq 0x10134(%rip), %rax     # 0x20778
leaq 0xfb3d(%rip), %rcx      # 0x20188
cmpq (%rcx), %rax
je 0x10668
movq 0x10121(%rip), %rax     # 0x20778
movq 0x20(%rax), %rax
movl (%rax), %eax
leaq 0xfcfc(%rip), %rcx      # 0x20360
cmpl (%rcx), %eax
jle 0x1069e
leaq 0xfbe1(%rip), %rax      # 0x20250
movq (%rax), %rax
leaq 0xfaff(%rip), %rcx      # 0x20178
cmpq (%rcx), %rax
je 0x10699
leaq 0xfbcb(%rip), %rax      # 0x20250
movq (%rax), %rax
movq 0x20(%rax), %rax
movl (%rax), %eax
leaq 0xfccb(%rip), %rcx      # 0x20360
cmpl (%rcx), %eax
jle 0x1069e
jmp 0x10c4b
movl $0x0, -0x18(%rbp)
cmpl $0x6, -0x18(%rbp)
jge 0x1070e
leaq 0xfb0e(%rip), %rax      # 0x201c0
movq (%rax), %rax
movslq -0x18(%rbp), %rcx
movl $0x0, 0x1c(%rax,%rcx,4)
leaq 0xfaf8(%rip), %rax      # 0x201c0
movq (%rax), %rax
movslq -0x18(%rbp), %rcx
movl $0x0, 0x34(%rax,%rcx,4)
leaq 0xfae2(%rip), %rax      # 0x201c0
movq (%rax), %rax
movslq -0x18(%rbp), %rcx
movl $0x0, 0x4c(%rax,%rcx,4)
leaq 0xfacc(%rip), %rax      # 0x201c0
movq (%rax), %rax
movslq -0x18(%rbp), %rcx
movl $0x0, 0x64(%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x106a5
jmp 0x10710
leaq 0xfba1(%rip), %rax      # 0x202b8
movq (%rax), %rcx
xorl %eax, %eax
leaq 0xfa85(%rip), %rdx      # 0x201a8
cmpq (%rdx), %rcx
movb %al, -0x19(%rbp)
je 0x10746
leaq 0xfb8e(%rip), %rax      # 0x202c0
movq (%rax), %rax
movl (%rax), %eax
leaq 0xfc22(%rip), %rcx      # 0x20360
cmpl (%rcx), %eax
setl %al
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %al
testb $0x1, %al
jne 0x1074f
jmp 0x10772
leaq 0xfb62(%rip), %rax      # 0x202b8
movq (%rax), %rdi
movl $0x1, %esi
callq 0x16d70
movq %rax, %rcx
leaq 0xfb4b(%rip), %rax      # 0x202b8
movq %rcx, (%rax)
jmp 0x10710
leaq 0xfa47(%rip), %rax      # 0x201c0
movq (%rax), %rax
movl 0x4(%rax), %ecx
leaq 0xfbaa(%rip), %rax      # 0x20330
movl %ecx, (%rax)
leaq 0xf9d1(%rip), %rax      # 0x20160
movq (%rax), %rsi
leaq 0xfb97(%rip), %rdi      # 0x20330
leaq 0x50e0(%rip), %rdx      # 0x15880
xorl %eax, %eax
movl %eax, %ecx
callq 0x16c50
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x107c0
leaq 0x76e6(%rip), %rdi      # 0x17ea1
callq 0x16e00
movq -0x8(%rbp), %rcx
addq $0x4, %rcx
leaq 0xfba9(%rip), %rax      # 0x20378
movq %rcx, (%rax)
leaq 0xf9e7(%rip), %rax      # 0x201c0
movq (%rax), %rax
cmpl $0x0, 0x18(%rax)
je 0x107f1
leaq 0xfb87(%rip), %rax      # 0x20370
movl $0x182, (%rax)          # imm = 0x182
jmp 0x107fe
leaq 0xfb78(%rip), %rax      # 0x20370
movl $0x11e, (%rax)          # imm = 0x11E
leaq 0xfb6b(%rip), %rax      # 0x20370
cmpl $0x182, (%rax)          # imm = 0x182
jne 0x1081c
leaq 0xfb60(%rip), %rax      # 0x20374
movl $0x4, (%rax)
jmp 0x10829
leaq 0xfb51(%rip), %rax      # 0x20374
movl $0x2, (%rax)
leaq 0xf908(%rip), %rax      # 0x20138
cmpl $0x3, (%rax)
jne 0x10a68
callq 0xe280
leaq 0xf97b(%rip), %rax      # 0x201c0
movq (%rax), %rax
cmpl $0x0, 0x14(%rax)
je 0x108cd
leaq 0xf873(%rip), %rax      # 0x200c8
cmpl $0x2, (%rax)
jne 0x1087c
leaq 0xfb17(%rip), %rax      # 0x20378
movq (%rax), %rdi
leaq 0x7655(%rip), %rsi      # 0x17ec0
leaq 0x794e(%rip), %rcx      # 0x181c0
movq %rcx, %rdx
callq 0xe2d0
jmp 0x108c8
leaq 0xfaf5(%rip), %rax      # 0x20378
movq (%rax), %rdi
leaq 0x7638(%rip), %rsi      # 0x17ec5
leaq 0x792c(%rip), %rcx      # 0x181c0
movq %rcx, %rdx
callq 0xe2d0
leaq 0xf91d(%rip), %rax      # 0x201c0
movq (%rax), %rax
movl $0x0, 0x20(%rax)
leaq 0xfaac(%rip), %rax      # 0x20360
movl (%rax), %ecx
leaq 0xf903(%rip), %rax      # 0x201c0
movq (%rax), %rax
movl %ecx, 0x38(%rax)
callq 0x123f0
jmp 0x10a4c
leaq 0xf7f4(%rip), %rax      # 0x200c8
cmpl $0x2, (%rax)
jne 0x10a2a
leaq 0xf8dc(%rip), %rax      # 0x201c0
movq (%rax), %rax
movq 0x8(%rax), %rdi
addq $0x4, %rdi
leaq 0x6c2b(%rip), %rsi      # 0x17521
callq 0x9040
cmpl $0x0, %eax
jne 0x10925
leaq 0xfa71(%rip), %rax      # 0x20378
movq (%rax), %rdi
leaq 0x75af(%rip), %rsi      # 0x17ec0
leaq 0x78a8(%rip), %rcx      # 0x181c0
movq %rcx, %rdx
callq 0xe2d0
jmp 0x10a28
leaq 0xf894(%rip), %rax      # 0x201c0
movq (%rax), %rax
movq 0x8(%rax), %rdi
addq $0x4, %rdi
leaq 0x6be8(%rip), %rsi      # 0x17526
callq 0x9040
cmpl $0x0, %eax
jne 0x1096d
leaq 0xfa29(%rip), %rax      # 0x20378
movq (%rax), %rdi
leaq 0x7574(%rip), %rsi      # 0x17ecd
leaq 0x7860(%rip), %rcx      # 0x181c0
movq %rcx, %rdx
callq 0xe2d0
jmp 0x10a26
leaq 0xf84c(%rip), %rax      # 0x201c0
movq (%rax), %rax
movq 0x8(%rax), %rdi
addq $0x4, %rdi
leaq 0x754c(%rip), %rsi      # 0x17ed2
callq 0x9040
cmpl $0x0, %eax
jne 0x109b2
leaq 0xf9e1(%rip), %rax      # 0x20378
movq (%rax), %rdi
leaq 0x7537(%rip), %rsi      # 0x17ed8
leaq 0x7818(%rip), %rcx      # 0x181c0
movq %rcx, %rdx
callq 0xe2d0
jmp 0x10a24
leaq 0xf807(%rip), %rax      # 0x201c0
movq (%rax), %rax
movq 0x8(%rax), %rdi
addq $0x4, %rdi
leaq 0x7512(%rip), %rsi      # 0x17edd
callq 0x9040
cmpl $0x0, %eax
jne 0x109f7
leaq 0xf99c(%rip), %rax      # 0x20378
movq (%rax), %rdi
leaq 0x74fd(%rip), %rsi      # 0x17ee3
leaq 0x77d3(%rip), %rcx      # 0x181c0
movq %rcx, %rdx
callq 0xe2d0
jmp 0x10a22
leaq 0xf97a(%rip), %rax      # 0x20378
movq (%rax), %rdi
leaq 0xf7b8(%rip), %rax      # 0x201c0
movq (%rax), %rax
movq 0x8(%rax), %rsi
addq $0x4, %rsi
leaq 0x77a6(%rip), %rcx      # 0x181c0
movq %rcx, %rdx
callq 0xe2d0
jmp 0x10a24
jmp 0x10a26
jmp 0x10a28
jmp 0x10a4a
leaq 0xf947(%rip), %rax      # 0x20378
movq (%rax), %rdi
leaq 0x748a(%rip), %rsi      # 0x17ec5
leaq 0x777e(%rip), %rcx      # 0x181c0
movq %rcx, %rdx
callq 0xe2d0
jmp 0x10a4c
movq 0xfd25(%rip), %rdi      # 0x20778
leaq 0xf906(%rip), %rax      # 0x20360
movl (%rax), %esi
callq 0x10520
movq %rax, 0xfd10(%rip)      # 0x20778
leaq 0xf751(%rip), %rax      # 0x201c0
movq (%rax), %rax
movl 0x14(%rax), %eax
movl %eax, -0x14(%rbp)
leaq 0xf7e1(%rip), %rax      # 0x20260
movq $0x0, (%rax)
leaq 0xf8db(%rip), %rax      # 0x20368
movq $0x0, (%rax)
callq 0x92d0
movq 0xfce0(%rip), %rax      # 0x20780
leaq 0xf6e9(%rip), %rcx      # 0x20190
cmpq (%rcx), %rax
je 0x10b83
jmp 0x10ab2
movq 0xfccf(%rip), %rax      # 0x20788
movl (%rax), %eax
leaq 0xf89e(%rip), %rcx      # 0x20360
cmpl (%rcx), %eax
jne 0x10b81
movq 0xfcaf(%rip), %rdi      # 0x20780
movl $0x1, %esi
callq 0x16d70
movq %rax, 0xfc9e(%rip)      # 0x20780
movq 0xfc97(%rip), %rax      # 0x20780
movq 0x20(%rax), %rax
movq %rax, -0x10(%rbp)
movq 0xfc88(%rip), %rax      # 0x20780
leaq 0xf691(%rip), %rcx      # 0x20190
cmpq (%rcx), %rax
je 0x10b5e
movq 0xfc7d(%rip), %rax      # 0x20788
cmpl $0x0, 0x8(%rax)
jne 0x10b5e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x10b5e
movq -0x10(%rbp), %rax
movl (%rax), %eax
leaq 0xf838(%rip), %rcx      # 0x20360
cmpl (%rcx), %eax
jne 0x10b5e
movq 0xfc55(%rip), %rax      # 0x20788
movl 0x4(%rax), %eax
movq 0xfc4b(%rip), %rcx      # 0x20788
addl 0x18(%rcx), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x10b5e
movq 0xfc38(%rip), %rdi      # 0x20788
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x103b0
jmp 0x10b71
movq 0xfc23(%rip), %rdi      # 0x20788
movl -0x14(%rbp), %edx
xorl %eax, %eax
movl %eax, %esi
callq 0x103b0
movq -0x10(%rbp), %rax
movq %rax, 0xfc0c(%rip)      # 0x20788
jmp 0x10ab2
jmp 0x10b83
leaq 0xf5ae(%rip), %rax      # 0x20138
cmpl $0x3, (%rax)
jne 0x10bab
leaq 0xf6c2(%rip), %rax      # 0x20258
movq (%rax), %rax
movl (%rax), %eax
leaq 0xf7be(%rip), %rcx      # 0x20360
cmpl (%rcx), %eax
jne 0x10bab
callq 0xe280
jmp 0x10bad
leaq 0xf6a4(%rip), %rax      # 0x20258
movq (%rax), %rax
movl (%rax), %eax
leaq 0xf7a0(%rip), %rcx      # 0x20360
cmpl (%rcx), %eax
jne 0x10bea
leaq 0xf68d(%rip), %rax      # 0x20258
movq (%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xf78f(%rip), %rax      # 0x20368
subq (%rax), %rdi
xorl %esi, %esi
callq 0xe940
callq 0xf180
jmp 0x10bad
leaq 0xf5cf(%rip), %rax      # 0x201c0
movq (%rax), %rax
movl 0x10(%rax), %eax
movl %eax, %edi
leaq 0xf768(%rip), %rax      # 0x20368
subq (%rax), %rdi
xorl %esi, %esi
callq 0xe940
leaq 0xf527(%rip), %rax      # 0x20138
cmpl $0x3, (%rax)
jne 0x10c4b
callq 0xe280
leaq 0xf4a6(%rip), %rax      # 0x200c8
cmpl $0x2, (%rax)
jne 0x10c29
jmp 0x10c49
leaq 0xf748(%rip), %rax      # 0x20378
movq (%rax), %rdi
leaq 0x72ae(%rip), %rsi      # 0x17ee8
leaq 0x757f(%rip), %rcx      # 0x181c0
movq %rcx, %rdx
callq 0xe2d0
jmp 0x10c4b
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)