// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movl (%rsi), %edi
cmpl %ebp, %edi
jne 0x110a3
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x10a5f
cmpl $0x6, %ebp
ja 0x110e0
movl %ebp, %eax
leaq 0x25bf(%rip), %rcx      # 0x13670
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x6, %edi
je 0x11261
cmpl $0x5, %edi
je 0x111d6
cmpl $0x1, %edi
jne 0x11166
cvttsd2si 0x18(%rbx), %rdi
jmp 0x11265
movl %ebp, %edi
callq 0x10138
leaq 0x272e(%rip), %rdi      # 0x1381c
movq %rax, %rsi
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x1032f
cmpl $0x5, %edi
jne 0x11166
movq 0x18(%rbx), %rdi
callq 0x10495
movl $0x4, (%rax)
jmp 0x11258
cmpl $0x6, %edi
je 0x11272
cmpl $0x5, %edi
je 0x11217
testl %edi, %edi
jne 0x11166
cvtsi2sdq 0x18(%rbx), %xmm0
jmp 0x1127a
cmpl $0x4, %edi
jne 0x11191
movq 0x18(%rbx), %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x104fa
cmpl $0x1, %edi
je 0x111b7
testl %edi, %edi
jne 0x11166
xorl %edi, %edi
cmpq $0x0, 0x18(%rbx)
setne %dil
jmp 0x111c9
callq 0x10138
movq %rax, %rbx
movl %ebp, %edi
callq 0x10138
leaq 0x2665(%rip), %rdi      # 0x137e1
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x1032f
movq %rbx, %rdi
callq 0xfc22
movq %rax, %rbx
movq %rax, %rdi
callq 0x104fa
movq %rax, %r14
movq %rbx, %rdi
callq 0x23f0
movq %r14, %rax
jmp 0x11258
xorpd %xmm0, %xmm0
cmpneqsd 0x18(%rbx), %xmm0
movq %xmm0, %rdi
andl $0x1, %edi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x10558
callq 0x2060
movq %rax, %r14
movl $0x0, (%rax)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
movq %rdi, (%rsi)
movl $0xa, %edx
callq 0x2260
cmpl $0x22, (%r14)
je 0x1120a
movq 0x8(%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x11287
movq 0x18(%rbx), %rsi
leaq 0x22f1(%rip), %rdi      # 0x13506
jmp 0x11251
callq 0x2060
movq %rax, %r14
movl $0x0, (%rax)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
movq %rdi, (%rsi)
callq 0x20b0
cmpl $0x22, (%r14)
je 0x11246
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x11291
movq 0x18(%rbx), %rsi
leaq 0x22c8(%rip), %rdi      # 0x13519
xorl %eax, %eax
callq 0x1032f
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movzbl 0x18(%rbx), %edi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x10437
movsbl 0x18(%rbx), %eax
cvtsi2sd %eax, %xmm0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x1045b
movq %rax, %rdi
callq 0x10437
jmp 0x11258
callq 0x1045b
jmp 0x11258