// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/parser_cond.c
// Function: subtilis_parser_if
void subtilis_parser_if(subtilis_parser_t *p, subtilis_token_t *t,
			subtilis_error_t *err)
{
	subtilis_exp_t *e;
	const char *tbuf;
	subtilis_ir_operand_t cond;
	subtilis_ir_operand_t true_label;
	subtilis_ir_operand_t false_label;
	subtilis_ir_operand_t end_label;
	int key_type;

	e = subtilis_parser_conditional_exp(p, t, &cond, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if ((t->type != SUBTILIS_TOKEN_KEYWORD) ||
	    (t->tok.keyword.type != SUBTILIS_KEYWORD_THEN)) {
		tbuf = subtilis_token_get_text(t);
		subtilis_error_set_expected(err, "THEN", tbuf,
					    p->l->stream->name, p->l->line);
		goto cleanup;
	}

	true_label.reg = subtilis_ir_section_new_label(p->current);
	false_label.reg = subtilis_ir_section_new_label(p->current);

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  cond, true_label, false_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	subtilis_ir_section_add_label(p->current, true_label.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	key_type = subtilis_parser_if_compound(p, t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (key_type == SUBTILIS_KEYWORD_ELSE) {
		end_label.reg = subtilis_ir_section_new_label(p->current);
		subtilis_ir_section_add_instr_no_reg(
		    p->current, SUBTILIS_OP_INSTR_JMP, end_label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		subtilis_ir_section_add_label(p->current, false_label.reg, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
		subtilis_parser_compound(p, t, SUBTILIS_KEYWORD_ENDIF, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		subtilis_ir_section_add_label(p->current, end_label.reg, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	} else {
		subtilis_ir_section_add_label(p->current, false_label.reg, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

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

cleanup:
	subtilis_exp_delete(e);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movq %rsp, %rdx
movq %r14, %rcx
callq 0x1d794
cmpl $0x0, (%r14)
je 0x1d864
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
cmpl $0x1, (%r12)
jne 0x1d96b
cmpl $0x82, 0x8(%r12)
jne 0x1d96b
movq 0x48(%r15), %rdi
callq 0x2b774
movq %rax, %rbp
movq 0x48(%r15), %rdi
callq 0x2b774
movq %rax, %r13
movq 0x48(%r15), %rdi
movq (%rsp), %rdx
pushq $0x43
popq %rsi
movq %rbp, %rcx
movq %rax, %r8
movq %r14, %r9
callq 0x2a8c1
cmpl $0x0, (%r14)
jne 0x1d9a0
movq 0x48(%r15), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x2b781
cmpl $0x0, (%r14)
jne 0x1d9a0
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x14e36
cmpl $0x0, (%r14)
jne 0x1d9a0
movq 0x48(%r15), %rdi
cmpl $0x23, %eax
jne 0x1d9b6
callq 0x2b774
movq %rax, %rbp
movq 0x48(%r15), %rdi
pushq $0x45
popq %rsi
movq %rax, %rdx
movq %r14, %rcx
callq 0x2a997
cmpl $0x0, (%r14)
jne 0x1d9a0
movq 0x48(%r15), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2b781
cmpl $0x0, (%r14)
jne 0x1d9a0
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x1d855
pushq $0x27
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x1d789
cmpl $0x0, (%r14)
jne 0x1d9a0
movq 0x48(%r15), %rdi
movq %rbp, %rsi
jmp 0x1d9b9
movq %r12, %rdi
callq 0x12a25
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x4fcd4(%rip), %r10     # 0x6d659
leaq 0x4f809(%rip), %rdx     # 0x6d195
pushq $0x1d
popq %rsi
movq %r14, %rdi
movq %rax, %rcx
pushq $0x52
pushq %r10
callq 0x140cd
popq %rax
popq %rcx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x29d88
movq %r13, %rsi
movq %r14, %rdx
callq 0x2b781
cmpl $0x0, (%r14)
jne 0x1d9a0
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
jmp 0x1d9a0
nop