// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/parser_loops.c
// Function: subtilis_parser_for
void subtilis_parser_for(subtilis_parser_t *p, subtilis_token_t *t,
			 subtilis_error_t *err)
{
	const char *tbuf;
	subtilis_type_t var_type;
	subtilis_for_context_t for_ctx;
	char *var_name = NULL;
	subtilis_exp_t *to = NULL;
	subtilis_exp_t *step = NULL;
	bool new_local = false;
	subtilis_step_type_t step_type = SUBTILIS_STEP_MAX;

	var_type.type = SUBTILIS_TYPE_VOID;
	for_ctx.type.type = SUBTILIS_TYPE_VOID;

	subtilis_lexer_get(p->l, t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	tbuf = subtilis_token_get_text_with_err(t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if (t->type == SUBTILIS_TOKEN_KEYWORD) {
		if (t->tok.keyword.type != SUBTILIS_KEYWORD_LOCAL) {
			subtilis_error_set_expected(
			    err, "LOCAL", tbuf, p->l->stream->name, p->l->line);
			return;
		}

		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		new_local = true;
		tbuf = subtilis_token_get_text_with_err(t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	if (t->type != SUBTILIS_TOKEN_IDENTIFIER) {
		subtilis_error_set_id_expected(err, tbuf, p->l->stream->name,
					       p->l->line);
		return;
	}

	var_type = t->tok.id_type;
	if (!subtilis_type_if_is_numeric(&var_type)) {
		subtilis_error_set_numeric_expected(
		    err, tbuf, p->l->stream->name, p->l->line);
		return;
	}

	var_name = malloc(subtilis_buffer_get_size(&t->buf));
	if (!var_name) {
		subtilis_error_set_oom(err);
		return;
	}
	strcpy(var_name, tbuf);

	prv_for_assignment(p, t, &for_ctx, new_local, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if ((t->type != SUBTILIS_TOKEN_KEYWORD) ||
	    (t->tok.keyword.type != SUBTILIS_KEYWORD_TO)) {
		tbuf = subtilis_token_get_text(t);
		subtilis_error_set_expected(err, "TO", tbuf, p->l->stream->name,
					    p->l->line);
		goto cleanup;
	}

	to = prv_numeric_expression(p, t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if ((t->type == SUBTILIS_TOKEN_KEYWORD) &&
	    (t->tok.keyword.type == SUBTILIS_KEYWORD_STEP)) {
		step = prv_numeric_expression(p, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		step_type = prv_compute_step_type(p, step, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		/* Takes ownership of to and step */

		if (step_type == SUBTILIS_STEP_VAR) {
			step = subtilis_type_if_copy_var(p, step, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
			if (subtilis_type_if_is_integer(&var_type))
				prv_for_step_int_var(p, t, to, step, &for_ctx,
						     err);
			else
				prv_for_step_generic_var(p, t, to, step,
							 &for_ctx, err);
		} else {
			prv_for_step_const(p, t, to, step, step_type, &for_ctx,
					   err);
		}
		step = NULL;
	} else {
		/* Takes ownership of to */

		prv_for_no_step(p, t, to, &for_ctx, err);
	}
	to = NULL;

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

	subtilis_lexer_get(p->l, t, err);

cleanup:

	subtilis_type_free(&var_type);
	subtilis_type_free(&for_ctx.type);
	subtilis_exp_delete(step);
	free(var_name);
	subtilis_exp_delete(to);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x300, %rsp            # imm = 0x300
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x2d0(%rbp)
movq $0x0, -0x2d8(%rbp)
movq $0x0, -0x2e0(%rbp)
movb $0x0, -0x2e1(%rbp)
movl $0x3, -0x2e8(%rbp)
movl $0x8, -0x168(%rbp)
movl $0x8, -0x2b0(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x133f0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28a3f
jmp 0x28ea7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12de0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28a5e
jmp 0x28ea7
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x28b06
movq -0x10(%rbp), %rax
cmpl $0x4a, 0x8(%rax)
je 0x28abc
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x1d, %esi
leaq 0x8160f(%rip), %rdx     # 0xaa0ae
leaq 0x81f04(%rip), %rax     # 0xaa9aa
movq %rax, (%rsp)
movl $0x356, 0x8(%rsp)       # imm = 0x356
callq 0x156d0
jmp 0x28ea7
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x133f0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28ade
jmp 0x28ea7
movb $0x1, -0x2e1(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12de0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28b04
jmp 0x28ea7
jmp 0x28b06
movq -0x10(%rbp), %rax
cmpl $0x6, (%rax)
je 0x28b56
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x12, %esi
leaq 0x8273d(%rip), %rcx     # 0xab276
leaq 0x81e6a(%rip), %rax     # 0xaa9aa
movq %rax, (%rsp)
movl $0x366, 0x8(%rsp)       # imm = 0x366
callq 0x156d0
jmp 0x28ea7
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
leaq -0x168(%rbp), %rdi
movl $0x148, %edx            # imm = 0x148
callq 0x12190
leaq -0x168(%rbp), %rdi
callq 0x49d10
testb $0x1, %al
jne 0x28bc6
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x2c, %esi
leaq 0x826cd(%rip), %rcx     # 0xab276
leaq 0x81dfa(%rip), %rax     # 0xaa9aa
movq %rax, (%rsp)
movl $0x36d, 0x8(%rsp)       # imm = 0x36D
callq 0x156d0
jmp 0x28ea7
movq -0x10(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0x16270
movq %rax, %rdi
callq 0x121b0
movq %rax, -0x2d0(%rbp)
cmpq $0x0, -0x2d0(%rbp)
jne 0x28c0e
movq -0x18(%rbp), %rdi
movl $0x1, %esi
leaq 0x81dab(%rip), %rdx     # 0xaa9aa
movl $0x373, %ecx            # imm = 0x373
callq 0x158e0
jmp 0x28ea7
movq -0x2d0(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x12060
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movb -0x2e1(%rbp), %al
movq -0x18(%rbp), %r8
leaq -0x2c8(%rbp), %rdx
andb $0x1, %al
movzbl %al, %ecx
callq 0x28eb0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28c4f
jmp 0x28e67
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x28c65
movq -0x10(%rbp), %rax
cmpl $0x86, 0x8(%rax)
je 0x28cb9
movq -0x10(%rbp), %rdi
callq 0x12d70
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x1d, %esi
leaq 0x81541(%rip), %rdx     # 0xaa1dd
leaq 0x81d07(%rip), %rax     # 0xaa9aa
movq %rax, (%rsp)
movl $0x380, 0x8(%rsp)       # imm = 0x380
callq 0x156d0
jmp 0x28e67
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x290e0
movq %rax, -0x2d8(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28cdf
jmp 0x28e67
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x28e1e
movq -0x10(%rbp), %rax
cmpl $0x76, 0x8(%rax)
jne 0x28e1e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x290e0
movq %rax, -0x2e0(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28d20
jmp 0x28e67
movq -0x8(%rbp), %rdi
movq -0x2e0(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x291b0
movl %eax, -0x2e8(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28d48
jmp 0x28e67
cmpl $0x2, -0x2e8(%rbp)
jne 0x28de0
movq -0x8(%rbp), %rdi
movq -0x2e0(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x47cd0
movq %rax, -0x2e0(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28d7e
jmp 0x28e67
leaq -0x168(%rbp), %rdi
callq 0x499a0
testb $0x1, %al
jne 0x28d90
jmp 0x28db8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x2d8(%rbp), %rdx
movq -0x2e0(%rbp), %rcx
movq -0x18(%rbp), %r9
leaq -0x2c8(%rbp), %r8
callq 0x293e0
jmp 0x28dde
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x2d8(%rbp), %rdx
movq -0x2e0(%rbp), %rcx
movq -0x18(%rbp), %r9
leaq -0x2c8(%rbp), %r8
callq 0x29880
jmp 0x28e11
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x2d8(%rbp), %rdx
movq -0x2e0(%rbp), %rcx
movl -0x2e8(%rbp), %r8d
movq -0x18(%rbp), %rax
leaq -0x2c8(%rbp), %r9
movq %rax, (%rsp)
callq 0x29c30
movq $0x0, -0x2e0(%rbp)
jmp 0x28e3d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x2d8(%rbp), %rdx
movq -0x18(%rbp), %r8
leaq -0x2c8(%rbp), %rcx
callq 0x29da0
movq $0x0, -0x2d8(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x28e53
jmp 0x28e67
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x133f0
leaq -0x168(%rbp), %rdi
callq 0x3e100
leaq -0x2c8(%rbp), %rdi
addq $0x18, %rdi
callq 0x3e100
movq -0x2e0(%rbp), %rdi
callq 0x36ee0
movq -0x2d0(%rbp), %rdi
callq 0x12290
movq -0x2d8(%rbp), %rdi
callq 0x36ee0
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq