// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, %r14
xorl %eax, %eax
leaq (%rsp,%rax), %rcx
addq $0x60, %rcx
movq %rcx, 0x8(%rcx)
movq %rcx, (%rcx)
movq $0x0, 0x10(%rcx)
addq $0x18, %rax
cmpq $0x60, %rax
jne 0x2c15
leaq 0xc0(%rsp), %rbx
cmpl $0x2, %edi
jne 0x2c5b
movq 0x8(%r14), %rdi
leaq 0x14cf(%rip), %rsi      # 0x411d
callq 0x2170
testl %eax, %eax
je 0x3032
movl $0x0, 0x14(%rsp)
movl $0x1, %r15d
leaq 0x50(%rsp), %r13
leaq 0xc0(%rsp), %r12
leaq 0x40(%rsp), %r14
movq 0x3346(%rip), %rax      # 0x5fc8
movq (%rax), %rdx
movq %r12, %rdi
movl $0x7f, %esi
callq 0x21a0
testq %rax, %rax
je 0x2e07
movq %r13, 0x40(%rsp)
movq %r12, %rdi
callq 0x2080
leaq (%rsp,%rax), %rdx
addq $0xc0, %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x317a
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x26c9
movl %eax, %ebp
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0x2ce4
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2130
testb %bpl, %bpl
je 0x2d41
movl 0x30(%rsp), %ebp
movb $0x1, %r14b
cmpq $0x3, %rbp
ja 0x2df1
movl $0x38, %edi
callq 0x2120
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
leaq 0x60(%rsp,%rcx,8), %rbp
movl 0x38(%rsp), %ecx
movl %ecx, 0x30(%rax)
movups 0x18(%rsp), %xmm0
movups 0x28(%rsp), %xmm1
movups %xmm1, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2040
incq 0x10(%rbp)
jmp 0x2df1
movb $0x1, %r14b
cmpl $-0x1, 0x30(%rsp)
jne 0x2df1
movq 0x3442(%rip), %rsi      # 0x6198
movq 0x3443(%rip), %rdx      # 0x61a0
movq 0x328c(%rip), %rdi      # 0x5ff0
callq 0x2150
movl $0x27, %edx
movq %rax, %rdi
leaq 0x13a8(%rip), %rsi      # 0x4120
callq 0x2150
movq 0x326c(%rip), %rdi      # 0x5ff0
movl %r15d, %esi
callq 0x21e0
movq 0x3425(%rip), %rsi      # 0x61b8
movq 0x3426(%rip), %rdx      # 0x61c0
movq %rax, %rdi
callq 0x2150
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x2080
movq 0x3215(%rip), %rdi      # 0x5ff0
movq %r12, %rsi
movq %rax, %rdx
callq 0x2150
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
xorl %r14d, %r14d
incl %r15d
testb %r14b, %r14b
leaq 0x40(%rsp), %r14
jne 0x2c7b
jmp 0x3042
movq 0x31c2(%rip), %rdi      # 0x5fd0
leaq 0x1333(%rip), %rsi      # 0x4148
movl $0x13, %edx
callq 0x2150
movq 0x88(%rsp), %rsi
movq 0x31a2(%rip), %rdi      # 0x5fd0
callq 0x2090
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq 0x316c(%rip), %rdi      # 0x5fd0
leaq 0x12f1(%rip), %rsi      # 0x415c
movl $0x13, %edx
callq 0x2150
movq 0xa0(%rsp), %rsi
movq 0x314c(%rip), %rdi      # 0x5fd0
callq 0x2090
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq 0x3116(%rip), %rdi      # 0x5fd0
leaq 0x12af(%rip), %rsi      # 0x4170
movl $0x13, %edx
callq 0x2150
movq 0xb8(%rsp), %rsi
movq 0x30f6(%rip), %rdi      # 0x5fd0
callq 0x2090
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq 0x30c0(%rip), %rdi      # 0x5fd0
leaq 0x126d(%rip), %rsi      # 0x4184
movl $0x13, %edx
callq 0x2150
movq 0xa0(%rsp), %rsi
imulq 0x88(%rsp), %rsi
imulq 0xb8(%rsp), %rsi
movq 0x308e(%rip), %rdi      # 0x5fd0
callq 0x2090
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
xorl %r15d, %r15d
leaq 0x18(%rsp), %r12
movq 0x3020(%rip), %r14      # 0x5fa0
xorl %r13d, %r13d
movl $0xfffffff8, %ebp       # imm = 0xFFFFFFF8
addl $0x8, %ebp
leaq 0xa8(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movl %r15d, %esi
movl %r13d, %edx
movl %ebp, %ecx
leaq 0x78(%rsp), %r8
leaq 0x90(%rsp), %r9
callq 0x2822
movq 0x18(%rsp), %rdi
movq (%r14), %rsi
callq 0x2140
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2fdd
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2130
cmpl $0xf8, %ebp
jb 0x2f88
movq 0x31cc(%rip), %rdi      # 0x61b8
movq (%r14), %rsi
callq 0x2140
movl $0x20, %edi
callq 0x2160
leal 0x40(%r13), %eax
cmpl $0xc0, %r13d
movl %eax, %r13d
jb 0x2f83
movl $0xa, %edi
callq 0x2160
leal 0xe(%r15), %eax
cmpl $0xf2, %r15d
movl %eax, %r15d
jb 0x2f80
jmp 0x3042
movq (%r14), %rdi
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
callq 0x2b6e
leaq 0x60(%rsp), %r14
movq -0x18(%rbx), %rdi
addq $-0x18, %rbx
cmpq %rbx, %rdi
je 0x3069
movq (%rdi), %r15
movl $0x38, %esi
callq 0x2130
movq %r15, %rdi
cmpq %rbx, %r15
jne 0x3054
cmpq %r14, %rbx
jne 0x3047
movl 0x14(%rsp), %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x30a6
jmp 0x30a6
movq %rax, %r14
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0x30a9
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2130
jmp 0x30a9
jmp 0x30a6
movq %rax, %r14
leaq 0x60(%rsp), %r15
movq -0x18(%rbx), %rdi
addq $-0x18, %rbx
cmpq %rbx, %rdi
je 0x30d0
movq (%rdi), %r12
movl $0x38, %esi
callq 0x2130
movq %r12, %rdi
cmpq %rbx, %r12
jne 0x30bb
cmpq %r15, %rbx
jne 0x30ae
movq %r14, %rdi
callq 0x21f0
nop