// File: /workspace/github_c_makefile_star2_O0/theandrew168[P]squeaky/src/reader.c
// Function: read_symbol
struct value*
read_symbol(struct vm* vm, FILE* fp)
{
    // temp buffer to hold the symbol's contents
    char buf[MAX_STRING_SIZE] = { 0 };
    long i = 0;

    // grab the first character
    int c = advance(fp);
    buf[i++] = c;

    // check for peculiar identifier
    if (is_peculiar_identifier(c)) {
        if (c == '+' || c == '-') {
            peek_expect_delimiter(fp);
            return vm_make_symbol(vm, buf);
        }

        // only other peculiar identifier left at this point is "..."
        buf[i++] = advance(fp);
        buf[i++] = advance(fp);
        if (strcmp(buf, "...") == 0) {
            peek_expect_delimiter(fp);
            return vm_make_symbol(vm, buf);
        }

        fprintf(stderr, "reader: invalid symbol: %s\n", buf);
        exit(EXIT_FAILURE);
    }

    // at this point, the first char in buf must be an 'initial'

    // read characters into the buffer until:
    // EOF is reached, non-subsequent char is read, or buffer is filled
    while ((c = advance(fp)) != EOF) {
        if (!is_subsequent(c)) break;

        // "- 2" here to account for terminator
        if (i >= MAX_SYMBOL_SIZE - 2) {
            fprintf(stderr, "reader: symbol larger than %d characters\n", MAX_SYMBOL_SIZE);
            exit(EXIT_FAILURE);
        }

        buf[i++] = c;
    }

    // put non-symbol char back and ensure it was a delimiter
    rollback(fp, c);
    peek_expect_delimiter(fp);
    return vm_make_symbol(vm, buf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10e0
movq $0x0, -0x128(%rbp)
movq -0x18(%rbp), %rdi
callq 0x74d0
movl %eax, -0x12c(%rbp)
movl -0x12c(%rbp), %eax
movb %al, %cl
movq -0x128(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x128(%rbp)
movb %cl, -0x120(%rbp,%rax)
movl -0x12c(%rbp), %eax
movsbl %al, %edi
callq 0x7a60
testb $0x1, %al
jne 0x78bb
jmp 0x79a0
cmpl $0x2b, -0x12c(%rbp)
je 0x78cd
cmpl $0x2d, -0x12c(%rbp)
jne 0x78ef
movq -0x18(%rbp), %rdi
callq 0x7590
movq -0x10(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x9070
movq %rax, -0x8(%rbp)
jmp 0x7a53
movq -0x18(%rbp), %rdi
callq 0x74d0
movb %al, %cl
movq -0x128(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x128(%rbp)
movb %cl, -0x120(%rbp,%rax)
movq -0x18(%rbp), %rdi
callq 0x74d0
movb %al, %cl
movq -0x128(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x128(%rbp)
movb %cl, -0x120(%rbp,%rax)
leaq -0x120(%rbp), %rdi
leaq 0x323e(%rip), %rsi      # 0xab89
callq 0x11d0
cmpl $0x0, %eax
jne 0x7977
movq -0x18(%rbp), %rdi
callq 0x7590
movq -0x10(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x9070
movq %rax, -0x8(%rbp)
jmp 0x7a53
movq 0x6662(%rip), %rax      # 0xdfe0
movq (%rax), %rdi
leaq -0x120(%rbp), %rdx
leaq 0x31fe(%rip), %rsi      # 0xab8d
movb $0x0, %al
callq 0x1200
movl $0x1, %edi
callq 0x11a0
jmp 0x79a2
movq -0x18(%rbp), %rdi
callq 0x74d0
movl %eax, -0x12c(%rbp)
cmpl $-0x1, %eax
je 0x7a27
movl -0x12c(%rbp), %eax
movsbl %al, %edi
callq 0x7aa0
testb $0x1, %al
jne 0x79ca
jmp 0x7a27
cmpq $0xfe, -0x128(%rbp)
jl 0x79fe
movq 0x6602(%rip), %rax      # 0xdfe0
movq (%rax), %rdi
leaq 0x31c1(%rip), %rsi      # 0xaba9
movl $0x100, %edx            # imm = 0x100
movb $0x0, %al
callq 0x1200
movl $0x1, %edi
callq 0x11a0
movl -0x12c(%rbp), %eax
movb %al, %cl
movq -0x128(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x128(%rbp)
movb %cl, -0x120(%rbp,%rax)
jmp 0x79a2
movq -0x18(%rbp), %rdi
movl -0x12c(%rbp), %esi
callq 0x7710
movq -0x18(%rbp), %rdi
callq 0x7590
movq -0x10(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x9070
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq