// File: /workspace/github_cpp_makefile_star2_O2/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, %r13
movq %rcx, %r14
movq %rdx, -0x38(%rbp)
movq %rsi, %rbx
movq %rdi, %r12
leaq -0x258(%rbp), %r15
movq %r15, %rdi
callq 0x32e0
leaq 0xf252(%rip), %rsi      # 0x146e9
movq %r15, %rdi
callq 0x31f0
leaq -0x258(%rbp), %rdi
movq %r13, %rsi
callq 0x31a0
movq %r13, -0x30(%rbp)
leaq -0x250(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x3380
pushq $0x38
popq %rdi
callq 0x3200
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movb $0x53, 0x30(%rax)
leaq -0xb8(%rbp), %rdi
movq %r12, %rsi
callq 0x32f0
leaq -0xb8(%rbp), %rdi
movq %rbx, %rsi
callq 0x5252
movq %r15, %rdi
addq $0x18, %rdi
leaq -0xc0(%rbp), %rsi
movq %rax, (%rsi)
callq 0x76e6
leaq -0xb8(%rbp), %rdi
callq 0x3448
movb $0x3c, %bl
cmpl $0x0, 0x2c(%r14)
jg 0x5533
movb $0x3e, %bl
jns 0x55fe
leaq -0x98(%rbp), %rdi
movq %r12, %rsi
callq 0x32f0
leaq -0x98(%rbp), %rdi
callq 0x4fc3
movzbl %bl, %edi
movq %rax, %rsi
movq -0x38(%rbp), %rdx
callq 0x4f20
movq %rax, %r13
leaq -0x98(%rbp), %rdi
callq 0x3448
leaq -0x78(%rbp), %rdi
movq %r12, %rsi
callq 0x32f0
leaq -0x58(%rbp), %rdi
movq %r12, %rsi
callq 0x32f0
leaq -0x58(%rbp), %rdi
callq 0x4fc3
pushq $0x2b
popq %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x4f20
leaq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x5252
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x3448
leaq -0x78(%rbp), %rdi
callq 0x3448
movq %r15, %rdi
movq %r13, %rsi
movq -0x30(%rbp), %rdx
movq %rbx, %rcx
callq 0x53cf
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x3448
leaq -0x258(%rbp), %rdi
callq 0x3080
movq %rbx, %rax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x169c3(%rip), %rdi     # 0x1bfc8
leaq 0xcb3d(%rip), %rsi      # 0x12149
callq 0x31f0
movq %rax, %rdi
callq 0x3100
xorl %edi, %edi
callq 0x32a0
jmp 0x562f
movq %rax, %rbx
jmp 0x565d
jmp 0x562f
jmp 0x562f
jmp 0x562f
jmp 0x564c
movq %rax, %rbx
jmp 0x5666
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
jmp 0x5661
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
jmp 0x5661
movq %rax, %rbx
jmp 0x5672
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x3448
leaq -0x78(%rbp), %rdi
callq 0x3448
leaq -0xe0(%rbp), %rdi
callq 0x3448
leaq -0x258(%rbp), %rdi
callq 0x3080
movq %rbx, %rdi
callq 0x33f0