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

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

	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 NULL;
	}

	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 NULL;
	}

	loc += (size_t)subtilis_type_rec_field_offset_id(rec, id);
	field_type = &rec->field_types[id];

	if ((subtilis_type_if_is_numeric(field_type) ||
	     field_type->type == SUBTILIS_TYPE_FN)) {
		e = subtilis_type_if_load_from_mem(p, field_type, mem_reg, loc,
						   err);
		if (err->type != SUBTILIS_ERROR_OK)
			return NULL;
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	} else if ((field_type->type == SUBTILIS_TYPE_STRING) ||
		   (field_type->type == SUBTILIS_TYPE_REC)) {
		reg = subtilis_reference_get_pointer(p, mem_reg, loc, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return NULL;
		e = subtilis_exp_new_var(field_type, reg, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return NULL;
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	} else if (subtilis_type_if_is_array(field_type)) {
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return NULL;
		if ((t->type != SUBTILIS_TOKEN_OPERATOR) || strcmp(tbuf, "(")) {
			subtilis_error_set_exp_expected(
			    err, "(", p->l->stream->name, p->l->line);
			return NULL;
		}
		e = subtils_parser_read_array_with_type(
		    p, t, field_type, mem_reg, loc, rec->fields[id].name, err);
	} else if (subtilis_type_if_is_vector(field_type)) {
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return NULL;
		if ((t->type != SUBTILIS_TOKEN_OPERATOR) || strcmp(tbuf, "{")) {
			subtilis_error_set_exp_expected(
			    err, "{", p->l->stream->name, p->l->line);
			return NULL;
		}
		e = subtils_parser_read_vector_with_type(
		    p, t, field_type, mem_reg, loc, rec->fields[id].name, err);
	} else {
		subtilis_error_set_assertion_failed(err);
	}

	return e;

cleanup:

	subtilis_exp_delete(e);
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbx
movq %r8, %rbp
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rdi
movq %r9, %rdx
callq 0x12e0e
cmpl $0x0, (%rbx)
jne 0x2871a
movq %r14, %rdi
callq 0x12a25
movq %rax, %rdx
cmpl $0x6, (%r14)
jne 0x286c3
movq %r12, 0x20(%rsp)
leaq 0x8(%r13), %r12
movq %r12, %rdi
movq %rdx, %rsi
movq %rdx, 0x8(%rsp)
callq 0x2e2d7
cmpq $-0x1, %rax
je 0x286e9
movq %r12, %rdi
movq %rax, %rsi
movq %rax, %r12
callq 0x2e515
movl %eax, %eax
addq %rbp, %rax
movq %rax, %rbp
movq %r12, 0x10(%rsp)
imulq $0x148, %r12, %rax      # imm = 0x148
movq %r13, 0x18(%rsp)
addq 0x18(%r13), %rax
movq %rax, %r13
movq %rax, %rdi
callq 0x35655
testb %al, %al
movq 0x20(%rsp), %r12
je 0x2872f
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x343a4
cmpl $0x0, (%rbx)
jne 0x2871a
movq %rax, %r12
movq (%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12e0e
cmpl $0x0, (%rbx)
je 0x2871d
movq %r12, %rdi
callq 0x29d88
jmp 0x2871a
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x453cd(%rip), %rax     # 0x6daa2
leaq 0x456e9(%rip), %rcx     # 0x6ddc5
pushq $0x12
popq %rsi
movq %rbx, %rdi
pushq $0x171                  # imm = 0x171
jmp 0x28712
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x453a7(%rip), %rax     # 0x6daa2
leaq 0x456c3(%rip), %rcx     # 0x6ddc5
pushq $0x69
popq %rsi
movq %rbx, %rdi
movq 0x8(%rsp), %rdx
pushq $0x179                  # imm = 0x179
pushq %rax
callq 0x140cd
popq %rax
popq %rcx
xorl %r12d, %r12d
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r13), %eax
cmpl $0x7, %eax
je 0x287bd
cmpl $0x16, %eax
je 0x287bd
cmpl $0x9, %eax
je 0x2868a
movq %r13, %rdi
callq 0x357cc
testb %al, %al
je 0x287e9
movq (%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12e0e
cmpl $0x0, (%rbx)
jne 0x2871a
movq %r13, %rdx
cmpl $0x2, (%r14)
movq 0x8(%rsp), %r13
jne 0x2878d
cmpb $0x28, (%r13)
jne 0x2878d
cmpb $0x0, 0x1(%r13)
je 0x28874
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x45303(%rip), %rax     # 0x6daa2
leaq 0x45a3c(%rip), %rdx     # 0x6e1e2
leaq 0x45618(%rip), %rcx     # 0x6ddc5
pushq $0x15
popq %rsi
movq %rbx, %rdi
pushq $0x19a                  # imm = 0x19A
jmp 0x28712
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x4ab28
cmpl $0x0, (%rbx)
jne 0x2871a
movq %r13, %rdi
movl %eax, %esi
movq %rbx, %rdx
callq 0x2a226
jmp 0x2869e
movq %r13, %rdi
callq 0x357ea
testb %al, %al
je 0x28858
movq (%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12e0e
cmpl $0x0, (%rbx)
jne 0x2871a
movq %r13, %rdx
cmpl $0x2, (%r14)
movq 0x8(%rsp), %r13
jne 0x28828
cmpb $0x7b, (%r13)
jne 0x28828
cmpb $0x0, 0x1(%r13)
je 0x2889f
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x45268(%rip), %rax     # 0x6daa2
leaq 0x47dc0(%rip), %rdx     # 0x70601
leaq 0x4557d(%rip), %rcx     # 0x6ddc5
pushq $0x15
popq %rsi
movq %rbx, %rdi
pushq $0x1a5                  # imm = 0x1A5
jmp 0x28712
leaq 0x45243(%rip), %rdx     # 0x6daa2
pushq $0xf
popq %rsi
movq %rbx, %rdi
movl $0x1ab, %ecx            # imm = 0x1AB
callq 0x1429e
jmp 0x2871a
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
imulq $0x18, 0x10(%rsp), %rcx
movq (%rax,%rcx), %r9
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rcx
movq %rbp, %r8
pushq %rbx
callq 0x156ac
jmp 0x288c8
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
imulq $0x18, 0x10(%rsp), %rcx
movq (%rax,%rcx), %r9
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rcx
movq %rbp, %r8
pushq %rbx
callq 0x15c22
addq $0x38, %rsp
jmp 0x28724