// File: /workspace/github_c_makefile_star2_O3/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 0xf599
movl %eax, %r15d
movl (%r14), %eax
movl %eax, 0x24(%rsp)
leaq 0xb9f8(%rip), %rax      # 0x1cf90
movq (%rax), %rsi
leaq 0x566(%rip), %rdx       # 0x11b08
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x1280f
movq %rax, %r14
testq %rax, %rax
jne 0x115c0
leaq 0x344d(%rip), %rdi      # 0x14a08
callq 0x128bc
addq $0x4, %r14
movq %r14, 0x18(%rsp)
movb $0x0, 0xd050(%rip)      # 0x1e620
notl %r15d
movswq %r15w, %r12
leaq 0x343f(%rip), %rax      # 0x14a1d
addq %rbx, %r12
je 0x11762
movq %rax, 0x10(%rsp)
leaq 0xd02d(%rip), %r13      # 0x1e620
leaq 0x2b12(%rip), %r14      # 0x1410c
decq %r12
callq 0xf4b4
cmpb $-0x1, %al
jne 0x11721
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0xf599
movl %eax, %ebp
leaq 0xb978(%rip), %rax      # 0x1cf98
movq (%rax), %rsi
movq %rbx, %rdi
leaq 0x6ff(%rip), %rdx       # 0x11d2c
xorl %ecx, %ecx
callq 0x1280f
movq %rax, %rbx
testq %rax, %rax
jne 0x11648
leaq 0x33e0(%rip), %rdi      # 0x14a23
callq 0x128bc
movl 0x4(%rbx), %eax
movl %eax, 0x28(%rsp)
leaq 0xb93a(%rip), %rax      # 0x1cf90
movq (%rax), %rsi
leaq 0x28(%rsp), %rdi
leaq 0x4a3(%rip), %rdx       # 0x11b08
xorl %ecx, %ecx
callq 0x1280f
movq %rax, %rbx
movq %r13, %rdi
callq 0x90b0
movq %rax, %r15
addq $0x4, %rbx
movq %rbx, %rdi
callq 0x90b0
addq %r15, %rax
cmpq $0x33, %rax
jb 0x116ea
movw %bp, 0xe(%rsp)
movq %r13, %rdi
callq 0x90b0
movw $0x5c, (%rax,%r13)
movq %r13, %rbp
movq 0x18(%rsp), %r13
movq %r13, %rdi
leaq 0x3380(%rip), %rsi      # 0x14a35
callq 0x9120
testl %eax, %eax
je 0x116d1
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0xcb44
movb $0x0, 0xcf48(%rip)      # 0x1e620
movq %r14, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbp, %r13
movzwl 0xe(%rsp), %ebp
movswq %bp, %rax
subq %rax, %r12
movq %r13, %rdi
movq %rbx, %rsi
callq 0x91a0
testq %r12, %r12
je 0x11767
movq %r13, %rdi
callq 0x90b0
movw $0x202c, (%rax,%r13)    # imm = 0x202C
movb $0x0, 0x2(%rax,%r13)
testq %r12, %r12
jne 0x115fa
jmp 0x11767
movzbl %al, %edi
leal -0xfa(%rdi), %eax
cmpl $0x4, %eax
ja 0x1175b
leaq 0x32be(%rip), %rcx      # 0x149f4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x940d
jmp 0x11716
callq 0x9497
jmp 0x11716
callq 0x943b
jmp 0x11716
callq 0x9469
jmp 0x11716
callq 0x94c5
jmp 0x11716
movq %rax, 0x10(%rsp)
leaq 0x32c7(%rip), %rsi      # 0x14a35
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x9120
testl %eax, %eax
je 0x1179f
leaq 0xce9a(%rip), %rdx      # 0x1e620
leaq 0x297f(%rip), %rcx      # 0x1410c
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xcb44
callq 0xcad9
movl 0x24(%rsp), %edi
callq 0x1152e
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop