// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movb $0x0, 0xb(%rsp)
leaq 0x28(%rsp), %rdx
movl $0x8, (%rdx)
movq %r14, %rcx
callq 0x18343
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x1862e
movq %r12, %rdi
callq 0x12ad0
movq %rax, %r13
cmpl $0x2, (%r12)
jne 0x1861d
leaq 0x5bccd(%rip), %rsi     # 0x74212
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
je 0x18652
leaq 0x5e0f5(%rip), %rsi     # 0x76651
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
je 0x18705
leaq 0x5b414(%rip), %rsi     # 0x73987
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
je 0x18774
subq $0x8, %rsp
leaq 0x18(%rsp), %rcx
leaq 0x1c8(%rsp), %r8
leaq 0x13(%rsp), %r9
movq %r15, %rdi
movq %rbx, %rdx
pushq %r14
callq 0x1840a
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x1862e
movb 0xb(%rsp), %bpl
testb %bpl, %bpl
jne 0x185d8
cmpl $0x16, 0x28(%rsp)
jne 0x185d8
leaq 0x5af3c(%rip), %rsi     # 0x73504
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
je 0x188db
leaq 0x5b025(%rip), %rsi     # 0x73604
movq %r13, %rdi
callq 0x12160
movl $0x0, 0x1c(%rsp)
movb $0x1, %cl
movl %ecx, 0xc(%rsp)
testl %eax, %eax
je 0x189f9
leaq 0x5b383(%rip), %rsi     # 0x73987
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
je 0x189f9
testb %bpl, %bpl
je 0x18903
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x18d3a
leaq 0x28(%rsp), %rdi
callq 0x2f843
movq %rbx, %rdi
callq 0x122c0
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x68(%r15), %rdi
movq %rbx, %rsi
callq 0x2eec8
movq %rax, 0x10(%rsp)
movl $0x2, %r8d
testq %rax, %rax
jne 0x18685
movq 0x60(%r15), %rdi
movq %rbx, %rsi
callq 0x2eec8
movq %rax, 0x10(%rsp)
movl $0x1, %r8d
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
je 0x186a8
cmpl $0x9, 0x8(%rdx)
jne 0x186a8
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rcx
movq %r14, %r9
callq 0x1c2c1
jmp 0x1862e
leaq 0x1c0(%rsp), %rsi
movl $0x8, (%rsi)
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0x3610f
cmpl $0x0, (%r14)
jne 0x1862e
leaq 0x170(%rsp), %rdx
movl $0xa, %ecx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1f017
cmpl $0x0, (%r14)
je 0x1882c
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1976e
jmp 0x18855
leaq 0x1c0(%rsp), %rsi
movl $0x8, (%rsi)
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0x36164
cmpl $0x0, (%r14)
jne 0x1862e
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1f50f
movq %rax, 0x170(%rsp)
cmpl $0x0, (%r14)
jne 0x18855
xorl %edx, %edx
testq %rax, %rax
setne %dl
leaq 0x170(%rsp), %rcx
leaq 0x1c0(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %r8
pushq %r14
pushq $0x0
jmp 0x1884c
movq 0x48(%r15), %rax
cmpq 0x50(%r15), %rax
jne 0x18789
cmpq $0x0, 0x78(%r15)
je 0x18898
movq 0x68(%r15), %rdi
movq %rbx, %rsi
callq 0x2eec8
testq %rax, %rax
je 0x187d2
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5ae00(%rip), %rax     # 0x735ac
leaq 0x5b642(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x20, %esi
movq %rbx, %rdx
pushq $0x260                  # imm = 0x260
pushq %rax
callq 0x1442a
addq $0x10, %rsp
jmp 0x1862e
leaq 0x28(%rsp), %rdi
callq 0x37676
testb %al, %al
je 0x18867
leaq 0x28(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1803b
cmpl $0x0, (%r14)
jne 0x1862e
movq %rax, %r12
movq 0x68(%r15), %rdi
movq 0x148(%rax), %rcx
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
movq %r14, %r8
callq 0x2ec2e
movq %r12, %rdi
callq 0x2b4c3
jmp 0x1862e
leaq 0x170(%rsp), %rcx
leaq 0x1c0(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %rbx, %r8
pushq %r14
pushq $0x1
callq 0x1982c
addq $0x10, %rsp
leaq 0x1c0(%rsp), %rdi
callq 0x2f843
jmp 0x1862e
movl 0x28(%rsp), %eax
cmpl $0x16, %eax
je 0x1894c
cmpl $0x9, %eax
jne 0x18967
leaq 0x28(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %r8
callq 0x18197
jmp 0x1862e
movq 0x60(%r15), %rdi
movq %rbx, %rsi
callq 0x2eec8
testq %rax, %rax
je 0x18789
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5aced(%rip), %rax     # 0x735ac
leaq 0x5b52f(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x52, %esi
movq %rbx, %rdx
pushq $0x259                  # imm = 0x259
jmp 0x187c3
movq 0x1c0(%rsp), %rcx
movq 0x10(%rsp), %rax
movq (%rax), %r8
leaq 0x28(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r9
callq 0x18d8e
jmp 0x1862e
leaq 0x5acd2(%rip), %rsi     # 0x735dc
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
je 0x189e9
leaq 0x5acbe(%rip), %rsi     # 0x735df
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
jne 0x189bb
leaq 0x28(%rsp), %rdi
callq 0x37676
testb %al, %al
je 0x189bb
movl $0x2, 0x1c(%rsp)
jmp 0x189f1
leaq 0x28(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %r8
callq 0x182be
jmp 0x1862e
leaq 0x28(%rsp), %rdi
callq 0x37833
testb %al, %al
je 0x18b75
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1eb88
cmpl $0x0, (%r14)
jne 0x1862e
movq %rax, %r12
movq 0x158(%rax), %rdx
movq 0x68(%r15), %rdi
testq %rdx, %rdx
je 0x18bed
movq %r12, %rsi
movq %rbx, %rcx
movq %r14, %r8
callq 0x2eb46
jmp 0x1881f
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5abdf(%rip), %rax     # 0x735ac
leaq 0x5b421(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x14, %esi
movq %r13, %rdx
pushq $0x461                  # imm = 0x461
jmp 0x187c3
movl $0x1, 0x1c(%rsp)
movl $0x0, 0xc(%rsp)
testb %bpl, %bpl
je 0x18a3d
movq 0x48(%r15), %rax
cmpb $0x1, 0xe0(%rax)
jne 0x18b1d
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5ab8b(%rip), %rax     # 0x735ac
leaq 0x5b3cd(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x6c, %esi
movq %rbx, %rdx
pushq $0x468                  # imm = 0x468
jmp 0x187c3
movq 0x10(%rsp), %rdx
addq $0x8, %rdx
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
movq %r14, %rcx
callq 0x37da0
cmpl $0x0, (%r14)
jne 0x1862e
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x1862e
movq %r12, %rdi
callq 0x12ad0
cmpl $0x16, 0x28(%rsp)
setne %cl
movl 0xc(%rsp), %edx
xorb $0x1, %dl
orb %cl, %dl
jne 0x18aaa
leaq 0x5b778(%rip), %rsi     # 0x74212
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
je 0x18b93
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1e874
cmpl $0x0, (%r14)
jne 0x1862e
movq %rax, %r12
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x8(%rax), %r13
movq %r13, %rdi
callq 0x37833
testb %al, %al
je 0x18bbb
cmpb $0x0, 0xc(%rsp)
je 0x18c93
movq 0x1c0(%rsp), %rdx
movq 0x20(%rsp), %rax
movq (%rax), %rcx
movq %r15, %rdi
movq %r13, %rsi
testb %bpl, %bpl
jne 0x18c17
movq %r12, %r8
movq %r14, %r9
callq 0x36040
jmp 0x1862e
cmpl $0x16, 0x28(%rsp)
setne %al
movl 0xc(%rsp), %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x18b57
subq $0x8, %rsp
leaq 0x30(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
pushq %r14
callq 0x29e86
jmp 0x187c9
movq 0x60(%r15), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
movq %r14, %rcx
callq 0x2e6e8
movq %rax, 0x10(%rsp)
jmp 0x18a56
leaq 0x5aa30(%rip), %rdx     # 0x735ac
movq %r14, %rdi
movl $0xf, %esi
movl $0x274, %ecx            # imm = 0x274
callq 0x145f4
jmp 0x1862e
movq 0x1c0(%rsp), %rcx
movq 0x10(%rsp), %rax
movq (%rax), %r8
leaq 0x28(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r9
callq 0x2a721
jmp 0x1862e
cmpl $0x9, 0x28(%rsp)
jne 0x18c27
cmpq $0x0, 0x160(%r12)
je 0x18c27
cmpl $0x9, (%r12)
jne 0x18cd6
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
movq %r12, %rdx
movq %r14, %rcx
callq 0x1d2a6
jmp 0x18c3d
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
movq %r14, %rcx
callq 0x2e6e8
cmpl $0x0, (%r14)
jne 0x1862e
movq (%rax), %rcx
leaq 0x28(%rsp), %rsi
movl $0x2, %edx
movq %r15, %rdi
movq %r12, %r8
movq %r14, %r9
callq 0x3600f
jmp 0x1862e
leaq 0x28(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x379c3
movq %rax, %r12
cmpl $0x0, (%r14)
jne 0x1862e
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movl 0x1c(%rsp), %ecx
movq %r14, %r8
callq 0x194e9
cmpl $0x0, (%r14)
jne 0x1862e
movq 0x20(%rsp), %rcx
cmpb $0x1, 0x2a8(%rcx)
jne 0x18d17
movq 0x20(%rsp), %rcx
movq (%rcx), %rsi
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
callq 0x363e2
jmp 0x1862e
cmpl $0x7, (%r13)
jne 0x18cbd
movq 0x1c0(%rsp), %rsi
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movq %r15, %rdi
movq %r12, %rcx
movq %r14, %r8
callq 0x4bf09
jmp 0x1862e
leaq 0x5a8e8(%rip), %rdx     # 0x735ac
movq %r14, %rdi
movl $0xf, %esi
movl $0x49d, %ecx            # imm = 0x49D
jmp 0x18b89
leaq 0x28(%rsp), %rdi
callq 0x2f882
movq %rax, %r13
movq %r12, %rdi
callq 0x2f882
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5a8af(%rip), %r10     # 0x735ac
movq %r14, %rdi
movl $0x1d, %esi
movq %r13, %rdx
movq %rax, %rcx
pushq $0x4a7                  # imm = 0x4A7
pushq %r10
jmp 0x187c4
movq 0x1c0(%rsp), %rsi
movq 0x20(%rsp), %rcx
movq (%rcx), %rdx
movq %r15, %rdi
movq %rax, %rcx
movq %r14, %r8
callq 0x36416
jmp 0x1862e