// File: /workspace/github_c_makefile_star2_O1/mahrr[P]raven/src/compiler.c
// Function: cond
static void cond(Parser *parser) {
    // Cond Control Flow:
    //
    // Condition (1)
    // OP_JMP_POP_FALSE  ---.
    //                      |
    // Expression (1)       |
    // OP_JMP            --------.
    //                      |    |
    // [Condition (2)]   <---    |
    // OP_JMP_POP_FALSE  ----    |
    //                      |    |
    // [Expression (2)]     |    |
    // OP_JMP            --------|
    //                      |    |
    // [Condition (3)]   <---    |
    // OP_JMP_POP_FALSE  ---.    |
    //                      |    |
    // [Expression (3)]     |    |
    // OP_JMP            --------|
    //                      |    |
    // ....                 .    .
    // ....                 .    .
    //                      |    |
    // [Condition (n)]   <---    |
    // OP_JMP_POP_FALSE  ---.    |
    //                      |    |
    // [Expression (n)]     |    |
    // OP_JMP            --------|
    //                      |    |
    // OP_PUSH_NIL <---------    |
    // ....        <--------------

    Debug_Log(parser);

    int cases_exit[COND_LIMIT];
    int cases_count = 0;

    do {
        if (cases_count == COND_LIMIT) {
            error_limit(parser, "cond cases", COND_LIMIT);
            break;
        }

        // Condition
        expression(parser);
        consume(parser, TOKEN_ARROW, "expect '->' after expression");
        int next_case = emit_jump(parser, OP_JMP_POP_FALSE);

        // Expression
        expression(parser);
        cases_exit[cases_count++] = emit_jump(parser, OP_JMP);

        patch_jump(parser, next_case);
    } while (consume_if(parser, TOKEN_COMMA));

    // If all conditions evaluate to false.
    emit_byte(parser, OP_PUSH_NIL);

    for (int i = 0; i < cases_count; i++) {
        patch_jump(parser, cases_exit[i]);
    }

    consume(parser, TOKEN_END, "expect 'end' after cond cases");

    Debug_Exit(parser);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rdi, %r14
leaq 0x18(%rdi), %r12
leaq 0x30(%rdi), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
leaq 0x10(%rsp), %r15
cmpq $0x100, %r13            # imm = 0x100
je 0x6da9
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ab6
cmpl $0x24, 0x18(%r14)
jne 0x6c37
movq 0x10(%r12), %rax
movq 0x8(%rsp), %rcx
movq %rax, 0x10(%rcx)
movups (%r12), %xmm0
movups %xmm0, (%rcx)
movq (%r14), %rsi
movq %r15, %rdi
callq 0x97fb
movq 0x20(%rsp), %rax
movq %rax, 0x10(%r12)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%r12)
cmpl $0x35, 0x18(%r14)
je 0x6c0f
jmp 0x6c49
movq %r14, %rdi
movq %r12, %rsi
leaq 0x4cfa(%rip), %rdx      # 0xb93e
callq 0x64ec
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%r14), %edx
movl $0x21, %esi
callq 0x4d19
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%r14), %edx
movl $0xff, %esi
callq 0x4d19
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%r14), %edx
movl $0xff, %esi
callq 0x4d19
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movslq 0x20(%rax), %rbp
addq $-0x2, %rbp
movq %r14, %rdi
movl $0x1, %esi
callq 0x6ab6
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%r14), %edx
movl $0x1e, %esi
callq 0x4d19
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%r14), %edx
movl $0xff, %esi
callq 0x4d19
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%r14), %edx
movl $0xff, %esi
callq 0x4d19
movq 0x8(%r14), %rax
movq 0x8(%rax), %rbx
movl 0x20(%rbx), %ecx
leal -0x2(%rcx), %eax
movl %eax, 0x30(%rsp,%r13,4)
subl %ebp, %ecx
cmpl $0x10002, %ecx          # imm = 0x10002
jl 0x6d41
movq %r14, %rdi
movq %r12, %rsi
leaq 0x4c4d(%rip), %rdx      # 0xb979
movq %r13, 0x28(%rsp)
movq %rcx, %r13
callq 0x64ec
movq %r13, %rcx
movq 0x28(%rsp), %r13
incq %r13
addl $-0x2, %ecx
movq 0x28(%rbx), %rax
movb %ch, (%rax,%rbp)
movq 0x28(%rbx), %rax
movb %cl, 0x1(%rax,%rbp)
movl (%r12), %ebp
cmpl $0x25, %ebp
jne 0x6da4
movq 0x10(%r12), %rax
movq 0x8(%rsp), %rcx
movq %rax, 0x10(%rcx)
movups (%r12), %xmm0
movups %xmm0, (%rcx)
movq (%r14), %rsi
movq %r15, %rdi
callq 0x97fb
movq 0x20(%rsp), %rax
movq %rax, 0x10(%r12)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%r12)
cmpl $0x35, 0x18(%r14)
je 0x6d75
cmpl $0x25, %ebp
je 0x6bd8
movl %r13d, %eax
jmp 0x6dc2
leaq 0x4bbe(%rip), %rsi      # 0xb96e
movq %r14, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x6518
movl $0x100, %eax            # imm = 0x100
movq %rax, 0x8(%rsp)
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl 0x44(%r14), %edx
movl $0x2, %esi
callq 0x4d19
xorl %r13d, %r13d
movslq 0x30(%rsp,%r13,4), %rbp
movq 0x8(%r14), %rax
movq 0x8(%rax), %r15
movl 0x20(%r15), %ebx
subl %ebp, %ebx
cmpl $0x10002, %ebx          # imm = 0x10002
jl 0x6e11
movq %r14, %rdi
movq %r12, %rsi
leaq 0x4b6d(%rip), %rdx      # 0xb979
callq 0x64ec
addl $-0x2, %ebx
movq 0x28(%r15), %rax
movb %bh, (%rax,%rbp)
movq 0x28(%r15), %rax
movb %bl, 0x1(%rax,%rbp)
incq %r13
cmpq %r13, 0x8(%rsp)
jne 0x6de4
cmpl $0x23, 0x18(%r14)
jne 0x6e74
movq 0x10(%r12), %rax
movq %rax, 0x40(%r14)
movups (%r12), %xmm0
movups %xmm0, 0x30(%r14)
leaq 0x10(%rsp), %r15
movq (%r14), %rsi
movq %r15, %rdi
callq 0x97fb
movq 0x20(%rsp), %rax
movq %rax, 0x10(%r12)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%r12)
cmpl $0x35, 0x18(%r14)
je 0x6e4c
jmp 0x6e86
leaq 0x4ae0(%rip), %rdx      # 0xb95b
movq %r14, %rdi
movq %r12, %rsi
callq 0x64ec
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq