// File: /workspace/github_c_makefile_star2_O2/janet-lang[P]janet/src/core/asm.c
// Function: doarg_1
static int32_t doarg_1(
    JanetAssembler *a,
    enum JanetOpArgType argtype,
    Janet x) {
    int32_t ret = -1;
    JanetTable *c;
    switch (argtype) {
        default:
            c = NULL;
            break;
        case JANET_OAT_SLOT:
            c = &a->slots;
            break;
        case JANET_OAT_ENVIRONMENT:
            c = &a->envs;
            break;
        case JANET_OAT_LABEL:
            c = &a->labels;
            break;
        case JANET_OAT_FUNCDEF:
            c = &a->defs;
            break;
    }
    switch (janet_type(x)) {
        default:
            goto error;
            break;
        case JANET_NUMBER: {
            double y = janet_unwrap_number(x);
            if (janet_checkintrange(y)) {
                ret = (int32_t) y;
            } else {
                goto error;
            }
            break;
        }
        case JANET_TUPLE: {
            const Janet *t = janet_unwrap_tuple(x);
            if (argtype == JANET_OAT_TYPE) {
                int32_t i = 0;
                ret = 0;
                for (i = 0; i < janet_tuple_length(t); i++) {
                    ret |= doarg_1(a, JANET_OAT_SIMPLETYPE, t[i]);
                }
            } else {
                goto error;
            }
            break;
        }
        case JANET_KEYWORD: {
            if (NULL != c && argtype == JANET_OAT_LABEL) {
                Janet result = janet_table_get(c, x);
                if (janet_checktype(result, JANET_NUMBER)) {
                    ret = janet_unwrap_integer(result) - a->bytecode_count;
                } else {
                    goto error;
                }
            } else if (argtype == JANET_OAT_TYPE || argtype == JANET_OAT_SIMPLETYPE) {
                const TypeAlias *alias = janet_strbinsearch(
                                             &type_aliases,
                                             sizeof(type_aliases) / sizeof(TypeAlias),
                                             sizeof(TypeAlias),
                                             janet_unwrap_keyword(x));
                if (alias) {
                    ret = alias->mask;
                } else {
                    janet_asm_errorv(a, janet_formatc("unknown type %v", x));
                }
            } else {
                goto error;
            }
            break;
        }
        case JANET_SYMBOL: {
            if (NULL != c) {
                Janet result = janet_table_get(c, x);
                if (janet_checktype(result, JANET_NUMBER)) {
                    ret = (int32_t) janet_unwrap_number(result);
                } else {
                    janet_asm_errorv(a, janet_formatc("unknown name %v", x));
                }
            } else {
                goto error;
            }
            if (argtype == JANET_OAT_ENVIRONMENT && ret == -1) {
                /* Add a new env */
                ret = janet_asm_addenv(a, x);
                if (ret < -1) {
                    janet_asm_errorv(a, janet_formatc("unknown environment %v", x));
                }
            }
            break;
        }
    }
    if (argtype == JANET_OAT_SLOT && ret >= a->def->slotcount)
        a->def->slotcount = (int32_t) ret + 1;
    return ret;

error:
    janet_asm_errorv(a, janet_formatc("error parsing instruction argument %v", x));
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
xorl %eax, %eax
xorl %edi, %edi
cmpl $0x7, %esi
ja 0x15b48
movl %r15d, %ecx
leaq 0x38343(%rip), %rdx     # 0x4de60
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
leaq 0x128(%rbx), %rdi
jmp 0x15b48
leaq 0xf8(%rbx), %rdi
jmp 0x15b48
leaq 0x158(%rbx), %rdi
jmp 0x15b48
leaq 0x188(%rbx), %rdi
movq %r14, %xmm0
movq %r14, %rcx
shrq $0x2f, %rcx
andl $0xf, %ecx
ucomisd %xmm0, %xmm0
cmovpl %ecx, %eax
cmpl $0x8, %eax
ja 0x15d10
leaq 0x38312(%rip), %rcx     # 0x4de80
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
ucomisd 0x388f9(%rip), %xmm0    # 0x4e478
jb 0x15d10
movsd 0x388f3(%rip), %xmm1    # 0x4e480
ucomisd %xmm0, %xmm1
jb 0x15d10
cvttpd2dq %xmm0, %xmm1
cvtdq2pd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x15d10
jp 0x15d10
cvttsd2si %xmm0, %r12d
jmp 0x15cb5
testq %rdi, %rdi
sete %al
cmpl $0x6, %r15d
setne %cl
orb %al, %cl
jne 0x15cce
movq %r14, %rsi
callq 0x43c35
movq %rax, %xmm0
ucomisd %xmm0, %xmm0
setp %cl
movabsq $0x7800000000000, %rdx  # imm = 0x7800000000000
testq %rdx, %rax
setne %al
testb %al, %cl
jne 0x15d10
cvttsd2si %xmm0, %r12d
subl 0xec(%rbx), %r12d
jmp 0x15cfe
movq %r14, %rdi
callq 0x4b1f1
cmpl $0x4, %r15d
jne 0x15d10
movq %rax, %r13
movl %r15d, -0x2c(%rbp)
xorl %r15d, %r15d
pushq $0x5
popq %r14
xorl %r12d, %r12d
movslq -0x10(%r13), %rax
cmpq %rax, %r15
jge 0x15cb1
movq (%r13,%r15,8), %rdx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x15af3
orl %eax, %r12d
incq %r15
jmp 0x15c2e
testq %rdi, %rdi
je 0x15d10
movq %r14, %rsi
callq 0x43c35
movq %rax, %xmm0
ucomisd %xmm0, %xmm0
setp %cl
movabsq $0x7800000000000, %rdx  # imm = 0x7800000000000
testq %rdx, %rax
setne %al
testb %al, %cl
jne 0x15d30
cvttsd2si %xmm0, %r12d
cmpl $0x1, %r15d
jne 0x15cb5
cmpl $-0x1, %r12d
jne 0x15cb5
movq %rbx, %rdi
movq %r14, %rsi
callq 0x15d42
movl %eax, %r12d
cmpl $-0x2, %eax
jg 0x15cfe
leaq 0x38e2a(%rip), %rdi     # 0x4ead9
jmp 0x15d17
movl -0x2c(%rbp), %r15d
testl %r15d, %r15d
jne 0x15cfe
movq 0x8(%rbx), %rax
cmpl 0x5c(%rax), %r12d
jl 0x15cfe
leal 0x1(%r12), %ecx
movl %ecx, 0x5c(%rax)
jmp 0x15cfe
andl $-0x2, %r15d
cmpl $0x4, %r15d
jne 0x15d10
movq %r14, %rdi
callq 0x4b1f1
leaq 0x646f9(%rip), %rdi     # 0x7a3e0
pushq $0x13
popq %rsi
pushq $0x10
popq %rdx
movq %rax, %rcx
callq 0x44cee
testq %rax, %rax
je 0x15d39
movl 0x8(%rax), %r12d
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38dd9(%rip), %rdi     # 0x4eaf0
movq %r14, %rsi
xorl %eax, %eax
callq 0x3c0ed
movq %rax, 0xd8(%rbx)
movq %rbx, %rdi
callq 0x15980
leaq 0x38d92(%rip), %rdi     # 0x4eac9
jmp 0x15d17
leaq 0x38d79(%rip), %rdi     # 0x4eab9
jmp 0x15d17