// File: /workspace/github_c_makefile_star2_O1/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 0x12eda
cmpl $0x0, (%rbx)
jne 0x29cc5
movq %r14, %rdi
callq 0x12ad0
movq %rax, %rdx
cmpl $0x6, (%r14)
jne 0x29c6a
movq %r12, 0x20(%rsp)
leaq 0x8(%r13), %r12
movq %r12, %rdi
movq %rdx, %rsi
movq %r13, 0x18(%rsp)
movq %rdx, %r13
callq 0x2feeb
cmpq $-0x1, %rax
je 0x29c92
movq %r13, 0x10(%rsp)
movq %r12, %rdi
movq %rax, %rsi
movq %rax, %r12
callq 0x30118
movl %eax, %eax
addq %rbp, %rax
movq %rax, (%rsp)
movq %r12, 0x8(%rsp)
imulq $0x148, %r12, %rbp      # imm = 0x148
movq 0x18(%rsp), %r13
addq 0x18(%r13), %rbp
movq %rbp, %rdi
callq 0x37676
testb %al, %al
movq 0x20(%rsp), %r12
je 0x29cda
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq (%rsp), %rcx
movq %rbx, %r8
callq 0x364c2
cmpl $0x0, (%rbx)
jne 0x29cc5
movq %rax, %r12
movq (%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12eda
cmpl $0x0, (%rbx)
je 0x29cc8
movq %r12, %rdi
callq 0x2b4c3
jmp 0x29cc5
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x49e56(%rip), %rax     # 0x73ad2
leaq 0x4a172(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0x12, %esi
pushq $0x171                  # imm = 0x171
jmp 0x29cbb
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x49e2e(%rip), %rax     # 0x73ad2
leaq 0x4a14a(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0x69, %esi
movq %r13, %rdx
pushq $0x179                  # imm = 0x179
pushq %rax
callq 0x1442a
addq $0x10, %rsp
xorl %r12d, %r12d
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%rbp), %eax
cmpl $0x7, %eax
je 0x29d68
cmpl $0x16, %eax
je 0x29d68
cmpl $0x9, %eax
je 0x29c30
movq %rbp, %rdi
callq 0x377f7
testb %al, %al
je 0x29d95
movq (%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12eda
cmpl $0x0, (%rbx)
jne 0x29cc5
cmpl $0x2, (%r14)
jne 0x29d36
leaq 0x4a4ee(%rip), %rsi     # 0x74212
movq 0x10(%rsp), %rdi
callq 0x12160
testl %eax, %eax
je 0x29e23
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x49d8a(%rip), %rax     # 0x73ad2
leaq 0x4a4c3(%rip), %rdx     # 0x74212
leaq 0x4a09f(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0x15, %esi
pushq $0x19a                  # imm = 0x19A
jmp 0x29cbb
movq %r15, %rdi
movq %r12, %rsi
movq (%rsp), %rdx
movq %rbx, %rcx
callq 0x4d763
cmpl $0x0, (%rbx)
jne 0x29cc5
movq %rbp, %rdi
movl %eax, %esi
movq %rbx, %rdx
callq 0x2b971
jmp 0x29c45
movq %rbp, %rdi
callq 0x37815
testb %al, %al
je 0x29e05
movq (%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12eda
cmpl $0x0, (%rbx)
jne 0x29cc5
cmpl $0x2, (%r14)
jne 0x29dd3
leaq 0x4c88c(%rip), %rsi     # 0x76651
movq 0x10(%rsp), %rdi
callq 0x12160
testl %eax, %eax
je 0x29e51
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x49ced(%rip), %rax     # 0x73ad2
leaq 0x4c865(%rip), %rdx     # 0x76651
leaq 0x4a002(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0x15, %esi
pushq $0x1a5                  # imm = 0x1A5
jmp 0x29cbb
leaq 0x49cc6(%rip), %rdx     # 0x73ad2
movq %rbx, %rdi
movl $0xf, %esi
movl $0x1ab, %ecx            # imm = 0x1AB
callq 0x145f4
jmp 0x29cc5
movq 0x20(%r13), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %r9
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r12, %rcx
movq 0x8(%rsp), %r8
pushq %rbx
callq 0x15b16
jmp 0x29e7d
movq 0x20(%r13), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %r9
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r12, %rcx
movq 0x8(%rsp), %r8
pushq %rbx
callq 0x160f5
addq $0x38, %rsp
jmp 0x29ccf