// File: /workspace/github_c_makefile_star2_O1/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 $0x98, %rsp
callq 0xf478
movzbl %al, %r13d
movl %r13d, %ebp
shrl $0x5, %ebp
cmpb $0x1f, %r13b
ja 0x11d83
callq 0xf4ac
callq 0xf478
cmpl $0x6, %ebp
jne 0x11d97
callq 0xf478
callq 0xf4ac
callq 0xf4ac
callq 0xf4ac
movw %ax, 0x6(%rsp)
movb $0x0, 0x10(%rsp)
leaq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0xf55d
leaq 0xb1d6(%rip), %rbx      # 0x1cf90
movq (%rbx), %rsi
leaq -0x348(%rip), %rdx      # 0x11a7c
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x1275f
movq %rax, %r12
testq %rax, %rax
jne 0x11de2
leaq 0x1768(%rip), %rdi      # 0x13545
callq 0x12808
leaq 0x68(%rsp), %r15
movl (%r15), %eax
movl %eax, 0xc(%rsp)
movq %r15, %rdi
callq 0xf55d
movq (%rbx), %rsi
leaq -0x384(%rip), %rdx      # 0x11a7c
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x1275f
movq %rax, %r15
testq %rax, %rax
jne 0x11e1e
leaq 0x2d52(%rip), %rdi      # 0x14b6b
callq 0x12808
movl %r13d, %ebx
shrl $0x2, %ebx
movl %r13d, %r14d
leaq 0x68(%rsp), %r13
movq %r13, %rdi
callq 0xf55d
leaq 0xb155(%rip), %rax      # 0x1cf90
movq (%rax), %rsi
leaq -0x3c9(%rip), %rdx      # 0x11a7c
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x1275f
testq %rax, %rax
jne 0x11e60
leaq 0x2d25(%rip), %rdi      # 0x14b80
callq 0x12808
andl $0x7, %ebx
andl $0x1, %r14d
leaq 0xb08a(%rip), %rax      # 0x1cef8
cmpl $0x0, (%rax)
movl %r14d, 0x8(%rsp)
je 0x11eb2
cmpb $0x0, 0x4(%r15)
movl %ebp, %eax
leaq 0xaf6a(%rip), %rcx      # 0x1cdf0
movq (%rcx,%rax,8), %rdx
movl %ebx, %eax
leaq 0xaf9d(%rip), %rcx      # 0x1ce30
movq (%rcx,%rax,8), %rcx
je 0x11f92
leaq 0x4(%r15), %r8
leaq 0x2d26(%rip), %rsi      # 0x14bce
leaq 0x10(%rsp), %rdi
jmp 0x11fb6
movl %r14d, %r13d
leaq 0xb034(%rip), %r14      # 0x1cef0
cmpl $0x0, (%r14)
jne 0x11f19
leaq 0x26f3(%rip), %rsi      # 0x145bc
leaq 0x223c(%rip), %r13      # 0x1410c
leaq 0x2cc0(%rip), %rcx      # 0x14b97
movq %r13, %rdi
movq %r13, %rdx
callq 0xcad8
leaq 0x26d9(%rip), %rsi      # 0x145c2
leaq 0x2cc0(%rip), %rcx      # 0x14bb0
movq %r13, %rdi
movq %r13, %rdx
movl 0x8(%rsp), %r13d
callq 0xcad8
callq 0xca6d
movl $0x1, (%r14)
leaq 0xafd1(%rip), %rax      # 0x1cee4
movl $0x182, (%rax)          # imm = 0x182
cmpb $0x0, 0x4(%r15)
leaq 0xafbf(%rip), %rax      # 0x1cee4
movl (%rax), %eax
movl %ebp, %ecx
leaq 0xaec0(%rip), %rdx      # 0x1cdf0
movq (%rdx,%rcx,8), %rdx
movl %ebx, %ecx
leaq 0xaef3(%rip), %rsi      # 0x1ce30
movq (%rsi,%rcx,8), %rcx
je 0x11f71
leaq 0x4(%r15), %r9
cmpl $0x182, %eax            # imm = 0x182
jne 0x11fa7
movl %r13d, %eax
leaq 0xaf18(%rip), %rsi      # 0x1ce70
movq (%rsi,%rax,8), %r8
leaq 0x2c68(%rip), %rsi      # 0x14bcb
leaq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x91b0
jmp 0x11fbd
cmpl $0x182, %eax            # imm = 0x182
jne 0x11f92
movl %r13d, %eax
leaq 0xaeee(%rip), %rsi      # 0x1ce70
movq (%rsi,%rax,8), %r8
leaq 0x2c4c(%rip), %rsi      # 0x14bd9
jmp 0x11ea8
leaq 0x2c43(%rip), %rsi      # 0x14bdc
leaq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x91b0
jmp 0x11fbd
leaq 0x2c20(%rip), %rsi      # 0x14bce
leaq 0x10(%rsp), %rdi
movq %r9, %r8
xorl %eax, %eax
callq 0x91b0
leaq 0xaf34(%rip), %rax      # 0x1cef8
cmpl $0x2, (%rax)
je 0x12006
leaq 0x4(%r12), %r13
leaq 0x1e4e(%rip), %rsi      # 0x13e23
leaq 0x2130(%rip), %rbp      # 0x1410c
leaq 0x10(%rsp), %rdx
movq %r13, %rdi
movq %rbp, %rcx
callq 0xcad8
leaq 0x1e53(%rip), %rsi      # 0x13e46
movq %r13, %rdi
movq %rbp, %rdx
movq %rbp, %rcx
callq 0xcad8
callq 0xca6d
movb 0x4(%r12), %bl
leaq 0x10(%rsp), %r13
movq %r13, %rcx
testb %bl, %bl
je 0x1203f
callq 0x9030
addq $0x5, %r12
leaq 0x10(%rsp), %rcx
movq (%rax), %rdx
movsbq %bl, %rsi
movb (%rdx,%rsi,4), %dl
movb %dl, (%rcx)
incq %rcx
movb (%r12), %bl
incq %r12
testb %bl, %bl
jne 0x12025
movb $0x0, (%rcx)
leaq 0x1531(%rip), %rsi      # 0x1357a
movq %r13, %rdi
callq 0x91e0
movq %rax, %r12
leaq 0x2b87(%rip), %rsi      # 0x14be2
movq %r13, %rdi
callq 0x91e0
movq %rax, %rbp
movb 0x4(%r15), %bl
testb %bl, %bl
je 0x12099
callq 0x9030
movq %r15, %rcx
addq $0x5, %rcx
leaq 0x10(%rsp), %r13
movq (%rax), %rdx
movsbq %bl, %rsi
movb (%rdx,%rsi,4), %dl
movb %dl, (%r13)
incq %r13
movb (%rcx), %bl
incq %rcx
testb %bl, %bl
jne 0x1207f
movb $0x0, (%r13)
leaq 0x14d5(%rip), %rsi      # 0x1357a
leaq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0x91e0
movq %rax, %r14
leaq 0x2b2d(%rip), %rsi      # 0x14be9
movq %r13, %rdi
callq 0x91e0
orq %r14, %rax
orq %rbp, %rax
xorl %r8d, %r8d
orq %r12, %rax
setne %r8b
movzwl 0x6(%rsp), %edx
movl 0xc(%rsp), %edi
movq %r15, %rsi
movl 0x8(%rsp), %ecx
callq 0x11cb6
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop