// File: /workspace/github_c_makefile_star2_O3/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)
movq $0x0, 0x10(%rsp)
movq (%rdi), %rdi
callq 0x12edc
cmpl $0x0, (%r14)
jne 0x25cc5
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1ec82
cmpl $0x0, (%r14)
jne 0x25cc5
movq %rax, %rbx
movq %r12, %rdi
callq 0x12ad0
movl (%r12), %ecx
cmpl $0x1, %ecx
je 0x25c09
cmpl $0x2, %ecx
jne 0x25c54
cmpb $0x2c, (%rax)
jne 0x25c54
cmpb $0x0, 0x1(%rax)
jne 0x25c54
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12edc
cmpl $0x0, (%r14)
jne 0x25c9d
movq %rsp, %rdx
movl $0x3, %ecx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1ecce
cmpl $0x0, (%r14)
jne 0x25c9d
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 0x2bea4
addq $0x10, %rsp
jmp 0x25c6c
cmpl $0x85, 0x8(%r12)
jne 0x25c54
testb $0x40, 0x8(%r15)
movq (%r15), %rdi
jne 0x25c8c
movq 0x30(%rdi), %r8
movl 0x38(%rdi), %r9d
leaq 0x4ddbf(%rip), %rax     # 0x739ec
leaq 0x4dda4(%rip), %rdx     # 0x739d8
leaq 0x4e1da(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x13, %esi
pushq $0x279                  # imm = 0x279
pushq %rax
callq 0x143da
addq $0x10, %rsp
jmp 0x25c9d
movq 0x48(%r15), %rdi
movq 0x148(%rbx), %rdx
movl $0x81, %esi
movq %r14, %rcx
callq 0x2be1f
xorl %r12d, %r12d
cmpl $0x0, (%r14)
jne 0x25ca0
cmpb $0x0, 0xb9(%r15)
jne 0x25ca0
movq %r15, %rdi
movq %r14, %rsi
callq 0x2b01f
jmp 0x25ca0
movq %r12, %rsi
movq %r14, %rdx
callq 0x12edc
cmpl $0x0, (%r14)
je 0x25cd1
xorl %r12d, %r12d
xorl %r14d, %r14d
movq (%rsp,%r14,8), %rdi
callq 0x2b166
incq %r14
cmpq $0x3, %r14
jne 0x25ca3
movq %r12, %rdi
callq 0x2b166
movq %rbx, %rdi
callq 0x2b166
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1ec82
movq %rax, %r12
cmpl $0x0, (%r14)
jne 0x25ca0
movq 0x48(%r15), %rdi
movq 0x148(%rbx), %rdx
movq 0x148(%r12), %rcx
movl $0x82, %esi
movq %r14, %r8
callq 0x2be2c
jmp 0x25c6f
nopl (%rax)