// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x17ccf
movq -0x18(%rbp), %rdi
callq 0x171d0
movq %rax, -0x8(%rbp)
jmp 0x1809d
movl -0xc(%rbp), %eax
movq %rax, -0x50(%rbp)
subq $0x6, %rax
ja 0x18080
movq -0x50(%rbp), %rax
leaq 0x3d45(%rip), %rcx      # 0x1ba30
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
subl $0x1, %eax
je 0x17d1f
jmp 0x17d04
movl -0x54(%rbp), %eax
subl $0x5, %eax
je 0x17d37
jmp 0x17d0e
movl -0x54(%rbp), %eax
subl $0x6, %eax
je 0x17db4
jmp 0x17dd0
movq -0x18(%rbp), %rax
cvttsd2si 0x18(%rax), %rdi
callq 0x16770
movq %rax, -0x8(%rbp)
jmp 0x1809d
callq 0x2050
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
movl $0xa, %edx
callq 0x2220
movq %rax, -0x28(%rbp)
callq 0x2050
cmpl $0x22, (%rax)
je 0x17d8d
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x17d8d
movq -0x28(%rbp), %rdi
callq 0x16770
movq %rax, -0x60(%rbp)
jmp 0x17da7
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0x3aa8(%rip), %rdi      # 0x1b844
movb $0x0, %al
callq 0x16600
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movb 0x18(%rax), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %edi
callq 0x16770
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movl (%rax), %edi
callq 0x161a0
movq %rax, -0x68(%rbp)
movl -0xc(%rbp), %edi
callq 0x161a0
movq -0x68(%rbp), %rsi
movq %rax, %rdx
leaq 0x3d34(%rip), %rdi      # 0x1bb29
movb $0x0, %al
callq 0x16600
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
testl %eax, %eax
je 0x17e2f
jmp 0x17e14
movl -0x6c(%rbp), %eax
subl $0x5, %eax
je 0x17e47
jmp 0x17e1e
movl -0x6c(%rbp), %eax
subl $0x6, %eax
je 0x17ec1
jmp 0x17edf
movq -0x18(%rbp), %rax
cvtsi2sdq 0x18(%rax), %xmm0
callq 0x167b0
movq %rax, -0x8(%rbp)
jmp 0x1809d
callq 0x2050
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2090
movsd %xmm0, -0x38(%rbp)
callq 0x2050
cmpl $0x22, (%rax)
je 0x17e9a
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x17e9a
movsd -0x38(%rbp), %xmm0
callq 0x167b0
movq %rax, -0x78(%rbp)
jmp 0x17eb4
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0x39ae(%rip), %rdi      # 0x1b857
movb $0x0, %al
callq 0x16600
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movb 0x18(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
callq 0x167b0
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movl (%rax), %edi
callq 0x161a0
movq %rax, -0x80(%rbp)
movl -0xc(%rbp), %edi
callq 0x161a0
movq -0x80(%rbp), %rsi
movq %rax, %rdx
leaq 0x3c25(%rip), %rdi      # 0x1bb29
movb $0x0, %al
callq 0x16600
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x17f33
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x168c0
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rdi
callq 0x15a40
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x168c0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x23a0
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x84(%rbp)
testl %eax, %eax
je 0x17f82
jmp 0x17f75
movl -0x84(%rbp), %eax
subl $0x1, %eax
je 0x17fb2
jmp 0x17ff0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
cmpl $0x0, %eax
setne %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x16930
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movsd 0x18(%rax), %xmm0
xorps %xmm1, %xmm1
xorl %eax, %eax
movl $0x1, %ecx
ucomisd %xmm1, %xmm0
setp %sil
setne %dl
orb %sil, %dl
cmovnel %ecx, %eax
cmpl $0x0, %eax
setne %al
movzbl %al, %edi
andl $0x1, %edi
callq 0x16930
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movl (%rax), %edi
callq 0x161a0
movq %rax, -0x90(%rbp)
movl -0xc(%rbp), %edi
callq 0x161a0
movq -0x90(%rbp), %rsi
movq %rax, %rdx
leaq 0x3b0e(%rip), %rdi      # 0x1bb29
movb $0x0, %al
callq 0x16600
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movl (%rax), %eax
subl $0x5, %eax
jne 0x18048
jmp 0x18035
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x16890
movq %rax, -0x8(%rbp)
jmp 0x1809d
movq -0x18(%rbp), %rax
movl (%rax), %edi
callq 0x161a0
movq %rax, -0x98(%rbp)
movl -0xc(%rbp), %edi
callq 0x161a0
movq -0x98(%rbp), %rsi
movq %rax, %rdx
leaq 0x3ab6(%rip), %rdi      # 0x1bb29
movb $0x0, %al
callq 0x16600
movq %rax, -0x8(%rbp)
jmp 0x1809d
movl -0xc(%rbp), %edi
callq 0x161a0
movq %rax, %rsi
leaq 0x3ad2(%rip), %rdi      # 0x1bb64
movb $0x0, %al
callq 0x16600
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)