// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rsi, %r12
callq 0x8234
movq %rax, %r15
callq 0x2300
movq %rax, %r14
movq (%rax), %rax
movzbl (%r15), %ecx
movzwl (%rax,%rcx,2), %ebp
testw $0xc00, %bp             # imm = 0xC00
je 0x872b
shrl $0xa, %ebp
andl $0x2, %ebp
leaq 0xf0a5(%rip), %rcx      # 0x17680
movl (%rcx), %ecx
pushq $0x1
popq %r13
movzbl (%r15,%r13), %esi
movzwl (%rax,%rsi,2), %edx
testw $0xc00, %dx             # imm = 0xC00
je 0x8608
btl $0xb, %edx
movl $0x0, %edx
adcw $-0x1, %dx
movswl %dx, %edx
addl %edx, %ebp
incq %r13
jmp 0x85e1
cmpl $0x24, %esi
je 0x85f1
cmpl $0x2e, %esi
je 0x85f1
cmpl $0x5f, %esi
jne 0x861b
testl %ecx, %ecx
jne 0x85f1
cmpl $0x2, %ebp
je 0x8773
testq %r12, %r12
je 0x8633
movq %r15, %rax
addq %r13, %rax
movq %rax, (%r12)
leaq 0xd4ae(%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 0xcd2d
movq %rax, %r12
movslq %r13d, %r13
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2220
movb $0x0, (%r12,%r13)
movq %r12, %rdi
callq 0xcd86
testq %rbx, %rbx
je 0x8757
andl $0x0, (%rbx)
cmpl $0x1, %ebp
jne 0x8766
cmpb $0x24, -0x1(%r12,%r13)
jne 0x876b
pushq $0x20
popq %rdi
callq 0x2230
movq %rax, %rdi
callq 0xcd2d
movq %rax, %r13
pushq $0xa
popq %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2210
leaq 0xd4a8(%rip), %r14      # 0x15b68
movl (%r14), %ecx
leaq 0x6fa2(%rip), %rsi      # 0xf66c
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22b0
leaq 0xd49a(%rip), %rax      # 0x15b78
cmpl $0x0, (%rax)
setne %al
leaq 0xef75(%rip), %rcx      # 0x17660
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x8712
movl (%r14), %edx
leaq 0x6f6e(%rip), %rsi      # 0xf673
movq %r12, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x21e0
movq %r12, %rdi
callq 0x2050
movl $0x20, (%rbx)
leaq 0xd445(%rip), %rax      # 0x15b6c
incl (%rax)
jmp 0x8776
cmpl $0x24, %ecx
je 0x85ce
cmpl $0x2e, %ecx
je 0x85ce
xorl %r13d, %r13d
cmpl $0x5f, %ecx
jne 0x8776
leaq 0xef34(%rip), %rcx      # 0x17680
cmpl $0x0, (%rcx)
jne 0x85ce
jmp 0x8776
movq (%r14), %rax
movzbl (%r12), %ecx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x876b
movq %r12, %r13
jmp 0x8776
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