// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
movq (%rdi), %rdi
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x24bf2
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1e00b
cmpl $0x0, (%r14)
jne 0x24bf2
movq %rax, %rbx
movq %r12, %rdi
callq 0x12a25
movl (%r12), %ecx
cmpl $0x1, %ecx
je 0x24b38
cmpl $0x2, %ecx
jne 0x24b7f
cmpb $0x2c, (%rax)
jne 0x24b7f
cmpb $0x0, 0x1(%rax)
jne 0x24b7f
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x24bc8
movq %rsp, %rdx
pushq $0x3
popq %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1e057
cmpl $0x0, (%r14)
jne 0x24bc8
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 0x2aa15
popq %rax
popq %rcx
jmp 0x24b97
cmpl $0x85, 0x8(%r12)
jne 0x24b7f
testb $0x40, 0x8(%r15)
movq (%r15), %rdi
jne 0x24bb7
movq 0x30(%rdi), %r8
movl 0x38(%rdi), %r9d
leaq 0x48e48(%rip), %rax     # 0x6d9a4
leaq 0x48e2d(%rip), %rdx     # 0x6d990
leaq 0x4925b(%rip), %rcx     # 0x6ddc5
pushq $0x13
popq %rsi
movq %r14, %rdi
pushq $0x279                  # imm = 0x279
pushq %rax
callq 0x140cd
popq %rax
popq %rcx
jmp 0x24bc8
movq 0x48(%r15), %rdi
movq 0x148(%rbx), %rdx
movl $0x81, %esi
movq %r14, %rcx
callq 0x2a997
xorl %r12d, %r12d
cmpl $0x0, (%r14)
jne 0x24bcb
cmpb $0x0, 0xb9(%r15)
jne 0x24bcb
movq %r15, %rdi
movq %r14, %rsi
callq 0x29c49
jmp 0x24bcb
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
je 0x24bfe
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpq $0x3, %r14
je 0x24be2
movq (%rsp,%r14,8), %rdi
callq 0x29d88
incq %r14
jmp 0x24bce
movq %r12, %rdi
callq 0x29d88
movq %rbx, %rdi
callq 0x29d88
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1e00b
movq %rax, %r12
cmpl $0x0, (%r14)
jne 0x24bcb
movq 0x48(%r15), %rdi
movq 0x148(%rbx), %rdx
movq 0x148(%r12), %rcx
movl $0x82, %esi
movq %r14, %r8
callq 0x2a9a4
jmp 0x24b9a
nop