// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_rec.c
// Function: prv_rec_init
static void prv_rec_init(subtilis_parser_t *p, subtilis_token_t *t,
			 const subtilis_type_t *type, size_t mem_reg,
			 size_t loc, bool push, subtilis_error_t *err)
{
	const char *tbuf;
	size_t id;
	const subtilis_type_rec_t *rec;
	const subtilis_type_t *field_type;
	uint32_t offset;
	subtilis_exp_t *e;

	tbuf = subtilis_token_get_text(t);
	if (!((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "("))) {
		/*
		 * We're copying one REC into another.  There's no
		 * initialisation list here.
		 */
		e = subtilis_parser_priority7(p, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		e = subtilis_type_if_coerce_type(p, e, type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		subtilis_rec_type_copy(p, type, mem_reg, loc, e->exp.ir_op.reg,
				       true, err);
		subtilis_exp_delete(e);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		if (push && subtilis_type_rec_need_deref(type))
			subtilis_reference_type_push_reference(p, type, mem_reg,
							       loc, err);
		return;
	}

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

	tbuf = subtilis_token_get_text(t);
	if ((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, ")")) {
		subtilis_rec_type_zero(p, type, mem_reg, loc, push, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		subtilis_lexer_get(p->l, t, err);
		return;
	}

	rec = &type->params.rec;

	/*
	 * TODO: All of this will need to be re-written as will the existing
	 * code to initialise arrays.  Basically, we want parse the expressions
	 * build up some sort of tree, and then anaylse the tree to figure out
	 * the most efficient way of initialising things.  This sort of thing
	 * will be easier though when have a two stage parser.  Othwerwise,
	 * we'll end up loading using too many regs.  We could bomb out if
	 * we hit a variable.  Can I do this withouth the re-write?
	 */

	for (id = 0; id < rec->num_fields; id++) {
		field_type = &rec->field_types[id];
		offset = subtilis_type_rec_field_offset_id(rec, id);
		if (subtilis_type_if_is_numeric(field_type) ||
		    field_type->type == SUBTILIS_TYPE_FN) {
			e = subtilis_parser_priority7(p, t, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			e = subtilis_type_if_coerce_type(p, e, field_type, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			subtilis_type_if_assign_to_mem(p, mem_reg, loc + offset,
						       e, err);
		} else if (field_type->type == SUBTILIS_TYPE_STRING) {
			e = subtilis_parser_priority7(p, t, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			subtilis_string_type_new_field_ref(
			    p, field_type, mem_reg, loc + offset, e, err);
		} else if (subtilis_type_if_is_array(field_type) ||
			   subtilis_type_if_is_vector(field_type)) {
			prv_array_field_init(p, t, &rec->fields[id], field_type,
					     mem_reg, loc + offset, err);
		} else if (field_type->type == SUBTILIS_TYPE_REC) {
			prv_rec_init(p, t, field_type, mem_reg, loc + offset,
				     false, err);
		} else {
			subtilis_error_set_assertion_failed(err);
			return;
		}

		if (err->type != SUBTILIS_ERROR_OK)
			return;

		tbuf = subtilis_token_get_text(t);
		if (t->type == SUBTILIS_TOKEN_OPERATOR) {
			if (!strcmp(tbuf, ",")) {
				if (id < rec->num_fields - 1) {
					subtilis_lexer_get(p->l, t, err);
					if (err->type != SUBTILIS_ERROR_OK)
						return;
				}
				continue;
			}
			if (!strcmp(tbuf, ")"))
				break;
		}
		subtilis_error_set_expected(err, ", or )", tbuf,
					    p->l->stream->name, p->l->line);
		return;
	}

	if (strcmp(tbuf, ")")) {
		subtilis_error_set_expected(err, ")", tbuf, p->l->stream->name,
					    p->l->line);
		return;
	}

	for (id = id + 1; id < rec->num_fields; id++) {
		field_type = &rec->field_types[id];
		offset = subtilis_type_rec_field_offset_id(rec, id);
		subtilis_rec_type_init_field(p, field_type, &rec->fields[id],
					     mem_reg, offset + loc, false, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	if (push && subtilis_type_rec_need_deref(type)) {
		subtilis_reference_type_push_reference(p, type, mem_reg, loc,
						       err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	subtilis_lexer_get(p->l, t, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %r9d, %r12d
movq %r8, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movq 0xc0(%rsp), %rbx
movq %rsi, %rdi
callq 0x12ad0
cmpl $0x2, (%r15)
jne 0x2a077
leaq 0x4a1ab(%rip), %rsi     # 0x74212
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
je 0x2a12a
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1e874
cmpl $0x0, (%rbx)
jne 0x2a142
movq %r14, %rdi
movq %rax, %rsi
movq 0x18(%rsp), %rdx
movq %rbx, %rcx
callq 0x379c3
cmpl $0x0, (%rbx)
jne 0x2a142
movq %rax, %r15
movq 0x148(%rax), %r8
subq $0x8, %rsp
movq %r14, %rdi
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
movl $0x1, %r9d
pushq %rbx
callq 0x46056
addq $0x10, %rsp
movq %r15, %rdi
callq 0x2b4c3
cmpl $0x0, (%rbx)
setne %al
xorb $0x1, %r12b
orb %al, %r12b
jne 0x2a142
movq 0x18(%rsp), %rdi
callq 0x3041c
testb %al, %al
je 0x2a142
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq %rbx, %r8
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4d4ea
movq (%r14), %rdi
movq %r15, 0x10(%rsp)
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12eda
cmpl $0x0, (%rbx)
je 0x2a154
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, 0x8(%rsp)
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x12ad0
movq %rax, %rbp
cmpl $0x2, (%r14)
jne 0x2a186
leaq 0x49977(%rip), %rsi     # 0x73aed
movq %rbp, %rdi
callq 0x12160
testl %eax, %eax
je 0x2a579
movq 0x18(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x48(%rsp)
cmpq $0x0, 0x28(%rax)
movq 0x30(%rsp), %r13
je 0x2a52c
movl $0x10, %ecx
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %rcx, 0x38(%rsp)
movq 0x18(%rax), %rbp
addq %r14, %rbp
movq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0x30118
movl %eax, 0x20(%rsp)
movq %rbp, %rdi
callq 0x37676
testb %al, %al
movq %r14, 0x60(%rsp)
jne 0x2a1ee
movl (%rbp), %eax
cmpl $0x7, %eax
je 0x2a247
cmpl $0x9, %eax
jne 0x2a289
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x1e874
cmpl $0x0, (%rbx)
jne 0x2a142
movq %r14, %rdi
movq %rax, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x379c3
cmpl $0x0, (%rbx)
jne 0x2a142
movl 0x20(%rsp), %edx
addq 0x28(%rsp), %rdx
movq %r14, %rdi
movq 0x30(%rsp), %rsi
movq %rax, %rcx
movq %rbx, %r8
callq 0x36416
jmp 0x2a419
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x1e874
cmpl $0x0, (%rbx)
jne 0x2a142
movl 0x20(%rsp), %ecx
addq 0x28(%rsp), %rcx
movq %r14, %rdi
movq %rbp, %rsi
movq 0x30(%rsp), %rdx
movq %rax, %r8
movq %rbx, %r9
callq 0x48f60
jmp 0x2a419
movq %rbp, %rdi
callq 0x377f7
testb %al, %al
jne 0x2a2a1
movq %rbp, %rdi
callq 0x37815
testb %al, %al
je 0x2a31e
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x58(%rsp)
movl 0x20(%rsp), %eax
addq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x12ad0
cmpl $0x2, (%r14)
jne 0x2a2e3
movq %rax, %rdi
leaq 0x49f38(%rip), %rsi     # 0x74212
callq 0x12160
testl %eax, %eax
je 0x2a358
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x1e874
cmpl $0x0, (%rbx)
jne 0x2a419
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq 0x20(%rsp), %rcx
movq %rax, %r8
movq %rbx, %r9
callq 0x43001
jmp 0x2a419
cmpl $0x16, (%rbp)
jne 0x2a703
movl 0x20(%rsp), %r8d
addq 0x28(%rsp), %r8
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
xorl %r9d, %r9d
pushq %rbx
callq 0x2a021
addq $0x10, %rsp
jmp 0x2a419
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x1eb88
cmpl $0x0, (%rbx)
jne 0x2a419
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %r14
movq 0x38(%rsp), %rax
movq -0x10(%r14,%rax), %rax
movq %rax, 0x68(%rsp)
movq %rbp, 0x70(%rsp)
movq %r13, 0x78(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x80(%rsp)
movq %rbp, %rdi
callq 0x377f7
testb %al, %al
je 0x2a3ce
movq 0x68(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq 0x20(%rsp), %r8
movq %rbx, %r9
callq 0x45894
jmp 0x2a3ef
movq 0x38(%rsp), %rax
movl (%r14,%rax), %r8d
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq 0x20(%rsp), %rcx
movq %rbx, %r9
callq 0x45950
cmpl $0x0, (%rbx)
movq 0x50(%rsp), %rcx
jne 0x2a419
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x68(%rsp), %rdx
movq %rbx, %r8
callq 0x16719
cmpl $0x0, (%rbx)
je 0x2a4b0
cmpl $0x0, (%rbx)
jne 0x2a142
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x12ad0
movq %rax, %rbp
cmpl $0x2, (%r14)
jne 0x2a676
movq %rbp, %rdi
leaq 0x49152(%rip), %rsi     # 0x73598
callq 0x12160
testl %eax, %eax
jne 0x2a65f
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
decq %rax
cmpq %rax, %r15
movq 0x8(%rsp), %rax
jae 0x2a482
movq (%rax), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x12eda
cmpl $0x0, (%rbx)
jne 0x2a142
incq %r15
movq 0x38(%rsp), %rcx
addq $0x18, %rcx
movq 0x60(%rsp), %r14
addq $0x148, %r14            # imm = 0x148
movq 0x18(%rsp), %rax
cmpq 0x28(%rax), %r15
movq 0x30(%rsp), %r13
jb 0x2a1af
jmp 0x2a52f
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x12ad0
movq %rax, %rbp
cmpl $0x2, (%r14)
jne 0x2a4d9
movq %rbp, %rdi
leaq 0x4961d(%rip), %rsi     # 0x73aed
callq 0x12160
testl %eax, %eax
je 0x2a512
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
movq %rbx, %rdi
movl $0x1d, %esi
leaq 0x495f5(%rip), %rdx     # 0x73aed
movq %rbp, %rcx
pushq $0x1db                  # imm = 0x1DB
leaq 0x495cb(%rip), %rax     # 0x73ad2
pushq %rax
callq 0x1442a
jmp 0x2a34f
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x12eda
jmp 0x2a419
xorl %r15d, %r15d
leaq 0x495b7(%rip), %rsi     # 0x73aed
movq %rbp, %rdi
callq 0x12160
testl %eax, %eax
je 0x2a5c6
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x49575(%rip), %rax     # 0x73ad2
leaq 0x49589(%rip), %rdx     # 0x73aed
movq %rbx, %rdi
movl $0x1d, %esi
movq %rbp, %rcx
pushq $0x287                  # imm = 0x287
jmp 0x2a6a4
movzbl %r12b, %r8d
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq %rbx, %r9
callq 0x45cd5
cmpl $0x0, (%rbx)
jne 0x2a142
movq (%r14), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12eda
leaq 0x1(%r15), %rbp
leaq (%r15,%r15,2), %rax
leaq 0x18(,%rax,8), %r13
imulq $0x148, %r15, %r14      # imm = 0x148
addq $0x148, %r14            # imm = 0x148
movl %r12d, 0x44(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x28(%rax), %rbp
jae 0x2a6b3
movq 0x18(%rax), %r15
addq %r14, %r15
movq 0x48(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %r12
movq %rax, %rbx
callq 0x30118
movq 0x20(%rbx), %rdx
movq %r12, %rbx
movl 0x44(%rsp), %r12d
addq %r13, %rdx
movl %eax, %r8d
addq 0x28(%rsp), %r8
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq 0x38(%rsp), %rcx
xorl %r9d, %r9d
pushq %rbx
callq 0x459be
addq $0x10, %rsp
incq %rbp
addq $0x18, %r13
addq $0x148, %r14            # imm = 0x148
cmpl $0x0, (%rbx)
je 0x2a5e9
jmp 0x2a142
leaq 0x49487(%rip), %rsi     # 0x73aed
movq %rbp, %rdi
callq 0x12160
testl %eax, %eax
je 0x2a52f
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x4945b(%rip), %rdx     # 0x73ae8
movq %rbx, %rdi
movl $0x1d, %esi
movq %rbp, %rcx
pushq $0x281                  # imm = 0x281
leaq 0x4942e(%rip), %rax     # 0x73ad2
pushq %rax
callq 0x1442a
addq $0x10, %rsp
jmp 0x2a142
testb %r12b, %r12b
movq 0x8(%rsp), %r14
je 0x2a6ee
movq 0x18(%rsp), %rdi
callq 0x3041c
testb %al, %al
je 0x2a6ee
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq %rbx, %r8
callq 0x4d4ea
cmpl $0x0, (%rbx)
jne 0x2a142
movq (%r14), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x12eda
jmp 0x2a142
leaq 0x493c8(%rip), %rdx     # 0x73ad2
movq %rbx, %rdi
movl $0xf, %esi
movl $0x26c, %ecx            # imm = 0x26C
callq 0x145f4
jmp 0x2a142