// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_loops.c
// Function: prv_for_step_int_var
static void prv_for_step_int_var(subtilis_parser_t *p, subtilis_token_t *t,
				 subtilis_exp_t *to, subtilis_exp_t *step,
				 const subtilis_for_context_t *for_ctx,
				 subtilis_error_t *err)
{
	subtilis_ir_operand_t start_label;
	subtilis_ir_operand_t true_label;
	subtilis_ir_operand_t final_label;
	subtilis_type_t step_type_const;
	subtilis_exp_t *step_dir = NULL;
	subtilis_exp_t *step_dup = NULL;
	subtilis_exp_t *conde = NULL;
	subtilis_exp_t *var = NULL;
	subtilis_exp_t *eor_var = NULL;
	subtilis_exp_t *eor_var_dup = NULL;
	subtilis_exp_t *zero = NULL;
	subtilis_exp_t *sub = NULL;

	step_type_const.type = SUBTILIS_TYPE_VOID;

	/*
	 * TODO: Add a runtime check for step variable of 0.
	 * and generate an error.
	 */

	step = subtilis_type_if_coerce_type(p, step, &for_ctx->type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	step_dup = subtilis_type_if_dup(step, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_type_if_const_of(&step->type, &step_type_const, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	step_dir = subtilis_type_if_top_bit(p, &step_type_const, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	step_dir = subtilis_type_if_and(p, step_dup, step_dir, err);
	step_dup = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	prv_for_loop_start(p, t, &start_label, &true_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	var = prv_increment_var(p, step, for_ctx, err);
	step = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (!subtilis_type_if_is_integer(&var->type)) {
		subtilis_error_set_assertion_failed(err);
		goto cleanup;
	}

	sub = subtilis_type_if_sub(p, to, var, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	var = NULL;
	to = NULL;

	step_dup = subtilis_type_if_dup(step_dir, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	eor_var = subtilis_type_if_eor(p, sub, step_dup, err);
	step_dup = NULL;
	sub = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	eor_var_dup = subtilis_type_if_dup(eor_var, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	zero = subtilis_type_if_zero(p, &step_type_const, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	conde = subtilis_exp_lt(p, eor_var, zero, err);
	eor_var = NULL;

	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  conde->exp.ir_op, true_label,
					  start_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, true_label.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_exp_delete(conde);
	conde = subtilis_type_if_neq(p, eor_var_dup, step_dir, err);
	eor_var_dup = NULL;
	step_dir = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	final_label.reg = subtilis_ir_section_new_label(p->current);
	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  conde->exp.ir_op, final_label,
					  start_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, final_label.reg, err);

cleanup:

	subtilis_exp_delete(sub);
	subtilis_exp_delete(eor_var_dup);
	subtilis_exp_delete(eor_var);
	subtilis_exp_delete(conde);
	subtilis_exp_delete(var);
	subtilis_exp_delete(to);
	subtilis_exp_delete(step_dir);
	subtilis_exp_delete(step_dup);
	subtilis_exp_delete(step);
	subtilis_type_free(&step_type_const);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %r9, %rbp
movq %r8, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movl $0x8, 0x40(%rsp)
leaq 0x18(%r8), %rdx
movq %rcx, %rsi
movq %r9, %rcx
callq 0x379c3
cmpl $0x0, (%rbp)
movq %r12, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x222f5
xorl %ebx, %ebx
movq $0x0, (%rsp)
jmp 0x22325
movq %rax, %r13
movq %rax, %rdi
movq %rbp, %rsi
callq 0x362d2
movq %rax, (%rsp)
cmpl $0x0, (%rbp)
jne 0x22323
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
movq %rbp, %rdx
callq 0x361b9
cmpl $0x0, (%rbp)
je 0x2239c
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %r13, %rdi
callq 0x2b4c3
movq %r15, %rdi
callq 0x2b4c3
movq %r12, %rdi
callq 0x2b4c3
movq %rbp, %rdi
callq 0x2b4c3
movq %r14, %rdi
callq 0x2b4c3
movq 0x18(%rsp), %rdi
callq 0x2b4c3
movq %rbx, %rdi
callq 0x2b4c3
movq (%rsp), %rdi
callq 0x2b4c3
movq 0x10(%rsp), %rdi
callq 0x2b4c3
leaq 0x40(%rsp), %rdi
callq 0x2f843
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x360a2
cmpl $0x0, (%rbp)
je 0x223c8
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %rax, %rbx
jmp 0x22333
movq %rbx, %rdi
movq (%rsp), %rsi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x36db8
movq %rax, 0x8(%rsp)
cmpl $0x0, (%rbp)
jne 0x22403
leaq 0x38(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %r8
callq 0x23be8
cmpl $0x0, (%rbp)
je 0x22423
movq $0x0, (%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x8(%rsp), %rbx
jmp 0x22333
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x23c62
movq %rax, %r14
cmpl $0x0, (%rbp)
jne 0x22497
movq %r14, %rdi
callq 0x373fd
testb %al, %al
je 0x2247e
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x36f23
movq %rax, %r13
cmpl $0x0, (%rbp)
je 0x224af
movq $0x0, 0x10(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0x22419
leaq 0x514e5(%rip), %rdx     # 0x7396a
movq %rbp, %rdi
movl $0xf, %esi
movl $0x298, %ecx            # imm = 0x298
callq 0x145f4
movq $0x0, 0x10(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
jmp 0x22410
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x362d2
cmpl $0x0, (%rbp)
je 0x224ed
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x8(%rsp), %rbx
movq %rax, (%rsp)
jmp 0x22333
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x36e3e
movq %rax, %r12
cmpl $0x0, (%rbp)
je 0x2252b
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
jmp 0x22413
movq %r12, %rdi
movq %rbp, %rsi
callq 0x362d2
movq %rax, 0x28(%rsp)
cmpl $0x0, (%rbp)
jne 0x22557
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x35f70
cmpl $0x0, (%rbp)
je 0x22588
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x8(%rsp), %rbx
movq 0x28(%rsp), %r15
jmp 0x22333
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x2bdca
movq %rax, 0x20(%rsp)
cmpl $0x0, (%rbp)
jne 0x225ec
movq 0x48(%rbx), %rdi
movq 0x20(%rsp), %rax
movq 0x148(%rax), %rdx
movq 0x30(%rsp), %r12
movq 0x38(%rsp), %r15
movl $0x43, %esi
movq %r12, %rcx
movq %r15, %r8
movq %rbp, %r9
callq 0x2c0c2
cmpl $0x0, (%rbp)
jne 0x225ec
movq 0x48(%rbx), %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x2d017
cmpl $0x0, (%rbp)
je 0x2261e
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, (%rsp)
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x8(%rsp), %rbx
movq 0x20(%rsp), %rbp
jmp 0x2257e
movq 0x20(%rsp), %rdi
callq 0x2b4c3
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbp, %rcx
callq 0x36ee0
movq %rax, 0x20(%rsp)
cmpl $0x0, (%rbp)
jne 0x2268c
movq 0x48(%rbx), %rdi
callq 0x2d00a
movq %rax, %r14
movq 0x48(%rbx), %rdi
movq 0x20(%rsp), %rax
movq 0x148(%rax), %rdx
movl $0x43, %esi
movq %r14, %rcx
movq %r15, %r8
movq %rbp, %r9
callq 0x2c0c2
cmpl $0x0, (%rbp)
jne 0x2268c
movq 0x48(%rbx), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2d017
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
xorl %ebx, %ebx
movq $0x0, (%rsp)
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x20(%rsp), %rbp
jmp 0x22333