// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_types.c
// Function: typeDeepCopy
void typeDeepCopy(Storage *storage, Type *dest, const Type *src)
{
    const Type *next = dest->next;
    *dest = *src;
    dest->next = next;

    if ((dest->kind == TYPE_STRUCT || dest->kind == TYPE_INTERFACE || dest->kind == TYPE_CLOSURE) && dest->numItems > 0)
    {
        dest->field = storageAdd(storage, dest->numItems * sizeof(Field *));
        for (int i = 0; i < dest->numItems; i++)
        {
            Field *field = storageAdd(storage, sizeof(Field));
            *field = *(src->field[i]);
            dest->field[i] = field;
        }
    }
    else if (typeEnum(dest) && dest->numItems > 0)
    {
        dest->enumConst = storageAdd(storage, dest->numItems * sizeof(EnumConst *));
        for (int i = 0; i < dest->numItems; i++)
        {
            EnumConst *enumConst = storageAdd(storage, sizeof(EnumConst));
            *enumConst = *(src->enumConst[i]);
            dest->enumConst[i] = enumConst;
        }
    }
    else if (dest->kind == TYPE_FN && dest->sig.numParams > 0)
    {
        for (int i = 0; i < dest->sig.numParams; i++)
        {
            Param *param = storageAdd(storage, sizeof(Param));
            *param = *(src->sig.param[i]);
            dest->sig.param[i] = param;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0xc8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0xd0, %edx
callq 0x3270
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x10(%rbp), %rax
cmpl $0x16, (%rax)
je 0x21da3
movq -0x10(%rbp), %rax
cmpl $0x17, (%rax)
je 0x21da3
movq -0x10(%rbp), %rax
cmpl $0x18, (%rax)
jne 0x21e38
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0x21e38
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x4b20
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x21e33
movq -0x8(%rbp), %rdi
movl $0x118, %esi            # imm = 0x118
callq 0x4b20
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl $0x118, %edx            # imm = 0x118
callq 0x3270
movq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x21dd8
jmp 0x21f51
movq -0x10(%rbp), %rdi
callq 0x21f60
testb $0x1, %al
jne 0x21e4a
jmp 0x21edc
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0x21edc
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x4b20
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x21eda
movq -0x8(%rbp), %rdi
movl $0x110, %esi            # imm = 0x110
callq 0x4b20
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl $0x110, %edx            # imm = 0x110
callq 0x3270
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x21e7f
jmp 0x21f4f
movq -0x10(%rbp), %rax
cmpl $0x1a, (%rax)
jne 0x21f4d
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jle 0x21f4d
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x21f4b
movq -0x8(%rbp), %rdi
movl $0x118, %esi            # imm = 0x118
callq 0x4b20
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq 0x38(%rax,%rcx,8), %rsi
movl $0x118, %edx            # imm = 0x118
callq 0x3270
movq -0x50(%rbp), %rdx
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq %rdx, 0x38(%rax,%rcx,8)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x21ef6
jmp 0x21f4d
jmp 0x21f4f
jmp 0x21f51
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)