// File: /workspace/github_c_makefile_star2_O3/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 0x12edc
cmpl $0x0, (%rbx)
jne 0x29a3c
movq %r14, %rdi
callq 0x12ad0
movq %rax, %rdx
cmpl $0x6, (%r14)
jne 0x299df
movq %r12, 0x20(%rsp)
leaq 0x8(%r13), %r12
movq %r12, %rdi
movq %rdx, %rsi
movq %rdx, 0x8(%rsp)
callq 0x2fc17
cmpq $-0x1, %rax
je 0x29a07
movq %r12, %rdi
movq %rax, %rsi
movq %rax, %r12
callq 0x2fe6a
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 0x37534
testb %al, %al
movq 0x20(%rsp), %r12
je 0x29a51
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x36372
cmpl $0x0, (%rbx)
jne 0x29a3c
movq %rax, %r12
movq (%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12edc
cmpl $0x0, (%rbx)
je 0x29a3f
movq %r12, %rdi
callq 0x2b166
jmp 0x29a3c
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x4a0f9(%rip), %rax     # 0x73aea
leaq 0x4a41d(%rip), %rcx     # 0x73e15
movq %rbx, %rdi
movl $0x12, %esi
pushq $0x171                  # imm = 0x171
jmp 0x29a32
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x4a0d1(%rip), %rax     # 0x73aea
leaq 0x4a3f5(%rip), %rcx     # 0x73e15
movq %rbx, %rdi
movl $0x69, %esi
movq 0x8(%rsp), %rdx
pushq $0x179                  # imm = 0x179
pushq %rax
callq 0x143da
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 (%r13), %eax
cmpl $0x7, %eax
je 0x29ae1
cmpl $0x16, %eax
je 0x29ae1
cmpl $0x9, %eax
je 0x299a6
movq %r13, %rdi
callq 0x376b5
testb %al, %al
je 0x29b0d
movq (%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12edc
cmpl $0x0, (%rbx)
jne 0x29a3c
movq %r13, %rdx
cmpl $0x2, (%r14)
movq 0x8(%rsp), %r13
jne 0x29aaf
cmpb $0x28, (%r13)
jne 0x29aaf
cmpb $0x0, 0x1(%r13)
je 0x29b9c
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x4a029(%rip), %rax     # 0x73aea
leaq 0x4a76a(%rip), %rdx     # 0x74232
leaq 0x4a346(%rip), %rcx     # 0x73e15
movq %rbx, %rdi
movl $0x15, %esi
pushq $0x19a                  # imm = 0x19A
jmp 0x29a32
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x4d71f
cmpl $0x0, (%rbx)
jne 0x29a3c
movq %r13, %rdi
movl %eax, %esi
movq %rbx, %rdx
callq 0x2b5fb
jmp 0x299ba
movq %r13, %rdi
callq 0x376d3
testb %al, %al
je 0x29b7e
movq (%r15), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12edc
cmpl $0x0, (%rbx)
jne 0x29a3c
movq %r13, %rdx
cmpl $0x2, (%r14)
movq 0x8(%rsp), %r13
jne 0x29b4c
cmpb $0x7b, (%r13)
jne 0x29b4c
cmpb $0x0, 0x1(%r13)
je 0x29bca
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x49f8c(%rip), %rax     # 0x73aea
leaq 0x4cb2c(%rip), %rdx     # 0x76691
leaq 0x4a2a9(%rip), %rcx     # 0x73e15
movq %rbx, %rdi
movl $0x15, %esi
pushq $0x1a5                  # imm = 0x1A5
jmp 0x29a32
leaq 0x49f65(%rip), %rdx     # 0x73aea
movq %rbx, %rdi
movl $0xf, %esi
movl $0x1ab, %ecx            # imm = 0x1AB
callq 0x145a4
jmp 0x29a3c
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %r9
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rcx
movq %rbp, %r8
pushq %rbx
callq 0x15a8e
jmp 0x29bf6
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %r9
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rcx
movq %rbp, %r8
pushq %rbx
callq 0x16094
addq $0x38, %rsp
jmp 0x29a46