// File: /workspace/github_cpp_makefile_star2_O3/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 0x312a
movq %rsi, %r15
testq %rsi, %rsi
je 0x3133
movq %rdx, %r12
testq %rdx, %rdx
je 0x313c
movb $0x1, %bl
cmpl $0xf, (%r15)
jne 0x306e
movq %rdi, %r14
movq 0x8(%r15), %rsi
movq %r12, %rdx
callq 0x278d
testb %al, %al
je 0x3013
leaq 0x2444(%rip), %rdi      # 0x5449
leaq 0x25fd(%rip), %rsi      # 0x5609
movl $0x242, %edx            # imm = 0x242
jmp 0x3052
leaq 0x2619(%rip), %rsi      # 0x5633
movl $0x5, %edx
movq %r14, %rdi
callq 0x156a
movb $0x0, 0x60(%r14)
movq 0x10(%r15), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x278d
testb %al, %al
je 0x3079
leaq 0x2403(%rip), %rdi      # 0x5449
leaq 0x25bc(%rip), %rsi      # 0x5609
movl $0x246, %edx            # imm = 0x246
xorl %eax, %eax
callq 0x1040
movq 0x18(%r15), %rdx
leaq 0x240a(%rip), %rdi      # 0x546e
movq %r15, %rsi
xorl %eax, %eax
callq 0x1040
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25b9(%rip), %rsi      # 0x5639
movl $0x5, %edx
movq %r14, %rdi
callq 0x156a
movq 0x20(%r15), %rax
cmpq $0x2, %rax
je 0x30b7
cmpq $0x1, %rax
jne 0x306e
movq 0x18(%r15), %rax
movzbl (%rax), %eax
cmpl $0x3e, %eax
je 0x30e9
cmpl $0x3c, %eax
jne 0x306e
leaq 0x2590(%rip), %rsi      # 0x5645
jmp 0x3102
movq 0x18(%r15), %rax
movzbl (%rax), %eax
cmpl $0x3c, %eax
jg 0x30d6
cmpl $0x21, %eax
je 0x30f2
cmpl $0x3c, %eax
jne 0x306e
leaq 0x257d(%rip), %rsi      # 0x5651
jmp 0x3102
cmpl $0x3d, %eax
je 0x30fb
cmpl $0x3e, %eax
jne 0x306e
leaq 0x2564(%rip), %rsi      # 0x564b
jmp 0x3102
leaq 0x254f(%rip), %rsi      # 0x563f
jmp 0x3102
leaq 0x1f87(%rip), %rsi      # 0x5080
jmp 0x3102
leaq 0x2555(%rip), %rsi      # 0x5657
movl $0x5, %edx
movq %r14, %rdi
callq 0x156a
leaq 0x285a(%rip), %rsi      # 0x5970
movl $0xf, %edx
movq %r14, %rdi
callq 0x156a
xorl %ebx, %ebx
jmp 0x306e
leaq 0x21b5(%rip), %rdi      # 0x52e6
jmp 0x3143
leaq 0x22eb(%rip), %rdi      # 0x5425
jmp 0x3143
leaq 0x234e(%rip), %rdi      # 0x5491
leaq 0x1f56(%rip), %rsi      # 0x50a0
leaq 0x24b8(%rip), %rcx      # 0x5609
movl $0x23d, %edx            # imm = 0x23D
callq 0x1090
nop