// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/crossassemblers/macro11/dumpobj.c
// Function: got_gsd
void got_gsd(
    char *cp,
    int len)
{
    int             i;
    char           *gsdline;

    for (i = 2; i < len; i += 8) {
        char            name[8];
        unsigned        value;
        unsigned        flags;

        gsdline = malloc(256);
        if (gsdline == NULL) {
            fprintf(stderr, "Out of memory\n");
            exit(EXIT_FAILURE);
        }

        unrad50(WORD(cp + i), name);
        unrad50(WORD(cp + i + 2), name + 3);
        name[6] = 0;

        value = WORD(cp + i + 6);
        flags = cp[i + 4] & 0xff;

        switch (cp[i + 5] & 0xff) {
        case 0:
            sprintf(gsdline, "\tMODNAME %s=%o flags=%o\n", name, value, flags);
            break;
        case 1:
            sprintf(gsdline, "\tCSECT %s=%o flags=%o\n", name, value, flags);
            break;
        case 2:
            sprintf(gsdline, "\tISD %s=%o flags=%o\n", name, value, flags);
            break;
        case 3:
            sprintf(gsdline, "\tXFER %s=%o flags=%o\n", name, value, flags);
            xferad = value;
            break;
        case 4:
            sprintf(gsdline, "\tGLOBAL %s=%o %s%s%s %s flags=%o\n", name, value,
                    flags &   01 ? "WEAK " : "",
                    flags &   04 ? "LIB "  : "",
                    flags &  010 ? "DEF"   : "REF",
                    flags &  040 ? "REL"   : "ABS",
                    flags);
            break;
        case 5:
            sprintf(gsdline, "\tPSECT %s=%o %s%s %s %s %s %s %s flags=%o\n", name, value,
                    flags &   01 ? "SAV " : "",
                    flags &   02 ? "LIB " : "",
                    flags &   04 ? "OVR"  : "CON",
                    flags &  020 ? "RO"   : "RW",
                    flags &  040 ? "REL"  : "ABS",
                    flags & 0100 ? "GBL"  : "LCL",
                    flags & 0200 ? "D"    : "I",
                    flags);
            psects[psectid] = strdup(name);
            trim(psects[psectid++]);
            psectid %= NPSECTS;
            break;
        case 6:
            sprintf(gsdline, "\tIDENT %s=%o flags=%o\n", name, value, flags);
            break;
        case 7:
            sprintf(gsdline, "\tVSECT %s=%o flags=%o\n", name, value, flags);
            break;
        case 010:
            sprintf(gsdline, "\tCompletion Routine Name %s=%o flags=%o\n", name, value, flags);
            break;
        default:
            sprintf(gsdline, "\t***Unknown GSD entry type %d flags=%o\n", cp[i + 5] & 0xff, flags);
            break;
        }

        gsdline = realloc(gsdline, strlen(gsdline) + 1);
        add_gsdline(gsdline);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0xb(%rsp), %r12
movslq %esi, %r15
pushq $0x2
popq %r14
movq %r15, 0x10(%rsp)
cmpq %r15, %r14
jge 0x1a5a
movl $0x100, %edi            # imm = 0x100
callq 0x1130
testq %rax, %rax
je 0x1a69
movq %rax, %r13
movzwl (%rbx,%r14), %edi
leaq 0x8(%rsp), %rsi
callq 0x239e
movzwl 0x2(%rbx,%r14), %edi
movq %r12, %rsi
callq 0x239e
movb $0x0, 0xe(%rsp)
movzbl 0x4(%rbx,%r14), %r10d
movzbl 0x5(%rbx,%r14), %edx
cmpq $0x8, %rdx
ja 0x1a44
movzwl 0x6(%rbx,%r14), %ebp
leaq 0x180c(%rip), %rcx      # 0x3004
movslq (%rcx,%rdx,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r13, %rdi
leaq 0x19a8(%rip), %rsi      # 0x31b3
jmp 0x1a0e
testb $0x1, %r10b
leaq 0x1a15(%rip), %r8       # 0x3230
leaq 0x18c8(%rip), %rax      # 0x30ea
cmoveq %rax, %r8
testb $0x4, %r10b
leaq 0x1a05(%rip), %r9       # 0x3236
cmoveq %rax, %r9
testb $0x8, %r10b
leaq 0x19fb(%rip), %r11      # 0x323b
leaq 0x19f8(%rip), %rax      # 0x323f
cmoveq %rax, %r11
testb $0x20, %r10b
leaq 0x19ed(%rip), %r15      # 0x3243
leaq 0x19ea(%rip), %rax      # 0x3247
cmoveq %rax, %r15
subq $0x8, %rsp
movq %r13, %rdi
leaq 0x199f(%rip), %rsi      # 0x320e
leaq 0x10(%rsp), %rdx
movl %ebp, %ecx
xorl %eax, %eax
pushq %r10
pushq %r15
movq 0x28(%rsp), %r15
pushq %r11
callq 0x1160
addq $0x20, %rsp
jmp 0x1a1f
movq %r13, %rdi
leaq 0x1948(%rip), %rsi      # 0x31e3
jmp 0x1a0e
movq %r13, %rdi
leaq 0x194e(%rip), %rsi      # 0x31f8
leaq 0x8(%rsp), %rdx
movl %ebp, %ecx
movl %r10d, %r8d
xorl %eax, %eax
callq 0x1160
movl %ebp, 0x382f(%rip)      # 0x50f0
jmp 0x1a1f
movq %r13, %rdi
leaq 0x19da(%rip), %rsi      # 0x32aa
jmp 0x1a0e
movq %r13, %rdi
leaq 0x18ed(%rip), %rsi      # 0x31cc
jmp 0x1a0e
testb $0x1, %r10b
leaq 0x1987(%rip), %r8       # 0x3276
leaq 0x17f4(%rip), %rax      # 0x30ea
cmoveq %rax, %r8
testb $0x2, %r10b
leaq 0x1931(%rip), %r9       # 0x3236
cmoveq %rax, %r9
testb $0x4, %r10b
leaq 0x1967(%rip), %rcx      # 0x327b
leaq 0x1964(%rip), %rax      # 0x327f
cmoveq %rax, %rcx
movq %rcx, 0x20(%rsp)
testb $0x10, %r10b
leaq 0x1954(%rip), %rcx      # 0x3283
leaq 0x1950(%rip), %rax      # 0x3286
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
testb $0x20, %r10b
leaq 0x18f9(%rip), %r12      # 0x3243
leaq 0x18f6(%rip), %rax      # 0x3247
cmoveq %rax, %r12
testb $0x40, %r10b
leaq 0x1929(%rip), %r11      # 0x3289
leaq 0x1926(%rip), %rax      # 0x328d
cmoveq %rax, %r11
testb %r10b, %r10b
leaq 0x1c65(%rip), %r15      # 0x35da
leaq 0x1915(%rip), %rax      # 0x3291
cmovnsq %rax, %r15
movq %r13, %rdi
leaq 0x18c1(%rip), %rsi      # 0x324b
leaq 0x8(%rsp), %rdx
movl %ebp, %ecx
xorl %eax, %eax
pushq %r10
pushq %r15
movq 0x20(%rsp), %r15
pushq %r11
pushq %r12
leaq 0x2b(%rsp), %r12
pushq 0x38(%rsp)
pushq 0x48(%rsp)
callq 0x1160
addq $0x30, %rsp
leaq 0x8(%rsp), %rdi
callq 0x1190
movslq 0x3779(%rip), %rcx      # 0x5140
leaq 0x37a2(%rip), %rdx      # 0x5170
movq %rax, (%rdx,%rcx,8)
incl %ecx
movl %ecx, 0x3766(%rip)      # 0x5140
movq %rax, %rdi
callq 0x16bc
movl 0x3758(%rip), %eax      # 0x5140
cltd
movl $0x100, %ecx            # imm = 0x100
idivl %ecx
movl %edx, 0x374a(%rip)      # 0x5140
jmp 0x1a1f
movq %r13, %rdi
leaq 0x1891(%rip), %rsi      # 0x3293
jmp 0x1a0e
movq %r13, %rdi
leaq 0x18b3(%rip), %rsi      # 0x32c1
leaq 0x8(%rsp), %rdx
movl %ebp, %ecx
movl %r10d, %r8d
xorl %eax, %eax
callq 0x1160
movq %r13, %rdi
callq 0x10a0
leaq 0x1(%rax), %rsi
movq %r13, %rdi
callq 0x1140
movq %rax, %rdi
callq 0x16df
addq $0x8, %r14
jmp 0x1794
movq %r13, %rdi
leaq 0x189c(%rip), %rsi      # 0x32ea
movl %r10d, %ecx
xorl %eax, %eax
callq 0x1160
jmp 0x1a1f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3588(%rip), %rax      # 0x4ff8
movq (%rax), %rcx
leaq 0x172a(%rip), %rdi      # 0x31a4
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x1180
pushq $0x1
popq %rdi
callq 0x1170