// File: /workspace/github_c_makefile_star2_O1/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 0xf55d
movl %eax, %r15d
movl (%r14), %eax
movl %eax, 0x24(%rsp)
leaq 0xba88(%rip), %rax      # 0x1cf90
movq (%rax), %rsi
leaq 0x56a(%rip), %rdx       # 0x11a7c
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x1275f
movq %rax, %r14
testq %rax, %rax
jne 0x11530
leaq 0x34dd(%rip), %rdi      # 0x14a08
callq 0x12808
addq $0x4, %r14
movq %r14, 0x18(%rsp)
movb $0x0, 0xd0e0(%rip)      # 0x1e620
notl %r15d
movswq %r15w, %r12
leaq 0x34cf(%rip), %rax      # 0x14a1d
addq %rbx, %r12
je 0x116d7
movq %rax, 0x10(%rsp)
leaq 0xd0bd(%rip), %r13      # 0x1e620
leaq 0x2ba2(%rip), %r14      # 0x1410c
decq %r12
callq 0xf478
cmpb $-0x1, %al
jne 0x11696
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0xf55d
movl %eax, %ebp
leaq 0xba08(%rip), %rax      # 0x1cf98
movq (%rax), %rsi
movq %rbx, %rdi
leaq 0x703(%rip), %rdx       # 0x11ca0
xorl %ecx, %ecx
callq 0x1275f
movq %rax, %rbx
testq %rax, %rax
jne 0x115b8
leaq 0x3470(%rip), %rdi      # 0x14a23
callq 0x12808
movl 0x4(%rbx), %eax
movl %eax, 0x28(%rsp)
leaq 0xb9ca(%rip), %rax      # 0x1cf90
movq (%rax), %rsi
leaq 0x28(%rsp), %rdi
leaq 0x4a7(%rip), %rdx       # 0x11a7c
xorl %ecx, %ecx
callq 0x1275f
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 0x1165a
movw %bp, 0xe(%rsp)
movq %r13, %rdi
callq 0x90b0
movw $0x5c, (%rax,%r13)
movq %r13, %rbp
movq 0x18(%rsp), %r13
movq %r13, %rdi
leaq 0x3410(%rip), %rsi      # 0x14a35
callq 0x9120
testl %eax, %eax
je 0x11641
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0xcad8
movb $0x0, 0xcfd8(%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 0x11688
movq %r13, %rdi
callq 0x90b0
movw $0x202c, (%rax,%r13)    # imm = 0x202C
movb $0x0, 0x2(%rax,%r13)
jmp 0x1168b
xorl %r12d, %r12d
testq %r12, %r12
jne 0x1156a
jmp 0x116dc
movzbl %al, %edi
leal -0xfa(%rdi), %eax
cmpl $0x4, %eax
ja 0x116d0
leaq 0x3349(%rip), %rcx      # 0x149f4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x940d
jmp 0x1168b
callq 0x9497
jmp 0x1168b
callq 0x943b
jmp 0x1168b
callq 0x9469
jmp 0x1168b
callq 0x94c5
jmp 0x1168b
movq %rax, 0x10(%rsp)
leaq 0x3352(%rip), %rsi      # 0x14a35
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x9120
testl %eax, %eax
je 0x11714
leaq 0xcf25(%rip), %rdx      # 0x1e620
leaq 0x2a0a(%rip), %rcx      # 0x1410c
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0xcad8
callq 0xca6d
movl 0x24(%rsp), %edi
callq 0x1149e
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop