// File: /workspace/github_c_makefile_star2_O2/Nico01[P]obj2asm/rec_grpdef.c
// Function: grpdef
void grpdef(size_t length)
{
    NAME_T  name_search;
    NAME_T  *group;
    NAME_T  *segment;
    SEG_T   seg_search;
    SEG_T   *seg;
    int     gcd;
    int     name_idx;
    char    *group_text;
    char    *group_name;

    length -= get_index( &name_search.index );

    name_idx = name_search.index;

    group = (NAME_T *)find( (char *)&name_search, name_tree, TC name_compare,
                                                                        NULL );

    if ( group == NULL ) {
        fmt_error("Undefined name index");
    }

    group_text = "GROUP";
    group_name = group->name;
    grp_operands[0] = '\0';

    --length;                  /* To account for check sum at bottom */
    while ( length ) {
        --length;
        gcd = get_byte();
        switch( gcd ) {
            case GRP_SI:  
                length -= get_index( &seg_search.index );
                seg = (SEG_T *)find( (char *)&seg_search,
                                             segment_tree, TC seg_compare, NULL );
                if ( seg == NULL ) fmt_error("Undefined segment" );
                name_search.index = seg->name;
                segment = (NAME_T *)find( (char *)&name_search,
                                         name_tree, TC name_compare, NULL );
                if ( strlen(grp_operands) + strlen(segment->name) > 50 ) {
                    strcat( grp_operands, "\\" );
                    if ( strcmp(group_name,"FLAT") != 0 ) {
                        out_line( group_name, group_text, grp_operands, "" );
                    }
                    group_name = "";
                    group_text = "";
                    grp_operands[0] = '\0';
                }

                strcat( grp_operands, segment->name );
                if ( length ) {
                    strcat( grp_operands, ", " );
                }
                break;
          case GRP_EI:
                fprintf( stderr, "Group Component: GRP_EI (External Index)\n");
                fmt_error("Un-implemented GROUP operands");
                break;
          case GRP_SCO:
                fprintf( stderr, "Group Component: GRP_SCO (Seg/Class/Ovly Index)\n");
                fmt_error("Un-implemented GROUP operands");
                break;
          case GRP_LTL:
                fprintf( stderr, "Group Component: GRP_LTL (LTL data)\n");
                fmt_error("Un-implemented GROUP operands");
                break;
          case GRP_ABS:
                fprintf( stderr, "Group Component: GRP_ABS (Absolute)\n");
                fmt_error("Un-implemented GROUP operands");
                break;
          default:
                fprintf( stderr, "Group Component: %02X (?)\n", gcd );
                fmt_error("Un-implemented GROUP operands");
                break;
        }
    }
    if ( strcmp(group_name,"FLAT") != 0 ) {
        out_line( group_name, group_text, grp_operands, "" );
        out_newline();          /* Leave a blank line after Group directive */
    }

    grp_insert( name_idx );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0xee13
movl %eax, %r15d
movl (%r14), %eax
movl %eax, 0x24(%rsp)
leaq 0xb216(%rip), %rax      # 0x1bf90
movq (%rax), %rsi
leaq 0x568(%rip), %rdx       # 0x112ec
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x11e3b
movq %rax, %r14
testq %rax, %rax
jne 0x10da2
leaq 0x2c6f(%rip), %rdi      # 0x13a0c
callq 0x11eec
addq $0x4, %r14
movq %r14, 0x18(%rsp)
movb $0x0, 0xc86e(%rip)      # 0x1d620
notl %r15d
movswq %r15w, %rax
addq %rbx, %rax
leaq 0x2c5e(%rip), %rcx      # 0x13a21
movq %rcx, 0x10(%rsp)
pushq $0x1
popq %r15
movq 0x7225(%rip), %r13      # 0x17ff8
leaq 0x2c1a(%rip), %r12      # 0x139f4
leaq 0xc83f(%rip), %rcx      # 0x1d620
movq %r15, %r14
subq %rax, %r14
pushq $0x24
popq %rbx
cmpq $0x1, %r14
je 0x10fb5
movq %rcx, %rbp
callq 0xed18
movzbl %al, %edx
leal -0xfa(%rdx), %eax
cmpl $0x5, %eax
ja 0x10e20
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r13), %rcx
leaq 0x2cbe(%rip), %rdi      # 0x13adc
jmp 0x10e3f
movq (%r13), %rdi
leaq 0x2cd6(%rip), %rsi      # 0x13b01
xorl %eax, %eax
callq 0x9140
jmp 0x10e69
movq (%r13), %rcx
leaq 0x2c78(%rip), %rdi      # 0x13ab7
movq %rbx, %rsi
jmp 0x10e61
movq (%r13), %rcx
leaq 0x2c37(%rip), %rdi      # 0x13a86
pushq $0x30
jmp 0x10e60
movq (%r13), %rcx
leaq 0x2be0(%rip), %rdi      # 0x13a3e
pushq $0x29
popq %rsi
movq %r15, %rdx
callq 0x91d0
leaq 0x2bf8(%rip), %rdi      # 0x13a68
callq 0x11eec
incq %r14
movq %rbp, %rcx
jmp 0x10dea
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0xee13
movw %ax, 0xe(%rsp)
leaq 0xb0ff(%rip), %rax      # 0x1bf98
movq (%rax), %rsi
movq %rbx, %rdi
leaq 0x64e(%rip), %rdx       # 0x114f4
xorl %ecx, %ecx
callq 0x11e3b
movq %rax, %r13
testq %rax, %rax
jne 0x10ec1
leaq 0x2b6b(%rip), %rdi      # 0x13a27
callq 0x11eec
movl 0x4(%r13), %eax
movl %eax, 0x28(%rsp)
leaq 0xb0c0(%rip), %rax      # 0x1bf90
movq (%rax), %rsi
leaq 0x28(%rsp), %rdi
leaq 0x40d(%rip), %rdx       # 0x112ec
xorl %ecx, %ecx
callq 0x11e3b
movq %rax, %r13
movq %rbp, %r15
movq %rbp, %rdi
callq 0x90b0
movq %rax, %rbx
addq $0x4, %r13
movq %r13, %rdi
callq 0x90b0
addq %rbx, %rax
cmpq $0x33, %rax
jb 0x10f64
movq %r15, %rdi
callq 0x90b0
movw $0x5c, (%rax,%r15)
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
leaq 0x2b0f(%rip), %rsi      # 0x13a39
callq 0x9120
testl %eax, %eax
leaq 0x21d4(%rip), %rax      # 0x1310c
je 0x10f53
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
movq %rax, %rbx
movq %rax, %rcx
callq 0xc585
movq %rbx, %rax
movb $0x0, 0xc6c6(%rip)      # 0x1d620
movq %rax, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movswq 0xe(%rsp), %rbx
negq %rbx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x91a0
movq %rbp, %rcx
movl $0x0, %eax
cmpq %r14, %rbx
pushq $0x1
popq %r15
movq 0x706a(%rip), %r13      # 0x17ff8
je 0x10de1
subq %r14, %rbx
movq %rbp, %rdi
callq 0x90b0
movq %rbp, %rcx
movw $0x202c, (%rax,%rbp)    # imm = 0x202C
movb $0x0, 0x2(%rax,%rbp)
movq %rbx, %rax
jmp 0x10de1
leaq 0x2a7d(%rip), %rsi      # 0x13a39
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x9120
testl %eax, %eax
je 0x10fed
leaq 0xc64c(%rip), %rdx      # 0x1d620
leaq 0x2131(%rip), %rcx      # 0x1310c
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xc585
callq 0xc54f
movl 0x24(%rsp), %edi
callq 0x10d12
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq