// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0xe1a9(%rip), %rbp      # 0x1bff0
movq (%rbp), %rax
movl (%rax), %ecx
leaq 0xe33c(%rip), %r12      # 0x1c190
movl %ecx, (%r12)
cmpl $0x0, 0x10(%rax)
je 0xdf79
pushq $-0x18
popq %rcx
testq %rcx, %rcx
je 0xde84
andl $0x0, 0x34(%rax,%rcx)
andl $0x0, 0x4c(%rax,%rcx)
andl $0x0, 0x64(%rax,%rcx)
andl $0x0, 0x7c(%rax,%rcx)
addq $0x4, %rcx
jmp 0xde65
leaq 0xe25d(%rip), %r14      # 0x1c0e8
movq (%r14), %rax
leaq 0xe143(%rip), %r15      # 0x1bfd8
leaq 0xe254(%rip), %r13      # 0x1c0f0
pushq $0x1
popq %rbx
cmpq (%r15), %rax
je 0xdebf
movq (%r13), %rcx
movl (%rcx), %ecx
cmpl (%r12), %ecx
jge 0xdebf
movq %rax, %rdi
movl %ebx, %esi
callq 0x11ebc
movq %rax, (%r14)
jmp 0xde9f
movq (%rbp), %rax
movl 0x4(%rax), %eax
leaq 0xe293(%rip), %rdi      # 0x1c160
movl %eax, (%rdi)
leaq 0xe0ba(%rip), %rax      # 0x1bf90
movq (%rax), %rsi
leaq 0x340c(%rip), %rdx      # 0x112ec
xorl %ecx, %ecx
callq 0x11e3b
movq %rax, %rbx
testq %rax, %rax
jne 0xdefb
leaq 0x4f09(%rip), %rdi      # 0x12dff
callq 0x11eec
addq $0x4, %rbx
leaq 0xe2a2(%rip), %r14      # 0x1c1a8
movq %rbx, (%r14)
movq (%rbp), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x18(%rax)
setne %cl
movl $0x11e, %edx            # imm = 0x11E
movl $0x182, %esi            # imm = 0x182
cmovel %edx, %esi
leaq 0xe276(%rip), %rdx      # 0x1c1a0
movl %esi, (%rdx)
leal 0x2(%rcx,%rcx), %ecx
leaq 0xe26d(%rip), %rdx      # 0x1c1a4
movl %ecx, (%rdx)
leaq 0xe028(%rip), %rcx      # 0x1bf68
cmpl $0x3, (%rcx)
jne 0xe09f
callq 0xc54f
movq (%rbp), %rax
cmpl $0x0, 0x14(%rax)
leaq 0xdf9b(%rip), %rcx      # 0x1bef8
movl (%rcx), %ecx
je 0xdfc3
movq (%r14), %rdi
cmpl $0x2, %ecx
jne 0xe03f
leaq 0x4eaa(%rip), %rsi      # 0x12e1e
jmp 0xe075
movq 0xe628(%rip), %rdx      # 0x1c5a8
leaq 0xe031(%rip), %rsi      # 0x1bfb8
cmpq (%rsi), %rdx
je 0xdf98
movq 0x20(%rdx), %rdx
cmpl %ecx, (%rdx)
jle 0xde62
leaq 0xe0e1(%rip), %rdx      # 0x1c080
movq (%rdx), %rdx
leaq 0xdfff(%rip), %rsi      # 0x1bfa8
cmpq (%rsi), %rdx
je 0xe1bd
movq 0x20(%rdx), %rdx
cmpl %ecx, (%rdx)
jle 0xde62
jmp 0xe1bd
cmpl $0x2, %ecx
jne 0xe06b
movq 0x8(%rax), %rbx
addq $0x4, %rbx
leaq 0x459f(%rip), %rsi      # 0x1257a
movq %rbx, %rdi
callq 0x9050
testl %eax, %eax
je 0xe1fa
leaq 0x458d(%rip), %rsi      # 0x1257f
movq %rbx, %rdi
callq 0x9050
testl %eax, %eax
je 0xe202
leaq 0x4e27(%rip), %rsi      # 0x12e30
movq %rbx, %rdi
callq 0x9050
testl %eax, %eax
je 0xe211
leaq 0x4e1b(%rip), %rsi      # 0x12e3b
movq %rbx, %rdi
callq 0x9050
movq (%r14), %rdi
testl %eax, %eax
je 0xe220
leaq 0x50d2(%rip), %rcx      # 0x1310c
movq %rbx, %rsi
jmp 0xe07c
leaq 0x4ddd(%rip), %rsi      # 0x12e23
leaq 0x50bf(%rip), %rcx      # 0x1310c
movq %rcx, %rdx
callq 0xc585
movq (%rbp), %rax
andl $0x0, 0x20(%rax)
movl (%r12), %ecx
movl %ecx, 0x38(%rax)
callq 0xf1c1
jmp 0xe084
movq (%r14), %rdi
leaq 0x4dae(%rip), %rsi      # 0x12e23
leaq 0x5090(%rip), %rcx      # 0x1310c
movq %rcx, %rdx
callq 0xc585
movq 0xe51d(%rip), %rdi      # 0x1c5a8
movl (%r12), %esi
callq 0xddbf
movq %rax, 0xe50d(%rip)      # 0x1c5a8
movq (%rbp), %rax
movl 0x14(%rax), %ebx
leaq 0xdfe7(%rip), %rax      # 0x1c090
andq $0x0, (%rax)
leaq 0xe0e4(%rip), %r13      # 0x1c198
andq $0x0, (%r13)
callq 0x92fc
movq 0xe4eb(%rip), %rax      # 0x1c5b0
leaq 0xdef4(%rip), %r15      # 0x1bfc0
cmpq (%r15), %rax
je 0xe142
movq 0xe4e0(%rip), %r14      # 0x1c5b8
pushq $0x1
popq %rbp
movl (%r14), %eax
cmpl (%r12), %eax
jne 0xe142
movq 0xe4c5(%rip), %rdi      # 0x1c5b0
movl %ebp, %esi
callq 0x11ebc
movq %rax, 0xe4b7(%rip)      # 0x1c5b0
movq 0x20(%rax), %r14
movq 0xe4b4(%rip), %rdi      # 0x1c5b8
cmpq (%r15), %rax
je 0xe130
cmpl $0x0, 0x8(%rdi)
jne 0xe130
cmpl $0x0, 0x8(%r14)
jne 0xe130
movl (%r14), %eax
cmpl (%r12), %eax
jne 0xe130
movl 0x18(%rdi), %eax
addl 0x4(%rdi), %eax
cmpl 0x4(%r14), %eax
jne 0xe130
movq %r14, %rsi
jmp 0xe132
xorl %esi, %esi
movl %ebx, %edx
callq 0xdc84
movq %r14, 0xe478(%rip)      # 0x1c5b8
jmp 0xe0db
leaq 0xde1f(%rip), %r15      # 0x1bf68
cmpl $0x3, (%r15)
jne 0xe166
leaq 0xdf32(%rip), %rax      # 0x1c088
movq (%rax), %rax
movl (%rax), %eax
cmpl (%r12), %eax
jne 0xe166
callq 0xc54f
leaq 0xdf1b(%rip), %rbx      # 0x1c088
leaq 0xde7c(%rip), %r14      # 0x1bff0
movq (%rbx), %rax
movl (%rax), %ecx
cmpl (%r12), %ecx
jne 0xe195
movq 0x8(%rax), %rdi
subq (%r13), %rdi
xorl %esi, %esi
callq 0xca11
callq 0xd050
jmp 0xe174
movq (%r14), %rax
movl 0x10(%rax), %edi
subq (%r13), %rdi
xorl %esi, %esi
callq 0xca11
cmpl $0x3, (%r15)
jne 0xe1bd
callq 0xc54f
leaq 0xdd40(%rip), %rax      # 0x1bef8
cmpl $0x2, (%rax)
jne 0xe1cc
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdfd5(%rip), %rax      # 0x1c1a8
movq (%rax), %rdi
leaq 0x4c69(%rip), %rsi      # 0x12e46
leaq 0x4f28(%rip), %rcx      # 0x1310c
movq %rcx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc585
movq (%r14), %rdi
jmp 0xdf6d
movq (%r14), %rdi
leaq 0x4c1f(%rip), %rsi      # 0x12e2b
jmp 0xe075
movq (%r14), %rdi
leaq 0x4c1b(%rip), %rsi      # 0x12e36
jmp 0xe075
leaq 0x4c1a(%rip), %rsi      # 0x12e41
jmp 0xe075