// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/parser_loops.c
// Function: prv_init_local_range_var
static void prv_init_local_range_var(subtilis_parser_t *p, subtilis_token_t *t,
				     subtilis_for_context_t *for_ctx,
				     const char *var_name,
				     const subtilis_type_t *type,
				     subtilis_error_t *err)
{
	const subtilis_symbol_t *s;

	if (subtilis_symbol_table_lookup(p->local_st, var_name)) {
		subtilis_error_set_already_defined(
		    err, var_name, p->l->stream->name, p->l->line);
		return;
	}

	if (subtilis_type_if_is_numeric(type) ||
	    type->type == SUBTILIS_TYPE_FN) {
		for_ctx->is_reg = true;

		subtilis_type_copy(&for_ctx->type, type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		if (subtilis_type_if_reg_type(&for_ctx->type) ==
		    SUBTILIS_IR_REG_TYPE_INTEGER)
			for_ctx->loc = p->current->reg_counter++;
		else
			for_ctx->loc = p->current->freg_counter++;
		(void)subtilis_symbol_table_insert_reg(
		    p->local_st, var_name, &for_ctx->type, for_ctx->loc, err);
		return;
	} else if (type->type == SUBTILIS_TYPE_REC) {
		/*
		 * TODO: So this isn't ideal.  The range loop value
		 * variable has copy semantics, so we need to
		 * allocate a block of memory large enough to copy the
		 * loop variable.  We only really need to do this
		 * if we know that the range variable will be modified.
		 */

		subtilis_type_copy(&for_ctx->type, type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		(void)subtilis_symbol_table_insert_no_rc(p->local_st, var_name,
							 &for_ctx->type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	} else {
		subtilis_type_copy(&for_ctx->type, type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	/*
	 * There's no need to initialise the range var as its lifetime is
	 * restricted to the lifetime of the loop and it's value will be
	 * set during the first iteration.
	 */

	s = subtilis_symbol_table_insert_no_rc(p->local_st, var_name, type,
					       err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	for_ctx->is_reg = s->is_reg;
	for_ctx->reg = SUBTILIS_IR_REG_LOCAL;
	for_ctx->loc = s->loc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3cff0
cmpq $0x0, %rax
je 0x2bf7e
movq -0x30(%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 $0x20, %esi
leaq 0x7f315(%rip), %rcx     # 0xab276
leaq 0x7ea42(%rip), %rax     # 0xaa9aa
movq %rax, (%rsp)
movl $0x66e, 0x8(%rsp)       # imm = 0x66E
callq 0x156d0
jmp 0x2c10e
movq -0x28(%rbp), %rdi
callq 0x49d10
testb $0x1, %al
jne 0x2bf98
movq -0x28(%rbp), %rax
cmpl $0x9, (%rax)
jne 0x2c03e
movq -0x18(%rbp), %rax
movb $0x1, (%rax)
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3e4f0
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2bfc2
jmp 0x2c10e
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
callq 0x4a550
cmpl $0x0, %eax
jne 0x2bff5
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x18(%rax), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x2c014
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x20(%rax), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x18, %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %r8
callq 0x3cc20
jmp 0x2c10e
movq -0x28(%rbp), %rax
cmpl $0x16, (%rax)
jne 0x2c094
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3e4f0
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2c06a
jmp 0x2c10e
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x18, %rdx
movq -0x30(%rbp), %rcx
callq 0x3c750
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2c092
jmp 0x2c10e
jmp 0x2c0b6
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3e4f0
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2c0b4
jmp 0x2c10e
jmp 0x2c0b6
jmp 0x2c0b8
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x3c750
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2c0e0
jmp 0x2c10e
movq -0x38(%rbp), %rax
movb 0x2a8(%rax), %cl
movq -0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movq $0x2, 0x8(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)