// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_graphics.c
// Function: subtilis_parser_colour
void subtilis_parser_colour(subtilis_parser_t *p, subtilis_token_t *t,
			    subtilis_error_t *err)
{
	size_t i;
	subtilis_exp_t *e;
	const char *tbuf;
	subtilis_exp_t *rgb[3];
	subtilis_exp_t *tint = NULL;

	memset(rgb, 0, sizeof(rgb));

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

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

	tbuf = subtilis_token_get_text(t);
	if ((t->type != SUBTILIS_TOKEN_OPERATOR) || strcmp(tbuf, ",")) {
		if ((t->type == SUBTILIS_TOKEN_KEYWORD) &&
		    (t->tok.keyword.type == SUBTILIS_KEYWORD_TINT)) {
			if (!(p->backend.caps & SUBTILIS_BACKEND_HAVE_TINT)) {
				subtilis_error_set_not_supported(
				    err, "TINT on this target",
				    p->l->stream->name, p->l->line);
				goto cleanup;
			}
			subtilis_lexer_get(p->l, t, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;

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

			subtilis_ir_section_add_instr_no_reg2(
			    p->current, SUBTILIS_OP_INSTR_TCOL_TINT,
			    e->exp.ir_op, tint->exp.ir_op, err);
		} else {
			subtilis_ir_section_add_instr_no_reg(
			    p->current, SUBTILIS_OP_INSTR_TCOL, e->exp.ir_op,
			    err);
		}
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	} else {
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		subtilis_parser_statement_int_args(p, t, rgb, 3, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		subtilis_ir_section_add_instr4(
		    p->current, SUBTILIS_OP_INSTR_PALETTE, e->exp.ir_op,
		    rgb[0]->exp.ir_op, rgb[1]->exp.ir_op, rgb[2]->exp.ir_op,
		    err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	if (!p->settings.ignore_graphics_errors)
		subtilis_exp_handle_errors(p, err);

cleanup:

	for (i = 0; i < 3; i++)
		subtilis_exp_delete(rgb[i]);

	subtilis_exp_delete(tint);
	subtilis_exp_delete(e);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq (%rdi), %rdi
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x25df8
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1ebbe
cmpl $0x0, (%r14)
jne 0x25df8
movq %rax, %rbx
movq %r12, %rdi
callq 0x12ad0
movl (%r12), %ebp
cmpl $0x1, %ebp
je 0x25cb3
cmpl $0x2, %ebp
jne 0x25d05
leaq 0x4d8fa(%rip), %rsi     # 0x73598
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
je 0x25d48
cmpl $0x1, %ebp
jne 0x25d05
cmpl $0x85, 0x8(%r12)
jne 0x25d05
testb $0x40, 0x8(%r15)
movq (%r15), %rdi
jne 0x25dbf
movq 0x30(%rdi), %r8
movl 0x38(%rdi), %r9d
leaq 0x4dcf1(%rip), %rax     # 0x739cc
leaq 0x4dcd6(%rip), %rdx     # 0x739b8
leaq 0x4e10c(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x13, %esi
pushq $0x279                  # imm = 0x279
pushq %rax
callq 0x1442a
addq $0x10, %rsp
jmp 0x25dd0
movq 0x48(%r15), %rdi
movq 0x148(%rbx), %rdx
movl $0x81, %esi
movq %r14, %rcx
callq 0x2c19f
xorl %r12d, %r12d
cmpl $0x0, (%r14)
jne 0x25dd3
cmpb $0x0, 0xb9(%r15)
jne 0x25dd3
movq %r15, %rdi
movq %r14, %rsi
callq 0x2b37c
jmp 0x25dd3
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x25dd0
movq %rsp, %rdx
movl $0x3, %ecx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1ec0a
cmpl $0x0, (%r14)
jne 0x25dd0
movq 0x48(%r15), %rdi
movq (%rsp), %rax
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r9
movq 0x148(%rbx), %rdx
movq 0x148(%rax), %rcx
movq 0x148(%rsi), %r8
movq 0x148(%r9), %r9
subq $0x8, %rsp
movl $0x83, %esi
pushq %r14
callq 0x2c224
addq $0x10, %rsp
jmp 0x25d1d
movq %r12, %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
je 0x25e05
xorl %r12d, %r12d
xorl %r14d, %r14d
movq (%rsp,%r14,8), %rdi
callq 0x2b4c3
incq %r14
cmpq $0x3, %r14
jne 0x25dd6
movq %r12, %rdi
callq 0x2b4c3
movq %rbx, %rdi
callq 0x2b4c3
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1ebbe
movq %rax, %r12
cmpl $0x0, (%r14)
jne 0x25dd3
movq 0x48(%r15), %rdi
movq 0x148(%rbx), %rdx
movq 0x148(%r12), %rcx
movl $0x82, %esi
movq %r14, %r8
callq 0x2c1ac
jmp 0x25d20
nopl (%rax)