// File: /workspace/github_cpp_makefile_star2_O2/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 0x1f2d
movq %rsi, %r14
movq %rdi, %r13
movq %rdx, -0x30(%rbp)
testq %r13, %r13
setne %r12b
je 0x1f0c
movb $0x10, %bl
movq %r13, %r15
cmpl $0x4, (%r15)
jne 0x1e77
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x1e2d
cmpl $0x4, (%rax)
jne 0x1e9b
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 0x3c56
cmpb $0x78, %bl
jne 0x1e66
leaq 0x2a02(%rip), %rdi      # 0x4863
callq 0x1170
movq 0x8(%r15), %r15
addb $0x8, %bl
testq %r15, %r15
jne 0x1e19
jmp 0x1f0c
cmpl $0xe, (%r13)
movq 0x8(%r13), %rdi
je 0x1eac
movq %r14, %rsi
movq -0x30(%rbp), %rdx
callq 0x1de3
testb %al, %al
jne 0x1f0f
movq 0x10(%r13), %r13
jmp 0x1e07
leaq 0x29ec(%rip), %rdi      # 0x488e
callq 0x1170
movb $0x1, %r12b
jmp 0x1f0f
testq %rdi, %rdi
movq -0x30(%rbp), %rbx
je 0x1f21
cmpl $0x8, (%rdi)
jne 0x1f21
movq 0x18(%rdi), %rsi
movq %r14, %rdi
callq 0x20b4
cmpb $0x1, %al
jne 0x1f0c
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 0x3c56
movb (%rbx), %al
cmpb $-0x80, %al
jne 0x1f08
leaq 0x2916(%rip), %rdi      # 0x4817
callq 0x1170
movb (%rbx), %al
addb $-0x8, %al
movb %al, (%rbx)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2919(%rip), %rdi      # 0x4841
jmp 0x1ea2
leaq 0x255d(%rip), %rdi      # 0x4491
leaq 0x2165(%rip), %rsi      # 0x40a0
leaq 0x2554(%rip), %rcx      # 0x4496
movl $0x172, %edx            # imm = 0x172
callq 0x1080