// File: /workspace/github_c_makefile_star2_O3/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 0x526e
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 0x4d5c(%rip), %rcx      # 0xb057
movq %rcx, 0x38(%rsp,%rax)
movl %r15d, 0x40(%rsp,%rax)
movb $0x0, 0x4c(%rsp,%rax)
cmpl $0x1, %ebp
jne 0x631c
movq 0x10(%rbx), %rdi
movq 0x38(%rbx), %rsi
movl 0x40(%rbx), %edx
jmp 0x6336
movl %ebp, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x6344
movq 0x10(%rbx), %rdi
leaq 0x546b(%rip), %rsi      # 0xb79c
movl $0x8, %edx
callq 0x4fd0
movq 0x20(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq 0x8(%rbx), %rax
incl 0x221c(%rax)
cmpl $0x2, %ebp
je 0x63a0
cmpl $0x1, %ebp
jne 0x63ad
leaq 0x18(%rbx), %r14
cmpl $0x28, 0x18(%rbx)
jne 0x64ba
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 0x941f
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movups (%rsp), %xmm0
movups %xmm0, (%r14)
cmpl $0x35, 0x18(%rbx)
je 0x6379
jmp 0x64cc
movq %rbx, %rdi
movl $0x24, %esi
callq 0x656f
movq %rbx, %rdi
movl $0x1, %esi
callq 0x679e
movq 0x8(%rbx), %rax
movq 0x8(%rax), %r14
movl 0x44(%rbx), %edx
leaq 0x20(%r14), %rdi
movl $0x34, %esi
callq 0x4af1
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 0x4b99
cmpl $0x100, %eax            # imm = 0x100
jl 0x6429
leaq 0x54e5(%rip), %rsi      # 0xb8eb
movq %rbx, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x621b
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
movl $0x0, 0x848(%rdi)
xorl %ebp, %ebp
jmp 0x6433
movl %eax, %ebp
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
movl 0x44(%rbx), %edx
addq $0x20, %rdi
movl $0x22, %esi
callq 0x4af1
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movzbl %bpl, %esi
callq 0x4af1
cmpl $0x0, 0x1c(%r14)
jle 0x64ac
xorl %r15d, %r15d
movzbl 0x2034(%rsp,%r15,2), %esi
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
callq 0x4af1
movzbl 0x2035(%rsp,%r15,2), %esi
movq 0x8(%rbx), %rax
movl 0x44(%rbx), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
callq 0x4af1
incq %r15
movslq 0x1c(%r14), %rax
cmpq %rax, %r15
jl 0x6466
addq $0x2238, %rsp           # imm = 0x2238
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5397(%rip), %rdx      # 0xb858
movq %rbx, %rdi
movq %r14, %rsi
callq 0x61ef
movq %rbx, %rdi
movl $0x29, %esi
callq 0x656f
movl (%r14), %eax
cmpl $0x23, %eax
je 0x6504
cmpl $0x36, %eax
je 0x64f0
movq %rbx, %rdi
callq 0x5bb5
jmp 0x64d9
leaq 0x53ca(%rip), %rdx      # 0xb8c1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x61ef
jmp 0x6539
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 0x941f
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movups (%rsp), %xmm0
movups %xmm0, (%r14)
cmpl $0x35, 0x18(%rbx)
je 0x6517
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 0x655d
decl %eax
movl %eax, (%rdi)
jmp 0x63ba
movl 0x44(%rbx), %edx
movl $0x4, %esi
callq 0x4af1
jmp 0x63ba