// File: /workspace/github_cpp_makefile_star2_O3/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
testq %rsi, %rsi
je 0x20cc
movq %rdi, %r13
testq %rdi, %rdi
setne %r12b
je 0x2035
movq %rdx, %rbx
movq %rsi, %r14
movq %rdx, -0x30(%rbp)
movl (%r13), %eax
cmpl $0x4, %eax
jne 0x200c
movb $0x10, %bl
movq %r13, %r15
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x1fb9
cmpl $0x4, (%rax)
jne 0x203a
movb %bl, 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 0x4025
cmpb $0x78, %bl
jne 0x1ff2
leaq 0x3876(%rip), %rdi      # 0x5863
callq 0x1180
movq 0x8(%r15), %r15
testq %r15, %r15
je 0x2035
addb $0x8, %bl
cmpl $0x4, (%r15)
je 0x1fa7
movl (%r13), %eax
movq -0x30(%rbp), %rbx
movq 0x8(%r13), %rdi
cmpl $0xe, %eax
je 0x205f
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1f65
testb %al, %al
jne 0x2049
movq 0x10(%r13), %r13
testq %r13, %r13
setne %r12b
jne 0x1f99
xorl %r12d, %r12d
jmp 0x2049
leaq 0x384d(%rip), %rdi      # 0x588e
callq 0x1180
movb $0x1, %r12b
andb $0x1, %r12b
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rdi, %rdi
je 0x20c0
cmpl $0x8, (%rdi)
jne 0x20c0
movq 0x18(%rdi), %rsi
movq %r14, %rdi
callq 0x2253
cmpb $0x1, %al
jne 0x2035
movb (%rbx), %al
movq 0x8(%r13), %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 0x4025
movb (%rbx), %al
cmpb $-0x80, %al
jne 0x20b7
leaq 0x3767(%rip), %rdi      # 0x5817
callq 0x1180
movb (%rbx), %al
addb $-0x8, %al
movb %al, (%rbx)
jmp 0x2035
leaq 0x377a(%rip), %rdi      # 0x5841
jmp 0x2041
leaq 0x33be(%rip), %rdi      # 0x5491
leaq 0x2fc6(%rip), %rsi      # 0x50a0
leaq 0x33b5(%rip), %rcx      # 0x5496
movl $0x172, %edx            # imm = 0x172
callq 0x1090