// File: /workspace/github_cpp_makefile_star2_O3/aempirei[P]Chat-Art/palette.cc
// Function: main
int main(int argc, char **argv) {

	char line[128];
	int line_num = 0;

	std::list<geometry> geometry_mode[4];

	std::list<geometry>& bgcolor = geometry_mode[geometry::BGCOLOR];
	std::list<geometry>& fgcolor = geometry_mode[geometry::FGCOLOR];
	std::list<geometry>& symbol = geometry_mode[geometry::SYMBOL];

	if(argc == 2 && strcmp(argv[1], "-h") == 0) {
		help(*argv);
		return -1;
	}

	while(fgets(line, sizeof(line) - 1, stdin) != NULL) {

		geometry g;

		line_num++;

		if(geometry_from_string(g, line)) {

			// good line

			if(g.mode >= geometry::MODE_MIN && g.mode <= geometry::MODE_MAX)
				geometry_mode[g.mode].push_back(g);

		} else if(g.mode == -1) {

			// bad line

			std::cerr << ansi::bold << "invalid calibration data on input line ";
			std::cerr << line_num << ansi::clear << std::endl;
			std::cerr << line;
			return -1;
		}
	}

	std::cout << "background colors: " << bgcolor.size() << std::endl;
	std::cout << "foreground colors: " << fgcolor.size() << std::endl;
	std::cout << "character symbols: " << symbol.size() << std::endl;
	std::cout << "max. palette size: " << (bgcolor.size() * fgcolor.size() * symbol.size()) << std::endl;

	for(int r = 0; r < 256; r += 14) {
		for(int g = 0; g < 256; g += 64) {
			for(int b = 0; b < 256; b += 8) {

				std::string s( ansi_match( r,g,b, bgcolor,fgcolor,symbol ));

				fputs(s.c_str(), stdout);
			}
			fputs(ansi::clear.c_str(), stdout);
			putchar(' ');
		}
		putchar('\n');
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
xorl %eax, %eax
leaq (%rsp,%rax), %rcx
addq $0x50, %rcx
movq %rcx, 0x8(%rcx)
movq %rcx, (%rcx)
movq $0x0, 0x10(%rcx)
addq $0x18, %rax
cmpq $0x60, %rax
jne 0x2c38
leaq 0xb0(%rsp), %r14
cmpl $0x2, %edi
jne 0x2c7f
movq 0x8(%rsi), %rax
cmpb $0x2d, (%rax)
jne 0x2c7f
cmpb $0x68, 0x1(%rax)
jne 0x2c7f
cmpb $0x0, 0x2(%rax)
je 0x3096
movq 0x3342(%rip), %rax      # 0x5fc8
movq (%rax), %rdx
leaq 0xb0(%rsp), %rdi
movl $0x7f, %esi
callq 0x2190
testq %rax, %rax
je 0x2d89
movl $0x1, %ebx
leaq 0xb0(%rsp), %r12
leaq 0x8(%rsp), %r15
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r12, %rdi
callq 0x2080
leaq (%rsp,%rax), %rdx
addq $0xb0, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x31a2
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x26b9
movl %eax, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2d09
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2130
movl 0x40(%rsp), %r13d
testb %bpl, %bpl
je 0x2d5d
cmpl $0x3, %r13d
ja 0x2d67
movl $0x38, %edi
callq 0x2120
leaq (,%r13,2), %rcx
addq %r13, %rcx
leaq 0x50(%rsp,%rcx,8), %r13
movl 0x48(%rsp), %ecx
movl %ecx, 0x30(%rax)
movups 0x28(%rsp), %xmm0
movups 0x38(%rsp), %xmm1
movups %xmm1, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movq %rax, %rdi
movq %r13, %rsi
callq 0x2040
incq 0x10(%r13)
jmp 0x2d67
cmpl $-0x1, %r13d
je 0x2fb3
movq 0x325a(%rip), %rax      # 0x5fc8
movq (%rax), %rdx
movq %r12, %rdi
movl $0x7f, %esi
callq 0x2190
incl %ebx
testq %rax, %rax
jne 0x2cb6
movq 0x3240(%rip), %rdi      # 0x5fd0
leaq 0x13ae(%rip), %rsi      # 0x4145
movl $0x13, %edx
callq 0x2150
movq 0x78(%rsp), %rsi
movq 0x3223(%rip), %rdi      # 0x5fd0
callq 0x2090
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq 0x31ed(%rip), %rdi      # 0x5fd0
leaq 0x136f(%rip), %rsi      # 0x4159
movl $0x13, %edx
callq 0x2150
movq 0x90(%rsp), %rsi
movq 0x31cd(%rip), %rdi      # 0x5fd0
callq 0x2090
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq 0x3197(%rip), %rdi      # 0x5fd0
leaq 0x132d(%rip), %rsi      # 0x416d
movl $0x13, %edx
callq 0x2150
movq 0xa8(%rsp), %rsi
movq 0x3177(%rip), %rdi      # 0x5fd0
callq 0x2090
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq 0x3141(%rip), %rdi      # 0x5fd0
leaq 0x12eb(%rip), %rsi      # 0x4181
movl $0x13, %edx
callq 0x2150
movq 0x90(%rsp), %rsi
imulq 0x78(%rsp), %rsi
imulq 0xa8(%rsp), %rsi
movq 0x3112(%rip), %rdi      # 0x5fd0
callq 0x2090
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
xorl %r15d, %r15d
leaq 0x28(%rsp), %r12
movq 0x30a4(%rip), %rbx      # 0x5fa0
xorl %r13d, %r13d
movl $0xfffffff8, %ebp       # imm = 0xFFFFFFF8
addl $0x8, %ebp
leaq 0x98(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movl %r15d, %esi
movl %r13d, %edx
movl %ebp, %ecx
leaq 0x68(%rsp), %r8
leaq 0x80(%rsp), %r9
callq 0x2812
movq 0x28(%rsp), %rdi
movq (%rbx), %rsi
callq 0x2140
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x2f59
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2130
cmpl $0xf8, %ebp
jb 0x2f04
movq 0x3240(%rip), %rdi      # 0x61a8
movq (%rbx), %rsi
callq 0x2140
movl $0x20, %edi
callq 0x2160
leal 0x40(%r13), %eax
cmpl $0xc0, %r13d
movl %eax, %r13d
jb 0x2eff
movl $0xa, %edi
callq 0x2160
leal 0xe(%r15), %eax
cmpl $0xf2, %r15d
movl %eax, %r15d
jb 0x2efc
xorl %ebx, %ebx
jmp 0x3056
movq 0x31ce(%rip), %rsi      # 0x6188
movq 0x31cf(%rip), %rdx      # 0x6190
movq 0x3028(%rip), %rdi      # 0x5ff0
callq 0x2150
leaq 0x1149(%rip), %rsi      # 0x411d
movl $0x27, %edx
movq %rax, %rdi
callq 0x2150
movq 0x3008(%rip), %rdi      # 0x5ff0
movl %ebx, %esi
callq 0x21d0
movq 0x31b2(%rip), %rsi      # 0x61a8
movq 0x31b3(%rip), %rdx      # 0x61b0
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0x2080
movq 0x2faa(%rip), %rdi      # 0x5ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2150
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x50(%rsp), %r15
movq -0x18(%r14), %rdi
addq $-0x18, %r14
cmpq %r14, %rdi
je 0x307d
movq (%rdi), %r12
movl $0x38, %esi
callq 0x2130
movq %r12, %rdi
cmpq %r14, %r12
jne 0x3068
cmpq %r15, %r14
jne 0x305b
movl %ebx, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsi), %rdi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x2b94
jmp 0x3056
jmp 0x30ce
jmp 0x30ce
jmp 0x30ce
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x30d1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2130
jmp 0x30d1
jmp 0x30ce
movq %rax, %rbx
leaq 0x50(%rsp), %r15
movq -0x18(%r14), %rdi
addq $-0x18, %r14
cmpq %r14, %rdi
je 0x30f8
movq (%rdi), %r12
movl $0x38, %esi
callq 0x2130
movq %r12, %rdi
cmpq %r14, %r12
jne 0x30e3
cmpq %r15, %r14
jne 0x30d6
movq %rbx, %rdi
callq 0x21e0
nop