// File: /workspace/github_c_makefile_star2_O3/voithos[P]awl/src/types.c
// Function: awlval_convert
awlval* awlval_convert(awlval_type_t t, const awlval* v) {
    if (v->type == t) {
        return awlval_copy(v);
    }

    switch (t) {
        case AWLVAL_INT:
            switch (v->type) {
                case AWLVAL_FLOAT:
                    return awlval_int((long)v->dbl);
                    break;

                case AWLVAL_STR:
                    {
                        errno = 0;
                        char* strend = v->str;
                        long x = strtol(v->str, &strend, 10);
                        return errno != ERANGE && *strend == '\0' ? awlval_int(x) : awlval_err("invalid number: %s", v->str);
                    }
                    break;

                case AWLVAL_BOOL:
                    return awlval_int(v->bln);
                    break;

                default:
                    return awlval_err("a direct conversion from type %s to type %s does not exist",
                            awlval_type_name(v->type), awlval_type_name(t));
                    break;
            }
            break;

        case AWLVAL_FLOAT:
            switch (v->type) {
                case AWLVAL_INT:
                    return awlval_float((double)v->lng);
                    break;

                case AWLVAL_STR:
                    {
                        errno = 0;
                        char* strend = v->str;
                        double x = strtod(v->str, &strend);
                        return errno != ERANGE && *strend == '\0' ? awlval_float(x) : awlval_err("invalid float: %s", v->str);
                    }
                    break;

                case AWLVAL_BOOL:
                    return awlval_float((double)v->bln);
                    break;

                default:
                    return awlval_err("a direct conversion from type %s to type %s does not exist",
                            awlval_type_name(v->type), awlval_type_name(t));
                    break;
            }
            break;

        case AWLVAL_STR:
            if (v->type == AWLVAL_QSYM) {
                return awlval_str(v->sym);
            } else {
                char* str = awlval_to_str(v);
                awlval* res = awlval_str(str);
                free(str);
                return res;
            }
            break;

        case AWLVAL_BOOL:
            switch (v->type) {
                case AWLVAL_INT:
                    return awlval_bool(v->lng != 0 ? true : false);
                    break;

                case AWLVAL_FLOAT:
                    return awlval_bool(v->dbl != 0.0 ? true : false);
                    break;

                default:
                    return awlval_err("a direct conversion from type %s to type %s does not exist",
                            awlval_type_name(v->type), awlval_type_name(t));
                    break;
            }
            break;

        case AWLVAL_QSYM:
            switch (v->type) {
                case AWLVAL_STR:
                    return awlval_qsym(v->str);
                    break;

                default:
                    return awlval_err("a direct conversion from type %s to type %s does not exist",
                            awlval_type_name(v->type), awlval_type_name(t));
                    break;
            }
            break;

        default:
            return awlval_err("no type can be directly converted to type %s", awlval_type_name(t));
            break;
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %eax
movl (%rsi), %edi
cmpl %eax, %edi
jne 0x10bc7
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x10597
cmpl $0x6, %eax
ja 0x10c04
movl %eax, %ecx
leaq 0x2af3(%rip), %rdx      # 0x136c8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0x6, %edi
je 0x10d80
cmpl $0x5, %edi
je 0x10cf4
cmpl $0x1, %edi
jne 0x10da4
cvttsd2si 0x18(%rbx), %rdi
jmp 0x10d84
movl %eax, %edi
callq 0xfc74
leaq 0x2c62(%rip), %rdi      # 0x13874
movq %rax, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xfe6b
cmpl $0x5, %edi
jne 0x10c8c
movq 0x18(%rbx), %rdi
callq 0xffcd
movl $0x4, (%rax)
jmp 0x10d78
cmpl $0x6, %edi
je 0x10d90
cmpl $0x5, %edi
je 0x10d36
testl %edi, %edi
jne 0x10db0
cvtsi2sdq 0x18(%rbx), %xmm0
jmp 0x10d98
cmpl $0x4, %edi
jne 0x10c9e
movq 0x18(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x10032
cmpl $0x1, %edi
je 0x10cc4
testl %edi, %edi
jne 0x10ce2
xorl %edi, %edi
cmpq $0x0, 0x18(%rbx)
setne %dil
jmp 0x10cd6
callq 0xfc74
movq %rax, %rbx
movl $0x4, %edi
jmp 0x10dbd
movq %rbx, %rdi
callq 0xf75a
movq %rax, %rbx
movq %rax, %rdi
callq 0x10032
movq %rax, %r14
movq %rbx, %rdi
callq 0x23f0
movq %r14, %rax
jmp 0x10d78
xorpd %xmm0, %xmm0
cmpneqsd 0x18(%rbx), %xmm0
movq %xmm0, %rdi
andl $0x1, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x10090
callq 0xfc74
movq %rax, %rbx
movl $0x6, %edi
jmp 0x10dbd
callq 0x2060
movq %rax, %r14
movl $0x0, (%rax)
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
movq %rdi, (%rsi)
movl $0xa, %edx
callq 0x2260
cmpl $0x22, (%r14)
je 0x10d29
movq (%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x10ddd
movq 0x18(%rbx), %rsi
leaq 0x282a(%rip), %rdi      # 0x1355e
jmp 0x10d71
callq 0x2060
movq %rax, %r14
movl $0x0, (%rax)
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
movq %rdi, (%rsi)
callq 0x20b0
cmpl $0x22, (%r14)
je 0x10d66
movq (%rsp), %rax
cmpb $0x0, (%rax)
je 0x10de7
movq 0x18(%rbx), %rsi
leaq 0x2800(%rip), %rdi      # 0x13571
xorl %eax, %eax
callq 0xfe6b
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movzbl 0x18(%rbx), %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xff6f
movsbl 0x18(%rbx), %eax
cvtsi2sd %eax, %xmm0
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xff93
callq 0xfc74
movq %rax, %rbx
xorl %edi, %edi
jmp 0x10dbd
callq 0xfc74
movq %rax, %rbx
movl $0x1, %edi
callq 0xfc74
leaq 0x2a70(%rip), %rdi      # 0x13839
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xfe6b
movq %rax, %rdi
callq 0xff6f
jmp 0x10d78
callq 0xff93
jmp 0x10d78