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

    if (el->type != COND)
        return 1;

    TryPrint (PrintArith, left);
    ElfAddBytes (elf, "\x66\x48\x0F\x7E\xC2", 5); // movq rdx, xmm0

    elf->xmm_counter = 0;
    TryPrint (PrintArith, right);
    ElfAddBytes (elf, "\x66\x48\x0F\x6E\xCA", 5); // movq xmm1, rdx

    switch (el->len)
    {
        case 1:
        {
            switch (el->ind[0])
            {
                case '>':
                    ElfAddBytes (elf, "\xC5\xF3\xC2\xD0\x02", 5); // vcmpsd xmm2, xmm1, xmm0, 2
                    break;

                case '<':
                    ElfAddBytes (elf, "\xC5\xF3\xC2\xD0\x0D", 5); // vcmpsd xmm2, xmm1, xmm0, 0x0D
                    break;

                default:
                    return 1;
            }
            break;
        }

        case 2:
        {
            switch (el->ind[0])
            {
                case '>':
                    ElfAddBytes (elf, "\xC5\xF3\xC2\xD0\x01", 5); // vcmpsd xmm2, xmm1, xmm0, 1
                    break;

                case '<':
                    ElfAddBytes (elf, "\xC5\xF3\xC2\xD0\x0E", 5); // vcmpsd xmm2, xmm1, xmm0, 0x0E
                    break;

                case '!':
                    ElfAddBytes (elf, "\xC5\xF3\xC2\xD0\x00", 5); // vcmpsd xmm2, xmm1, xmm0, 0
                    break;

                case '=':
                    ElfAddBytes (elf, "\xC5\xF3\xC2\xD0\x04", 5); // vcmpsd xmm2, xmm1, xmm0, 4
                    break;

                default:
                    return 1;
            }
            break;
        }

        default:
            return 1;
    }

    ElfAddBytes (elf, "\x66\x48\x0F\x7E\xD0"        // movq rax, xmm2
                      "\x48\x83\xF8\x00"            // cmp rax, 0
                      "\x0F\x85\x00\x00\x00\x00",   // jne 00 00 00 00 (will be patched)
                      15);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x315d
movq %rsi, %r15
testq %rsi, %rsi
je 0x3166
movq %rdx, %r12
testq %rdx, %rdx
je 0x316f
movb $0x1, %bl
cmpl $0xf, (%r15)
jne 0x30a1
movq %rdi, %r14
movq 0x8(%r15), %rsi
movq %r12, %rdx
callq 0x27c6
testb %al, %al
je 0x3046
leaq 0x2439(%rip), %rdi      # 0x5471
leaq 0x25f2(%rip), %rsi      # 0x5631
movl $0x242, %edx            # imm = 0x242
jmp 0x3085
leaq 0x260e(%rip), %rsi      # 0x565b
movl $0x5, %edx
movq %r14, %rdi
callq 0x15a4
movb $0x0, 0x60(%r14)
movq 0x10(%r15), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x27c6
testb %al, %al
je 0x30ac
leaq 0x23f8(%rip), %rdi      # 0x5471
leaq 0x25b1(%rip), %rsi      # 0x5631
movl $0x246, %edx            # imm = 0x246
xorl %eax, %eax
callq 0x1040
movq 0x18(%r15), %rdx
leaq 0x23ff(%rip), %rdi      # 0x5496
movq %r15, %rsi
xorl %eax, %eax
callq 0x1040
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25ae(%rip), %rsi      # 0x5661
movl $0x5, %edx
movq %r14, %rdi
callq 0x15a4
movq 0x20(%r15), %rax
cmpq $0x2, %rax
je 0x30ea
cmpq $0x1, %rax
jne 0x30a1
movq 0x18(%r15), %rax
movzbl (%rax), %eax
cmpl $0x3e, %eax
je 0x311c
cmpl $0x3c, %eax
jne 0x30a1
leaq 0x2585(%rip), %rsi      # 0x566d
jmp 0x3135
movq 0x18(%r15), %rax
movzbl (%rax), %eax
cmpl $0x3c, %eax
jg 0x3109
cmpl $0x21, %eax
je 0x3125
cmpl $0x3c, %eax
jne 0x30a1
leaq 0x2572(%rip), %rsi      # 0x5679
jmp 0x3135
cmpl $0x3d, %eax
je 0x312e
cmpl $0x3e, %eax
jne 0x30a1
leaq 0x2559(%rip), %rsi      # 0x5673
jmp 0x3135
leaq 0x2544(%rip), %rsi      # 0x5667
jmp 0x3135
leaq 0x1f7c(%rip), %rsi      # 0x50a8
jmp 0x3135
leaq 0x254a(%rip), %rsi      # 0x567f
movl $0x5, %edx
movq %r14, %rdi
callq 0x15a4
leaq 0x1ed7(%rip), %rsi      # 0x5020
movl $0xf, %edx
movq %r14, %rdi
callq 0x15a4
xorl %ebx, %ebx
jmp 0x30a1
leaq 0x21aa(%rip), %rdi      # 0x530e
jmp 0x3176
leaq 0x22e0(%rip), %rdi      # 0x544d
jmp 0x3176
leaq 0x2343(%rip), %rdi      # 0x54b9
leaq 0x1f4b(%rip), %rsi      # 0x50c8
leaq 0x24ad(%rip), %rcx      # 0x5631
movl $0x23d, %edx            # imm = 0x23D
callq 0x1090
nop