// File: /workspace/github_c_makefile_star2_O2/Nico01[P]obj2asm/rec_segdef.c
// Function: segdef
void segdef()
{
    NAME_T          search;
    NAME_T          *segment;
    NAME_T          *class;
    NAME_T          *overlay;
    char            operands[80];
    uchar           acbp;
    int             align;
    int             combine;
    int             big;
    int             page;
    int             frame;
    int             ltl;
    uchar           offset;
    int             max_len;
    int             grp_off;
    word            length;
    int             name_idx;
    int             code;

    acbp = get_byte();

    align   = (acbp & 0xE0) >> 5;
    combine = (acbp & 0x1C) >> 2;
    big     = (acbp & 0x02) >> 1;
    page    = (acbp & 0x01);

    if ( align == 0 ) {
        frame  = get_word();
        offset = get_byte();
    }

    if ( align == 6 ) {
        ltl = get_byte();
        max_len = get_word();
        grp_off = get_word();
    }

    length = get_word();                    /* Length of segment */

#ifdef DEBUG
printf("Length of segment = %04X\n",length );
#endif

    operands[0] = '\0';                     /* No operands yet */

    get_index( &search.index );
    segment = (NAME_T *)find( (char *)&search, name_tree, TC name_compare, NULL );
    if ( segment == NULL ) fmt_error( "Undefined segment name" );
    name_idx = search.index;

    get_index( &search.index );
    class = (NAME_T *)find( (char *)&search, name_tree, TC name_compare, NULL );
    if ( class == NULL ) fmt_error( "Undefined class name" );

    get_index( &search.index );
    overlay = (NAME_T *)find( (char *)&search, name_tree, TC name_compare, NULL );
    if ( overlay == NULL ) fmt_error( "Undefined overlay name" );

    if ( compatibility == 0 ) {
        if ( !processor_type_comment_occurred ) {
            out_line( "", ".386p", "", "Enable USE32/USE16 usage" );
            out_line( "", ".387", "", "Enable floating point also" );
            out_newline();
            processor_type_comment_occurred = TRUE;
            processor_mode = 386;
        }

        /* page will now be 0 only for 16-bit segments */
        /* before 32-bit segments                      */

        if ( strlen(class->name) ) {
            if ( processor_mode == 386 ) {
                sprintf( operands, "%s %s %s '%s'", al_text[align],
                        cb_text[combine], use_text[page], class->name );
            } else {
                sprintf( operands, "%s %s '%s'", al_text[align],
                            cb_text[combine], class->name );
            }
        } else {
            if ( processor_mode == 386 ) {
                sprintf( operands, "%s %s %s", al_text[align],
                            cb_text[combine], use_text[page] );
            } else {
                sprintf( operands, "%s %s", al_text[align],
                                              cb_text[combine] );
            }
        }
    } else {
        if ( strlen(class->name) ) {
            sprintf( operands, "%s %s '%s'", al_text[align], 
                                            cb_text[combine], class->name );
        } else {
            sprintf( operands, "%s %s", al_text[align], cb_text[combine] );
        }
    }

    if ( compatibility == 2 ) {
        /*
        ** No pre-output segment listing for RASM86 files
        */
    } else {
        out_line( segment->name, "SEGMENT", operands, "" );
        out_line( segment->name, "ENDS", "", "" );
        out_newline();
    }

    code = FALSE;
    upstr( operands, segment->name );
    if ( strstr(operands,"CODE") ) {
        code = TRUE;
    }
    if ( strstr(operands, "DRIVER") ) {
        code = TRUE;
    }

    upstr( operands, class->name );
    if ( strstr(operands,"CODE") ) {
        code = TRUE;
    }
    if ( strstr(operands,"TEXT") ) {
        code = TRUE;
    }

    seg_insert( name_idx, class, length, page, code );
    big     = big;
    frame = frame;
    offset = offset;
    ltl = ltl;
    max_len = max_len;
    grp_off = grp_off;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
callq 0xed18
movzbl %al, %ebx
movl %ebx, %ebp
shrl $0x5, %ebp
cmpb $0x1f, %bl
ja 0x115d9
callq 0xed6b
callq 0xed18
cmpl $0x6, %ebp
jne 0x115ed
callq 0xed18
callq 0xed6b
callq 0xed6b
callq 0xed6b
movw %ax, 0xe(%rsp)
movb $0x0, 0x20(%rsp)
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0xee13
leaq 0xa980(%rip), %r12      # 0x1bf90
movq (%r12), %rsi
leaq -0x32f(%rip), %rdx      # 0x112ec
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x11e3b
movq %rax, %r14
testq %rax, %rax
jne 0x11639
leaq 0xf11(%rip), %rdi       # 0x12545
callq 0x11eec
leaq 0x78(%rsp), %r15
movl (%r15), %eax
movl %eax, 0x1c(%rsp)
movq %r15, %rdi
callq 0xee13
movq (%r12), %rsi
leaq -0x36c(%rip), %rdx      # 0x112ec
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x11e3b
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x11678
leaq 0x24fc(%rip), %rdi      # 0x13b6f
callq 0x11eec
movl %ebx, %r15d
shrl $0x2, %r15d
leaq 0x78(%rsp), %r13
movq %r13, %rdi
callq 0xee13
movq (%r12), %rsi
leaq -0x3ab(%rip), %rdx      # 0x112ec
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x11e3b
testq %rax, %rax
jne 0x116b2
leaq 0x24d7(%rip), %rdi      # 0x13b84
callq 0x11eec
andl $0x7, %r15d
andl $0x1, %ebx
leaq 0xa838(%rip), %r13      # 0x1bef8
cmpl $0x0, (%r13)
je 0x11710
movq 0x10(%rsp), %r12
cmpb $0x0, 0x4(%r12)
movl %ebp, %eax
leaq 0xa715(%rip), %rcx      # 0x1bdf0
movq (%rcx,%rax,8), %rdx
movl %r15d, %eax
leaq 0xa747(%rip), %rcx      # 0x1be30
movq (%rcx,%rax,8), %rcx
je 0x117df
leaq 0x4(%r12), %r8
leaq 0x24d3(%rip), %rsi      # 0x13bd2
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x91b0
jmp 0x117f2
leaq 0xa7d9(%rip), %r12      # 0x1bef0
cmpl $0x0, (%r12)
jne 0x11778
leaq 0x1e97(%rip), %rsi      # 0x135bc
leaq 0x19e0(%rip), %r13      # 0x1310c
leaq 0x2468(%rip), %rcx      # 0x13b9b
movq %r13, %rdi
movq %r13, %rdx
callq 0xc585
leaq 0x1e7d(%rip), %rsi      # 0x135c2
leaq 0x2468(%rip), %rcx      # 0x13bb4
movq %r13, %rdi
movq %r13, %rdx
leaq 0xa79f(%rip), %r13      # 0x1bef8
callq 0xc585
callq 0xc54f
movl $0x1, (%r12)
leaq 0xa772(%rip), %rax      # 0x1bee4
movl $0x182, (%rax)          # imm = 0x182
movq 0x10(%rsp), %rdi
cmpb $0x0, 0x4(%rdi)
leaq 0xa75c(%rip), %rax      # 0x1bee4
movl (%rax), %eax
movl %ebp, %ecx
leaq 0xa65d(%rip), %rdx      # 0x1bdf0
movq (%rdx,%rcx,8), %rdx
movl %r15d, %ecx
leaq 0xa68f(%rip), %rsi      # 0x1be30
movq (%rsi,%rcx,8), %rcx
je 0x118f9
leaq 0x4(%rdi), %r9
cmpl $0x182, %eax            # imm = 0x182
movq %rdi, %r15
jne 0x11922
movl %ebx, %eax
leaq 0xa6aa(%rip), %rsi      # 0x1be70
movq (%rsi,%rax,8), %r8
leaq 0x23fe(%rip), %rsi      # 0x13bcf
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x91b0
jmp 0x117f5
leaq 0x23fa(%rip), %rsi      # 0x13be0
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x91b0
movq %r12, %r15
cmpl $0x2, (%r13)
je 0x11838
leaq 0x4(%r14), %r13
leaq 0x161c(%rip), %rsi      # 0x12e23
leaq 0x18fe(%rip), %rbp      # 0x1310c
leaq 0x20(%rsp), %rdx
movq %r13, %rdi
movq %rbp, %rcx
callq 0xc585
leaq 0x1621(%rip), %rsi      # 0x12e46
movq %r13, %rdi
movq %rbp, %rdx
movq %rbp, %rcx
callq 0xc585
callq 0xc54f
addq $0x4, %r14
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x1156b
leaq 0xd27(%rip), %rbp       # 0x1257a
movq %r13, %rdi
movq %rbp, %rsi
callq 0x91e0
movq %rax, %r12
leaq 0x237e(%rip), %rsi      # 0x13be6
movq %r13, %rdi
callq 0x91e0
movq %rax, %r14
movq %r15, %rsi
addq $0x4, %rsi
movq %r13, %rdi
callq 0x1156b
movq %r13, %rdi
movq %rbp, %rsi
callq 0x91e0
movq %rax, %rbp
leaq 0x2356(%rip), %rsi      # 0x13bed
movq %r13, %rdi
callq 0x91e0
movq %rbp, %xmm0
movq %rax, %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movq %r12, %xmm0
movq %r14, %xmm2
punpcklqdq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0]
por %xmm1, %xmm2
pxor %xmm0, %xmm0
pcmpeqd %xmm2, %xmm0
movmskps %xmm0, %eax
xorl %r8d, %r8d
xorl $0xf, %eax
setne %r8b
movzwl 0xe(%rsp), %edx
movl 0x1c(%rsp), %edi
movq %r15, %rsi
movl %ebx, %ecx
callq 0x1150a
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x182, %eax            # imm = 0x182
jne 0x1193d
movl %ebx, %eax
leaq 0xa567(%rip), %rsi      # 0x1be70
movq (%rsi,%rax,8), %r8
leaq 0x22c9(%rip), %rsi      # 0x13bdd
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x91b0
jmp 0x11950
leaq 0x22a9(%rip), %rsi      # 0x13bd2
leaq 0x20(%rsp), %rdi
movq %r9, %r8
xorl %eax, %eax
callq 0x91b0
jmp 0x117f5
leaq 0x229c(%rip), %rsi      # 0x13be0
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x91b0
movq 0x10(%rsp), %r15
jmp 0x117f5
nop