// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/parser_rec.c
// Function: subtilis_parser_rec_field_lvalue
size_t subtilis_parser_rec_field_lvalue(subtilis_parser_t *p,
					subtilis_token_t *t,
					const subtilis_type_t *type,
					size_t mem_reg, size_t loc,
					subtilis_type_t *dst_type,
					subtilis_error_t *err)
{
	size_t id;
	const subtilis_type_t *field_type;
	const subtilis_type_rec_t *rec;
	const char *tbuf;
	const char *obkt = NULL;
	const char *cbkt = NULL;

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

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

		rec = &type->params.rec;
		id = subtilis_type_rec_find_field(rec, tbuf);
		if (id == SIZE_MAX) {
			subtilis_error_set_unknown_field(
			    err, tbuf, p->l->stream->name, p->l->line);
			return SIZE_MAX;
		}

		loc += (size_t)subtilis_type_rec_field_offset_id(rec, id);
		field_type = &rec->field_types[id];
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;
		tbuf = subtilis_token_get_text(t);
		if (field_type->type != SUBTILIS_TYPE_REC)
			break;
		type = field_type;
	} while ((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "."));

	if (subtilis_type_if_is_array(field_type)) {
		obkt = "(";
		cbkt = ")";
	} else if (subtilis_type_if_is_vector(field_type)) {
		obkt = "{";
		cbkt = "}";
	}

	if (obkt) {
		tbuf = subtilis_token_get_text(t);
		if ((t->type != SUBTILIS_TOKEN_OPERATOR) ||
		    strcmp(tbuf, obkt)) {
			subtilis_error_set_exp_expected(
			    err, obkt, p->l->stream->name, p->l->line);
			return SIZE_MAX;
		}
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;
		tbuf = subtilis_token_get_text(t);
		if ((t->type != SUBTILIS_TOKEN_OPERATOR) ||
		    strcmp(tbuf, cbkt)) {
			subtilis_error_set_exp_expected(
			    err, cbkt, p->l->stream->name, p->l->line);
			return SIZE_MAX;
		}
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;
	}

	subtilis_type_copy(dst_type, field_type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	return subtilis_reference_get_pointer(p, mem_reg, loc, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x20(%rsp)
movq %r8, %r14
movq %rcx, 0x18(%rsp)
movq %rdx, %r15
movq %rsi, %rbp
movq %rdi, 0x8(%rsp)
movq 0x60(%rsp), %r12
movq %r12, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x12e0e
cmpl $0x0, (%r12)
jne 0x28508
movq %rbp, %rdi
callq 0x12a25
movq %rax, %rdx
cmpl $0x6, (%rbp)
jne 0x284a7
movq %r15, %r12
addq $0x8, %r15
movq %r15, %rdi
movq %rdx, %r13
movq %rdx, %rsi
callq 0x2e2d7
cmpq $-0x1, %rax
je 0x284d2
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x2e515
movl %eax, %r15d
imulq $0x148, %rbx, %rbx      # imm = 0x148
addq 0x18(%r12), %rbx
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %r12
movq %r12, %rdx
callq 0x12e0e
cmpl $0x0, (%r12)
jne 0x28508
movl %r15d, %eax
addq %rax, %r14
movq %rbp, %rdi
callq 0x12a25
cmpl $0x16, (%rbx)
jne 0x2841e
cmpl $0x2, (%rbp)
jne 0x2841e
cmpb $0x2e, (%rax)
jne 0x2841e
cmpb $0x0, 0x1(%rax)
movq %rbx, %r15
je 0x28361
movq %rbx, %rdi
callq 0x357cc
testb %al, %al
je 0x2843a
leaq 0x4568c(%rip), %r15     # 0x6dabd
leaq 0x45daa(%rip), %r13     # 0x6e1e2
jmp 0x28458
movq %rbx, %rdi
callq 0x357ea
testb %al, %al
je 0x2859d
leaq 0x45206(%rip), %r15     # 0x6d657
leaq 0x481a9(%rip), %r13     # 0x70601
movq %rbp, %rdi
callq 0x12a25
cmpl $0x2, (%rbp)
jne 0x28479
movq %rax, %rdi
movq %r13, %rsi
callq 0x12160
testl %eax, %eax
je 0x2851a
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x45612(%rip), %rax     # 0x6daa2
leaq 0x4592e(%rip), %rcx     # 0x6ddc5
pushq $0x15
popq %rsi
movq %r12, %rdi
movq %r13, %rdx
pushq $0x144                  # imm = 0x144
jmp 0x28500
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x455e4(%rip), %rax     # 0x6daa2
leaq 0x45900(%rip), %rcx     # 0x6ddc5
pushq $0x12
popq %rsi
movq %r12, %rdi
pushq $0x120                  # imm = 0x120
jmp 0x28500
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x455b9(%rip), %rax     # 0x6daa2
leaq 0x458d5(%rip), %rcx     # 0x6ddc5
pushq $0x69
popq %rsi
movq 0x10(%rsp), %rdi
movq %r13, %rdx
pushq $0x128                  # imm = 0x128
pushq %rax
callq 0x140cd
popq %rax
popq %rcx
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x12e0e
cmpl $0x0, (%r12)
jne 0x28508
movq %rbp, %rdi
callq 0x12a25
cmpl $0x2, (%rbp)
jne 0x28551
movq %rax, %rdi
movq %r15, %rsi
callq 0x12160
testl %eax, %eax
je 0x2857f
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x4553a(%rip), %rax     # 0x6daa2
leaq 0x45856(%rip), %rcx     # 0x6ddc5
pushq $0x15
popq %rsi
movq %r12, %rdi
movq %r15, %rdx
pushq $0x14e                  # imm = 0x14E
jmp 0x28500
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x12e0e
cmpl $0x0, (%r12)
jne 0x28508
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2de8a
cmpl $0x0, (%r12)
jne 0x28508
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
movq %r12, %rcx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4ab28