// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_expr.c
// Function: parseBuiltinAppendCall
static void parseBuiltinAppendCall(Compiler *comp, const Type **type, Const *constant)
{
    if (constant)
        comp->error.handler(comp->error.context, "Function is not allowed in constant expressions");

    // Dynamic array
    *type = NULL;
    parseExpr(comp, type, NULL);
    typeAssertCompatibleBuiltin(&comp->types, *type, BUILTIN_APPEND, (*type)->kind == TYPE_DYNARRAY);

    lexEat(&comp->lex, TOK_COMMA);

    // New item (must always be a pointer, even for value types) or right-hand side dynamic array
    const Type *itemType = (*type)->base;
    parseExpr(comp, &itemType, NULL);

    bool singleItem = true;
    if (typeEquivalent(*type, itemType))
        singleItem = false;
    else if (itemType->kind == TYPE_ARRAY && typeEquivalent((*type)->base, itemType->base))
    {
        doImplicitTypeConv(comp, *type, &itemType, NULL);
        singleItem = false;
    }

    if (singleItem)
    {
        doAssertImplicitTypeConv(comp, (*type)->base, &itemType, NULL);

        if (!typeStructured(itemType))
        {
            // Assignment to an anonymous stack area does not require updating reference counts
            int itemOffset = identAllocStack(&comp->idents, &comp->types, &comp->blocks, itemType);
            genPushLocalPtr(&comp->gen, itemOffset);
            genSwapAssign(&comp->gen, itemType->kind, 0);

            genPushLocalPtr(&comp->gen, itemOffset);
        }
    }

    // 'Append single item' flag (hidden parameter)
    genPushIntConst(&comp->gen, singleItem);

    // Pointer to result (hidden parameter)
    int resultOffset = identAllocStack(&comp->idents, &comp->types, &comp->blocks, *type);
    genPushLocalPtr(&comp->gen, resultOffset);

    genCallTypedBuiltin(&comp->gen, *type, BUILTIN_APPEND);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x11a4c
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1c7293(%rip), %rsi    # 0x1d8cdb
movb $0x0, %al
callq *%rcx
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xe8c0
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x13, (%rax)
sete %al
movzbl %al, %ecx
andl $0x1, %ecx
movl $0x1c, %edx
callq 0x229e0
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x3f, %esi
callq 0x1b150
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xe8c0
movb $0x1, -0x21(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x22250
testb $0x1, %al
jne 0x11ae6
jmp 0x11aec
movb $0x0, -0x21(%rbp)
jmp 0x11b31
movq -0x20(%rbp), %rax
cmpl $0x12, (%rax)
jne 0x11b2f
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x22250
testb $0x1, %al
jne 0x11b13
jmp 0x11b2f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd190
movb $0x0, -0x21(%rbp)
jmp 0x11b31
testb $0x1, -0x21(%rbp)
je 0x11bd1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rsi
leaq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0xd6e0
movq -0x20(%rbp), %rdi
callq 0xcfa0
testb $0x1, %al
jne 0x11bcf
movq -0x8(%rbp), %rdi
addq $0x4e38, %rdi           # imm = 0x4E38
movq -0x8(%rbp), %rsi
addq $0x4e18, %rsi           # imm = 0x4E18
movq -0x8(%rbp), %rdx
addq $0x4220, %rdx           # imm = 0x4220
movq -0x20(%rbp), %rcx
callq 0x1a320
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x28(%rbp), %esi
callq 0x169a0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x20(%rbp), %rax
movl (%rax), %esi
xorl %edx, %edx
callq 0x17120
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x28(%rbp), %esi
callq 0x169a0
jmp 0x11bd1
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
callq 0x16850
movq -0x8(%rbp), %rdi
addq $0x4e38, %rdi           # imm = 0x4E38
movq -0x8(%rbp), %rsi
addq $0x4e18, %rsi           # imm = 0x4E18
movq -0x8(%rbp), %rdx
addq $0x4220, %rdx           # imm = 0x4220
movq -0x10(%rbp), %rax
movq (%rax), %rcx
callq 0x1a320
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x2c(%rbp), %esi
callq 0x169a0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movl $0x1c, %edx
callq 0x182e0
addq $0x30, %rsp
popq %rbp
retq