// File: /workspace/github_c_makefile_star2_O1/vtereshkov[P]umka-lang/src/umka_types.c
// Function: typeSpellingRecursive
static char *typeSpellingRecursive(const Type *type, char *buf, int size, int depth)
{
    if (type->block == 0 && type->typeIdent)
        snprintf(buf, size, "%s", type->typeIdent->name);
    else
    {
        int len = 0;

        if (type->kind == TYPE_ARRAY)
        {
            len += snprintf(buf + len, nonneg(size - len), "[%d]", type->numItems);
        }
        else if (typeEnum(type))
        {
            len += snprintf(buf + len, nonneg(size - len), "enum(%s)", typeKindSpelling(type->kind));
        }
        else if (type->kind == TYPE_MAP)
        {
            char keyBuf[DEFAULT_STR_LEN + 1];
            len += snprintf(buf + len, nonneg(size - len), "map[%s]", typeSpellingRecursive(typeMapKey(type), keyBuf, DEFAULT_STR_LEN + 1, depth - 1));
        }
        else if (typeExprListStruct(type))
        {
            len += snprintf(buf + len, nonneg(size - len), "{ ");
            for (int i = 0; i < type->numItems; i++)
            {
                char fieldBuf[DEFAULT_STR_LEN + 1];
                len += snprintf(buf + len, nonneg(size - len), "%s ", typeSpellingRecursive(type->field[i]->type, fieldBuf, DEFAULT_STR_LEN + 1, depth - 1));
            }
            len += snprintf(buf + len, nonneg(size - len), "}");
        }
        else if (type->kind == TYPE_FN || type->kind == TYPE_CLOSURE)
        {
            const bool isClosure = type->kind == TYPE_CLOSURE;
            if (isClosure)
                type = type->field[0]->type;

            len += snprintf(buf + len, nonneg(size - len), "fn (");

            if (type->sig.isMethod)
            {
                char paramBuf[DEFAULT_STR_LEN + 1];
                len += snprintf(buf + len, nonneg(size - len), "%s) (", typeSpellingRecursive(type->sig.param[0]->type, paramBuf, DEFAULT_STR_LEN + 1, depth - 1));
            }

            const int numPreHiddenParams = 1;                                                 // #self or #upvalues
            const int numPostHiddenParams = typeStructured(type->sig.resultType) ? 1 : 0;     // #result

            for (int i = numPreHiddenParams; i < type->sig.numParams - numPostHiddenParams; i++)
            {
                if (i > numPreHiddenParams)
                    len += snprintf(buf + len, nonneg(size - len), ", ");

                char paramBuf[DEFAULT_STR_LEN + 1];
                len += snprintf(buf + len, nonneg(size - len), "%s", typeSpellingRecursive(type->sig.param[i]->type, paramBuf, DEFAULT_STR_LEN + 1, depth - 1));
            }

            len += snprintf(buf + len, nonneg(size - len), ")");

            if (type->sig.resultType->kind != TYPE_VOID)
            {
                char resultBuf[DEFAULT_STR_LEN + 1];
                len += snprintf(buf + len, nonneg(size - len), ": %s", typeSpellingRecursive(type->sig.resultType, resultBuf, DEFAULT_STR_LEN + 1, depth - 1));
            }

            if (isClosure)
                len += snprintf(buf + len, nonneg(size - len), " |...|");
        }
        else
        {
            snprintf(buf + len, nonneg(size - len), "%s", spelling[type->kind]);
        }

        if (type->kind == TYPE_PTR || type->kind == TYPE_WEAKPTR || type->kind == TYPE_ARRAY || type->kind == TYPE_DYNARRAY || type->kind == TYPE_MAP)
        {
            const Type *itemType = (type->kind == TYPE_MAP) ? typeMapItem(type) : type->base;

            char itemBuf[DEFAULT_STR_LEN + 1];
            if (depth > 0)
                strncat(buf, typeSpellingRecursive(itemType, itemBuf, DEFAULT_STR_LEN + 1, depth - 1), nonneg(size - len - 1));
            else
                strncat(buf, "...", nonneg(size - len - 1));
        }
    }
    return buf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %edx, %ebx
movq %rsi, %r12
movq %rdi, %r13
cmpl $0x0, 0x4(%rdi)
je 0x1feca
movl (%r13), %ebp
cmpq $0x12, %rbp
jne 0x1fe9c
movl 0x10(%r13), %ecx
leaq 0x58e62(%rip), %rdx     # 0x78cea
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
xorl %eax, %eax
callq 0x3170
jmp 0x20190
leal -0x4(%rbp), %eax
cmpl $0x7, %eax
ja 0x1fef2
cmpb $0x1, 0x16(%r13)
jne 0x1fef2
leaq 0x6ec6e(%rip), %rax     # 0x8eb20
movq (%rax,%rbp,8), %rcx
leaq 0x58e32(%rip), %rdx     # 0x78cef
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
jmp 0x20189
movq 0x18(%r13), %rcx
testq %rcx, %rcx
je 0x1fe73
addq $0x4, %rcx
leaq 0x58e39(%rip), %rdx     # 0x78d17
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
xorl %eax, %eax
callq 0x3170
jmp 0x201f1
leal -0x15(%rbp), %eax
cmpl $0x5, %eax
ja 0x202c8
leaq 0x58b5b(%rip), %rcx     # 0x78a60
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %r12, 0x8(%rsp)
jmpq *%rax
cmpl $0x18, %ebp
jne 0x1ff26
movq 0x28(%r13), %rax
movq (%rax), %rax
movq 0x108(%rax), %r13
movb $0x0, 0x4(%r12)
movl $0x28206e66, (%r12)     # imm = 0x28206E66
movl $0x4, %eax
cmpb $0x1, 0x30(%r13)
jne 0x1ff7c
leaq 0x4(%r12), %r14
movq 0x38(%r13), %rax
movq 0x108(%rax), %rdi
leal -0x1(%rbx), %edx
leaq 0x30(%rsp), %r12
movq %r12, %rsi
callq 0x1fe54
leaq 0x58da5(%rip), %rdx     # 0x78d0c
movl $0xfc, %esi
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x3170
addl $0x4, %eax
movq 0xb8(%r13), %rcx
movl (%rcx), %ecx
addl $-0x12, %ecx
xorl %esi, %esi
cmpl $0x6, %ecx
ja 0x1ff9b
movl %ecx, %ecx
leaq 0x58b40(%rip), %rdx     # 0x78ad8
movl (%rdx,%rcx,4), %esi
movq %r13, 0x10(%rsp)
movl 0x28(%r13), %ecx
addl %esi, %ecx
cmpl $0x2, %ecx
movq %rbx, 0x18(%rsp)
movq %rbp, 0x28(%rsp)
jl 0x2007d
leal -0x1(%rbx), %ecx
movl %ecx, 0x24(%rsp)
movl $0x8, %ebx
movl %esi, 0x20(%rsp)
leaq -0x7(%rbx), %rcx
cmpq $0x2, %rcx
jb 0x20004
movslq %eax, %r14
movq 0x8(%rsp), %r12
leaq (%r12,%r14), %rdi
movl $0x100, %esi            # imm = 0x100
subl %r14d, %esi
testl %esi, %esi
movl $0x0, %ebp
cmovlel %ebp, %esi
leaq 0x58d1a(%rip), %rdx     # 0x78d12
xorl %eax, %eax
callq 0x3170
addl %r14d, %eax
jmp 0x2000b
movq 0x8(%rsp), %r12
xorl %ebp, %ebp
movslq %eax, %r15
addq %r15, %r12
movl $0x100, %r14d           # imm = 0x100
subl %r15d, %r14d
testl %r14d, %r14d
cmovlel %ebp, %r14d
movq 0x10(%rsp), %rbp
movq (%rbp,%rbx,8), %rax
movq 0x108(%rax), %rdi
leaq 0x30(%rsp), %r13
movq %r13, %rsi
movl 0x24(%rsp), %edx
callq 0x1fe54
movq %r12, %rdi
movq %r14, %rsi
leaq 0x58cc7(%rip), %rdx     # 0x78d17
movq %r13, %rcx
xorl %eax, %eax
callq 0x3170
addl %r15d, %eax
movl 0x28(%rbp), %ecx
movl 0x20(%rsp), %esi
addl %esi, %ecx
movslq %ecx, %rcx
leaq 0x1(%rbx), %rdx
addq $-0x6, %rbx
cmpq %rcx, %rbx
movq %rdx, %rbx
jl 0x1ffc9
movslq %eax, %rbx
movq 0x8(%rsp), %r15
leaq (%r15,%rbx), %rdi
movl $0x100, %r14d           # imm = 0x100
movl $0x100, %esi            # imm = 0x100
subl %ebx, %esi
xorl %r13d, %r13d
testl %esi, %esi
cmovlel %r13d, %esi
leaq 0x5c2bb(%rip), %rdx     # 0x7c361
xorl %eax, %eax
callq 0x3170
movl %eax, %ebp
addl %ebx, %ebp
movq 0x10(%rsp), %rcx
movq 0xb8(%rcx), %rax
cmpl $0x2, (%rax)
je 0x2010a
movslq %ebp, %rbx
leaq (%r15,%rbx), %r12
subl %ebx, %r14d
testl %r14d, %r14d
cmovlel %r13d, %r14d
movq 0xb8(%rcx), %rdi
movq 0x18(%rsp), %rax
leal -0x1(%rax), %edx
leaq 0x30(%rsp), %r13
movq %r13, %rsi
callq 0x1fe54
leaq 0x58c1f(%rip), %rdx     # 0x78d15
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rcx
xorl %eax, %eax
callq 0x3170
movl %eax, %ebp
addl %ebx, %ebp
cmpl $0x18, 0x28(%rsp)
jne 0x2013f
movslq %ebp, %rbx
movq 0x8(%rsp), %r12
leaq (%r12,%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
subl %ebx, %esi
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
leaq 0x58be8(%rip), %rdx     # 0x78d1a
xorl %eax, %eax
callq 0x3170
movl %eax, %ebp
addl %ebx, %ebp
jmp 0x20144
movq 0x8(%rsp), %r12
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r13
jmp 0x20192
movq 0x8(%r13), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq 0x108(%rax), %rax
movq 0x8(%rax), %rdi
leal -0x1(%rbx), %edx
leaq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0x1fe54
leaq 0x58b7a(%rip), %rdx     # 0x78cf8
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3170
movl %eax, %ebp
movl (%r13), %eax
leal -0x10(%rax), %ecx
cmpl $0x4, %ecx
jb 0x201b6
cmpl $0x15, %eax
jne 0x201f1
movq 0x8(%r13), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rax
movq 0x108(%rax), %r13
testl %ebx, %ebx
jle 0x201d1
movq 0x8(%r13), %rdi
decl %ebx
leaq 0x30(%rsp), %r14
movq %r14, %rsi
movl %ebx, %edx
callq 0x1fe54
jmp 0x201d8
leaq 0x58b49(%rip), %r14     # 0x78d21
movl $0xff, %eax
subl %ebp, %eax
xorl %edx, %edx
testl %eax, %eax
cmovgl %eax, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x31b0
movq %r12, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x1, 0x14(%r13)
jne 0x202ba
cmpl $0x0, 0x10(%r13)
jle 0x202ba
movb $0x0, 0x2(%r12)
movw $0x207b, (%r12)         # imm = 0x207B
cmpl $0x0, 0x10(%r13)
movq %rbx, 0x18(%rsp)
jle 0x202f0
leal -0x1(%rbx), %eax
movl %eax, 0x10(%rsp)
movl $0x2, %eax
xorl %ebx, %ebx
movslq %eax, %rbp
movq %r13, %r14
movl $0x100, %r13d           # imm = 0x100
subl %ebp, %r13d
testl %r13d, %r13d
movl $0x0, %eax
cmovlel %eax, %r13d
movq 0x8(%rsp), %rax
leaq (%rax,%rbp), %r12
movq 0x28(%r14), %rax
movq (%rax,%rbx,8), %rax
movq 0x108(%rax), %rdi
leaq 0x30(%rsp), %r15
movq %r15, %rsi
movl 0x10(%rsp), %edx
callq 0x1fe54
movq %r12, %rdi
movq 0x8(%rsp), %r12
movq %r13, %rsi
movq %r14, %r13
leaq 0x58a63(%rip), %rdx     # 0x78d03
movq %r15, %rcx
xorl %eax, %eax
callq 0x3170
addl %ebp, %eax
incq %rbx
movslq 0x10(%r14), %rcx
cmpq %rcx, %rbx
jl 0x20247
jmp 0x202f5
movl %ebp, %eax
orl $0x2, %eax
cmpl $0x1a, %eax
je 0x1ff13
leaq 0x6e851(%rip), %rax     # 0x8eb20
movq (%rax,%rbp,8), %rcx
leaq 0x58a3d(%rip), %rdx     # 0x78d17
xorl %ebp, %ebp
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
xorl %eax, %eax
callq 0x3170
jmp 0x20192
movl $0x2, %eax
movslq %eax, %rbx
leaq (%r12,%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
subl %ebx, %esi
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
leaq 0x5817c(%rip), %rdx     # 0x7848d
xorl %eax, %eax
callq 0x3170
movl %eax, %ebp
addl %ebx, %ebp
movq 0x18(%rsp), %rbx
jmp 0x20192