// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq 0xc8(%rsi), %r12
movl $0xd0, %edx
movq %rsi, %rdi
movq %rbx, %rsi
callq 0x3260
movq %r12, 0xc8(%r14)
movl (%r14), %eax
leal -0x16(%rax), %ecx
cmpl $0x2, %ecx
ja 0x1ed0f
movslq 0x10(%r14), %rsi
testq %rsi, %rsi
jle 0x1ed0f
shlq $0x3, %rsi
movq %r15, %rdi
callq 0xcca8
movq %rax, 0x28(%r14)
cmpl $0x0, 0x10(%r14)
jle 0x1edc9
xorl %r13d, %r13d
movl $0x118, %esi            # imm = 0x118
movq %r15, %rdi
callq 0xcca8
movq %rax, %r12
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rsi
movl $0x118, %edx            # imm = 0x118
movq %r12, %rdi
callq 0x3260
movq 0x28(%r14), %rax
movq %r12, (%rax,%r13,8)
incq %r13
movslq 0x10(%r14), %rax
cmpq %rax, %r13
jl 0x1ecd1
jmp 0x1edc9
leal -0x4(%rax), %ecx
cmpl $0x7, %ecx
ja 0x1ed80
cmpb $0x1, 0x16(%r14)
jne 0x1ed80
movslq 0x10(%r14), %rsi
testq %rsi, %rsi
jle 0x1ed80
shlq $0x3, %rsi
movq %r15, %rdi
callq 0xcca8
movq %rax, 0x28(%r14)
cmpl $0x0, 0x10(%r14)
jle 0x1edc9
xorl %r13d, %r13d
movl $0x110, %esi            # imm = 0x110
movq %r15, %rdi
callq 0xcca8
movq %rax, %r12
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rsi
movl $0x110, %edx            # imm = 0x110
movq %r12, %rdi
callq 0x3260
movq 0x28(%r14), %rax
movq %r12, (%rax,%r13,8)
incq %r13
movslq 0x10(%r14), %rax
cmpq %rax, %r13
jl 0x1ed45
jmp 0x1edc9
cmpl $0x1a, %eax
jne 0x1edc9
cmpl $0x0, 0x28(%r14)
jle 0x1edc9
cmpl $0x0, 0x28(%r14)
jle 0x1edc9
xorl %r13d, %r13d
movl $0x118, %esi            # imm = 0x118
movq %r15, %rdi
callq 0xcca8
movq %rax, %r12
movq 0x38(%rbx,%r13,8), %rsi
movl $0x118, %edx            # imm = 0x118
movq %rax, %rdi
callq 0x3260
movq %r12, 0x38(%r14,%r13,8)
incq %r13
movslq 0x28(%r14), %rax
cmpq %rax, %r13
jl 0x1ed96
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq