// File: /workspace/github_cpp_makefile_star2_O1/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 0x12732(%rip), %rsi     # 0x18729
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 0x5cc8
movq %rax, -0x48(%rbp)
movq 0x20(%r15), %rsi
cmpq 0x28(%r15), %rsi
je 0x6093
movq %rax, (%rsi)
addq $0x8, 0x20(%r15)
jmp 0x60a3
movq %r15, %rdi
addq $0x18, %rdi
leaq -0x48(%rbp), %rdx
callq 0x8754
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x60b4
callq 0x3230
movb $0x3c, %r14b
movq -0x30(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jg 0x60ca
movb $0x3e, %r14b
jns 0x6272
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 0x59d8
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 0x6153
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 0x59d8
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 0x5cc8
movq %rax, %r14
movq -0xa8(%rbp), %rdi
cmpq %r13, %rdi
je 0x6202
callq 0x3230
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x6214
callq 0x3230
movq %r15, %rdi
movq %rbx, %rsi
movq -0x38(%rbp), %rdx
movq %r14, %rcx
callq 0x5edf
movq %rax, %rbx
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x623e
callq 0x3230
movq 0x18d83(%rip), %rsi     # 0x1efc8
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 0x18d57(%rip), %rdi     # 0x1efd0
leaq 0xfee9(%rip), %rsi      # 0x16169
movl $0x22, %edx
callq 0x32b0
movq 0x18d3f(%rip), %rdi     # 0x1efd0
callq 0x3110
xorl %edi, %edi
callq 0x3310
jmp 0x62bd
movq %rax, %rbx
jmp 0x62eb
jmp 0x62bd
jmp 0x62bd
jmp 0x62bd
jmp 0x62d2
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
jne 0x62f8
jmp 0x62fd
movq %rax, %rbx
jmp 0x62fd
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
jmp 0x62f3
movq %rax, %rbx
jmp 0x6312
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r13, %rdi
je 0x62eb
callq 0x3230
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x62fd
callq 0x3230
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6312
callq 0x3230
movq 0x18caf(%rip), %rsi     # 0x1efc8
leaq -0x260(%rbp), %rdi
callq 0x3140
leaq -0x1f0(%rbp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x3470