// File: /workspace/github_c_makefile_star2_O2/jiribenes[P]scheme/src/write.c
// Function: write
void write(FILE *f, value_t val) {
    if (IS_NUM(val)) {
        write_number(f, AS_NUM(val));
    } else if (IS_NIL(val)) {
        fprintf(f, "()");
    } else if (IS_TRUE(val)) {
        fprintf(f, "#t");
    } else if (IS_FALSE(val)) {
        fprintf(f, "#f");
    } else if (IS_UNDEFINED(val)) {
        fprintf(f, "#<undefined>");
    } else if (IS_VOID(val)) {
        fprintf(f, "#<void>");
    } else if (IS_EOF(val)) {
        fprintf(f, "#<eof>");
    } else if (IS_PTR(val)) {
        if (IS_CONS(val)) {
            cons_t *cons = AS_CONS(val);

            fprintf(f, "(");
            write_cons(f, cons);
            fprintf(f, ")");
        } else if (IS_STRING(val)) {
            string_t *str = AS_STRING(val);
            write_string(f, str);
        } else if (IS_SYMBOL(val)) {
            symbol_t *sym = AS_SYMBOL(val);
            fprintf(f, "%s", sym->name);
        } else if (IS_PRIMITIVE(val)) {
            // TODO: A lot of repetition going on here, can we shorten this?
            primitive_t *prim = AS_PRIMITIVE(val);
            fprintf(f, "#<primitive ");
            if (prim->name != NULL) {
                display(f, PTR_VAL(prim->name));
            } else {
                fprintf(f, "?");
            }
            fprintf(f, ">");
        } else if (IS_FUNCTION(val)) {
            fprintf(f, "#<function ");
            function_t *fn = AS_FUNCTION(val);
            if (fn->name != NULL) {
                display(f, PTR_VAL(fn->name));
            } else {
                fprintf(f, "?");
            }
            fprintf(f, " ");
            write(f, fn->params);
            fprintf(f, ">");
        } else if (IS_MACRO(val)) {
            fprintf(f, "#<macro ");
            function_t *mac = AS_MACRO(val);
            if (mac->name != NULL) {
                display(f, PTR_VAL(mac->name));
            } else {
                fprintf(f, "?");
            }
            fprintf(f, ">");
        } else if (IS_VECTOR(val)) {
            vector_t *vec = AS_VECTOR(val);
            write_vector(f, vec);
        } else if (IS_ENV(val)) {
            env_t *env = (env_t *) AS_PTR(val);
            fprintf(f, "#<");
            if (env == NULL) {
                fprintf(f, "top level ");
            }
            fprintf(f, "environment>");
        } else {
            fprintf(f, "#<unknown ptrvalue>");
        }
    } else {
        fprintf(f, "#<unknown value>");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
movabsq $0x7ffc000000000000, %r12 # imm = 0x7FFC000000000000
movq %rsi, %rax
notq %rax
testq %r12, %rax
jne 0x52a5
movabsq $-0x7ffc000000000001, %rax # imm = 0x8003FFFFFFFFFFFF
addq %r15, %rax
cmpq $0x5, %rax
ja 0x5350
leaq 0x1a78(%rip), %rcx      # 0x6d08
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1aa0(%rip), %rdi      # 0x6d40
jmp 0x5329
movq %r15, %xmm0
ucomisd %xmm0, %xmm0
jp 0x5636
btrq $0x3f, %r15
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
cmpq %rax, %r15
jne 0x52db
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x52fa
leaq 0x1afa(%rip), %rdi      # 0x6dd3
jmp 0x5334
leaq 0x1aff(%rip), %rsi      # 0x6de1
movq %rbx, %rdi
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1130
leaq 0x1ad9(%rip), %rdi      # 0x6dda
jmp 0x5334
leaq 0x1a4c(%rip), %rdi      # 0x6d56
pushq $0x7
jmp 0x5336
leaq 0x1a31(%rip), %rdi      # 0x6d46
jmp 0x5329
leaq 0x1a2b(%rip), %rdi      # 0x6d49
pushq $0xc
jmp 0x5336
leaq 0x1a1a(%rip), %rdi      # 0x6d43
pushq $0x2
jmp 0x5336
leaq 0x1a2a(%rip), %rdi      # 0x6d5e
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11c0
movabsq $-0x4000000000000, %rbp # imm = 0xFFFC000000000000
leaq -0x1(%rbp), %r13
cmpq %r13, %r15
jbe 0x540a
movabsq $0x3ffffffffffff, %rax  # imm = 0x3FFFFFFFFFFFF
movq %r15, %r14
andq %rax, %r14
movl (%r14), %eax
cmpq $0x7, %rax
ja 0x55a4
leaq 0x1995(%rip), %rcx      # 0x6d20
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x28
popq %rdi
movq %rbx, %rsi
callq 0x1100
movq %r15, %rdi
callq 0x4378
cmpl $-0x1, %eax
je 0x55e5
incq %r12
pushq $0x20
popq %rbp
movabsq $0x3ffffffffffff, %r14  # imm = 0x3FFFFFFFFFFFF
cmpq %r12, %r15
je 0x561d
andq %r14, %r15
movq 0x10(%r15), %rsi
movq %rbx, %rdi
callq 0x524c
movq 0x18(%r15), %rax
cmpq %r12, %rax
je 0x561d
cmpq %r13, %rax
jbe 0x55fc
andq %r14, %rax
cmpl $0x0, (%rax)
jne 0x55fc
movl %ebp, %edi
movq %rbx, %rsi
callq 0x1100
movq 0x18(%r15), %r15
jmp 0x53c0
leaq 0x19a5(%rip), %rdi      # 0x6db6
pushq $0x10
jmp 0x5336
leaq 0x1953(%rip), %rdi      # 0x6d72
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11c0
movq 0x10(%r14), %rsi
testq %rsi, %rsi
je 0x55bf
orq %rbp, %rsi
movq %rbx, %rdi
callq 0x5642
jmp 0x55ca
addq $0x20, %r14
movq %r14, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10d0
leaq 0x18f7(%rip), %rdi      # 0x6d65
pushq $0xc
jmp 0x552f
leaq 0x190b(%rip), %rdi      # 0x6d87
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11c0
testq %r14, %r14
jne 0x54a4
leaq 0x18f4(%rip), %rdi      # 0x6d8a
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x18ea(%rip), %rdi      # 0x6d95
jmp 0x531e
pushq $0x22
popq %rdi
movq %rbx, %rsi
callq 0x1100
xorl %ebp, %ebp
pushq $0x2
popq %r12
pushq $0x1
popq %r13
leaq 0x1930(%rip), %r15      # 0x6dfc
movl 0x10(%r14), %eax
cmpq %rax, %rbp
jae 0x551f
movzbl 0x18(%r14,%rbp), %eax
cmpl $0x5c, %eax
je 0x54f8
cmpl $0x22, %eax
je 0x54ef
cmpl $0xa, %eax
jne 0x550f
movq %r15, %rdi
jmp 0x54ff
leaq 0x190c(%rip), %rdi      # 0x6e02
jmp 0x54ff
leaq 0x1900(%rip), %rdi      # 0x6dff
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x11c0
jmp 0x551a
movsbl %al, %edi
movq %rbx, %rsi
callq 0x1100
incq %rbp
jmp 0x54cc
pushq $0x22
jmp 0x561f
leaq 0x1851(%rip), %rdi      # 0x6d7e
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11c0
movq 0x10(%r14), %rsi
testq %rsi, %rsi
je 0x55b2
orq %rbp, %rsi
movq %rbx, %rdi
callq 0x5642
jmp 0x55e1
leaq 0x18aa(%rip), %rdi      # 0x6e05
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11c0
xorl %r15d, %r15d
pushq $0x20
popq %rbp
movl 0x14(%r14), %eax
cmpq %rax, %r15
jae 0x561d
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
callq 0x524c
incq %r15
movl 0x14(%r14), %eax
cmpq %rax, %r15
je 0x556f
movl %ebp, %edi
movq %rbx, %rsi
callq 0x1100
jmp 0x556f
leaq 0x17f7(%rip), %rdi      # 0x6da2
pushq $0x13
jmp 0x5336
pushq $0x3f
popq %rdi
movq %rbx, %rsi
callq 0x1100
jmp 0x55e1
pushq $0x3f
popq %rdi
movq %rbx, %rsi
callq 0x1100
pushq $0x20
popq %rdi
movq %rbx, %rsi
callq 0x1100
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x524c
pushq $0x3e
jmp 0x561f
leaq 0x17fb(%rip), %rdi      # 0x6de7
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11c0
jmp 0x561d
leaq 0x17f5(%rip), %rdi      # 0x6df8
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11c0
movq 0x18(%r15), %rsi
movq %rbx, %rdi
callq 0x524c
pushq $0x29
popq %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1100
leaq 0x178f(%rip), %rdi      # 0x6dcc
jmp 0x5334