// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movb %r9b, %al
movq 0x10(%rbp), %r9
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x10(%rbp), %rdi
callq 0x12d70
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x35137
movq -0x38(%rbp), %rdi
leaq 0x76173(%rip), %rsi     # 0xab29c
callq 0x12140
cmpl $0x0, %eax
je 0x351f9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x24550
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x3515a
jmp 0x35688
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x4a2e0
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x35181
jmp 0x35688
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %rax
movq 0x148(%rax), %r8
movq 0x10(%rbp), %rax
movl $0x1, %r9d
movq %rax, (%rsp)
callq 0x62680
movq -0x60(%rbp), %rdi
callq 0x36ee0
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x351c6
jmp 0x35688
testb $0x1, -0x29(%rbp)
je 0x351f4
movq -0x18(%rbp), %rdi
callq 0x3f560
testb $0x1, %al
jne 0x351db
jmp 0x351f4
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq 0x10(%rbp), %r8
callq 0x6d540
jmp 0x35688
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x133f0
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x3521b
jmp 0x35688
movq -0x10(%rbp), %rdi
callq 0x12d70
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x3528f
movq -0x38(%rbp), %rdi
leaq 0x75915(%rip), %rsi     # 0xaab51
callq 0x12140
cmpl $0x0, %eax
jne 0x3528f
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movb -0x29(%rbp), %al
movq 0x10(%rbp), %r9
andb $0x1, %al
movzbl %al, %r8d
callq 0x62290
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x35276
jmp 0x35688
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x133f0
jmp 0x35688
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x35548
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x148, -0x40(%rbp), %rcx # imm = 0x148
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3efb0
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rdi
callq 0x49d10
testb $0x1, %al
jne 0x352f2
movq -0x50(%rbp), %rax
cmpl $0x9, (%rax)
jne 0x35360
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x24550
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x35315
jmp 0x35688
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x4a2e0
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x3533c
jmp 0x35688
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0x54(%rbp), %eax
addq %rax, %rdx
movq -0x60(%rbp), %rcx
movq 0x10(%rbp), %r8
callq 0x47f20
jmp 0x35463
movq -0x50(%rbp), %rax
cmpl $0x7, (%rax)
jne 0x353b4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x24550
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x3538c
jmp 0x35688
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x54(%rbp), %eax
addq %rax, %rcx
movq -0x60(%rbp), %r8
movq 0x10(%rbp), %r9
callq 0x67070
jmp 0x35461
movq -0x50(%rbp), %rdi
callq 0x49ff0
testb $0x1, %al
jne 0x353d0
movq -0x50(%rbp), %rdi
callq 0x4a040
testb $0x1, %al
jne 0x353d0
jmp 0x35409
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdx
imulq $0x18, -0x40(%rbp), %rax
addq %rax, %rdx
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movl -0x54(%rbp), %eax
addq %rax, %r9
movq 0x10(%rbp), %rax
movq %rax, (%rsp)
callq 0x36160
jmp 0x3545f
movq -0x50(%rbp), %rax
cmpl $0x16, (%rax)
jne 0x3543e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movl -0x54(%rbp), %eax
addq %rax, %r8
movq 0x10(%rbp), %rax
xorl %r9d, %r9d
movq %rax, (%rsp)
callq 0x350e0
jmp 0x3545d
movq 0x10(%rbp), %rdi
movl $0xf, %esi
leaq 0x756e8(%rip), %rdx     # 0xaab36
movl $0x26c, %ecx            # imm = 0x26C
callq 0x158e0
jmp 0x35688
jmp 0x3545f
jmp 0x35461
jmp 0x35463
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x35471
jmp 0x35688
movq -0x10(%rbp), %rdi
callq 0x12d70
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x354f0
movq -0x38(%rbp), %rdi
leaq 0x75117(%rip), %rsi     # 0xaa5a9
callq 0x12140
cmpl $0x0, %eax
jne 0x354d7
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
movq 0x20(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x354d5
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x133f0
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x354d3
jmp 0x35688
jmp 0x354d5
jmp 0x35537
movq -0x38(%rbp), %rdi
leaq 0x7566f(%rip), %rsi     # 0xaab51
callq 0x12140
cmpl $0x0, %eax
jne 0x354ee
jmp 0x35548
jmp 0x354f0
movq 0x10(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x1d, %esi
leaq 0x75632(%rip), %rdx     # 0xaab4c
leaq 0x75615(%rip), %rax     # 0xaab36
movq %rax, (%rsp)
movl $0x281, 0x8(%rsp)       # imm = 0x281
callq 0x156d0
jmp 0x35688
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x352a3
movq -0x38(%rbp), %rdi
leaq 0x755fe(%rip), %rsi     # 0xaab51
callq 0x12140
cmpl $0x0, %eax
je 0x355a4
movq 0x10(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x1d, %esi
leaq 0x755ca(%rip), %rdx     # 0xaab51
leaq 0x755a8(%rip), %rax     # 0xaab36
movq %rax, (%rsp)
movl $0x287, 0x8(%rsp)       # imm = 0x287
callq 0x156d0
jmp 0x35688
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x35639
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x148, -0x40(%rbp), %rcx # imm = 0x148
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3efb0
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdx
imulq $0x18, -0x40(%rbp), %rax
addq %rax, %rdx
movq -0x20(%rbp), %rcx
movl -0x54(%rbp), %eax
movl %eax, %r8d
addq -0x28(%rbp), %r8
movq 0x10(%rbp), %rax
xorl %r9d, %r9d
movq %rax, (%rsp)
callq 0x61fd0
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x35626
jmp 0x35688
jmp 0x35628
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x355b0
testb $0x1, -0x29(%rbp)
je 0x35674
movq -0x18(%rbp), %rdi
callq 0x3f560
testb $0x1, %al
jne 0x3564e
jmp 0x35674
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq 0x10(%rbp), %r8
callq 0x6d540
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x35672
jmp 0x35688
jmp 0x35674
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x133f0
addq $0x70, %rsp
popq %rbp
retq
nop