// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/parser_assignment.c
// Function: subtilis_parser_assignment
void subtilis_parser_assignment(subtilis_parser_t *p, subtilis_token_t *t,
				subtilis_error_t *err)
{
	const char *tbuf;
	subtilis_ir_operand_t op1;
	const subtilis_symbol_t *s;
	subtilis_assign_type_t at;
	subtilis_type_t type;
	size_t mem_reg = SUBTILIS_IR_REG_LOCAL;
	bool new_global = false;
	char *var_name = NULL;
	subtilis_exp_t *e = NULL;

	type.type = SUBTILIS_TYPE_VOID;

	var_name = subtilis_parser_get_assignment_var(p, t, &type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	tbuf = subtilis_token_get_text(t);
	if (t->type != SUBTILIS_TOKEN_OPERATOR) {
		prv_missing_operator_error(p, tbuf, var_name, err);
		goto cleanup;
	}

	if (!strcmp(tbuf, "(")) {
		s = subtilis_symbol_table_lookup(p->local_st, var_name);
		if (!s) {
			s = subtilis_symbol_table_lookup(p->st, var_name);
			mem_reg = SUBTILIS_IR_REG_GLOBAL;
		}
		if (s && s->t.type == SUBTILIS_TYPE_FN)
			subtilis_parser_call_ptr(p, t, s, var_name, mem_reg,
						 err);
		else
			prv_assign_array(p, t, var_name, &type, err);
		goto cleanup;
	}

	if (!strcmp(tbuf, "{")) {
		prv_assign_vector(p, t, var_name, &type, err);
		goto cleanup;
	}

	if (!strcmp(tbuf, ":=")) {
		prv_assignment_local(p, t, var_name, &type, err);
		goto cleanup;
	}

	subtilis_parser_lookup_assignment_var(p, t, var_name, &s, &op1.reg,
					      &new_global, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (!new_global && (type.type == SUBTILIS_TYPE_REC) &&
	    !strcmp(tbuf, ".")) {
		prv_assign_field(p, t, &type, op1.reg, s->loc, err);
		goto cleanup;
	} else if (!strcmp(tbuf, "=") || !strcmp(tbuf, ":=")) {
		at = SUBTILIS_ASSIGN_TYPE_EQUAL;
	} else if (new_global) {
		prv_missing_operator_error(p, tbuf, var_name, err);
		goto cleanup;
	} else if (!strcmp(tbuf, "+=")) {
		at = SUBTILIS_ASSIGN_TYPE_PLUS_EQUAL;
	} else if (!strcmp(tbuf, "-=") && subtilis_type_if_is_numeric(&type)) {
		at = SUBTILIS_ASSIGN_TYPE_MINUS_EQUAL;
	} else {
		subtilis_error_set_assignment_op_expected(
		    err, tbuf, p->l->stream->name, p->l->line);
		goto cleanup;
	}

	if (new_global) {
		if (p->current->proc_called) {
			subtilis_error_set_global_after_proc(
			    err, var_name, p->l->stream->name, p->l->line);
			goto cleanup;
		}
		if ((type.type == SUBTILIS_TYPE_REC) &&
		    (at == SUBTILIS_ASSIGN_TYPE_EQUAL)) {
			subtilis_parser_rec_init(p, t, &type, var_name, false,
						 true, err);
			goto cleanup;
		}
		s = subtilis_symbol_table_insert(p->st, var_name, &type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	} else {
		/*
		 * We need to check that the id type matches the type in the
		 * symbol table.  The compiler can still generate correct code
		 * because it knows the correct type, but the code still looks
		 * weird.
		 */

		subtilis_type_compare_diag(p, &type, &s->t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

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

	tbuf = subtilis_token_get_text(t);
	if ((type.type == SUBTILIS_TYPE_REC) &&
	    (at == SUBTILIS_ASSIGN_TYPE_EQUAL) && !strcmp(tbuf, "(")) {
		subtilis_parser_rec_reset(p, t, &type, op1.reg, s->loc, err);
		goto cleanup;
	}

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

	/* Ownership of e is passed to the following functions. */

	if (subtilis_type_if_is_reference(&s->t)) {
		if (at == SUBTILIS_ASSIGN_TYPE_EQUAL) {
			if (new_global)
				subtilis_type_if_new_ref(p, &s->t, op1.reg,
							 s->loc, e, err);
			else
				subtilis_type_if_assign_ref(p, &s->t, op1.reg,
							    s->loc, e, err);
		} else if (s->t.type == SUBTILIS_TYPE_STRING) {
			subtilis_string_type_add_eq(p, op1.reg, s->loc, e, err);
		} else {
			subtilis_error_set_assertion_failed(err);
		}
		goto cleanup;
	}

	if ((type.type == SUBTILIS_TYPE_FN) && (e->partial_name)) {
		if (e->type.type != SUBTILIS_TYPE_FN) {
			subtilis_error_set_expected(
			    err, subtilis_type_name(&type),
			    subtilis_type_name(&e->type), p->l->stream->name,
			    p->l->line);
			goto cleanup;
		}
		subtilis_parser_call_add_addr(p, &type, e, err);
	} else {
		e = subtilis_type_if_coerce_type(p, e, &type, err);
	}
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	e = prv_assignment_operator(p, var_name, e, at, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (s->is_reg)
		subtilis_type_if_assign_to_reg(p, s->loc, e, err);
	else
		subtilis_type_if_assign_to_mem(p, op1.reg, s->loc, e, err);

cleanup:

	subtilis_type_free(&type);
	free(var_name);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x2, -0x188(%rbp)
movb $0x0, -0x189(%rbp)
movq $0x0, -0x198(%rbp)
movq $0x0, -0x1a0(%rbp)
movl $0x8, -0x180(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rcx
leaq -0x180(%rbp), %rdx
callq 0x1b590
movq %rax, -0x198(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1b876
jmp 0x1bf22
movq -0x10(%rbp), %rdi
callq 0x12d70
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
je 0x1b8a9
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x1bf50
jmp 0x1bf22
movq -0x20(%rbp), %rdi
leaq 0x8f9e8(%rip), %rsi     # 0xab29c
callq 0x12140
cmpl $0x0, %eax
jne 0x1b95e
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x198(%rbp), %rsi
callq 0x3cff0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x1b904
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x198(%rbp), %rsi
callq 0x3cff0
movq %rax, -0x30(%rbp)
movq $0x1, -0x188(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1b93a
movq -0x30(%rbp), %rax
cmpl $0x9, 0x8(%rax)
jne 0x1b93a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x198(%rbp), %rcx
movq -0x188(%rbp), %r8
movq -0x18(%rbp), %r9
callq 0x20090
jmp 0x1b959
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq -0x18(%rbp), %r8
leaq -0x180(%rbp), %rcx
callq 0x1bfd0
jmp 0x1bf22
movq -0x20(%rbp), %rdi
leaq 0x91ca2(%rip), %rsi     # 0xad60b
callq 0x12140
cmpl $0x0, %eax
jne 0x1b997
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq -0x18(%rbp), %r8
leaq -0x180(%rbp), %rcx
callq 0x1c0c0
jmp 0x1bf22
movq -0x20(%rbp), %rdi
leaq 0x8f025(%rip), %rsi     # 0xaa9c7
callq 0x12140
cmpl $0x0, %eax
jne 0x1b9d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq -0x18(%rbp), %r8
leaq -0x180(%rbp), %rcx
callq 0x1c1a0
jmp 0x1bf22
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq -0x18(%rbp), %rax
leaq -0x30(%rbp), %rcx
leaq -0x28(%rbp), %r8
leaq -0x189(%rbp), %r9
movq %rax, (%rsp)
callq 0x1b6a0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1ba09
jmp 0x1bf22
testb $0x1, -0x189(%rbp)
jne 0x1ba58
cmpl $0x16, -0x180(%rbp)
jne 0x1ba58
movq -0x20(%rbp), %rdi
leaq 0x8eaef(%rip), %rsi     # 0xaa515
callq 0x12140
cmpl $0x0, %eax
jne 0x1ba58
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %r8
movq -0x18(%rbp), %r9
leaq -0x180(%rbp), %rdx
callq 0x1c440
jmp 0x1bf22
movq -0x20(%rbp), %rdi
leaq 0x8ebb1(%rip), %rsi     # 0xaa614
callq 0x12140
cmpl $0x0, %eax
je 0x1ba82
movq -0x20(%rbp), %rdi
leaq 0x8ef4f(%rip), %rsi     # 0xaa9c7
callq 0x12140
cmpl $0x0, %eax
jne 0x1ba8e
movl $0x0, -0x34(%rbp)
jmp 0x1bb4f
testb $0x1, -0x189(%rbp)
je 0x1bab4
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x1bf50
jmp 0x1bf22
movq -0x20(%rbp), %rdi
leaq 0x8eb2d(%rip), %rsi     # 0xaa5ec
callq 0x12140
cmpl $0x0, %eax
jne 0x1bad2
movl $0x1, -0x34(%rbp)
jmp 0x1bb4b
movq -0x20(%rbp), %rdi
leaq 0x8eb12(%rip), %rsi     # 0xaa5ef
callq 0x12140
cmpl $0x0, %eax
jne 0x1bb02
leaq -0x180(%rbp), %rdi
callq 0x49d10
testb $0x1, %al
jne 0x1baf9
jmp 0x1bb02
movl $0x2, -0x34(%rbp)
jmp 0x1bb49
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 $0x14, %esi
leaq 0x8f74a(%rip), %rcx     # 0xab276
leaq 0x8ea89(%rip), %rax     # 0xaa5bc
movq %rax, (%rsp)
movl $0x461, 0x8(%rsp)       # imm = 0x461
callq 0x156d0
jmp 0x1bf22
jmp 0x1bb4b
jmp 0x1bb4d
jmp 0x1bb4f
jmp 0x1bb51
testb $0x1, -0x189(%rbp)
je 0x1bc2c
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
testb $0x1, 0xe0(%rax)
je 0x1bbb9
movq -0x18(%rbp), %rdi
movq -0x198(%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 $0x6c, %esi
leaq 0x8f6da(%rip), %rcx     # 0xab276
leaq 0x8ea19(%rip), %rax     # 0xaa5bc
movq %rax, (%rsp)
movl $0x468, 0x8(%rsp)       # imm = 0x468
callq 0x156d0
jmp 0x1bf22
cmpl $0x16, -0x180(%rbp)
jne 0x1bbf9
cmpl $0x0, -0x34(%rbp)
jne 0x1bbf9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x198(%rbp), %rcx
movq -0x18(%rbp), %rax
leaq -0x180(%rbp), %rdx
xorl %r8d, %r8d
movl $0x1, %r9d
movq %rax, (%rsp)
callq 0x34e20
jmp 0x1bf22
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x198(%rbp), %rsi
movq -0x18(%rbp), %rcx
leaq -0x180(%rbp), %rdx
callq 0x3c480
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1bc2a
jmp 0x1bf22
jmp 0x1bc58
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
addq $0x8, %rdx
movq -0x18(%rbp), %rcx
leaq -0x180(%rbp), %rsi
callq 0x4a960
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1bc56
jmp 0x1bf22
jmp 0x1bc58
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 0x1bc7a
jmp 0x1bf22
movq -0x10(%rbp), %rdi
callq 0x12d70
movq %rax, -0x20(%rbp)
cmpl $0x16, -0x180(%rbp)
jne 0x1bcd3
cmpl $0x0, -0x34(%rbp)
jne 0x1bcd3
movq -0x20(%rbp), %rdi
leaq 0x8f5fb(%rip), %rsi     # 0xab29c
callq 0x12140
cmpl $0x0, %eax
jne 0x1bcd3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %r8
movq -0x18(%rbp), %r9
leaq -0x180(%rbp), %rdx
callq 0x35690
jmp 0x1bf22
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x24550
movq %rax, -0x1a0(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1bcf9
jmp 0x1bf22
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
callq 0x4a090
testb $0x1, %al
jne 0x1bd0f
jmp 0x1bdbc
cmpl $0x0, -0x34(%rbp)
jne 0x1bd70
testb $0x1, -0x189(%rbp)
je 0x1bd47
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x1a0(%rbp), %r8
movq -0x18(%rbp), %r9
callq 0x47710
jmp 0x1bd6e
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x1a0(%rbp), %r8
movq -0x18(%rbp), %r9
callq 0x477a0
jmp 0x1bdb7
movq -0x30(%rbp), %rax
cmpl $0x7, 0x8(%rax)
jne 0x1bd9b
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rdx
movq -0x1a0(%rbp), %rcx
movq -0x18(%rbp), %r8
callq 0x6b320
jmp 0x1bdb5
movq -0x18(%rbp), %rdi
movl $0xf, %esi
leaq 0x8e811(%rip), %rdx     # 0xaa5bc
movl $0x49d, %ecx            # imm = 0x49D
callq 0x158e0
jmp 0x1bdb7
jmp 0x1bf22
cmpl $0x9, -0x180(%rbp)
jne 0x1be7a
movq -0x1a0(%rbp), %rax
cmpq $0x0, 0x160(%rax)
je 0x1be7a
movq -0x1a0(%rbp), %rax
cmpl $0x9, (%rax)
je 0x1be5d
movq -0x18(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x3e190
movq %rax, -0x1a8(%rbp)
movq -0x1a0(%rbp), %rdi
callq 0x3e190
movq -0x1b0(%rbp), %rdi
movq -0x1a8(%rbp), %rdx
movq %rax, %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 0x8e775(%rip), %rax     # 0xaa5bc
movq %rax, (%rsp)
movl $0x4a7, 0x8(%rsp)       # imm = 0x4A7
callq 0x156d0
jmp 0x1bf22
movq -0x8(%rbp), %rdi
movq -0x1a0(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq -0x180(%rbp), %rsi
callq 0x21910
jmp 0x1be9c
movq -0x8(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
movq -0x18(%rbp), %rcx
leaq -0x180(%rbp), %rdx
callq 0x4a2e0
movq %rax, -0x1a0(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1bea7
jmp 0x1bf22
movq -0x8(%rbp), %rdi
movq -0x198(%rbp), %rsi
movq -0x1a0(%rbp), %rdx
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %r8
callq 0x1c8f0
movq %rax, -0x1a0(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1bed7
jmp 0x1bf22
movq -0x30(%rbp), %rax
testb $0x1, 0x2a8(%rax)
je 0x1bf01
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq -0x1a0(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x47ea0
jmp 0x1bf20
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rdx
movq -0x1a0(%rbp), %rcx
movq -0x18(%rbp), %r8
callq 0x47f20
jmp 0x1bf22
leaq -0x180(%rbp), %rdi
callq 0x3e100
movq -0x198(%rbp), %rdi
callq 0x12290
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
nopw %cs:(%rax,%rax)