// File: /workspace/github_c_makefile_star2_O3/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
movq 0x10(%rbp), %r15
cmpl $0x1, %esi
jle 0x4126f
leaq 0x2759a(%rip), %rsi     # 0x68807
jmp 0x41294
movq (%r15), %r14
testq %r14, %r14
je 0x4128d
movq %rdx, %r12
movl %esi, %r13d
testb $0x21, 0x6c(%r14)
jne 0x412c8
movq 0x8(%r14), %r14
testq %r14, %r14
jne 0x4127d
leaq 0x2758f(%rip), %rsi     # 0x68823
movq %r15, %rdi
callq 0x1bb46
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4ece6
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1baf6
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0x1ba98
movl 0x6c(%r14), %eax
testb $0x1, %al
jne 0x41316
testl %r13d, %r13d
je 0x4130c
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 0x1c7be
movq %r15, %rdi
movl $0x9c, %esi
jmp 0x41388
testl %r13d, %r13d
je 0x41350
andl $0x20, %eax
jne 0x41350
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 0x1c7be
jmp 0x4129c
testl %r13d, %r13d
je 0x41380
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 0x1c7be
movq %r15, %rdi
movl $0x4, %esi
callq 0x21728
jmp 0x4129c