// File: /workspace/github_c_makefile_star2_O1/mahrr[P]raven/src/compiler.c
// Function: function
static void function(Parser *parser, FunctionType type) {
    Context context;
    init_context(&context, parser, type);
    begin_scope(parser);

    if (type == FunctionDeclaration) {
        consume(parser, TOKEN_LEFT_PAREN, "expect '(' after name");
        parameters(parser, TOKEN_RIGHT_PAREN);
        function_block(parser);
    } else if (type == FunctionLambda) {
        parameters(parser, TOKEN_ARROW);
        expression(parser);
    } else if (type == FunctionLambdaHeadless) {
        expression(parser);
    } else {
        assert(!"invalid function type");
    }

    RavFunction *function = end_context(parser, false);
    uint8_t index = make_constant(parser, Obj_Value(function));
    emit_bytes(parser, OP_CLOSURE, index);

    for (int i = 0; i < function->upvalue_count; i++) {
        emit_byte(parser, context.upvalues[i].is_local ? 1 : 0);
        emit_byte(parser, context.upvalues[i].index);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x2238, %rsp           # imm = 0x2238
movl %esi, %ebp
movq %rdi, %rbx
movq 0x8(%rdi), %rax
leaq 0x18(%rsp), %r14
movq %rax, (%r14)
movq %r14, 0x8(%rdi)
testl %esi, %esi
sete 0x10(%r14)
xorl %r15d, %r15d
movl %r15d, 0x2018(%r14)
movl %r15d, 0x221c(%r14)
movq 0x10(%rdi), %rdi
callq 0x554a
movq %rax, 0x8(%r14)
movslq 0x2018(%r14), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x2018(%r14)
shlq $0x5, %rax
movl %r15d, 0x48(%rsp,%rax)
leaq 0x4a5e(%rip), %rcx      # 0xb057
movq %rcx, 0x38(%rsp,%rax)
movl %r15d, 0x40(%rsp,%rax)
movb $0x0, 0x4c(%rsp,%rax)
cmpl $0x1, %ebp
jne 0x661a
movq 0x10(%rbx), %rdi
movq 0x38(%rbx), %rsi
movl 0x40(%rbx), %edx
jmp 0x6634
movl %ebp, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x6642
movq 0x10(%rbx), %rdi
leaq 0x512d(%rip), %rsi      # 0xb75c
movl $0x8, %edx
callq 0x52a0
movq 0x20(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq 0x8(%rbx), %rax
incl 0x221c(%rax)
cmpl $0x2, %ebp
je 0x669e
cmpl $0x1, %ebp
jne 0x66ab
leaq 0x18(%rbx), %r14
cmpl $0x28, 0x18(%rbx)
jne 0x67b8
movq 0x10(%r14), %rax
movq %rax, 0x40(%rbx)
movups (%r14), %xmm0
movups %xmm0, 0x30(%rbx)
movq %rsp, %r15
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x97fb
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movups (%rsp), %xmm0
movups %xmm0, (%r14)
cmpl $0x35, 0x18(%rbx)
je 0x6677
jmp 0x67ca
movq %rbx, %rdi
movl $0x24, %esi
callq 0x686d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x6ab6
movq 0x8(%rbx), %rax
movq 0x8(%rax), %r14
leaq 0x20(%r14), %rdi
movl 0x44(%rbx), %edx
movl $0x34, %esi
callq 0x4d19
movq 0x8(%rbx), %rax
movq (%rax), %rax
movq %rax, 0x8(%rbx)
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
orq %r14, %rsi
movq 0x8(%rax), %rdi
addq $0x20, %rdi
callq 0x4db9
cmpl $0x100, %eax            # imm = 0x100
jl 0x6727
leaq 0x51a7(%rip), %rsi      # 0xb8ab
movq %rbx, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x6518
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rax
movl $0x0, 0x848(%rax)
xorl %ebp, %ebp
jmp 0x6729
movl %eax, %ebp
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%rbx), %edx
movl $0x22, %esi
callq 0x4d19
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%rbx), %edx
movzbl %bpl, %esi
callq 0x4d19
cmpl $0x0, 0x1c(%r14)
jle 0x67aa
xorl %r15d, %r15d
movzbl 0x2034(%rsp,%r15,2), %esi
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%rbx), %edx
callq 0x4d19
movzbl 0x2035(%rsp,%r15,2), %esi
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%rbx), %edx
callq 0x4d19
incq %r15
movslq 0x1c(%r14), %rax
cmpq %rax, %r15
jl 0x6764
addq $0x2238, %rsp           # imm = 0x2238
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5059(%rip), %rdx      # 0xb818
movq %rbx, %rdi
movq %r14, %rsi
callq 0x64ec
movq %rbx, %rdi
movl $0x29, %esi
callq 0x686d
movl (%r14), %eax
cmpl $0x23, %eax
je 0x6802
cmpl $0x36, %eax
je 0x67ee
movq %rbx, %rdi
callq 0x5eca
jmp 0x67d7
leaq 0x508c(%rip), %rdx      # 0xb881
movq %rbx, %rdi
movq %r14, %rsi
callq 0x64ec
jmp 0x6837
movq 0x10(%r14), %rax
movq %rax, 0x40(%rbx)
movups (%r14), %xmm0
movups %xmm0, 0x30(%rbx)
movq %rsp, %r15
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x97fb
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movups (%rsp), %xmm0
movups %xmm0, (%r14)
cmpl $0x35, 0x18(%rbx)
je 0x6815
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rax
leaq 0x20(%rax), %rdi
movq 0x28(%rax), %rcx
movslq 0x20(%rax), %rax
cmpb $0x5, -0x1(%rcx,%rax)
jne 0x685b
decl %eax
movl %eax, (%rdi)
jmp 0x66b8
movl 0x44(%rbx), %edx
movl $0x4, %esi
callq 0x4d19
jmp 0x66b8