// File: /workspace/github_c_makefile_star2_O0/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
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x1b8(%rbp)
movq %rdi, -0x1b0(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x8(%rbp)
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, -0x10(%rbp)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rdx
movslq 0x10(%rdx), %rdx
addq %rdx, %rcx
movq %rcx, -0x18(%rbp)
movl (%rax), %ecx
movl %ecx, -0x1c(%rbp)
movl $0x0, (%rax)
callq 0x7a790
movq -0x1a8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x19c(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movl -0x19c(%rbp), %ecx
movl %ecx, 0xf0(%rax)
leaq -0x118(%rbp), %rdi
callq 0x79b10
leaq -0x118(%rbp), %rdi
addq $0x20, %rdi
callq 0x12580
movl %eax, -0x11c(%rbp)
cmpl $0x0, -0x11c(%rbp)
jne 0x3116d
movl -0x1c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x30d21
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
subq %rax, %rsi
movl $0x20000, %edx          # imm = 0x20000
xorl %eax, %eax
movl %eax, %ecx
leaq -0x10(%rbp), %r8
callq 0x436f0
movq %rax, -0x128(%rbp)
xorl %eax, %eax
testb $0x1, %al
jne 0x30c65
jmp 0x30c91
movsd -0x128(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x30c7a
jmp 0x30cbd
movq -0x128(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x30cbd
jmp 0x30cb1
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x128(%rbp), %rax
movabsq $-0x3800000000000, %rcx # imm = 0xFFFC800000000000
cmpq %rcx, %rax
je 0x30cbd
leaq 0x570d6(%rip), %rdi     # 0x87d8e
callq 0x1ad60
movq -0x128(%rbp), %rdi
callq 0x7b260
movq %rax, -0x1c0(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq -0x1c0(%rbp), %rcx
movq %rcx, 0x68(%rax)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x68(%rax), %rdi
movabsq $-0x3800000000000, %rsi # imm = 0xFFFC800000000000
callq 0x7b610
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rdi
callq 0x39200
movl -0x1c(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x30d83
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
subq %rax, %rsi
movl $0x20000, %edx          # imm = 0x20000
xorl %eax, %eax
movl %eax, %ecx
leaq -0x10(%rbp), %r8
callq 0x436f0
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rdi
callq 0x7b260
movq %rax, -0x1c8(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq -0x1c8(%rbp), %rcx
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x30f0d
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x13c(%rbp)
movl -0x13c(%rbp), %eax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
subq $0x4, %rax
movl $0x28, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x1d0(%rbp), %rax
cmpq %rcx, %rax
jbe 0x30ded
leaq 0x56fcb(%rip), %rdi     # 0x87db3
callq 0x1ad60
movq -0x148(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq -0x1e8(%rbp), %rcx
movq %rcx, 0x58(%rax)
movq -0x148(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq -0x1e0(%rbp), %rcx
movq %rcx, 0x50(%rax)
imulq $0x28, -0x148(%rbp), %rdi
callq 0x12770
movq %rax, -0x1d8(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq -0x1d8(%rbp), %rcx
movq %rcx, 0x48(%rax)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
cmpq $0x0, 0x48(%rax)
jne 0x30eb5
jmp 0x30e87
movq 0x7f162(%rip), %rax     # 0xafff0
movq (%rax), %rdi
leaq 0x4d16c(%rip), %rsi     # 0x7e004
leaq 0x569d9(%rip), %rdx     # 0x87878
movl $0xbd8, %ecx            # imm = 0xBD8
movb $0x0, %al
callq 0x125f0
movl $0x1, %edi
callq 0x12a70
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movl $0x1, 0x60(%rax)
movq -0x10(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x10(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rsi
imulq $0x28, -0x148(%rbp), %rdx
callq 0x12680
imulq $0x28, -0x148(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
subq %rax, %rsi
movl $0x20000, %edx          # imm = 0x20000
xorl %eax, %eax
movl %eax, %ecx
leaq -0x10(%rbp), %r8
callq 0x436f0
movq %rax, -0x150(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
subq %rax, %rsi
movl $0x20000, %edx          # imm = 0x20000
xorl %eax, %eax
movl %eax, %ecx
leaq -0x10(%rbp), %r8
callq 0x436f0
movq %rax, -0x158(%rbp)
xorl %eax, %eax
testb $0x1, %al
jne 0x30f65
jmp 0x30f98
movsd -0x150(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x30f7d
jmp 0x31092
movq -0x150(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x31092
jmp 0x30fbc
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x150(%rbp), %rax
movabsq $-0x6800000000000, %rcx # imm = 0xFFF9800000000000
cmpq %rcx, %rax
je 0x31092
xorl %eax, %eax
testb $0x1, %al
jne 0x30fc4
jmp 0x30ff0
movsd -0x150(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x30fd9
jmp 0x31025
movq -0x150(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x31025
jmp 0x31010
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x150(%rbp), %rax
movabsq $-0x2000000000000, %rcx # imm = 0xFFFE000000000000
cmpq %rcx, %rax
je 0x31025
movq -0x150(%rbp), %rsi
leaq 0x56dac(%rip), %rdi     # 0x87dca
movb $0x0, %al
callq 0x1ac40
movq -0x150(%rbp), %rdi
callq 0x7b260
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rdi
movq -0x168(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x64(%rax), %edx
movl $0x40, %esi
leaq -0x158(%rbp), %rcx
callq 0x36450
movq %rax, -0x160(%rbp)
cmpq $0x0, -0x160(%rbp)
jne 0x3107d
leaq 0x56d77(%rip), %rdi     # 0x87ded
movb $0x0, %al
callq 0x1ac40
movq -0x160(%rbp), %rax
movl 0x10(%rax), %ecx
orl $0x1f2, %ecx            # imm = 0x1F2
movl %ecx, 0x10(%rax)
jmp 0x310a5
movq -0x150(%rbp), %rdi
callq 0x7b260
movq %rax, -0x160(%rbp)
movl -0x1c(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x31125
movq -0x160(%rbp), %rcx
xorl %eax, %eax
cmpq 0x28(%rcx), %rax
jne 0x310d4
xorl %edi, %edi
callq 0x692f0
movq %rax, %rcx
movq -0x160(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x160(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x1f0(%rbp)
leaq 0x56c59(%rip), %rdi     # 0x87d46
callq 0x68d90
movq %rax, %rdi
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
callq 0x7b550
movq -0x1f0(%rbp), %rdi
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rsi
movq -0x158(%rbp), %rdx
callq 0x697e0
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq (%rax), %rcx
movq -0x160(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x160(%rbp), %rdi
movq -0x158(%rbp), %rsi
callq 0x2b160
callq 0x2eba0
movq -0x1a8(%rbp), %rax
movl $0x0, (%rax)
jmp 0x312e5
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq (%rax), %rax
movq %rax, -0x178(%rbp)
xorl %eax, %eax
cmpq -0x178(%rbp), %rax
je 0x3121b
leaq 0x64a91(%rip), %rdi     # 0x95c2e
callq 0x68d90
movq %rax, %rdi
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
callq 0x7b550
movq %rax, -0x190(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x1f8(%rbp)
leaq -0x190(%rbp), %rdi
movl $0x2, %esi
callq 0x6a7d0
movq %rax, %rdi
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
callq 0x7b550
movq -0x1f8(%rbp), %rdi
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rsi
movl $0x2, %edx
callq 0x2c160
jmp 0x312e3
movl -0x1c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3124e
movq 0x7edc3(%rip), %rax     # 0xafff0
movq (%rax), %rsi
movq -0x30(%rbp), %rcx
leaq 0x567f3(%rip), %rdi     # 0x87a2e
leaq 0x56bd8(%rip), %rdx     # 0x87e1a
movb $0x0, %al
callq 0x3fa20
jmp 0x312e1
xorl %eax, %eax
testb $0x1, %al
jne 0x31256
jmp 0x3127c
movsd -0x30(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x31268
jmp 0x31299
movq -0x30(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x31299
jmp 0x312c7
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0x30(%rbp), %rax
movabsq $-0x6000000000000, %rcx # imm = 0xFFFA000000000000
cmpq %rcx, %rax
jne 0x312c7
movq -0x1a8(%rbp), %rax
movl $0x6, (%rax)
movq -0x30(%rbp), %rdi
callq 0x7b260
movq %rax, %rdi
callq 0x12b40
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x312df
movq -0x1a8(%rbp), %rax
movl $0x5, (%rax)
leaq 0x56b59(%rip), %rcx     # 0x87e34
movq %rcx, 0x8(%rax)
jmp 0x312e1
jmp 0x312e3
jmp 0x312e5
leaq -0x118(%rbp), %rdi
callq 0x79c40
movq -0x8(%rbp), %rdi
callq 0x18460
movq -0x8(%rbp), %rdi
callq 0x120b0
callq 0x7ab60
movq -0x1a8(%rbp), %rdx
movq -0x1b8(%rbp), %rcx
movq -0x1b0(%rbp), %rax
movq (%rdx), %rsi
movq %rsi, (%rcx)
movq 0x8(%rdx), %rsi
movq %rsi, 0x8(%rcx)
movq 0x10(%rdx), %rsi
movq %rsi, 0x10(%rcx)
movq 0x18(%rdx), %rdx
movq %rdx, 0x18(%rcx)
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
nopw %cs:(%rax,%rax)