// File: /workspace/github_cpp_makefile_star2_O2/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 $0x148, %rsp            # imm = 0x148
xorl %eax, %eax
leaq (%rsp,%rax), %rcx
addq $0x40, %rcx
movq %rcx, 0x8(%rcx)
movq %rcx, (%rcx)
andq $0x0, 0x10(%rcx)
addq $0x18, %rax
cmpq $0x60, %rax
jne 0x2a62
cmpl $0x2, %edi
jne 0x2a9e
movq 0x8(%rsi), %rax
cmpb $0x2d, (%rax)
jne 0x2a9e
cmpb $0x68, 0x1(%rax)
jne 0x2a9e
cmpb $0x0, 0x2(%rax)
je 0x2d11
leaq 0x70(%rsp), %r14
pushq $0x1
popq %rbp
movq 0x351b(%rip), %rbx      # 0x5fc8
leaq 0xc0(%rsp), %r15
leaq 0xa0(%rsp), %r13
movq (%rbx), %rdx
movq %r15, %rdi
pushq $0x7f
popq %rsi
callq 0x21a0
testq %rax, %rax
je 0x2b2b
movq %r13, %rdi
movq %r15, %rsi
leaq 0x17(%rsp), %rdx
callq 0x2d5c
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x260d
movl %eax, %r12d
movq %r13, %rdi
callq 0x2208
movl 0x30(%rsp), %eax
testb %r12b, %r12b
je 0x2b1e
cmpl $0x3, %eax
ja 0x2b27
imulq $0x18, %rax, %rax
leaq (%rsp,%rax), %rdi
addq $0x40, %rdi
leaq 0x18(%rsp), %rsi
callq 0x2e08
jmp 0x2b27
cmpl $-0x1, %eax
je 0x2c85
incl %ebp
jmp 0x2abd
movq 0x349e(%rip), %rdi      # 0x5fd0
leaq 0x160f(%rip), %rsi      # 0x4148
callq 0x2120
movq 0x68(%rsp), %rsi
movq %rax, %rdi
callq 0x2090
movq %rax, %rdi
callq 0x2070
movq 0x3476(%rip), %rdi      # 0x5fd0
leaq 0x15fb(%rip), %rsi      # 0x415c
callq 0x2120
movq 0x80(%rsp), %rsi
movq %rax, %rdi
callq 0x2090
movq %rax, %rdi
callq 0x2070
movq 0x344b(%rip), %rdi      # 0x5fd0
leaq 0x15e4(%rip), %rsi      # 0x4170
callq 0x2120
movq 0x98(%rsp), %rsi
movq %rax, %rdi
callq 0x2090
movq %rax, %rdi
callq 0x2070
movq 0x3420(%rip), %rdi      # 0x5fd0
leaq 0x15cd(%rip), %rsi      # 0x4184
callq 0x2120
movq 0x80(%rsp), %rsi
imulq 0x68(%rsp), %rsi
imulq 0x98(%rsp), %rsi
movq %rax, %rdi
callq 0x2090
movq %rax, %rdi
callq 0x2070
leaq 0x18(%rsp), %r15
movq 0x33b9(%rip), %rbx      # 0x5fa8
xorl %ebp, %ebp
cmpl $0xff, %ebp
ja 0x2c81
xorl %r13d, %r13d
cmpl $0xff, %r13d
ja 0x2c71
xorl %r12d, %r12d
cmpl $0x100, %r12d           # imm = 0x100
jae 0x2c54
leaq 0x88(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %edx
movl %r12d, %ecx
leaq 0x58(%rsp), %r8
movq %r14, %r9
callq 0x2753
movq 0x18(%rsp), %rdi
movq (%rbx), %rsi
callq 0x2150
movq %r15, %rdi
callq 0x2208
addl $0x8, %r12d
jmp 0x2c0c
movq 0x354d(%rip), %rdi      # 0x61a8
movq (%rbx), %rsi
callq 0x2150
pushq $0x20
popq %rdi
callq 0x2180
addl $0x40, %r13d
jmp 0x2c00
pushq $0xa
popq %rdi
callq 0x2180
addl $0xe, %ebp
jmp 0x2bf1
xorl %ebp, %ebp
jmp 0x2ce3
movq 0x3364(%rip), %rdi      # 0x5ff0
leaq 0x34f5(%rip), %rsi      # 0x6188
callq 0x2100
leaq 0x1481(%rip), %rsi      # 0x4120
movq %rax, %rdi
callq 0x2120
movq 0x3342(%rip), %rdi      # 0x5ff0
movl %ebp, %esi
callq 0x21d0
leaq 0x34ec(%rip), %rsi      # 0x61a8
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2070
movq 0x331d(%rip), %rdi      # 0x5ff0
leaq 0xc0(%rsp), %rsi
callq 0x2120
pushq $-0x1
popq %rbp
pushq $0x48
popq %rbx
leaq (%rsp,%rbx), %rdi
addq $0x40, %rdi
callq 0x2e68
addq $-0x18, %rbx
cmpq $-0x18, %rbx
jne 0x2ce6
movl %ebp, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsi), %rdi
callq 0x2a02
jmp 0x2ce0
jmp 0x2d35
jmp 0x2d35
jmp 0x2d35
jmp 0x2d35
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x2208
jmp 0x2d38
movq %rax, %rbx
pushq $0x48
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x40, %rdi
callq 0x2e68
addq $-0x18, %r14
cmpq $-0x18, %r14
jne 0x2d3c
movq %rbx, %rdi
callq 0x21e0
nop