// File: /workspace/github_cpp_makefile_star2_O1/aempirei[P]Chat-Art/palette.cc
// Function: ansi_match(int, int, int, std::__cxx11::list<geometry, std::allocator<geometry>> const&, std::__cxx11::list<geometry, std::allocator<geometry>> const&, std::__cxx11::list<geometry, std::allocator<geometry>> const&)
std::string ansi_match(int R, int G, int B, const geometry_list& bg, const geometry_list& fg, const geometry_list& sym) {
	char best[128];
	int min = INT_MAX;
	for(auto b : bg) {
		for(auto f : fg) {
			for(auto s : sym) {

				rgb_sum_t y;

				for(int i = 0; i < 3; i++) { 
					y[i] = b.color[i] * (s.n() - s.ratio) + f.color[i] * s.ratio;
					y[i] *= 255;
					y[i] /= 64 * s.n();
				}

				int dr = labs(R - y[0]);
				int dg = labs(G - y[1]);
				int db = labs(B - y[2]);

				long test = ms({dr,dg,db});


				if(test < min) {
					min = test;
					snprintf(best, sizeof(best),
							"%s%c",
							ansi::esc({f.base, f.code + 30, b.code + 40}, 'm').c_str(),
							s.base + s.code);
				}
			}
		}
	}
	return std::string(best);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %r9, 0x30(%rsp)
movl %ecx, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movl %esi, 0x14(%rsp)
movq %rdi, 0x48(%rsp)
movq (%r8), %rcx
movq %r8, 0x50(%rsp)
cmpq %r8, %rcx
je 0x2afd
movl $0x7fffffff, 0x4(%rsp)  # imm = 0x7FFFFFFF
leaq 0x80(%rsp), %r12
leaq 0x68(%rsp), %r14
movl 0x30(%rcx), %eax
movl %eax, 0xf0(%rsp)
movups 0x10(%rcx), %xmm0
movq %rcx, 0x58(%rsp)
movups 0x20(%rcx), %xmm1
movaps %xmm1, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movq 0x30(%rsp), %rax
movq (%rax), %rcx
cmpq %rax, %rcx
je 0x2aea
movl 0xec(%rsp), %eax
addl $0x28, %eax
movl %eax, 0x8(%rsp)
movl 0x30(%rcx), %eax
movl %eax, 0xc0(%rsp)
movups 0x10(%rcx), %xmm0
movq %rcx, 0x60(%rsp)
movups 0x20(%rcx), %xmm1
movaps %xmm1, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movq 0x1c0(%rsp), %rax
movq (%rax), %rbp
cmpq %rax, %rbp
je 0x2ad7
movl 0xbc(%rsp), %eax
movl 0xc0(%rsp), %ecx
movl %ecx, 0xc(%rsp)
addl $0x1e, %eax
movl %eax, 0x10(%rsp)
movl 0x14(%rbp), %ecx
movl 0x24(%rbp), %eax
movl 0x2c(%rbp), %edx
movl %edx, 0x20(%rsp)
movl 0x30(%rbp), %r15d
imull 0x10(%rbp), %ecx
movl %ecx, %edx
subl %eax, %edx
movl %edx, %esi
shll $0x8, %esi
subl %edx, %esi
movl %eax, %edi
shll $0x8, %edi
subl %eax, %edi
shll $0x6, %ecx
movl $0x2, %r8d
movl 0xd0(%rsp,%r8,4), %edx
imull %esi, %edx
movl 0xa0(%rsp,%r8,4), %eax
imull %edi, %eax
addl %edx, %eax
cltd
idivl %ecx
movl %eax, 0x34(%rsp,%r8,4)
incq %r8
cmpq $0x5, %r8
jne 0x2939
movl 0x14(%rsp), %eax
subl 0x3c(%rsp), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl 0x18(%rsp), %eax
subl 0x40(%rsp), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
movl 0x1c(%rsp), %eax
subl 0x44(%rsp), %eax
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
movslq %ecx, %rax
movq %rax, 0x68(%rsp)
movslq %edx, %rax
movq %rax, 0x70(%rsp)
movslq %esi, %rax
movq %rax, 0x78(%rsp)
movl $0x3, %edx
movq %r12, %rdi
movq %r14, %rsi
leaq 0x24(%rsp), %rcx
callq 0x30de
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0x29e7
movq %rdi, %rax
xorl %r13d, %r13d
movq 0x10(%rax), %rcx
movq (%rax), %rdx
imulq %rcx, %rcx
addq %rcx, %r13
movq %rdx, %rax
cmpq %r12, %rdx
jne 0x29cf
jmp 0x29ea
xorl %r13d, %r13d
cmpq %r12, %rdi
je 0x2a04
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2130
movq %rbx, %rdi
cmpq %r12, %rbx
jne 0x29ef
movslq 0x4(%rsp), %rax
cmpq %rax, %r13
jge 0x2ac5
movl 0xc(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl $0x3, %edx
movq %r14, %rdi
leaq 0x24(%rsp), %rsi
leaq 0x3(%rsp), %rcx
callq 0x312c
movq %r12, %rdi
movq %r14, %rsi
movl $0x6d, %edx
callq 0x2484
movq 0x80(%rsp), %rcx
addl 0x20(%rsp), %r15d
movl $0x80, %esi
leaq 0x100(%rsp), %rdi
leaq 0x1667(%rip), %rdx      # 0x40d9
movl %r15d, %r8d
xorl %eax, %eax
callq 0x21c0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x2aa1
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2130
movq 0x68(%rsp), %rdi
cmpq %r14, %rdi
je 0x2ac0
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x2130
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x2aab
movl %r13d, 0x4(%rsp)
movq (%rbp), %rbp
cmpq 0x1c0(%rsp), %rbp
jne 0x2909
movq 0x60(%rsp), %rcx
movq (%rcx), %rcx
cmpq 0x30(%rsp), %rcx
jne 0x28b5
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
cmpq 0x50(%rsp), %rcx
jne 0x286f
movq 0x48(%rsp), %r14
leaq 0x10(%r14), %rax
movq %rax, (%r14)
leaq 0x100(%rsp), %rbx
movq %rbx, %rdi
callq 0x2080
leaq (%rsp,%rax), %rdx
addq $0x100, %rdx            # imm = 0x100
movq %r14, %rdi
movq %rbx, %rsi
callq 0x317a
movq %r14, %rax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r14, %rdi
je 0x2b66
movq (%rdi), %r15
movl $0x18, %esi
callq 0x2130
movq %r15, %rdi
cmpq %r14, %r15
jne 0x2b51
movq %rbx, %rdi
callq 0x21f0