// File: /workspace/github_c_makefile_star2_O1/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 0xeaf1(%rip), %r15      # 0x1cff0
movq (%r15), %rax
movl (%rax), %ecx
leaq 0xec85(%rip), %r12      # 0x1d190
movl %ecx, (%r12)
cmpl $0x0, 0x10(%rax)
je 0xe629
xorps %xmm0, %xmm0
movups %xmm0, 0x6c(%rax)
movups %xmm0, 0x5c(%rax)
movups %xmm0, 0x4c(%rax)
movups %xmm0, 0x3c(%rax)
movups %xmm0, 0x2c(%rax)
movups %xmm0, 0x1c(%rax)
leaq 0xebad(%rip), %rbx      # 0x1d0e8
movq (%rbx), %rax
leaq 0xea93(%rip), %r14      # 0x1cfd8
cmpq (%r14), %rax
je 0xe572
leaq 0xeb9f(%rip), %r13      # 0x1d0f0
movq (%r13), %rcx
movl (%rcx), %ecx
cmpl (%r12), %ecx
jge 0xe572
movq %rax, %rdi
movl $0x1, %esi
callq 0x127da
movq %rax, (%rbx)
cmpq (%r14), %rax
jne 0xe551
movq (%r15), %rax
movl 0x4(%rax), %eax
leaq 0xebe1(%rip), %rdi      # 0x1d160
movl %eax, (%rdi)
leaq 0xea08(%rip), %rax      # 0x1cf90
movq (%rax), %rsi
leaq 0x34ea(%rip), %rdx      # 0x11a7c
xorl %ecx, %ecx
callq 0x1275f
movq %rax, %rbx
testq %rax, %rax
jne 0xe5ad
leaq 0x5857(%rip), %rdi      # 0x13dff
callq 0x12808
addq $0x4, %rbx
leaq 0xebf0(%rip), %r14      # 0x1d1a8
movq %rbx, (%r14)
movq (%r15), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x18(%rax)
setne %cl
movl $0x11e, %eax            # imm = 0x11E
movl $0x182, %edx            # imm = 0x182
cmovel %eax, %edx
leaq 0xebc5(%rip), %rax      # 0x1d1a0
movl %edx, (%rax)
leal 0x2(%rcx,%rcx), %eax
leaq 0xebbc(%rip), %rcx      # 0x1d1a4
movl %eax, (%rcx)
leaq 0xe977(%rip), %rax      # 0x1cf68
cmpl $0x3, (%rax)
jne 0xe74d
callq 0xca6d
movq (%r15), %rax
cmpl $0x0, 0x14(%rax)
leaq 0xe8eb(%rip), %rcx      # 0x1cef8
movl (%rcx), %ecx
je 0xe673
movq (%r14), %rdi
cmpl $0x2, %ecx
jne 0xe6ef
leaq 0x57fa(%rip), %rsi      # 0x13e1e
jmp 0xe727
movq 0xef78(%rip), %rdx      # 0x1d5a8
leaq 0xe981(%rip), %rsi      # 0x1cfb8
cmpq (%rsi), %rdx
je 0xe648
movq 0x20(%rdx), %rdx
cmpl %ecx, (%rdx)
jle 0xe519
leaq 0xea31(%rip), %rdx      # 0x1d080
movq (%rdx), %rdx
leaq 0xe94f(%rip), %rsi      # 0x1cfa8
cmpq (%rsi), %rdx
je 0xe872
movq 0x20(%rdx), %rdx
cmpl %ecx, (%rdx)
jle 0xe519
jmp 0xe872
cmpl $0x2, %ecx
jne 0xe71d
movq 0x8(%rax), %rbx
addq $0x4, %rbx
leaq 0x4eef(%rip), %rsi      # 0x1357a
movq %rbx, %rdi
callq 0x9050
testl %eax, %eax
je 0xe8af
leaq 0x4edd(%rip), %rsi      # 0x1357f
movq %rbx, %rdi
callq 0x9050
testl %eax, %eax
je 0xe8b7
leaq 0x5777(%rip), %rsi      # 0x13e30
movq %rbx, %rdi
callq 0x9050
testl %eax, %eax
je 0xe8c6
leaq 0x576b(%rip), %rsi      # 0x13e3b
movq %rbx, %rdi
callq 0x9050
movq (%r14), %rdi
testl %eax, %eax
je 0xe8d5
leaq 0x5a22(%rip), %rcx      # 0x1410c
movq %rbx, %rsi
jmp 0xe72e
leaq 0x572d(%rip), %rsi      # 0x13e23
leaq 0x5a0f(%rip), %rcx      # 0x1410c
movq %rcx, %rdx
callq 0xcad8
movq (%r15), %rax
movl $0x0, 0x20(%rax)
movl (%r12), %ecx
movl %ecx, 0x38(%rax)
callq 0xf919
jmp 0xe736
movq (%r14), %rdi
leaq 0x56fc(%rip), %rsi      # 0x13e23
leaq 0x59de(%rip), %rcx      # 0x1410c
movq %rcx, %rdx
callq 0xcad8
movq 0xee6b(%rip), %rdi      # 0x1d5a8
movl (%r12), %esi
callq 0xe46a
movq %rax, 0xee5b(%rip)      # 0x1d5a8
movq (%r15), %rax
movl 0x14(%rax), %ebx
leaq 0xe936(%rip), %rax      # 0x1d090
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0xea32(%rip), %r13      # 0x1d198
movq %rcx, (%r13)
callq 0x960c
movq 0xee3a(%rip), %rax      # 0x1d5b0
leaq 0xe843(%rip), %rbp      # 0x1cfc0
cmpq (%rbp), %rax
je 0xe7fe
movq 0xee2e(%rip), %rax      # 0x1d5b8
movl (%rax), %eax
cmpl (%r12), %eax
jne 0xe7fe
movq 0xee17(%rip), %rdi      # 0x1d5b0
movl $0x1, %esi
callq 0x127da
movq %rax, 0xee06(%rip)      # 0x1d5b0
movq 0x20(%rax), %r14
cmpq (%rbp), %rax
je 0xe7e2
movq 0xedfd(%rip), %rdi      # 0x1d5b8
cmpl $0x0, 0x8(%rdi)
jne 0xe7e2
cmpl $0x0, 0x8(%r14)
jne 0xe7e2
movl (%r14), %eax
cmpl (%r12), %eax
jne 0xe7e2
movl 0x18(%rdi), %eax
addl 0x4(%rdi), %eax
cmpl 0x4(%r14), %eax
jne 0xe7e2
movq %r14, %rsi
jmp 0xe7eb
movq 0xedcf(%rip), %rdi      # 0x1d5b8
xorl %esi, %esi
movl %ebx, %edx
callq 0xe323
movq %r14, 0xedbf(%rip)      # 0x1d5b8
movl (%r14), %eax
jmp 0xe78c
leaq 0xe763(%rip), %r14      # 0x1cf68
cmpl $0x3, (%r14)
jne 0xe822
leaq 0xe876(%rip), %rax      # 0x1d088
movq (%rax), %rax
movl (%rax), %eax
cmpl (%r12), %eax
jne 0xe822
callq 0xca6d
leaq 0xe85f(%rip), %rbx      # 0x1d088
movq (%rbx), %rax
movl (%rax), %ecx
cmpl (%r12), %ecx
jne 0xe84a
movq 0x8(%rax), %rdi
subq (%r13), %rdi
xorl %esi, %esi
callq 0xcfba
callq 0xd63e
jmp 0xe829
movq (%r15), %rax
movl 0x10(%rax), %edi
subq (%r13), %rdi
xorl %esi, %esi
callq 0xcfba
cmpl $0x3, (%r14)
jne 0xe872
callq 0xca6d
leaq 0xe68b(%rip), %rax      # 0x1cef8
cmpl $0x2, (%rax)
jne 0xe881
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe920(%rip), %rax      # 0x1d1a8
movq (%rax), %rdi
leaq 0x55b4(%rip), %rsi      # 0x13e46
leaq 0x5873(%rip), %rcx      # 0x1410c
movq %rcx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcad8
movq (%r14), %rdi
jmp 0xe61d
movq (%r14), %rdi
leaq 0x556a(%rip), %rsi      # 0x13e2b
jmp 0xe727
movq (%r14), %rdi
leaq 0x5566(%rip), %rsi      # 0x13e36
jmp 0xe727
leaq 0x5565(%rip), %rsi      # 0x13e41
jmp 0xe727