// File: /workspace/github_cpp_makefile_star2_O3/nyorain[P]bintoheader/bintoheader.cpp
// Function: main
int main(int argc, char** argv)
{
	// parse args
	const flags::args args(argc, argv);

	// help
	auto help = args.get<bool>("help", false);
	if(help) {
		std::cout << "Transforms a file into a c/cpp header holding its binary data as array.\n";
		std::cout << "Valid Usages:\n\n";
		std::cout << "\tbintoheader <INPUT> [<OUTPUT>] [<ARGS>]\n";
		std::cout << "\tbintoheader <ARGS>\n\n";
		std::cout << "The following arguments are recognized:\n\n";
		std::cout << "\t-i\tThe input file\n";
		std::cout << "\t-o\tThe output file [defaulted to '<input>.h']\n";
		std::cout << "\t-name\tThe name of the c array\n";
		std::cout << "\t\tDefaulted to '<input>.h' with path stripped all '.' replaced by '.'\n";
		std::cout << "\t-size\tThe size of the array values in bits. Defaulted to 8.\n";
		std::cout << "\t\tThe file size must be a multiple of the size value\n";
		std::cout << "\t-help\tShow this error message\n\n";
		std::cout << "The program is released into the public domain\n";
		std::cout << "A copy of the source can be obtained under\n";
		std::cout << "https://github.com/nyorain/bintoheader\n";
		return 0;
	}

	// input, output
	auto input = args.get<std::string>("i", {});
	auto output = args.get<std::string>("o", {});
	const auto& pos = args.positional();

	auto current = 0u;
	if(input.empty() && pos.size() > current)
		input = pos[current++];

	if(output.empty() && pos.size() > current)
		output = pos[current++];

	if(output.empty())
		output = input + ".h";

	if(input.empty()) {
		std::cout << "Must give a valid input file\n";
		std::cout << "Use -h for help\n";
		return 2;
	}

	if(output.empty()) {
		std::cout << "Invalid output file name\n";
		std::cout << "Use -h for help\n";
		return 3;
	}

	// name, size
	auto name = args.get<std::string>("name", {});
	if(name.empty()) {
		name = input + "_data";
		stripPath(name);
		replace(name, ".", "_");
	}

	if(name.empty()) {
		std::cout << "Empty array name is invalid!\n";
		std::cout << "Use -h for help\n";
		return 4;
	}

	auto size = args.get<unsigned int>("size", 8);
	if(size != 8 && size != 16 && size != 32 && size != 64) {
		std::cout << "Invalid size parameter\n";
		std::cout << "Must be one of {8, 16, 32, 64}\n";
		std::cout << "Use -h for help\n";
		return 5;
	}

	auto data = loadFile(input);
	outputData(data, output, name, size);
	std::cout << "Succesfully created " << name << ": " << data.size () << " bytes\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rdx
movl %edi, %esi
leaq -0x130(%rbp), %rdi
callq 0x3d72
leaq -0xa8(%rbp), %rsi
movq $0x4, (%rsi)
leaq 0x1ff6(%rip), %rax      # 0x51e9
movq %rax, 0x8(%rsi)
leaq -0x118(%rbp), %rbx
movq %rbx, %rdi
callq 0x25b1
btl $0x8, %eax
setae %cl
notb %al
orb %cl, %al
testb $0x1, %al
jne 0x3389
movq 0x4db0(%rip), %rdi      # 0x7fd0
leaq 0x1fc7(%rip), %rsi      # 0x51ee
movl $0x48, %edx
callq 0x21d0
movq 0x4d98(%rip), %rdi      # 0x7fd0
leaq 0x1ff8(%rip), %rsi      # 0x5237
movl $0xf, %edx
callq 0x21d0
movq 0x4d80(%rip), %rdi      # 0x7fd0
leaq 0x1ff0(%rip), %rsi      # 0x5247
movl $0x29, %edx
callq 0x21d0
movq 0x4d68(%rip), %rdi      # 0x7fd0
leaq 0x2002(%rip), %rsi      # 0x5271
movl $0x15, %edx
callq 0x21d0
movq 0x4d50(%rip), %rdi      # 0x7fd0
leaq 0x2000(%rip), %rsi      # 0x5287
movl $0x29, %edx
callq 0x21d0
movq 0x4d38(%rip), %rdi      # 0x7fd0
leaq 0x2012(%rip), %rsi      # 0x52b1
movl $0x13, %edx
callq 0x21d0
movq 0x4d20(%rip), %rdi      # 0x7fd0
leaq 0x200e(%rip), %rsi      # 0x52c5
movl $0x2f, %edx
callq 0x21d0
movq 0x4d08(%rip), %rdi      # 0x7fd0
leaq 0x2026(%rip), %rsi      # 0x52f5
movl $0x1f, %edx
callq 0x21d0
movq 0x4cf0(%rip), %rdi      # 0x7fd0
leaq 0x202e(%rip), %rsi      # 0x5315
movl $0x46, %edx
callq 0x21d0
movq 0x4cd8(%rip), %rdi      # 0x7fd0
leaq 0x205d(%rip), %rsi      # 0x535c
movl $0x3d, %edx
callq 0x21d0
movq 0x4cc0(%rip), %rdi      # 0x7fd0
leaq 0x2083(%rip), %rsi      # 0x539a
movl $0x35, %edx
callq 0x21d0
movq 0x4ca8(%rip), %rdi      # 0x7fd0
leaq 0x20a1(%rip), %rsi      # 0x53d0
movl $0x20, %edx
callq 0x21d0
movq 0x4c90(%rip), %rdi      # 0x7fd0
leaq 0x20aa(%rip), %rsi      # 0x53f1
movl $0x2f, %edx
callq 0x21d0
movq 0x4c78(%rip), %rdi      # 0x7fd0
leaq 0x20c2(%rip), %rsi      # 0x5421
movl $0x2b, %edx
callq 0x21d0
xorl %r14d, %r14d
movq 0x4c5d(%rip), %rdi      # 0x7fd0
leaq 0x20d3(%rip), %rsi      # 0x544d
movl $0x27, %edx
callq 0x21d0
jmp 0x38b8
leaq -0x68(%rbp), %rdx
movq $0x1, (%rdx)
leaq 0x1e4c(%rip), %rax      # 0x51e7
movq %rax, 0x8(%rdx)
leaq -0x78(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
leaq -0xa8(%rbp), %rdi
leaq -0x130(%rbp), %rsi
leaq -0x88(%rbp), %rcx
callq 0x3aaa
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x33e5
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x48(%rbp), %rdx
movq $0x1, (%rdx)
leaq 0x214c(%rip), %rax      # 0x5543
movq %rax, 0x8(%rdx)
leaq -0x58(%rbp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
leaq -0x88(%rbp), %rdi
leaq -0x130(%rbp), %rsi
leaq -0x68(%rbp), %rcx
callq 0x3aaa
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x343e
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
cmpq $0x0, -0xa0(%rbp)
je 0x344d
xorl %r14d, %r14d
jmp 0x347a
movq -0xe0(%rbp), %rax
cmpq %rax, -0xd8(%rbp)
je 0x3448
movq (%rax), %r8
movq 0x8(%rax), %rcx
movl $0x1, %r14d
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2290
cmpq $0x0, -0x80(%rbp)
jne 0x3517
movq -0xe0(%rbp), %rax
movq -0xd8(%rbp), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq %r14, %rcx
jbe 0x34c3
shll $0x4, %r14d
movq (%rax,%r14), %r8
movq 0x8(%rax,%r14), %rcx
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2290
cmpq $0x0, -0x80(%rbp)
jne 0x3517
leaq -0x68(%rbp), %rdi
movq %r12, (%rdi)
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
addq %rsi, %rdx
callq 0x4482
leaq 0x1f8e(%rip), %rsi      # 0x5475
leaq -0x68(%rbp), %rdi
callq 0x2350
leaq -0x88(%rbp), %rdi
leaq -0x68(%rbp), %r14
movq %r14, %rsi
callq 0x2200
movq (%r14), %rdi
cmpq %r12, %rdi
je 0x3517
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
cmpq $0x0, -0xa0(%rbp)
je 0x3770
cmpq $0x0, -0x80(%rbp)
je 0x37ab
leaq -0xc8(%rbp), %rdx
movq $0x4, (%rdx)
leaq 0x1f7c(%rip), %rax      # 0x54c1
movq %rax, 0x8(%rdx)
leaq -0x38(%rbp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
leaq -0x68(%rbp), %rdi
leaq -0x130(%rbp), %rsi
leaq -0x48(%rbp), %rcx
callq 0x3aaa
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x3587
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
cmpq $0x0, -0x60(%rbp)
jne 0x367a
leaq -0x48(%rbp), %rdi
movq %r13, (%rdi)
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
addq %rsi, %rdx
callq 0x4482
leaq 0x1f10(%rip), %rsi      # 0x54c6
leaq -0x48(%rbp), %rdi
callq 0x2350
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %r14
movq %r14, %rsi
callq 0x2200
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x35e3
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x68(%rbp), %rdi
callq 0x26ce
leaq -0x48(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x1ed2(%rip), %rsi      # 0x54cc
leaq 0x1ecc(%rip), %rdx      # 0x54cd
callq 0x4520
leaq -0xb8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1eb6(%rip), %rsi      # 0x54ce
leaq 0x1eb0(%rip), %rdx      # 0x54cf
leaq -0xc8(%rbp), %rdi
callq 0x4520
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
callq 0x2660
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x365a
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x366f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
cmpq $0x0, -0x60(%rbp)
je 0x3836
leaq -0x48(%rbp), %rsi
movq $0x4, (%rsi)
leaq 0x1e62(%rip), %rax      # 0x54ee
movq %rax, 0x8(%rsi)
movq %rbx, %rdi
callq 0x4660
btq $0x20, %rax
movl $0x8, %r14d
cmovbl %eax, %r14d
leal -0x8(%r14), %eax
roll $0x1d, %eax
cmpl $0x7, %eax
ja 0x37e6
movl $0x8b, %ecx
btl %eax, %ecx
jae 0x37e6
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2712
leaq -0x48(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movl %r14d, %ecx
callq 0x28fd
movq 0x48dd(%rip), %rdi      # 0x7fd0
leaq 0x1e31(%rip), %rsi      # 0x552b
movl $0x14, %edx
callq 0x21d0
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x48bd(%rip), %rdi      # 0x7fd0
callq 0x21d0
movq %rax, %r14
leaq 0x19e1(%rip), %rsi      # 0x5103
movl $0x2, %edx
movq %rax, %rdi
callq 0x21d0
movq -0x40(%rbp), %rsi
subq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x2110
leaq 0x19a6(%rip), %rsi      # 0x50ec
movl $0x7, %edx
movq %rax, %rdi
callq 0x21d0
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x3768
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x2190
xorl %r14d, %r14d
jmp 0x386c
movq 0x4859(%rip), %rdi      # 0x7fd0
leaq 0x1cfa(%rip), %rsi      # 0x5478
movl $0x1d, %edx
callq 0x21d0
movl $0x2, %r14d
movq 0x483b(%rip), %rdi      # 0x7fd0
leaq 0x1cfa(%rip), %rsi      # 0x5496
movl $0x10, %edx
callq 0x21d0
jmp 0x3881
movq 0x481e(%rip), %rdi      # 0x7fd0
leaq 0x1cee(%rip), %rsi      # 0x54a7
movl $0x19, %edx
callq 0x21d0
movl $0x3, %r14d
movq 0x4800(%rip), %rdi      # 0x7fd0
leaq 0x1cbf(%rip), %rsi      # 0x5496
movl $0x10, %edx
callq 0x21d0
jmp 0x3881
movq 0x47e3(%rip), %rdi      # 0x7fd0
leaq 0x1cff(%rip), %rsi      # 0x54f3
movl $0x17, %edx
callq 0x21d0
movq 0x47cb(%rip), %rdi      # 0x7fd0
leaq 0x1cff(%rip), %rsi      # 0x550b
movl $0x1f, %edx
callq 0x21d0
movl $0x5, %r14d
movq 0x47ad(%rip), %rdi      # 0x7fd0
leaq 0x1c6c(%rip), %rsi      # 0x5496
movl $0x10, %edx
callq 0x21d0
jmp 0x386c
movq 0x4793(%rip), %rdi      # 0x7fd0
leaq 0x1c8c(%rip), %rsi      # 0x54d0
movl $0x1d, %edx
callq 0x21d0
movl $0x4, %r14d
movq 0x4775(%rip), %rdi      # 0x7fd0
leaq 0x1c34(%rip), %rsi      # 0x5496
movl $0x10, %edx
callq 0x21d0
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x3881
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x3899
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38b8
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x38d3
movq -0xd0(%rbp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x43fa
movl %r14d, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x3917
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x3917
jmp 0x3914
jmp 0x3935
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x398b
movq -0x38(%rbp), %rsi
incq %rsi
jmp 0x3986
jmp 0x3935
jmp 0x3935
jmp 0x3935
jmp 0x3935
jmp 0x39a2
jmp 0x3935
movq %rax, %rbx
jmp 0x398b
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x39a5
movq -0x38(%rbp), %rsi
jmp 0x3998
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x39bd
movq -0x58(%rbp), %rsi
jmp 0x39b5
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x39e3
movq -0x78(%rbp), %rsi
jmp 0x39d4
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x398b
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x2190
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x39a5
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x39a5
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x39bd
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39e3
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x39e3
jmp 0x39e0
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x3b2a
movq %rbx, %rdi
callq 0x2320
nop