// File: AndreyVV-100[P]GachiLang/Backend/Backend.cpp
// Function: PrintCall(Elf*, element*, Stack*)
bool PrintCall  (Elf* elf, element* el, Stack* vars)
{
    print_ass;

    if (strcmp (SQRT_STR, el->ind) == 0)
        return PrintSqrt (elf, el, vars);

    PrintSaveXMM (elf);

    int push_shift = 0; // number of pushes on bytes
    if (PrintCallParam (elf, el->left, vars, &push_shift))
        return 1;

    // ToDo: Sin, cos, pow, sqrt
    
    ElfAddPlace (elf, el->ind, elf->text_size + 1);
    ElfAddBytes (elf, "\xE8\x00\x00\x00\x00", 5); // call 00 00 00 00
    
    // This is delete pushes
    ElfAddBytes (elf, "\x48\x81\xC4", 3); // add rsp, push_shift
    ElfAddBytes (elf, (char*) &push_shift, 4);
    mov_xmm_rax // movq xmm?, rax

    PrintLoadXMM (elf);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x2a5d
jmp 0x2a7c
leaq 0x38f8(%rip), %rdi      # 0x635c
leaq 0x36ab(%rip), %rsi      # 0x6116
movl $0x1f9, %edx            # imm = 0x1F9
leaq 0x3c76(%rip), %rcx      # 0x66ed
callq 0x1080
cmpq $0x0, -0x18(%rbp)
je 0x2a85
jmp 0x2aa4
leaq 0x3a71(%rip), %rdi      # 0x64fd
leaq 0x3683(%rip), %rsi      # 0x6116
movl $0x1f9, %edx            # imm = 0x1F9
leaq 0x3c4e(%rip), %rcx      # 0x66ed
callq 0x1080
cmpq $0x0, -0x20(%rbp)
je 0x2aad
jmp 0x2acc
leaq 0x3ab5(%rip), %rdi      # 0x6569
leaq 0x365b(%rip), %rsi      # 0x6116
movl $0x1f9, %edx            # imm = 0x1F9
leaq 0x3c26(%rip), %rcx      # 0x66ed
callq 0x1080
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0x3620(%rip), %rdi      # 0x60fb
callq 0x1130
cmpl $0x0, %eax
jne 0x2b00
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x35b0
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x2c43
movq -0x10(%rbp), %rdi
callq 0x3750
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x20(%rbp), %rdx
leaq -0x24(%rbp), %rcx
callq 0x3840
testb $0x1, %al
jne 0x2b2f
jmp 0x2b38
movb $0x1, -0x1(%rbp)
jmp 0x2c43
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdx
addq $0x1, %rdx
callq 0x1890
movq -0x10(%rbp), %rdi
leaq 0x35aa(%rip), %rsi      # 0x610a
movl $0x5, %edx
callq 0x1690
movq -0x10(%rbp), %rdi
leaq 0x3ba2(%rip), %rsi      # 0x6717
movl $0x3, %edx
callq 0x1690
movq -0x10(%rbp), %rdi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
callq 0x1690
movq -0x10(%rbp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x10, %eax
jge 0x2c22
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x8, %eax
jge 0x2bc4
leaq 0x3b5d(%rip), %rax      # 0x671b
movq %rax, -0x38(%rbp)
jmp 0x2bd1
leaq 0x3b55(%rip), %rax      # 0x6720
movq %rax, -0x38(%rbp)
jmp 0x2bd1
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x4, %edx
callq 0x1690
movq -0x10(%rbp), %rax
movsbl 0x60(%rax), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %edx, %eax
shll $0x3, %eax
addl $0xc0, %eax
movb %al, -0x25(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x60(%rax), %ecx
addl $0x1, %ecx
movb %cl, 0x60(%rax)
movq -0x10(%rbp), %rdi
leaq -0x25(%rbp), %rsi
movl $0x1, %edx
callq 0x1690
jmp 0x2c36
leaq 0x3afc(%rip), %rdi      # 0x6725
movb $0x0, %al
callq 0x1040
movb $0x1, -0x1(%rbp)
jmp 0x2c43
movq -0x10(%rbp), %rdi
callq 0x39e0
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nop