// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
xorl %ebx, %ebx
leaq 0x18(%rsp), %r15
movq %r14, %rdi
movl $0x1, %esi
callq 0x679e
cmpl $0x24, 0x18(%r14)
jne 0x6911
movq 0x10(%r12), %rax
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
movups (%r12), %xmm0
movups %xmm0, (%rcx)
movq (%r14), %rsi
movq %r15, %rdi
callq 0x941f
movq 0x28(%rsp), %rax
movq %rax, 0x10(%r12)
movups 0x18(%rsp), %xmm0
movups %xmm0, (%r12)
cmpl $0x35, 0x18(%r14)
je 0x68e9
jmp 0x6923
movq %r14, %rdi
movq %r12, %rsi
leaq 0x5060(%rip), %rdx      # 0xb97e
callq 0x61ef
movq 0x8(%r14), %rax
movl 0x44(%r14), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0x21, %esi
callq 0x4af1
movq 0x8(%r14), %rax
movl 0x44(%r14), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0xff, %esi
callq 0x4af1
movq 0x8(%r14), %rax
movl 0x44(%r14), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0xff, %esi
callq 0x4af1
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movslq 0x20(%rax), %rbp
addq $-0x2, %rbp
movq %r14, %rdi
movl $0x1, %esi
callq 0x679e
movq 0x8(%r14), %rax
movl 0x44(%r14), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0x1e, %esi
callq 0x4af1
movq 0x8(%r14), %rax
movl 0x44(%r14), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0xff, %esi
callq 0x4af1
movq 0x8(%r14), %rax
movl 0x44(%r14), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0xff, %esi
callq 0x4af1
movq 0x8(%r14), %rax
movq 0x8(%rax), %r13
movl 0x20(%r13), %ecx
leal -0x2(%rcx), %eax
movl %eax, 0x30(%rsp,%rbx,4)
subl %ebp, %ecx
cmpl $0x10002, %ecx          # imm = 0x10002
jl 0x6a1b
movq %r14, %rdi
movq %r12, %rsi
leaq 0x4fb3(%rip), %rdx      # 0xb9b9
movq %rbx, 0x8(%rsp)
movq %rcx, %rbx
callq 0x61ef
movq %rbx, %rcx
movq 0x8(%rsp), %rbx
incq %rbx
addl $-0x2, %ecx
movq 0x28(%r13), %rax
movb %ch, (%rax,%rbp)
movq 0x28(%r13), %rax
movb %cl, 0x1(%rax,%rbp)
cmpl $0x25, (%r12)
jne 0x6a9c
movq 0x10(%r12), %rax
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
movups (%r12), %xmm0
movups %xmm0, (%rcx)
movq (%r14), %rsi
movq %r15, %rdi
callq 0x941f
movq 0x28(%rsp), %rax
movq %rax, 0x10(%r12)
movups 0x18(%rsp), %xmm0
movups %xmm0, (%r12)
cmpl $0x35, 0x18(%r14)
je 0x6a4d
cmpq $0x100, %rbx            # imm = 0x100
jne 0x68bf
leaq 0x4f27(%rip), %rsi      # 0xb9ae
movq %r14, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x621b
movl $0x100, %r15d           # imm = 0x100
jmp 0x6a9f
movl %ebx, %r15d
movq 0x8(%r14), %rax
movl 0x44(%r14), %edx
movq 0x8(%rax), %rdi
addq $0x20, %rdi
movl $0x2, %esi
callq 0x4af1
xorl %ebp, %ebp
movq %r15, 0x8(%rsp)
movslq 0x30(%rsp,%rbp,4), %rcx
movq 0x8(%r14), %rax
movq 0x8(%rax), %r13
movl 0x20(%r13), %ebx
subl %ecx, %ebx
cmpl $0x10002, %ebx          # imm = 0x10002
jl 0x6af8
movq %r14, %rdi
movq %r12, %rsi
leaq 0x4ed1(%rip), %rdx      # 0xb9b9
movq %rcx, %r15
callq 0x61ef
movq %r15, %rcx
movq 0x8(%rsp), %r15
addl $-0x2, %ebx
movq 0x28(%r13), %rax
movb %bh, (%rax,%rcx)
movq 0x28(%r13), %rax
movb %bl, 0x1(%rax,%rcx)
incq %rbp
cmpq %rbp, %r15
jne 0x6ac0
cmpl $0x23, (%r12)
jne 0x6b5c
movq 0x10(%r12), %rax
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
movups (%r12), %xmm0
movups %xmm0, (%rcx)
leaq 0x18(%rsp), %r15
movq (%r14), %rsi
movq %r15, %rdi
callq 0x941f
movq 0x28(%rsp), %rax
movq %rax, 0x10(%r12)
movups 0x18(%rsp), %xmm0
movups %xmm0, (%r12)
cmpl $0x35, 0x18(%r14)
je 0x6b34
jmp 0x6b6e
leaq 0x4e38(%rip), %rdx      # 0xb99b
movq %r14, %rdi
movq %r12, %rsi
callq 0x61ef
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq