// File: /workspace/github_cpp_makefile_star2_O3/kallaballa[P]PixelStencil/PixelStencil.cpp
// Function: main
int main(int argc, char** argv) {
	using namespace kallaballa;

	if(argc != 5) {
		std::cerr << "Usage: PixelStencil <img file> <pixel width mm> <pixel margin mm> <board margin mm>" << std::endl;
		return 1;
	}

	NamedColorTable ral;
	ral.readFromCSV("colors.txt");
	PixelPlanes pp(argv[1]);
	size_t pixelWidthMM = atoi(argv[2]);
	size_t pixelMarginMM = atoi(argv[3]);
	size_t boardMarginMM = atoi(argv[4]);

	int i = 0;
	for(auto it = pp.begin(); it != pp.end(); ++it) {
		const Color& color = (*it).first;
    const PixelList& pl = (*it).second;

    NamedColor sample;
    sample.rgb = color;
    auto nearest = ral.find_nearest(sample);
		std::cerr << std::dec << int(nearest.second) << "\t#" << std::setfill('0') << std::setw(6) << std::hex << (*nearest.first).rgb << '\t' << color << '\t' << (*nearest.first).name << std::endl;

		SVGStencil stencil((string(argv[1]) + std::to_string(i) + ".svg").c_str(),
		    *nearest.first,
		    pp.getWidth(),
				pp.getHeight(),
				pixelWidthMM,
				pixelMarginMM,
				boardMarginMM);

		for(auto it_l = pl.begin(); it_l != pl.end(); ++it_l) {
			stencil.writePixel((*it_l).first, (*it_l).second);
		}
		i++;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
cmpl $0x5, %edi
jne 0x4e9e
movq %rsi, %r15
leaq 0x120(%rsp), %rax
movq $0x0, 0x18(%rax)
leaq 0x2773c(%rip), %rcx     # 0x2c038
movq %rcx, 0x20(%rax)
movq %rax, 0x8(%rax)
movq %rax, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x8(%rax)
leaq 0x1c8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x28b4c(%rip), %rsi     # 0x2d46e
leaq 0x28b4f(%rip), %rdx     # 0x2d478
leaq 0x1b8(%rsp), %rdi
callq 0x2b95e
leaq 0x110(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x2c222
movq 0x1b8(%rsp), %rdi
cmpq %r14, %rdi
je 0x4968
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x32d0
movq 0x8(%r15), %rsi
leaq 0x150(%rsp), %rdi
callq 0x3b1c
movq 0x10(%r15), %rdi
callq 0x3430
movl %eax, %ebx
movq 0x18(%r15), %rdi
callq 0x3430
movl %eax, %ebp
movq %r15, 0x108(%rsp)
movq 0x20(%r15), %rdi
callq 0x3430
leaq 0x190(%rsp), %rcx
movq 0x10(%rcx), %r14
cmpq %rcx, %r14
je 0x4e80
movslq %ebx, %rcx
movq %rcx, 0x100(%rsp)
movslq %ebp, %rcx
movq %rcx, 0xf8(%rsp)
cltq
movq %rax, 0xf0(%rsp)
xorl %r13d, %r13d
movq 0x35611(%rip), %r12     # 0x39ff0
leaq 0x1b8(%rsp), %rbp
leaq 0xb8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq $0x0, 0xb0(%rsp)
movb $0x0, 0xb8(%rsp)
movl 0x20(%r14), %eax
movl %eax, 0xa0(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x50ee
movq (%r12), %rax
movq -0x18(%rax), %rax
movl 0x18(%r12,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%r12,%rax)
cvttsd2si 0x98(%rsp), %esi
movq %r12, %rdi
callq 0x34c0
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
leaq 0x28a0b(%rip), %rsi     # 0x2d479
callq 0x3330
movq (%r15), %rax
movq -0x18(%rax), %rcx
movq %r15, %rbx
addq %rcx, %rbx
cmpb $0x0, 0xe1(%r15,%rcx)
jne 0x4aa2
movq %rbx, %rdi
movl $0x20, %esi
callq 0x3290
movb $0x1, 0xe1(%rbx)
movq (%r15), %rax
movb $0x30, 0xe0(%rbx)
movq -0x18(%rax), %rcx
movq $0x6, 0x10(%r15,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%r15,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r15,%rax)
movq 0x90(%rsp), %rax
movl 0x18(%rax), %esi
movq %r15, %rdi
callq 0x31a0
movb $0x9, 0x1b8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3330
movl 0x20(%r14), %esi
movq %rax, %rdi
callq 0x31a0
movb $0x9, 0x1b8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3330
movq 0x90(%rsp), %rcx
movq 0x20(%rcx), %rsi
movq 0x28(%rcx), %rdx
movq %rax, %rdi
callq 0x3330
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3050
movq %rax, %rdi
callq 0x31b0
movq 0x108(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x50(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x50b0
movl $0x1, %r15d
cmpl $0xa, %r13d
jb 0x4bc9
movl $0x4, %r15d
movl %r13d, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x4bc0
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x4bc6
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x4bc9
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r15d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x4b90
addl $-0x3, %r15d
jmp 0x4bc9
addl $-0x2, %r15d
jmp 0x4bc9
decl %r15d
movl %r15d, %esi
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rdi
movl $0x2d, %edx
callq 0x3340
movq 0x30(%rsp), %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x534f
movq 0x50(%rsp), %rcx
movl $0xf, %edi
leaq 0x60(%rsp), %rax
cmpq %rax, %rcx
je 0x4c0e
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %r8
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x4c3f
movl $0xf, %edi
leaq 0x40(%rsp), %r9
cmpq %r9, %rsi
je 0x4c3a
movq 0x40(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x4c4b
leaq 0x50(%rsp), %rdi
callq 0x30b0
jmp 0x4c59
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3320
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x4c7e
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x4c84
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x10(%rsp), %rdi
leaq 0x287cf(%rip), %rsi     # 0x2d47c
callq 0x3530
leaq 0x80(%rsp), %rsi
movq %rsi, 0x70(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4ce0
movq %rdx, 0x70(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x80(%rsp)
jmp 0x4ce6
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x70(%rsp), %r15
movq 0x90(%rsp), %rax
movl 0x18(%rax), %ecx
movl %ecx, 0xc8(%rsp)
leaq 0xe0(%rsp), %rcx
movq %rcx, 0xd0(%rsp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq 0xd0(%rsp), %rdi
callq 0x52ba
movq 0x178(%rsp), %rcx
movq 0x180(%rsp), %r8
movq %rbp, %rdi
movq %r15, %rsi
leaq 0xc8(%rsp), %rdx
movq 0x100(%rsp), %r9
pushq 0xf0(%rsp)
pushq 0x100(%rsp)
callq 0x3cc4
addq $0x10, %rsp
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x4d9f
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x32d0
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x4dc1
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x32d0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4ddd
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x32d0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4df9
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x32d0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4e15
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x32d0
movq 0x28(%r14), %rbx
cmpq 0x30(%r14), %rbx
je 0x4e34
movslq (%rbx), %rsi
movslq 0x4(%rbx), %rdx
movq %rbp, %rdi
callq 0x461e
addq $0x8, %rbx
jmp 0x4e19
movq %rbp, %rdi
callq 0x4542
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x4e61
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32d0
incl %r13d
movq %r14, %rdi
callq 0x31c0
movq %rax, %r14
leaq 0x190(%rsp), %rax
cmpq %rax, %r14
jne 0x49e7
leaq 0x150(%rsp), %rdi
callq 0x3c7e
leaq 0x110(%rsp), %rdi
callq 0x5216
xorl %eax, %eax
jmp 0x4ee5
movq 0x3514b(%rip), %rbx     # 0x39ff0
leaq 0x2856e(%rip), %rsi     # 0x2d41a
movl $0x53, %edx
movq %rbx, %rdi
callq 0x3330
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3050
movq %rax, %rdi
callq 0x31b0
movl $0x1, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4f22
movq %rax, %rbx
movq 0x1b8(%rsp), %rdi
cmpq %r14, %rdi
je 0x502a
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x32d0
jmp 0x502a
movq %rax, %rbx
jmp 0x502a
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x4f6b
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x32d0
jmp 0x4f6b
jmp 0x4fe3
movq %rax, %rbx
jmp 0x4fc5
movq %rax, %rbx
jmp 0x4fa9
movq %rax, %rbx
jmp 0x4f8d
movq %rax, %rbx
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x4f8d
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x32d0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4fa9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x32d0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4fc5
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x32d0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4ff8
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x32d0
jmp 0x4ff8
movq %rax, %rbx
jmp 0x4ff8
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x4542
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x501d
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32d0
leaq 0x150(%rsp), %rdi
callq 0x3c7e
leaq 0x110(%rsp), %rdi
callq 0x5216
movq %rbx, %rdi
callq 0x34d0
nop