// File: /workspace/github_cpp_makefile_star2_O3/johan-bjareholt[P]lua-compiler/src/ir.cc
// Function: For(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Expression*, Expression*, Expression*, Statement*)
Statement *For(std::string varname, Expression* varval, Expression* boundry, Expression* step, Statement* body){
    // Get statement pointer as address
    std::ostringstream address;
    address << "_l";
    address << (void const *)body;
    std:string labelname = address.str();

    // Loop start (assign)
    Statement *pre = new Statement('S');
	pre->children.push_back(Assign(varname, varval));
	// Loop body (if,code,increment,if etc.)
    char checktoken = '=';
    if (step->value > 0)
        checktoken = '<';
    else if (step->value < 0)
        checktoken = '>';
    else {
        std::cout << "Step value in for loop cannot be 0" << std::endl;
        exit(0);
    }
    Expression* check = BinOp(checktoken,Variable(varname),boundry);
    // Increment
	Statement *post = Assign(varname, BinOp('+',Variable(varname),step));
    // Return
	return Loop(pre, check, body, post);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %r8, %r14
movq %rcx, -0x30(%rbp)
movq %rdx, -0x40(%rbp)
movq %rsi, %rbx
movq %rdi, %r12
leaq -0x260(%rbp), %r15
movq %r15, %rdi
callq 0x3340
leaq 0x1172d(%rip), %rsi     # 0x17709
movl $0x2, %edx
movq %r15, %rdi
callq 0x32b0
leaq -0x260(%rbp), %rdi
movq %r14, %rsi
callq 0x31d0
leaq -0x258(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x3400
movq %r14, -0x38(%rbp)
movl $0x38, %edi
callq 0x3260
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movb $0x53, 0x30(%rax)
leaq -0xb8(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x4baa
leaq -0xc8(%rbp), %rdi
movq %rbx, %rsi
callq 0x5cca
movq %rax, -0x48(%rbp)
movq 0x20(%r15), %rsi
cmpq 0x28(%r15), %rsi
je 0x6078
movq %rax, (%rsi)
addq $0x8, 0x20(%r15)
jmp 0x6088
movq %r15, %rdi
addq $0x18, %rdi
leaq -0x48(%rbp), %rdx
callq 0x872a
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x6099
callq 0x3230
movb $0x3c, %r14b
movq -0x30(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jg 0x60af
movb $0x3e, %r14b
jns 0x6257
leaq -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x4baa
leaq -0x88(%rbp), %rdi
callq 0x59da
movq %rax, %r13
movl $0x50, %edi
callq 0x3260
movq %rax, %rbx
movq %r13, (%rax)
movq -0x40(%rbp), %rax
movq %rax, 0x8(%rbx)
leaq 0x10(%rbx), %rax
movq %rax, 0x18(%rbx)
movq %rax, 0x10(%rbx)
xorl %eax, %eax
movq %rax, 0x20(%rbx)
movb $0x4e, 0x28(%rbx)
movq %rbx, %rcx
addq $0x40, %rcx
movq %rcx, 0x30(%rbx)
movq %rax, 0x38(%rbx)
movb $0x0, 0x40(%rbx)
movb %r14b, 0x29(%rbx)
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x6138
callq 0x3230
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x4baa
leaq -0x98(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x4baa
leaq -0xa8(%rbp), %rdi
callq 0x59da
movq %rax, %r12
movl $0x50, %edi
callq 0x3260
movq %r12, (%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq 0x10(%rax), %rcx
movq %rcx, 0x18(%rax)
movq %rcx, 0x10(%rax)
xorl %ecx, %ecx
movq %rcx, 0x20(%rax)
movw $0x2b4e, 0x28(%rax)     # imm = 0x2B4E
movq %rax, %rdx
addq $0x40, %rdx
movq %rdx, 0x30(%rax)
movq %rcx, 0x38(%rax)
movb $0x0, 0x40(%rax)
leaq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x5cca
movq %rax, %r14
movq -0xa8(%rbp), %rdi
cmpq %r13, %rdi
je 0x61e7
callq 0x3230
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x61f9
callq 0x3230
movq %r15, %rdi
movq %rbx, %rsi
movq -0x38(%rbp), %rdx
movq %r14, %rcx
callq 0x5ec6
movq %rax, %rbx
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6223
callq 0x3230
movq 0x16d9e(%rip), %rsi     # 0x1cfc8
leaq -0x260(%rbp), %rdi
callq 0x3140
leaq -0x1f0(%rbp), %rdi
callq 0x30c0
movq %rbx, %rax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x16d72(%rip), %rdi     # 0x1cfd0
leaq 0xef04(%rip), %rsi      # 0x15169
movl $0x22, %edx
callq 0x32b0
movq 0x16d5a(%rip), %rdi     # 0x1cfd0
callq 0x3110
xorl %edi, %edi
callq 0x3310
jmp 0x62a2
movq %rax, %rbx
jmp 0x62d0
jmp 0x62a2
jmp 0x62a2
jmp 0x62a2
jmp 0x62b7
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
jne 0x62dd
jmp 0x62e2
movq %rax, %rbx
jmp 0x62e2
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
jmp 0x62d8
movq %rax, %rbx
jmp 0x62f7
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r13, %rdi
je 0x62d0
callq 0x3230
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x62e2
callq 0x3230
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x62f7
callq 0x3230
movq 0x16cca(%rip), %rsi     # 0x1cfc8
leaq -0x260(%rbp), %rdi
callq 0x3140
leaq -0x1f0(%rbp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x3470