// File: /workspace/github_c_makefile_star2_O3/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 0xeac1(%rip), %r15      # 0x1cff0
movq (%r15), %rcx
movl (%rcx), %eax
leaq 0xec55(%rip), %r12      # 0x1d190
movl %eax, (%r12)
cmpl $0x0, 0x10(%rcx)
je 0xe659
xorps %xmm0, %xmm0
movups %xmm0, 0x6c(%rcx)
movups %xmm0, 0x5c(%rcx)
movups %xmm0, 0x4c(%rcx)
movups %xmm0, 0x3c(%rcx)
movups %xmm0, 0x2c(%rcx)
movups %xmm0, 0x1c(%rcx)
leaq 0xeb7d(%rip), %rbx      # 0x1d0e8
movq (%rbx), %rax
leaq 0xea63(%rip), %r14      # 0x1cfd8
cmpq (%r14), %rax
je 0xe5a5
leaq 0xeb6f(%rip), %r13      # 0x1d0f0
movq (%r13), %rcx
movl (%rcx), %ecx
cmpl (%r12), %ecx
jge 0xe5a2
movq %rax, %rdi
movl $0x1, %esi
callq 0x1288c
movq %rax, (%rbx)
cmpq (%r14), %rax
jne 0xe581
movq (%r15), %rcx
movl 0x4(%rcx), %eax
leaq 0xebb1(%rip), %rdi      # 0x1d160
movl %eax, (%rdi)
leaq 0xe9d8(%rip), %rax      # 0x1cf90
movq (%rax), %rsi
leaq 0x3546(%rip), %rdx      # 0x11b08
xorl %ecx, %ecx
callq 0x1280f
movq %rax, %rbx
testq %rax, %rax
jne 0xe5dd
leaq 0x5827(%rip), %rdi      # 0x13dff
callq 0x128bc
addq $0x4, %rbx
leaq 0xebc0(%rip), %r14      # 0x1d1a8
movq %rbx, (%r14)
movq (%r15), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x18(%rax)
setne %cl
movl $0x11e, %edx            # imm = 0x11E
movl $0x182, %esi            # imm = 0x182
cmovel %edx, %esi
leaq 0xeb95(%rip), %rdx      # 0x1d1a0
movl %esi, (%rdx)
leal 0x2(%rcx,%rcx), %ecx
leaq 0xeb8c(%rip), %rdx      # 0x1d1a4
movl %ecx, (%rdx)
leaq 0xe947(%rip), %rcx      # 0x1cf68
cmpl $0x3, (%rcx)
jne 0xe780
callq 0xcad9
movq (%r15), %rax
cmpl $0x0, 0x14(%rax)
leaq 0xe8bb(%rip), %rcx      # 0x1cef8
movl (%rcx), %ecx
je 0xe6a3
movq (%r14), %rdi
cmpl $0x2, %ecx
jne 0xe71f
leaq 0x57ca(%rip), %rsi      # 0x13e1e
jmp 0xe757
movq 0xef48(%rip), %rdx      # 0x1d5a8
leaq 0xe951(%rip), %rsi      # 0x1cfb8
cmpq (%rsi), %rdx
je 0xe678
movq 0x20(%rdx), %rdx
cmpl %eax, (%rdx)
jle 0xe549
leaq 0xea01(%rip), %rdx      # 0x1d080
movq (%rdx), %rdx
leaq 0xe91f(%rip), %rsi      # 0x1cfa8
cmpq (%rsi), %rdx
je 0xe89d
movq 0x20(%rdx), %rdx
cmpl %eax, (%rdx)
jle 0xe549
jmp 0xe89d
cmpl $0x2, %ecx
jne 0xe74d
movq 0x8(%rax), %rbx
addq $0x4, %rbx
leaq 0x4ebf(%rip), %rsi      # 0x1357a
movq %rbx, %rdi
callq 0x9050
testl %eax, %eax
je 0xe8da
leaq 0x4ead(%rip), %rsi      # 0x1357f
movq %rbx, %rdi
callq 0x9050
testl %eax, %eax
je 0xe8e2
leaq 0x5747(%rip), %rsi      # 0x13e30
movq %rbx, %rdi
callq 0x9050
testl %eax, %eax
je 0xe8f1
leaq 0x573b(%rip), %rsi      # 0x13e3b
movq %rbx, %rdi
callq 0x9050
movq (%r14), %rdi
testl %eax, %eax
je 0xe900
leaq 0x59f2(%rip), %rcx      # 0x1410c
movq %rbx, %rsi
jmp 0xe75e
leaq 0x56fd(%rip), %rsi      # 0x13e23
leaq 0x59df(%rip), %rcx      # 0x1410c
movq %rcx, %rdx
callq 0xcb44
movq (%r15), %rax
movl $0x0, 0x20(%rax)
movl (%r12), %ecx
movl %ecx, 0x38(%rax)
callq 0xf955
jmp 0xe766
movq (%r14), %rdi
leaq 0x56cc(%rip), %rsi      # 0x13e23
leaq 0x59ae(%rip), %rcx      # 0x1410c
movq %rcx, %rdx
callq 0xcb44
movq 0xee3b(%rip), %rdi      # 0x1d5a8
movl (%r12), %esi
callq 0xe49a
movq %rax, 0xee2b(%rip)      # 0x1d5a8
movq (%r15), %rax
movl 0x14(%rax), %ebx
leaq 0xe906(%rip), %rax      # 0x1d090
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0xea02(%rip), %r13      # 0x1d198
movq %rcx, (%r13)
callq 0x960c
movq 0xee0a(%rip), %rcx      # 0x1d5b0
leaq 0xe813(%rip), %rbp      # 0x1cfc0
movl (%r12), %eax
cmpq (%rbp), %rcx
je 0xe82b
movq 0xedfa(%rip), %rcx      # 0x1d5b8
cmpl %eax, (%rcx)
jne 0xe82b
movq 0xede7(%rip), %rdi      # 0x1d5b0
movl $0x1, %esi
callq 0x1288c
movq %rax, 0xedd6(%rip)      # 0x1d5b0
movq 0x20(%rax), %r14
movq 0xedd3(%rip), %rdi      # 0x1d5b8
cmpq (%rbp), %rax
je 0xe812
cmpl $0x0, 0x8(%rdi)
jne 0xe812
cmpl $0x0, 0x8(%r14)
jne 0xe812
movl (%r14), %eax
cmpl (%r12), %eax
jne 0xe812
movl 0x18(%rdi), %eax
addl 0x4(%rdi), %eax
cmpl 0x4(%r14), %eax
jne 0xe812
movq %r14, %rsi
jmp 0xe814
xorl %esi, %esi
movl %ebx, %edx
callq 0xe347
movq %r14, 0xed96(%rip)      # 0x1d5b8
movl (%r12), %eax
cmpl %eax, (%r14)
je 0xe7c2
leaq 0xe736(%rip), %r14      # 0x1cf68
cmpl $0x3, (%r14)
leaq 0xe84b(%rip), %rbx      # 0x1d088
movq (%rbx), %rcx
jne 0xe852
cmpl %eax, (%rcx)
jne 0xe852
callq 0xcad9
movq (%rbx), %rcx
movl (%r12), %eax
cmpl %eax, (%rcx)
jne 0xe875
movq 0x8(%rcx), %rdi
subq (%r13), %rdi
xorl %esi, %esi
callq 0xd01d
callq 0xd687
movq (%rbx), %rcx
movl (%rcx), %eax
cmpl (%r12), %eax
je 0xe856
movq (%r15), %rax
movl 0x10(%rax), %edi
subq (%r13), %rdi
xorl %esi, %esi
callq 0xd01d
cmpl $0x3, (%r14)
jne 0xe89d
callq 0xcad9
leaq 0xe660(%rip), %rax      # 0x1cef8
cmpl $0x2, (%rax)
jne 0xe8ac
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe8f5(%rip), %rax      # 0x1d1a8
movq (%rax), %rdi
leaq 0x5589(%rip), %rsi      # 0x13e46
leaq 0x5848(%rip), %rcx      # 0x1410c
movq %rcx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcb44
movq (%r14), %rdi
jmp 0xe64d
movq (%r14), %rdi
leaq 0x553f(%rip), %rsi      # 0x13e2b
jmp 0xe757
movq (%r14), %rdi
leaq 0x553b(%rip), %rsi      # 0x13e36
jmp 0xe757
leaq 0x553a(%rip), %rsi      # 0x13e41
jmp 0xe757