// File: /workspace/github_c_makefile_star2_O3/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, 0xf(%rsp)
leaq 0x78(%rsp), %rdx
movl $0x8, (%rdx)
movq %r14, %rcx
callq 0x18243
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x1863c
movq %r12, %rdi
callq 0x12ad0
movq %rax, %r13
cmpl $0x2, (%r12)
jne 0x1862b
movzbl (%r13), %eax
cmpl $0x7b, %eax
je 0x184eb
cmpl $0x3a, %eax
je 0x18485
cmpl $0x28, %eax
jne 0x184f6
cmpb $0x0, 0x1(%r13)
jne 0x184f6
movq 0x68(%r15), %rdi
movq %rbx, %rsi
callq 0x2ebbc
testq %rax, %rax
je 0x18695
movl $0x2, %r8d
jmp 0x186ac
cmpb $0x3d, 0x1(%r13)
jne 0x184f6
cmpb $0x0, 0x2(%r13)
jne 0x184f6
movq 0x48(%r15), %rax
cmpq 0x50(%r15), %rax
jne 0x184a8
cmpq $0x0, 0x78(%r15)
je 0x18999
movq 0x68(%r15), %rdi
movq %rbx, %rsi
callq 0x2ebbc
testq %rax, %rax
je 0x187d3
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5b0d5(%rip), %rax     # 0x735a4
leaq 0x5b93f(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x20, %esi
movq %rbx, %rdx
pushq $0x260                  # imm = 0x260
jmp 0x1877f
cmpb $0x0, 0x1(%r13)
je 0x185a4
subq $0x8, %rsp
leaq 0x28(%rsp), %rcx
leaq 0x1c8(%rsp), %r8
leaq 0x17(%rsp), %r9
movq %r15, %rdi
movq %rbx, %rdx
pushq %r14
callq 0x1830a
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x1863c
movb 0xf(%rsp), %bpl
movl 0x78(%rsp), %eax
cmpl $0x16, %eax
sete %cl
movl %ebp, %edx
notb %dl
andb %cl, %dl
movb (%r13), %cl
movzbl %cl, %ecx
cmpb $0x2e, %cl
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x18586
cmpb $0x0, 0x1(%r13)
jne 0x18626
movq 0x1c0(%rsp), %rcx
movq 0x20(%rsp), %rax
movq (%rax), %r8
leaq 0x78(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r9
callq 0x18c9f
jmp 0x1863c
cmpl $0x3a, %ecx
je 0x18609
cmpl $0x3d, %ecx
jne 0x18626
cmpb $0x0, 0x1(%r13)
jne 0x18626
jmp 0x1878e
leaq 0x1c0(%rsp), %rsi
movl $0x8, (%rsi)
leaq 0x78(%rsp), %rdi
movq %r14, %rdx
callq 0x36014
cmpl $0x0, (%r14)
jne 0x1863c
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1f564
movq %rax, 0x20(%rsp)
cmpl $0x0, (%r14)
jne 0x18958
xorl %edx, %edx
testq %rax, %rax
setne %dl
leaq 0x20(%rsp), %rcx
leaq 0x1c0(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %r8
pushq %r14
pushq $0x0
jmp 0x1894f
cmpb $0x3d, 0x1(%r13)
jne 0x18626
cmpb $0x0, 0x2(%r13)
je 0x1878e
testb %bpl, %bpl
je 0x18756
jmp 0x1862b
testb %bpl, %bpl
je 0x18660
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x18c4b
leaq 0x78(%rsp), %rdi
callq 0x2f56e
movq %rbx, %rdi
callq 0x122c0
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2d, %ecx
je 0x18725
cmpl $0x2b, %ecx
jne 0x18756
cmpb $0x3d, 0x1(%r13)
jne 0x18756
cmpb $0x0, 0x2(%r13)
jne 0x18756
movl $0x1, 0x14(%rsp)
jmp 0x18749
movq 0x60(%r15), %rdi
movq %rbx, %rsi
callq 0x2ebbc
testq %rax, %rax
je 0x186cb
movl $0x1, %r8d
cmpl $0x9, 0x8(%rax)
jne 0x186cb
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %rbx, %rcx
movq %r14, %r9
callq 0x1c41b
jmp 0x1863c
leaq 0x1c0(%rsp), %rsi
movl $0x8, (%rsi)
leaq 0x78(%rsp), %rdi
movq %r14, %rdx
callq 0x35fbf
cmpl $0x0, (%r14)
jne 0x1863c
leaq 0x20(%rsp), %rdx
movl $0xa, %ecx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1f0d1
cmpl $0x0, (%r14)
je 0x18932
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x19675
jmp 0x18958
cmpb $0x3d, 0x1(%r13)
jne 0x18756
cmpb $0x0, 0x2(%r13)
jne 0x18756
leaq 0x78(%rsp), %rdi
callq 0x37534
testb %al, %al
je 0x18756
movl $0x2, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
jmp 0x1883b
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5ae3c(%rip), %rax     # 0x735a4
leaq 0x5b6a6(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x14, %esi
movq %r13, %rdx
pushq $0x461                  # imm = 0x461
pushq %rax
callq 0x143da
addq $0x10, %rsp
jmp 0x1863c
testb %bpl, %bpl
je 0x1882d
movq 0x48(%r15), %rcx
cmpb $0x1, 0xe0(%rcx)
jne 0x1896a
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5adea(%rip), %rax     # 0x735a4
leaq 0x5b654(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x6c, %esi
movq %rbx, %rdx
pushq $0x468                  # imm = 0x468
jmp 0x1877f
leaq 0x78(%rsp), %rdi
callq 0x37534
testb %al, %al
je 0x18901
leaq 0x78(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x17f3b
cmpl $0x0, (%r14)
jne 0x1863c
movq %rax, %r12
movq 0x68(%r15), %rdi
movq 0x148(%rax), %rcx
leaq 0x78(%rsp), %rdx
movq %rbx, %rsi
movq %r14, %r8
callq 0x2e922
movq %r12, %rdi
callq 0x2b166
jmp 0x1863c
movb $0x1, %al
movl %eax, 0x10(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x20(%rsp), %r13
leaq 0x8(%r13), %rdx
leaq 0x78(%rsp), %rsi
movq %r15, %rdi
movq %r14, %rcx
callq 0x37c3d
cmpl $0x0, (%r14)
jne 0x1863c
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12edc
cmpl $0x0, (%r14)
jne 0x1863c
movq %r12, %rdi
callq 0x12ad0
cmpl $0x16, 0x78(%rsp)
setne %cl
movl 0x10(%rsp), %edx
xorb $0x1, %dl
orb %cl, %dl
jne 0x188a0
cmpb $0x28, (%rax)
jne 0x188a0
cmpb $0x0, 0x1(%rax)
je 0x18b38
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1e938
cmpl $0x0, (%r14)
jne 0x1863c
movq %rax, 0x18(%rsp)
leaq 0x8(%r13), %r12
movq %r12, %rdi
callq 0x376f1
testb %al, %al
je 0x18a9e
cmpb $0x0, 0x10(%rsp)
je 0x18b5c
movq 0x1c0(%rsp), %rdx
movq (%r13), %rcx
movq %r15, %rdi
movq %r12, %rsi
testb %bpl, %bpl
je 0x18bbe
movq 0x18(%rsp), %r8
jmp 0x18bb1
movl 0x78(%rsp), %eax
cmpl $0x16, %eax
je 0x18a15
cmpl $0x9, %eax
jne 0x18a30
leaq 0x78(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %r8
callq 0x18097
jmp 0x1863c
leaq 0x20(%rsp), %rcx
leaq 0x1c0(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %rbx, %r8
pushq %r14
pushq $0x1
callq 0x19733
addq $0x10, %rsp
leaq 0x1c0(%rsp), %rdi
callq 0x2f56e
jmp 0x1863c
cmpl $0x16, %eax
jne 0x189dc
subq $0x8, %rsp
leaq 0x80(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
pushq %r14
callq 0x29bff
jmp 0x18785
movq 0x60(%r15), %rdi
movq %rbx, %rsi
callq 0x2ebbc
testq %rax, %rax
je 0x184a8
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5abe4(%rip), %rax     # 0x735a4
leaq 0x5b44e(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x52, %esi
movq %rbx, %rdx
pushq $0x259                  # imm = 0x259
jmp 0x1877f
movq 0x60(%r15), %rdi
leaq 0x78(%rsp), %rdx
movq %rbx, %rsi
movq %r14, %rcx
callq 0x2e3cd
movq %rax, 0x20(%rsp)
cmpl $0x0, (%r14)
jne 0x1863c
movq %rax, %r13
movb $0x1, %al
movl %eax, 0x10(%rsp)
movl $0x0, 0x14(%rsp)
jmp 0x1885e
leaq 0x78(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %r8
callq 0x181be
jmp 0x1863c
leaq 0x78(%rsp), %rdi
callq 0x376f1
testb %al, %al
je 0x18a80
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1ec4c
cmpl $0x0, (%r14)
jne 0x1863c
movq %rax, %r12
movq 0x158(%rax), %rdx
movq 0x68(%r15), %rdi
testq %rdx, %rdx
je 0x18b84
movq %r12, %rsi
movq %rbx, %rcx
movq %r14, %r8
callq 0x2e83a
jmp 0x18820
leaq 0x5ab1d(%rip), %rdx     # 0x735a4
movq %r14, %rdi
movl $0xf, %esi
movl $0x274, %ecx            # imm = 0x274
callq 0x145a4
jmp 0x1863c
cmpl $0x9, 0x78(%rsp)
movq 0x18(%rsp), %rsi
jne 0x18ada
cmpq $0x0, 0x160(%rsi)
je 0x18ada
cmpl $0x9, (%rsi)
jne 0x18be9
leaq 0x78(%rsp), %rsi
movq %r15, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rdx
movq %r14, %rcx
callq 0x1d3d0
movq %r12, %rax
jmp 0x18aea
leaq 0x78(%rsp), %rdx
movq %r15, %rdi
movq %r14, %rcx
callq 0x37860
cmpl $0x0, (%r14)
jne 0x1863c
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movl 0x14(%rsp), %ecx
movq %r14, %r8
callq 0x193f9
cmpl $0x0, (%r14)
jne 0x1863c
cmpb $0x1, 0x2a8(%r13)
jne 0x18c2c
movq (%r13), %rsi
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
callq 0x36292
jmp 0x1863c
movq 0x1c0(%rsp), %rcx
movq (%r13), %r8
leaq 0x78(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r9
callq 0x2a40f
jmp 0x1863c
cmpl $0x7, (%r12)
jne 0x18bd0
movq 0x1c0(%rsp), %rsi
movq (%r13), %rdx
movq %r15, %rdi
movq 0x18(%rsp), %rcx
movq %r14, %r8
callq 0x4bec6
jmp 0x1863c
leaq 0x78(%rsp), %rdx
movq %rbx, %rsi
movq %r14, %rcx
callq 0x2e3cd
cmpl $0x0, (%r14)
jne 0x1863c
movq (%rax), %rcx
leaq 0x78(%rsp), %rsi
movl $0x2, %edx
movq %r15, %rdi
movq %r12, %r8
movq %r14, %r9
callq 0x35ebf
jmp 0x1863c
movq 0x18(%rsp), %r8
movq %r14, %r9
callq 0x35ef0
jmp 0x1863c
leaq 0x5a9cd(%rip), %rdx     # 0x735a4
movq %r14, %rdi
movl $0xf, %esi
movl $0x49d, %ecx            # imm = 0x49D
jmp 0x18a94
leaq 0x78(%rsp), %rdi
callq 0x2f5ad
movq %rax, %r12
movq 0x18(%rsp), %rdi
callq 0x2f5ad
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5a992(%rip), %r10     # 0x735a4
movq %r14, %rdi
movl $0x1d, %esi
movq %r12, %rdx
movq %rax, %rcx
pushq $0x4a7                  # imm = 0x4A7
pushq %r10
jmp 0x18780
movq 0x1c0(%rsp), %rsi
movq (%r13), %rdx
movq %r15, %rdi
movq %rax, %rcx
movq %r14, %r8
callq 0x362c6
jmp 0x1863c