// File: /workspace/github_c_makefile_star2_O0/jiribenes[P]scheme/src/read.c
// Function: read_list
static void read_list(reader_t *reader) {
    eat_whitespace(reader);
    next_token(reader);
    if (reader->toktype == TOK_RPAREN) {
        next_char(reader);
        reader->tokval = NIL_VAL;
        return;
    } else if (reader->toktype == TOK_EOF) {
        error_print(reader, "Unexpected EOF while parsing");
        return;
    } else if (reader->toktype == TOK_DOT) {
        error_print(reader, "Unexpected dot in list");
        return;
    }

    read1(reader);
    eat_whitespace(reader);
    value_t val = reader->tokval;

    cons_t *head, *tail;
    head = tail = AS_CONS(cons_fn(reader->vm, val, NIL_VAL));

    while (reader->toktype != TOK_EOF) {
        next_token(reader);
        if (reader->toktype == TOK_RPAREN) {
            reader->tokval = PTR_VAL(head);
            next_char(reader);
            return;
        } else if (reader->toktype == TOK_EOF) {
            error_print(reader, "Unexpected EOF while parsing");
            return;
        } else if (reader->toktype == TOK_DOT) {
            next_char(reader);
            next_token(reader);

            read1(reader);

            tail->cdr = reader->tokval;
            reader->tokval = PTR_VAL(head);

            next_char(reader);
            return;
        }

        read1(reader);
        val = reader->tokval;

        tail->cdr = cons_fn(reader->vm, val, NIL_VAL);
        tail = AS_CONS(tail->cdr);
    }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x52f0
movq 0x20(%rsp), %rdi
callq 0x4ea0
movq 0x20(%rsp), %rax
cmpl $0x3, 0x30(%rax)
jne 0x581a
movq 0x20(%rsp), %rdi
callq 0x5720
movq 0x20(%rsp), %rax
movabsq $0x7ffc000000000001, %rcx # imm = 0x7FFC000000000001
movq %rcx, 0x28(%rax)
jmp 0x59e3
movq 0x20(%rsp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x583d
movq 0x20(%rsp), %rdi
leaq 0x4f3e(%rip), %rsi      # 0xa76f
movb $0x0, %al
callq 0x55b0
jmp 0x59e3
movq 0x20(%rsp), %rax
cmpl $0x4, 0x30(%rax)
jne 0x5860
movq 0x20(%rsp), %rdi
leaq 0x4f38(%rip), %rsi      # 0xa78c
movb $0x0, %al
callq 0x55b0
jmp 0x59e3
jmp 0x5862
jmp 0x5864
movq 0x20(%rsp), %rdi
callq 0x5130
movq 0x20(%rsp), %rdi
callq 0x52f0
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq 0x18(%rsp), %rsi
movabsq $0x7ffc000000000001, %rdx # imm = 0x7FFC000000000001
callq 0x6d00
movabsq $0x3ffffffffffff, %rcx  # imm = 0x3FFFFFFFFFFFF
andq %rcx, %rax
movq %rax, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rax
cmpl $0x0, 0x30(%rax)
je 0x59e3
movq 0x20(%rsp), %rdi
callq 0x4ea0
movq 0x20(%rsp), %rax
cmpl $0x3, 0x30(%rax)
jne 0x5902
movq 0x10(%rsp), %rdi
callq 0x5e30
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x20(%rsp), %rdi
callq 0x5720
jmp 0x59e3
movq 0x20(%rsp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x5925
movq 0x20(%rsp), %rdi
leaq 0x4e56(%rip), %rsi      # 0xa76f
movb $0x0, %al
callq 0x55b0
jmp 0x59e3
movq 0x20(%rsp), %rax
cmpl $0x4, 0x30(%rax)
jne 0x5982
movq 0x20(%rsp), %rdi
callq 0x5720
movq 0x20(%rsp), %rdi
callq 0x4ea0
movq 0x20(%rsp), %rdi
callq 0x5130
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rsp), %rdi
callq 0x5e30
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x20(%rsp), %rdi
callq 0x5720
jmp 0x59e3
jmp 0x5984
jmp 0x5986
movq 0x20(%rsp), %rdi
callq 0x5130
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq 0x18(%rsp), %rsi
movabsq $0x7ffc000000000001, %rdx # imm = 0x7FFC000000000001
callq 0x6d00
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x8(%rsp), %rcx
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
andq 0x18(%rcx), %rax
movq %rax, 0x8(%rsp)
jmp 0x58b9
addq $0x28, %rsp
retq
nopl (%rax,%rax)