// File: 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
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x94(%rbp)
leaq -0x100(%rbp), %rax
movq %rax, %rcx
addq $0x60, %rcx
movq %rcx, -0x1b0(%rbp)
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x3ec0
movq -0x1b8(%rbp), %rax
movq -0x1b0(%rbp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x1a8(%rbp)
jne 0x32cf
leaq -0x100(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x110(%rbp)
leaq -0x100(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x118(%rbp)
cmpl $0x2, -0x8(%rbp)
jne 0x3390
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2dd5(%rip), %rsi      # 0x6120
callq 0x2260
cmpl $0x0, %eax
jne 0x3390
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3230
jmp 0x3363
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x128(%rbp)
jmp 0x3866
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
jmp 0x38bc
jmp 0x3392
movq 0x6c2f(%rip), %rax      # 0x9fc8
movq (%rax), %rdx
leaq -0x90(%rbp), %rdi
movl $0x7f, %esi
callq 0x2290
movq %rax, -0x1c0(%rbp)
jmp 0x33b6
movq -0x1c0(%rbp), %rax
cmpq $0x0, %rax
je 0x357c
movl -0x94(%rbp), %eax
incl %eax
movl %eax, -0x94(%rbp)
leaq -0x171(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x22e0
movq -0x1c8(%rbp), %rdx
leaq -0x170(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3920
jmp 0x3404
leaq -0x14c(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x2a30
movb %al, -0x1c9(%rbp)
jmp 0x341f
leaq -0x170(%rbp), %rdi
callq 0x2328
leaq -0x171(%rbp), %rdi
callq 0x21e0
movb -0x1c9(%rbp), %al
testb $0x1, %al
jne 0x3443
jmp 0x34c0
cmpl $0x0, -0x134(%rbp)
jl 0x34bb
cmpl $0x3, -0x134(%rbp)
jg 0x34bb
movslq -0x134(%rbp), %rax
leaq (%rax,%rax,2), %rax
leaq -0x100(%rbp,%rax,8), %rdi
leaq -0x14c(%rbp), %rsi
callq 0x3ee0
jmp 0x3476
jmp 0x34bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
jmp 0x34aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x2328
leaq -0x171(%rbp), %rdi
callq 0x21e0
jmp 0x38bc
jmp 0x3577
cmpl $-0x1, -0x134(%rbp)
jne 0x3575
movq 0x6b1c(%rip), %rdi      # 0x9ff0
leaq 0x6d3d(%rip), %rsi      # 0xa218
callq 0x2160
movq %rax, -0x1d8(%rbp)
jmp 0x34e9
movq -0x1d8(%rbp), %rdi
leaq 0x2c2c(%rip), %rsi      # 0x6123
callq 0x2190
jmp 0x34fe
movl -0x94(%rbp), %esi
movq 0x6ae5(%rip), %rdi      # 0x9ff0
callq 0x22c0
movq %rax, -0x1e0(%rbp)
jmp 0x3519
movq -0x1e0(%rbp), %rdi
leaq 0x6d11(%rip), %rsi      # 0xa238
callq 0x2160
movq %rax, -0x1e8(%rbp)
jmp 0x3535
movq -0x1e8(%rbp), %rdi
movq 0x6a6d(%rip), %rsi      # 0x9fb0
callq 0x21c0
jmp 0x354a
movq 0x6a9f(%rip), %rdi      # 0x9ff0
leaq -0x90(%rbp), %rsi
callq 0x2190
jmp 0x355f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x128(%rbp)
jmp 0x3866
jmp 0x3577
jmp 0x3392
movq 0x6a4d(%rip), %rdi      # 0x9fd0
leaq 0x2bc1(%rip), %rsi      # 0x614b
callq 0x2190
movq %rax, -0x1f0(%rbp)
jmp 0x3598
movq -0x108(%rbp), %rdi
callq 0x3f20
movq -0x1f0(%rbp), %rdi
movq %rax, %rsi
callq 0x2050
movq %rax, -0x1f8(%rbp)
jmp 0x35bc
movq -0x1f8(%rbp), %rdi
movq 0x69e6(%rip), %rsi      # 0x9fb0
callq 0x21c0
jmp 0x35d1
movq 0x69f8(%rip), %rdi      # 0x9fd0
leaq 0x2b80(%rip), %rsi      # 0x615f
callq 0x2190
movq %rax, -0x200(%rbp)
jmp 0x35ed
movq -0x110(%rbp), %rdi
callq 0x3f20
movq -0x200(%rbp), %rdi
movq %rax, %rsi
callq 0x2050
movq %rax, -0x208(%rbp)
jmp 0x3611
movq -0x208(%rbp), %rdi
movq 0x6991(%rip), %rsi      # 0x9fb0
callq 0x21c0
jmp 0x3626
movq 0x69a3(%rip), %rdi      # 0x9fd0
leaq 0x2b3f(%rip), %rsi      # 0x6173
callq 0x2190
movq %rax, -0x210(%rbp)
jmp 0x3642
movq -0x118(%rbp), %rdi
callq 0x3f20
movq -0x210(%rbp), %rdi
movq %rax, %rsi
callq 0x2050
movq %rax, -0x218(%rbp)
jmp 0x3666
movq -0x218(%rbp), %rdi
movq 0x693c(%rip), %rsi      # 0x9fb0
callq 0x21c0
jmp 0x367b
movq 0x694e(%rip), %rdi      # 0x9fd0
leaq 0x2afe(%rip), %rsi      # 0x6187
callq 0x2190
movq %rax, -0x220(%rbp)
jmp 0x3697
movq -0x108(%rbp), %rdi
callq 0x3f20
movq %rax, -0x238(%rbp)
movq -0x110(%rbp), %rdi
callq 0x3f20
movq %rax, %rcx
movq -0x238(%rbp), %rax
imulq %rcx, %rax
movq %rax, -0x230(%rbp)
movq -0x118(%rbp), %rdi
callq 0x3f20
movq -0x230(%rbp), %rsi
movq -0x220(%rbp), %rdi
imulq %rax, %rsi
callq 0x2050
movq %rax, -0x228(%rbp)
jmp 0x36f7
movq -0x228(%rbp), %rdi
movq 0x68ab(%rip), %rsi      # 0x9fb0
callq 0x21c0
jmp 0x370c
movl $0x0, -0x178(%rbp)
cmpl $0x100, -0x178(%rbp)    # imm = 0x100
jge 0x385c
movl $0x0, -0x17c(%rbp)
cmpl $0x100, -0x17c(%rbp)    # imm = 0x100
jge 0x383a
movl $0x0, -0x180(%rbp)
cmpl $0x100, -0x180(%rbp)    # imm = 0x100
jge 0x37f8
movl -0x178(%rbp), %esi
movl -0x17c(%rbp), %edx
movl -0x180(%rbp), %ecx
movq -0x108(%rbp), %r8
movq -0x110(%rbp), %r9
movq -0x118(%rbp), %rdi
movq %rsp, %rax
movq %rdi, (%rax)
leaq -0x1a0(%rbp), %rdi
callq 0x2c90
jmp 0x3795
leaq -0x1a0(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
movq 0x67f5(%rip), %rax      # 0x9fa0
movq (%rax), %rsi
callq 0x2210
jmp 0x37b5
leaq -0x1a0(%rbp), %rdi
callq 0x2328
movl -0x180(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x180(%rbp)
jmp 0x374a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x2328
jmp 0x38bc
leaq 0x6a39(%rip), %rdi      # 0xa238
callq 0x2090
movq %rax, %rdi
movq 0x6792(%rip), %rax      # 0x9fa0
movq (%rax), %rsi
callq 0x2210
jmp 0x3818
movl $0x20, %edi
callq 0x2250
jmp 0x3824
jmp 0x3826
movl -0x17c(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x17c(%rbp)
jmp 0x3730
movl $0xa, %edi
callq 0x2250
jmp 0x3846
jmp 0x3848
movl -0x178(%rbp), %eax
addl $0xe, %eax
movl %eax, -0x178(%rbp)
jmp 0x3716
movl $0x0, -0x128(%rbp)
leaq -0x100(%rbp), %rax
movq %rax, -0x248(%rbp)
addq $0x60, %rax
movq %rax, -0x240(%rbp)
movq -0x240(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x250(%rbp)
callq 0x3f50
movq -0x248(%rbp), %rcx
movq -0x250(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x240(%rbp)
jne 0x387f
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
leaq -0x100(%rbp), %rax
movq %rax, -0x260(%rbp)
addq $0x60, %rax
movq %rax, -0x258(%rbp)
movq -0x258(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x268(%rbp)
callq 0x3f50
movq -0x260(%rbp), %rcx
movq -0x268(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x258(%rbp)
jne 0x38d5
jmp 0x3908
movq -0x120(%rbp), %rdi
callq 0x22d0
nopw %cs:(%rax,%rax)
nop