// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/crossassemblers/macro11/parse.c
// Function: get_symbol
char           *get_symbol(
    char *cp,
    char **endp,
    int *islocal)
{
    int             len;
    char           *symcp;
    int             digits = 0;

    cp = skipwhite(cp);                /* Skip leading whitespace */

    if (!issym((unsigned char)*cp))
        return NULL;

    digits = 0;
    if (isdigit((unsigned char)*cp))
        digits = 2;                    /* Think about digit count */

    for (symcp = cp + 1; issym((unsigned char)*symcp); symcp++) {
        if (!isdigit((unsigned char)*symcp)) /* Not a digit? */
            digits--;                  /* Make a note. */
    }

    if (digits == 2)
        return NULL;                   /* Not a symbol, it's a digit string */

    if (endp)
        *endp = symcp;

    len = (int) (symcp - cp);

    /* Now limit length */
    if (len > symbol_len)
        len = symbol_len;

    symcp = memcheck(malloc(len + 1));

    memcpy(symcp, cp, len);
    symcp[len] = 0;
    upcase(symcp);

    if (islocal) {
        *islocal = 0;

        /* Turn to local label format */
        if (digits == 1) {
            if (symcp[len - 1] == '$') {
                char           *newsym = memcheck(malloc(32));  /* Overkill */

                sprintf(newsym, "%ld$%d", strtol(symcp, NULL, 10), lsb);
                if (enabl_debug && lstfile) {
                    fprintf(lstfile, "lsb %d: %s -> %s\n",
                            lsb, symcp, newsym);
                }
                free(symcp);
                symcp = newsym;
                if (islocal)
                    *islocal = SYMBOLFLAG_LOCAL;
                lsb_used++;
            } else {
                free(symcp);
                return NULL;
            }
        }
    } else {
        /* disallow local label format */
        if (isdigit((unsigned char)*symcp)) {
            free(symcp);
            return NULL;
        }
    }

    return symcp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, (%rsp)
movq %rsi, %r12
movq %rdi, %r14
movzbl (%r14), %ebx
cmpl $0x20, %ebx
je 0x8c3d
cmpl $0x9, %ebx
jne 0x8c42
incq %r14
jmp 0x8c2f
callq 0x2300
movq %rax, %r15
movq (%rax), %rax
movzwl (%rax,%rbx,2), %ebp
testl $0xc00, %ebp            # imm = 0xC00
je 0x8dc6
shrl $0xa, %ebp
andl $0x2, %ebp
leaq 0xea16(%rip), %rcx      # 0x17680
movl (%rcx), %ecx
movl $0x1, %r13d
movzbl (%r14,%r13), %esi
movzwl (%rax,%rsi,2), %edx
testl $0xc00, %edx            # imm = 0xC00
je 0x8c9a
btl $0xb, %edx
movl $0x0, %edx
adcw $-0x1, %dx
movswl %dx, %edx
addl %edx, %ebp
incq %r13
jmp 0x8c72
cmpl $0x24, %esi
je 0x8c83
cmpl $0x2e, %esi
je 0x8c83
cmpl $0x5f, %esi
jne 0x8cad
testl %ecx, %ecx
jne 0x8c83
cmpl $0x2, %ebp
je 0x8e0f
testq %r12, %r12
je 0x8cc3
leaq (%r14,%r13), %rax
movq %rax, (%r12)
leaq 0xce1e(%rip), %rax      # 0x15ae8
movl (%rax), %eax
cmpl %r13d, %eax
cmovll %eax, %r13d
leal 0x1(%r13), %eax
movslq %eax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0xe34f
movq %rax, %r12
movslq %r13d, %r13
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2220
movb $0x0, (%r12,%r13)
movq %r12, %rdi
callq 0xe393
movq (%rsp), %r14
testq %r14, %r14
je 0x8df3
movl $0x0, (%r14)
cmpl $0x1, %ebp
jne 0x8e02
cmpb $0x24, -0x1(%r12,%r13)
jne 0x8e07
movl $0x20, %edi
callq 0x2230
movq %rax, %rdi
callq 0xe34f
movq %rax, %r13
movq %r12, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x2210
leaq 0xce0c(%rip), %rbx      # 0x15b68
movl (%rbx), %ecx
leaq 0x78c7(%rip), %rsi      # 0x1062c
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22b0
leaq 0xcdff(%rip), %rax      # 0x15b78
cmpl $0x0, (%rax)
setne %al
leaq 0xe8da(%rip), %rcx      # 0x17660
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x8dac
movl (%rbx), %edx
leaq 0x7894(%rip), %rsi      # 0x10633
movq %r12, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x21e0
movq %r12, %rdi
callq 0x2050
movl $0x20, (%r14)
leaq 0xcdaa(%rip), %rax      # 0x15b6c
incl (%rax)
jmp 0x8e12
cmpq $0x24, %rbx
je 0x8c5d
cmpl $0x2e, %ebx
je 0x8c5d
xorl %r13d, %r13d
cmpl $0x5f, %ebx
jne 0x8e12
leaq 0xe898(%rip), %rcx      # 0x17680
cmpl $0x0, (%rcx)
jne 0x8c5d
jmp 0x8e12
movq (%r15), %rax
movzbl (%r12), %ecx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x8e07
movq %r12, %r13
jmp 0x8e12
movq %r12, %rdi
callq 0x2050
xorl %r13d, %r13d
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq