// File: /workspace/github_c_makefile_star2_O3/vtereshkov[P]umka-lang/src/umka_const.c
// Function: constAssign
void constAssign(const Consts *consts, void *lhs, const Const *rhs, TypeKind typeKind, int size)
{
    if (typeOverflow(typeKind, *rhs))
        consts->error->handler(consts->error->context, "Overflow in assignment to %s", typeKindSpelling(typeKind));

    switch (typeKind)
    {
        case TYPE_INT8:         *(int8_t        *)lhs = rhs->intVal;         break;
        case TYPE_INT16:        *(int16_t       *)lhs = rhs->intVal;         break;
        case TYPE_INT32:        *(int32_t       *)lhs = rhs->intVal;         break;
        case TYPE_INT:          *(int64_t       *)lhs = rhs->intVal;         break;
        case TYPE_UINT8:        *(uint8_t       *)lhs = rhs->intVal;         break;
        case TYPE_UINT16:       *(uint16_t      *)lhs = rhs->intVal;         break;
        case TYPE_UINT32:       *(uint32_t      *)lhs = rhs->intVal;         break;
        case TYPE_UINT:         *(uint64_t      *)lhs = rhs->uintVal;        break;
        case TYPE_BOOL:         *(bool          *)lhs = rhs->intVal;         break;
        case TYPE_CHAR:         *(unsigned char *)lhs = rhs->intVal;         break;
        case TYPE_REAL32:       *(float         *)lhs = rhs->realVal;        break;
        case TYPE_REAL:         *(double        *)lhs = rhs->realVal;        break;
        case TYPE_PTR:          *(void *        *)lhs = rhs->ptrVal;         break;
        case TYPE_WEAKPTR:      *(uint64_t      *)lhs = rhs->weakPtrVal;     break;
        case TYPE_STR:          *(void *        *)lhs = rhs->ptrVal;         break;
        case TYPE_ARRAY:
        case TYPE_DYNARRAY:
        case TYPE_STRUCT:
        case TYPE_INTERFACE:
        case TYPE_CLOSURE:      memcpy(lhs, rhs->ptrVal, size);              break;
        case TYPE_FIBER:        *(void *        *)lhs = rhs->ptrVal;         break;
        case TYPE_FN:           *(int64_t       *)lhs = rhs->intVal;         break;

        default:          consts->error->handler(consts->error->context, "Illegal type"); return;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
leal -0x4(%rcx), %r13d
cmpl $0x16, %r13d
ja 0x9dda
movq (%r14), %rax
movq %rax, %xmm0
leaq 0x6bf08(%rip), %rdx     # 0x75c44
movslq (%rdx,%r13,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
cmpq $0xff, %rax
ja 0x9dda
jmp 0x9e4a
movslq %eax, %rdx
cmpq %rax, %rdx
jne 0x9dda
jmp 0x9e5b
movsbq %al, %rdx
cmpq %rax, %rdx
jne 0x9dda
jmp 0x9e4a
cmpq $0x1, %rax
ja 0x9dda
jmp 0x9e63
movdqa 0x6c22c(%rip), %xmm1    # 0x75fb0
pand %xmm0, %xmm1
ucomisd 0x6c268(%rip), %xmm1    # 0x75ff8
ja 0x9dda
jmp 0x9e71
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x9dda
jmp 0x9e52
movdqa 0x6c204(%rip), %xmm1    # 0x75fb0
pand %xmm0, %xmm1
ucomisd 0x6c238(%rip), %xmm1    # 0x75ff0
ja 0x9dda
jmp 0x9ea4
movswq %ax, %rdx
cmpq %rax, %rdx
jne 0x9dda
jmp 0x9e52
movq %rax, %rdx
shrq $0x20, %rdx
je 0x9e5b
movq (%rdi), %rax
movq (%rax), %rdx
movq %rdx, (%rsp)
movq 0x20(%rax), %r12
movq %rdi, %rbp
movl %ecx, %edi
movl %r8d, %ebx
callq 0x1adb4
leaq 0x6c221(%rip), %rsi     # 0x7601d
movq %r12, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq *(%rsp)
movq %rbp, %rdi
movl %ebx, %r8d
cmpl $0x16, %r13d
ja 0x9e7c
leaq 0x6be86(%rip), %rax     # 0x75ca0
movslq (%rax,%r13,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq (%r14), %rax
movq %rax, (%r15)
jmp 0x9ea9
movq (%r14), %rsi
movslq %r8d, %rdx
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3260
movq (%r14), %rax
movb %al, (%r15)
jmp 0x9ea9
movq (%r14), %rax
movw %ax, (%r15)
jmp 0x9ea9
movq (%r14), %rax
movl %eax, (%r15)
jmp 0x9ea9
movq (%r14), %rax
testq %rax, %rax
setne (%r15)
jmp 0x9ea9
movq (%r14), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r15)
jmp 0x9ea9
movq (%rdi), %rax
movq (%rax), %rcx
movq 0x20(%rax), %rdi
leaq 0x6c183(%rip), %rsi     # 0x76010
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rcx
movq (%r14), %xmm0
movq %xmm0, (%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq