// File: /workspace/github_c_makefile_star2_O3/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 0x37860
cmpl $0x0, (%rbp)
movq %r12, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x22251
xorl %ebx, %ebx
movq $0x0, (%rsp)
jmp 0x22281
movq %rax, %r13
movq %rax, %rdi
movq %rbp, %rsi
callq 0x36182
movq %rax, (%rsp)
cmpl $0x0, (%rbp)
jne 0x2227f
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
movq %rbp, %rdx
callq 0x36069
cmpl $0x0, (%rbp)
je 0x222f8
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %r13, %rdi
callq 0x2b166
movq %r15, %rdi
callq 0x2b166
movq %r12, %rdi
callq 0x2b166
movq %rbp, %rdi
callq 0x2b166
movq %r14, %rdi
callq 0x2b166
movq 0x18(%rsp), %rdi
callq 0x2b166
movq %rbx, %rdi
callq 0x2b166
movq (%rsp), %rdi
callq 0x2b166
movq 0x10(%rsp), %rdi
callq 0x2b166
leaq 0x40(%rsp), %rdi
callq 0x2f56e
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 0x35f52
cmpl $0x0, (%rbp)
je 0x22324
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %rax, %rbx
jmp 0x2228f
movq %rbx, %rdi
movq (%rsp), %rsi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x36c60
movq %rax, 0x8(%rsp)
cmpl $0x0, (%rbp)
jne 0x2235f
leaq 0x38(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %r8
callq 0x23ae5
cmpl $0x0, (%rbp)
je 0x2237f
movq $0x0, (%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x8(%rsp), %rbx
jmp 0x2228f
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x23b5f
movq %rax, %r14
cmpl $0x0, (%rbp)
jne 0x223f3
movq %r14, %rdi
callq 0x372bf
testb %al, %al
je 0x223da
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x36de4
movq %rax, %r13
cmpl $0x0, (%rbp)
je 0x2240b
movq $0x0, 0x10(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0x22375
leaq 0x515ab(%rip), %rdx     # 0x7398c
movq %rbp, %rdi
movl $0xf, %esi
movl $0x298, %ecx            # imm = 0x298
callq 0x145a4
movq $0x0, 0x10(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
jmp 0x2236c
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x36182
cmpl $0x0, (%rbp)
je 0x22449
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 0x2228f
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x36cf0
movq %rax, %r12
cmpl $0x0, (%rbp)
je 0x22487
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
jmp 0x2236f
movq %r12, %rdi
movq %rbp, %rsi
callq 0x36182
movq %rax, 0x28(%rsp)
cmpl $0x0, (%rbp)
jne 0x224b3
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x35e20
cmpl $0x0, (%rbp)
je 0x224e4
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 0x2228f
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x2ba46
movq %rax, 0x20(%rsp)
cmpl $0x0, (%rbp)
jne 0x22548
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 0x2bd42
cmpl $0x0, (%rbp)
jne 0x22548
movq 0x48(%rbx), %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x2cca6
cmpl $0x0, (%rbp)
je 0x2257a
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 0x224da
movq 0x20(%rsp), %rdi
callq 0x2b166
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbp, %rcx
callq 0x36d9c
movq %rax, 0x20(%rsp)
cmpl $0x0, (%rbp)
jne 0x225e8
movq 0x48(%rbx), %rdi
callq 0x2cc99
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 0x2bd42
cmpl $0x0, (%rbp)
jne 0x225e8
movq 0x48(%rbx), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2cca6
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 0x2228f