// File: /workspace/github_cpp_makefile_star2_O1/AndreyVV-100[P]GachiLang/Backend/Backend.cpp
// Function: TakeFuncVars(element*, Stack*, char*)
bool TakeFuncVars (element* el, Stack* vars, char* var_count)
{
    assert (vars);
    if (!el)
        return 0;

    element* el_now  = el;
    char param_count = FIRST_PARAMETER; 
    // First param - [rbp + 0x10], second - [rbp + 0x18] and ect.

    while (el_now->type == PARAM)
    {
        if (el->left && el->left->type != PARAM)
        {
            printf ("TakeFuncVars error: bad parameters.\n");
            return 1;
        }

        el_now->var_pos = param_count;
        StackPush (vars, *el_now);

        if (param_count == MAX_PARAMETER)
            printf ("Warning: Maybe parameter counter overfull.\n");
        param_count += SIZEOF_ALIGN;

        if (el_now->left == nullptr)
            return 0;
        else
            el_now = el_now->left;
    }

    if (el->type == EQUAL)
    {
        if (!(el->left) || el->left->type != VAR)
        {
            printf ("TakeFuncVars error: bad equality.\n");
            return 1;
        }

        if (VarNumber (vars, el->left->ind) != VAR_WASNT_CREATED)
            return 0;

        el->left->var_pos = *var_count;
        StackPush (vars, *(el->left));

        if (*var_count == MAX_LOCAL_VAR)
            printf ("Warning: Maybe variable counter overfull.\n");
        *var_count -= SIZEOF_ALIGN;

        return 0;
    }

    if (TakeFuncVars (el->left, vars, var_count))
        return 1;
    return TakeFuncVars (el->right, vars, var_count);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, -0x30(%rbp)
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x38a5(%rip), %r12      # 0x588b
testq %r14, %r14
je 0x2110
testq %rbx, %rbx
je 0x20f3
cmpl $0x4, (%rbx)
jne 0x205e
movb $0x10, %r13b
movq %rbx, %r15
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x2011
cmpl $0x4, (%rax)
jne 0x2080
movb %r13b, 0x28(%r15)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x4062
cmpb $0x78, %r13b
jne 0x2047
movq %r12, %rdi
callq 0x1180
movq 0x8(%r15), %r15
testq %r15, %r15
je 0x20f3
addb $0x8, %r13b
cmpl $0x4, (%r15)
je 0x2003
cmpl $0xe, (%rbx)
movq 0x8(%rbx), %rdi
je 0x2090
movq %r14, %rsi
movq -0x30(%rbp), %rdx
callq 0x1fc4
testb %al, %al
jne 0x208c
movq 0x10(%rbx), %rbx
jmp 0x1fe6
leaq 0x382f(%rip), %rdi      # 0x58b6
callq 0x1180
movb $0x1, %al
jmp 0x20f5
testq %rdi, %rdi
je 0x2104
cmpl $0x8, (%rdi)
jne 0x2104
movq 0x18(%rdi), %rsi
movq %r14, %rdi
callq 0x2297
cmpb $0x1, %al
jne 0x20f3
movq -0x30(%rbp), %r15
movb (%r15), %al
movq 0x8(%rbx), %rcx
movb %al, 0x28(%rcx)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x4062
xorl %eax, %eax
cmpb (%r15), %al
jno 0x20ec
leaq 0x3758(%rip), %rdi      # 0x583f
callq 0x1180
movq -0x30(%rbp), %rax
addb $-0x8, (%rax)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x375e(%rip), %rdi      # 0x5869
jmp 0x2087
leaq 0x33a2(%rip), %rdi      # 0x54b9
leaq 0x2faa(%rip), %rsi      # 0x50c8
leaq 0x3399(%rip), %rcx      # 0x54be
movl $0x172, %edx            # imm = 0x172
callq 0x1090