// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_const.c
// Function: constDeref
void constDeref(const Consts *consts, Const *constant, TypeKind typeKind)
{
    if (!constant->ptrVal)
        consts->error->handler(consts->error->context, "Pointer is null");

    switch (typeKind)
    {
        case TYPE_INT8:         constant->intVal     = *(int8_t         *)constant->ptrVal; break;
        case TYPE_INT16:        constant->intVal     = *(int16_t        *)constant->ptrVal; break;
        case TYPE_INT32:        constant->intVal     = *(int32_t        *)constant->ptrVal; break;
        case TYPE_INT:          constant->intVal     = *(int64_t        *)constant->ptrVal; break;
        case TYPE_UINT8:        constant->intVal     = *(uint8_t        *)constant->ptrVal; break;
        case TYPE_UINT16:       constant->intVal     = *(uint16_t       *)constant->ptrVal; break;
        case TYPE_UINT32:       constant->intVal     = *(uint32_t       *)constant->ptrVal; break;
        case TYPE_UINT:         constant->uintVal    = *(uint64_t       *)constant->ptrVal; break;
        case TYPE_BOOL:         constant->intVal     = *(bool           *)constant->ptrVal; break;
        case TYPE_CHAR:         constant->intVal     = *(unsigned char  *)constant->ptrVal; break;
        case TYPE_REAL32:       constant->realVal    = *(float          *)constant->ptrVal; break;
        case TYPE_REAL:         constant->realVal    = *(double         *)constant->ptrVal; break;
        case TYPE_PTR:          constant->ptrVal     = *(void *         *)constant->ptrVal; break;
        case TYPE_WEAKPTR:      constant->weakPtrVal = *(uint64_t       *)constant->ptrVal; break;
        case TYPE_STR:          constant->ptrVal     = *(void *         *)constant->ptrVal; break;
        case TYPE_ARRAY:
        case TYPE_DYNARRAY:
        case TYPE_STRUCT:
        case TYPE_INTERFACE:
        case TYPE_CLOSURE:      break;  // Always represented by pointer, not dereferenced
        case TYPE_FIBER:        constant->ptrVal     = *(void *         *)constant->ptrVal; break;
        case TYPE_FN:           constant->intVal     = *(int64_t        *)constant->ptrVal; break;

        default:                consts->error->handler(consts->error->context, "Illegal type"); return;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x86ed
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x1cf8e7(%rip), %rsi    # 0x1d7fd0
movb $0x0, %al
callq *%rcx
movl -0x14(%rbp), %eax
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x16, %eax
ja 0x8896
movq -0x20(%rbp), %rax
leaq 0x1cf4db(%rip), %rcx    # 0x1d7be8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movswq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movzbl (%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movzwl (%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movzbl (%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x88b6
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x1cf72e(%rip), %rsi    # 0x1d7fe0
movb $0x0, %al
callq *%rcx
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)