// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/ev.c
// Function: janet_go_thread_subr
static JanetEVGenericMessage janet_go_thread_subr(JanetEVGenericMessage args) {
    JanetBuffer *buffer = (JanetBuffer *) args.argp;
    const uint8_t *nextbytes = buffer->data;
    const uint8_t *endbytes = nextbytes + buffer->count;
    uint32_t flags = args.tag;
    args.tag = 0;
    janet_init();
    janet_vm.sandbox_flags = (uint32_t) args.argi;
    JanetTryState tstate;
    JanetSignal signal = janet_try(&tstate);
    if (!signal) {

        /* Set abstract registry */
        if (!(flags & 0x2)) {
            Janet aregv = janet_unmarshal(nextbytes, endbytes - nextbytes,
                                          JANET_MARSHAL_UNSAFE, NULL, &nextbytes);
            if (!janet_checktype(aregv, JANET_TABLE)) janet_panic("expected table for abstract registry");
            janet_vm.abstract_registry = janet_unwrap_table(aregv);
            janet_gcroot(janet_wrap_table(janet_vm.abstract_registry));
        }

        /* Get supervisor */
        if (flags & JANET_THREAD_SUPERVISOR_FLAG) {
            Janet sup =
                janet_unmarshal(nextbytes, endbytes - nextbytes,
                                JANET_MARSHAL_UNSAFE, NULL, &nextbytes);
            /* Hack - use a global variable to avoid longjmp clobber */
            janet_vm.user = janet_unwrap_pointer(sup);
        }

        /* Set cfunction registry */
        if (!(flags & 0x4)) {
            uint32_t count1;
            memcpy(&count1, nextbytes, sizeof(count1));
            size_t count = (size_t) count1;
            /* Use division to avoid overflowing size_t */
            if (count > (endbytes - nextbytes - sizeof(count1)) / sizeof(JanetCFunRegistry)) {
                janet_panic("thread message invalid");
            }
            janet_vm.registry_count = count;
            janet_vm.registry_cap = count;
            janet_vm.registry = janet_malloc(count * sizeof(JanetCFunRegistry));
            if (janet_vm.registry == NULL) {
                JANET_OUT_OF_MEMORY;
            }
            janet_vm.registry_dirty = 1;
            nextbytes += sizeof(uint32_t);
            memcpy(janet_vm.registry, nextbytes, count * sizeof(JanetCFunRegistry));
            nextbytes += count * sizeof(JanetCFunRegistry);
        }

        Janet fiberv = janet_unmarshal(nextbytes, endbytes - nextbytes,
                                       JANET_MARSHAL_UNSAFE, NULL, &nextbytes);
        Janet value = janet_unmarshal(nextbytes, endbytes - nextbytes,
                                      JANET_MARSHAL_UNSAFE, NULL, &nextbytes);
        JanetFiber *fiber;
        if (!janet_checktype(fiberv, JANET_FIBER)) {
            if (!janet_checktype(fiberv, JANET_FUNCTION)) {
                janet_panicf("expected function or fiber, got %v", fiberv);
            }
            JanetFunction *func = janet_unwrap_function(fiberv);
            fiber = janet_fiber(func, 64, func->def->min_arity, &value);
            if (fiber == NULL) {
                janet_panicf("thread function must accept 0 or 1 arguments");
            }
            fiber->flags |=
                JANET_FIBER_MASK_ERROR |
                JANET_FIBER_MASK_USER0 |
                JANET_FIBER_MASK_USER1 |
                JANET_FIBER_MASK_USER2 |
                JANET_FIBER_MASK_USER3 |
                JANET_FIBER_MASK_USER4;
        } else {
            fiber = janet_unwrap_fiber(fiberv);
        }
        if (flags & 0x8) {
            if (NULL == fiber->env) fiber->env = janet_table(0);
            janet_table_put(fiber->env, janet_ckeywordv("task-id"), value);
        }
        fiber->supervisor_channel = janet_vm.user;
        janet_schedule(fiber, value);
        janet_loop();
        args.tag = JANET_EV_TCTAG_NIL;
    } else {
        void *supervisor = janet_vm.user;
        if (NULL != supervisor) {
            /* Got a supervisor, write error there */
            Janet pair[] = {
                janet_ckeywordv("error"),
                tstate.payload
            };
            janet_channel_push((JanetChannel *)supervisor,
                               janet_wrap_tuple(janet_tuple_n(pair, 2)), 2);
        } else if (flags & 0x1) {
            /* No wait, just print to stderr */
            janet_eprintf("thread start failure: %v\n", tstate.payload);
        } else {
            /* Make ev/thread call from parent thread error */
            if (janet_checktype(tstate.payload, JANET_STRING)) {
                args.tag = JANET_EV_TCTAG_ERR_STRINGF;
                args.argp = strdup((const char *) janet_unwrap_string(tstate.payload));
            } else {
                args.tag = JANET_EV_TCTAG_ERR_STRING;
                args.argp = "failed to start thread";
            }
        }
    }
    janet_restore(&tstate);
    janet_buffer_deinit(buffer);
    janet_free(buffer);
    janet_deinit();
    return args;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdi, -0x40(%rbp)
leaq 0x10(%rbp), %r12
movq 0x8(%r12), %rax
movq 0x18(%rax), %r15
movq %r15, -0x30(%rbp)
movq %rax, -0x68(%rbp)
movslq 0x10(%rax), %r14
movl (%r12), %r13d
movl $0x0, (%r12)
callq 0x4e80b
movl 0x4(%r12), %ebx
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movl %ebx, 0xf0(%rax)
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
callq 0x4e11e
leaq -0x140(%rbp), %rdi
callq 0x12580
testl %eax, %eax
je 0x2607a
movq (%rbx), %r15
testq %r15, %r15
je 0x260fa
leaq 0x4277e(%rip), %rdi     # 0x6879e
callq 0x47261
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
movq %rax, %rdi
callq 0x4ed39
leaq -0x60(%rbp), %rdi
movq %rax, (%rdi)
movq -0x78(%rbp), %rax
movq %rax, 0x8(%rdi)
movl $0x2, %ebx
movl %ebx, %esi
callq 0x47fef
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rax, %rdi
callq 0x4ed39
movq %r15, %rdi
movq %rax, %rsi
movl %ebx, %edx
callq 0x23191
movq -0x40(%rbp), %r14
jmp 0x26366
movq %r14, %r12
movabsq $-0x800000000000, %r14  # imm = 0xFFFF800000000000
movq %r15, %rdi
testb $0x2, %r13b
jne 0x260e4
xorl %eax, %eax
movl %eax, %ecx
leaq -0x30(%rbp), %r8
movq %r15, %rdi
movq %r12, %rsi
movl $0x20000, %edx          # imm = 0x20000
callq 0x30fa5
movq %rax, %rcx
andq %r14, %rcx
movabsq $-0x3800000000000, %r14 # imm = 0xFFFC800000000000
cmpq %r14, %rcx
jne 0x263b4
movq %rax, %rdi
callq 0x4ebc4
movq %rax, 0x68(%rbx)
movq %rax, %rdi
movq %r14, %rsi
callq 0x4ed7e
movq %rax, %rdi
callq 0x2b13a
movq -0x30(%rbp), %rdi
movq %r15, %r14
addq %r12, %r14
btl $0x8, %r13d
movq %rbx, -0x38(%rbp)
jb 0x26138
movq %rdi, %rbx
jmp 0x26161
testb $0x1, %r13b
movq -0x40(%rbp), %r14
jne 0x2632d
movq -0x78(%rbp), %rdi
movq %rdi, %rax
shrq $0x2f, %rax
cmpl $0x1fff4, %eax          # imm = 0x1FFF4
jne 0x26352
movl $0x6, (%r12)
callq 0x4ebc4
movq %rax, %rdi
callq 0x12b30
jmp 0x26361
movq %r14, %rsi
subq %rdi, %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x30(%rbp), %r15
movl $0x20000, %edx          # imm = 0x20000
movq %r15, %r8
callq 0x30fa5
movq %rax, %rdi
callq 0x4ebc4
movq %rax, (%rbx)
movq (%r15), %rbx
testb $0x4, %r13b
movl %r13d, -0x44(%rbp)
jne 0x261e9
movl (%rbx), %eax
movl %eax, %ecx
movq %r14, %rax
subq %rbx, %rax
addq $-0x4, %rax
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rdx
shrq $0x5, %rdx
cmpq %rcx, %rdx
jb 0x263c0
movq -0x38(%rbp), %r12
movq %rcx, 0x58(%r12)
movq %rcx, 0x50(%r12)
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %r15
movq %r15, %rdi
callq 0x12760
movq %rax, 0x48(%r12)
testq %rax, %rax
je 0x263dd
movq %rax, %rdi
movl $0x1, 0x60(%r12)
leaq 0x4(%rbx), %rsi
movq %rsi, -0x30(%rbp)
movq %r15, %rdx
callq 0x12670
leaq (%rbx,%r15), %rdi
addq $0x4, %rdi
movq %rdi, -0x30(%rbp)
jmp 0x261ec
movq %rbx, %rdi
movq %r14, %rsi
subq %rdi, %rsi
xorl %eax, %eax
movl %eax, %r12d
movl $0x20000, %edx          # imm = 0x20000
leaq -0x30(%rbp), %rbx
movq %r12, %rcx
movq %rbx, %r8
callq 0x30fa5
movq %rax, %r15
movq %rax, %r13
movq (%rbx), %rdi
subq %rdi, %r14
movq %r14, %rsi
movl $0x20000, %edx          # imm = 0x20000
movq %r12, %rcx
movq %rbx, %r8
callq 0x30fa5
movq %rax, -0x60(%rbp)
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq %r15, %rax
movabsq $-0x6800000000000, %rcx # imm = 0xFFF9800000000000
cmpq %rcx, %rax
je 0x2629e
movabsq $-0x2000000000000, %rcx # imm = 0xFFFE000000000000
cmpq %rcx, %rax
movq -0x40(%rbp), %r14
leaq 0x10(%rbp), %r12
movq -0x38(%rbp), %rbx
jne 0x263cc
movq %r13, %rdi
callq 0x4ebc4
movq 0x10(%rax), %rcx
movl 0x64(%rcx), %edx
leaq -0x60(%rbp), %rcx
movq %rax, %rdi
movl $0x40, %esi
callq 0x295e4
testq %rax, %rax
je 0x263e2
movq %rax, %r15
orl $0x1f2, 0x10(%rax)      # imm = 0x1F2
jmp 0x262b5
movq %r13, %rdi
callq 0x4ebc4
movq %rax, %r15
movq -0x40(%rbp), %r14
leaq 0x10(%rbp), %r12
movq -0x38(%rbp), %rbx
movl -0x44(%rbp), %eax
testb $0x8, %al
je 0x26307
movq 0x28(%r15), %rax
movq %rax, %rbx
testq %rax, %rax
jne 0x262d6
xorl %edi, %edi
callq 0x47425
movq %rax, %rbx
movq %rax, 0x28(%r15)
leaq 0x34a34(%rip), %rdi     # 0x5ad11
callq 0x47261
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
movq %rax, %rdi
callq 0x4ed39
movq -0x60(%rbp), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x476f0
movq -0x38(%rbp), %rbx
movq (%rbx), %rax
movq %rax, 0x68(%r15)
movq -0x60(%rbp), %rsi
xorl %ecx, %ecx
movq %r15, %rdi
movl %ecx, %edx
callq 0x2283b
callq 0x24ef2
movl $0x0, (%r12)
jmp 0x26366
movq 0x5ecbc(%rip), %rax     # 0x84ff0
movq (%rax), %rsi
movq -0x78(%rbp), %rcx
leaq 0x346dc(%rip), %rdi     # 0x5aa1e
leaq 0x34a9c(%rip), %rdx     # 0x5ade5
xorl %eax, %eax
callq 0x2ed91
jmp 0x26366
movl $0x5, (%r12)
leaq 0x34a9e(%rip), %rax     # 0x5adff
movq %rax, 0x8(%r12)
leaq -0x160(%rbp), %rdi
callq 0x4e18d
movq -0x68(%rbp), %r15
movq %r15, %rdi
callq 0x176e1
movq %r15, %rdi
callq 0x120b0
callq 0x4e954
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%r14)
movups %xmm0, (%r14)
movq %r14, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3499e(%rip), %rdi     # 0x5ad59
callq 0x191a3
leaq 0x349b7(%rip), %rdi     # 0x5ad7e
callq 0x191a3
leaq 0x349c2(%rip), %rdi     # 0x5ad95
xorl %eax, %eax
movq %r13, %rsi
callq 0x190bb
callq 0x13690
leaq 0x349cf(%rip), %rdi     # 0x5adb8
xorl %eax, %eax
callq 0x190bb