// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/asm.c
// Function: read_instruction
static uint32_t read_instruction(
    JanetAssembler *a,
    const JanetInstructionDef *idef,
    const Janet *argt) {
    uint32_t instr = idef->opcode;
    enum JanetInstructionType type = janet_instructions[idef->opcode];
    switch (type) {
        case JINT_0: {
            if (janet_tuple_length(argt) != 1)
                janet_asm_error(a, "expected 0 arguments: (op)");
            break;
        }
        case JINT_S: {
            if (janet_tuple_length(argt) != 2)
                janet_asm_error(a, "expected 1 argument: (op, slot)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 2, 0, argt[1]);
            break;
        }
        case JINT_L: {
            if (janet_tuple_length(argt) != 2)
                janet_asm_error(a, "expected 1 argument: (op, label)");
            instr |= doarg(a, JANET_OAT_LABEL, 1, 3, 1, argt[1]);
            break;
        }
        case JINT_SS: {
            if (janet_tuple_length(argt) != 3)
                janet_asm_error(a, "expected 2 arguments: (op, slot, slot)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 1, 0, argt[1]);
            instr |= doarg(a, JANET_OAT_SLOT, 2, 2, 0, argt[2]);
            break;
        }
        case JINT_SL: {
            if (janet_tuple_length(argt) != 3)
                janet_asm_error(a, "expected 2 arguments: (op, slot, label)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 1, 0, argt[1]);
            instr |= doarg(a, JANET_OAT_LABEL, 2, 2, 1, argt[2]);
            break;
        }
        case JINT_ST: {
            if (janet_tuple_length(argt) != 3)
                janet_asm_error(a, "expected 2 arguments: (op, slot, type)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 1, 0, argt[1]);
            instr |= doarg(a, JANET_OAT_TYPE, 2, 2, 0, argt[2]);
            break;
        }
        case JINT_SI:
        case JINT_SU: {
            if (janet_tuple_length(argt) != 3)
                janet_asm_error(a, "expected 2 arguments: (op, slot, integer)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 1, 0, argt[1]);
            instr |= doarg(a, JANET_OAT_INTEGER, 2, 2, type == JINT_SI, argt[2]);
            break;
        }
        case JINT_SD: {
            if (janet_tuple_length(argt) != 3)
                janet_asm_error(a, "expected 2 arguments: (op, slot, funcdef)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 1, 0, argt[1]);
            instr |= doarg(a, JANET_OAT_FUNCDEF, 2, 2, 0, argt[2]);
            break;
        }
        case JINT_SSS: {
            if (janet_tuple_length(argt) != 4)
                janet_asm_error(a, "expected 3 arguments: (op, slot, slot, slot)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 1, 0, argt[1]);
            instr |= doarg(a, JANET_OAT_SLOT, 2, 1, 0, argt[2]);
            instr |= doarg(a, JANET_OAT_SLOT, 3, 1, 0, argt[3]);
            break;
        }
        case JINT_SSI:
        case JINT_SSU: {
            if (janet_tuple_length(argt) != 4)
                janet_asm_error(a, "expected 3 arguments: (op, slot, slot, integer)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 1, 0, argt[1]);
            instr |= doarg(a, JANET_OAT_SLOT, 2, 1, 0, argt[2]);
            instr |= doarg(a, JANET_OAT_INTEGER, 3, 1, type == JINT_SSI, argt[3]);
            break;
        }
        case JINT_SES: {
            JanetAssembler *b = a;
            uint32_t env;
            if (janet_tuple_length(argt) != 4)
                janet_asm_error(a, "expected 3 arguments: (op, slot, environment, envslot)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 1, 0, argt[1]);
            env = doarg(a, JANET_OAT_ENVIRONMENT, 0, 1, 0, argt[2]);
            instr |= env << 16;
            for (env += 1; env > 0; env--) {
                b = b->parent;
                if (NULL == b)
                    janet_asm_error(a, "invalid environment index");
            }
            instr |= doarg(b, JANET_OAT_SLOT, 3, 1, 0, argt[3]);
            break;
        }
        case JINT_SC: {
            if (janet_tuple_length(argt) != 3)
                janet_asm_error(a, "expected 2 arguments: (op, slot, constant)");
            instr |= doarg(a, JANET_OAT_SLOT, 1, 1, 0, argt[1]);
            instr |= doarg(a, JANET_OAT_CONSTANT, 2, 2, 0, argt[2]);
            break;
        }
    }
    return instr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
leaq 0x98fc2(%rip), %rax     # 0xb0650
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq %rax, -0x38(%rbp)
subq $0xd, %rax
ja 0x17be6
movq -0x38(%rbp), %rax
leaq 0x67778(%rip), %rcx     # 0x7ee28
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
cmpl $0x1, -0x10(%rax)
je 0x176d3
movq -0x8(%rbp), %rdi
leaq 0x6817c(%rip), %rsi     # 0x7f84a
callq 0x17500
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x2, -0x10(%rax)
je 0x176f2
movq -0x8(%rbp), %rdi
leaq 0x68178(%rip), %rsi     # 0x7f865
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %edx
movl $0x2, %ecx
movl %r8d, %esi
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x2, -0x10(%rax)
je 0x17738
movq -0x8(%rbp), %rdi
leaq 0x68152(%rip), %rsi     # 0x7f885
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
movl $0x6, %esi
movl $0x1, %r8d
movl $0x3, %ecx
movl %r8d, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x3, -0x10(%rax)
je 0x17781
movq -0x8(%rbp), %rdi
leaq 0x6812a(%rip), %rsi     # 0x7f8a6
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r9
xorl %r8d, %r8d
movl $0x2, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x3, -0x10(%rax)
je 0x177e8
movq -0x8(%rbp), %rdi
leaq 0x680ea(%rip), %rsi     # 0x7f8cd
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r9
movl $0x6, %esi
movl $0x2, %ecx
movl $0x1, %r8d
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x3, -0x10(%rax)
je 0x17854
movq -0x8(%rbp), %rdi
leaq 0x680a6(%rip), %rsi     # 0x7f8f5
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r9
movl $0x4, %esi
movl $0x2, %ecx
xorl %r8d, %r8d
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x3, -0x10(%rax)
je 0x178bd
movq -0x8(%rbp), %rdi
leaq 0x68064(%rip), %rsi     # 0x7f91c
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
cmpl $0x6, -0x20(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %r8d
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r9
movl $0x3, %esi
movl $0x2, %ecx
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x3, -0x10(%rax)
je 0x17930
movq -0x8(%rbp), %rdi
leaq 0x6801b(%rip), %rsi     # 0x7f946
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r9
movl $0x7, %esi
movl $0x2, %ecx
xorl %r8d, %r8d
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x4, -0x10(%rax)
je 0x17999
movq -0x8(%rbp), %rdi
leaq 0x67fdc(%rip), %rsi     # 0x7f970
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r9
xorl %r8d, %r8d
movl $0x2, %edx
movl $0x1, %ecx
movl %r8d, %esi
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %r9
xorl %r8d, %r8d
movl $0x3, %edx
movl $0x1, %ecx
movl %r8d, %esi
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x4, -0x10(%rax)
je 0x17a2a
movq -0x8(%rbp), %rdi
leaq 0x67f78(%rip), %rsi     # 0x7f99d
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r9
xorl %r8d, %r8d
movl $0x2, %edx
movl $0x1, %ecx
movl %r8d, %esi
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
cmpl $0xa, -0x20(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %r8d
movq -0x18(%rbp), %rax
movq 0x18(%rax), %r9
movl $0x3, %edx
movl $0x1, %ecx
movl %edx, %esi
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x4, -0x10(%rax)
je 0x17acc
movq -0x8(%rbp), %rdi
leaq 0x67f06(%rip), %rsi     # 0x7f9cd
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r9
movl $0x1, %ecx
xorl %r8d, %r8d
movl %ecx, %esi
movl %r8d, %edx
callq 0x17bf0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll $0x10, %eax
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jbe 0x17b5c
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
xorl %eax, %eax
cmpq -0x28(%rbp), %rax
jne 0x17b4f
movq -0x8(%rbp), %rdi
leaq 0x67eba(%rip), %rsi     # 0x7fa04
callq 0x17500
jmp 0x17b51
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x17b26
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %r9
xorl %r8d, %r8d
movl $0x3, %edx
movl $0x1, %ecx
movl %r8d, %esi
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17be6
movq -0x18(%rbp), %rax
cmpl $0x3, -0x10(%rax)
je 0x17b9f
movq -0x8(%rbp), %rdi
leaq 0x67e84(%rip), %rsi     # 0x7fa1e
callq 0x17500
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %r9
xorl %r8d, %r8d
movl $0x1, %ecx
movl %r8d, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %r9
movl $0x2, %ecx
xorl %r8d, %r8d
movl %ecx, %esi
movl %ecx, %edx
callq 0x17bf0
orl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop