// File: /workspace/github_c_makefile_star2_O2/janet-lang[P]janet/src/core/specials.c
// Function: janetc_break
static JanetSlot janetc_break(JanetFopts opts, int32_t argn, const Janet *argv) {
    JanetCompiler *c = opts.compiler;
    JanetScope *scope = c->scope;
    if (argn > 1) {
        janetc_cerror(c, "expected at most 1 argument");
        return janetc_cslot(janet_wrap_nil());
    }

    /* Find scope to break from */
    while (scope) {
        if (scope->flags & (JANET_SCOPE_FUNCTION | JANET_SCOPE_WHILE))
            break;
        scope = scope->parent;
    }
    if (NULL == scope) {
        janetc_cerror(c, "break must occur in while loop or closure");
        return janetc_cslot(janet_wrap_nil());
    }

    /* Emit code to break from that scope */
    JanetFopts subopts = janetc_fopts_default(c);
    if (scope->flags & JANET_SCOPE_FUNCTION) {
        if (!(scope->flags & JANET_SCOPE_WHILE) && argn) {
            /* Closure body with return argument */
            subopts.flags |= JANET_FOPTS_TAIL;
            janetc_value(subopts, argv[0]);
            return janetc_cslot(janet_wrap_nil());
        } else {
            /* while loop IIFE or no argument */
            if (argn) {
                subopts.flags |= JANET_FOPTS_DROP;
                janetc_value(subopts, argv[0]);
            }
            janetc_emit(c, JOP_RETURN_NIL);
            return janetc_cslot(janet_wrap_nil());
        }
    } else {
        if (argn) {
            subopts.flags |= JANET_FOPTS_DROP;
            janetc_value(subopts, argv[0]);
        }
        /* Tag the instruction so the while special can turn it into a proper jump */
        janetc_emit(c, 0x80 | JOP_JUMP);
        return janetc_cslot(janet_wrap_nil());
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movabsq $-0x77fffffffffff, %r15 # imm = 0xFFF8800000000001
movq 0x10(%rbp), %r14
cmpl $0x1, %esi
jle 0x3dc78
leaq 0x26bbc(%rip), %rsi     # 0x64827
movq %r14, %rdi
callq 0x19fa9
jmp 0x3dd88
movq %rdx, %r12
movl %esi, %r13d
movq %r14, %r15
movq (%r15), %r15
testq %r15, %r15
je 0x3dc96
testb $0x21, 0x6c(%r15)
jne 0x3dcb4
addq $0x8, %r15
jmp 0x3dc81
leaq 0x26ba6(%rip), %rsi     # 0x64843
movq %r14, %rdi
callq 0x19fa9
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
jmp 0x3dd8b
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x19f04
movl 0x6c(%r15), %eax
testb $0x1, %al
jne 0x3dd0c
testl %r13d, %r13d
movabsq $-0x77fffffffffff, %r15 # imm = 0xFFF8800000000001
je 0x3dd02
orb $0x4, -0x2e(%rbp)
movq (%r12), %rsi
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x68(%rbp), %rdi
callq 0x1abbf
movq %r14, %rdi
movl $0x9c, %esi
jmp 0x3dd83
testl %r13d, %r13d
movabsq $-0x77fffffffffff, %r15 # imm = 0xFFF8800000000001
je 0x3dd4d
andl $0x20, %eax
jne 0x3dd4d
orb $0x1, -0x2e(%rbp)
movq (%r12), %rsi
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x68(%rbp), %rdi
callq 0x1abbf
jmp 0x3dd88
testl %r13d, %r13d
je 0x3dd7d
orb $0x4, -0x2e(%rbp)
movq (%r12), %rsi
movq -0x30(%rbp), %rax
movq %rax, 0x20(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x68(%rbp), %rdi
callq 0x1abbf
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x1f7c4
movq %r15, %rdi
callq 0x4b313
movq %rbx, %rdi
movq %rax, %rsi
callq 0x19f5c
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq