// File: /workspace/github_cpp_makefile_star2_O1/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 0x3da2
leaq -0xa8(%rbp), %rsi
movq $0x4, (%rsi)
leaq 0x1fdd(%rip), %rax      # 0x51e9
movq %rax, 0x8(%rsi)
leaq -0x118(%rbp), %rbx
movq %rbx, %rdi
callq 0x25d4
btl $0x8, %eax
setae %cl
notb %al
orb %cl, %al
testb $0x1, %al
jne 0x33a2
movq 0x4d97(%rip), %rdi      # 0x7fd0
leaq 0x1fae(%rip), %rsi      # 0x51ee
movl $0x48, %edx
callq 0x21d0
movq 0x4d7f(%rip), %rdi      # 0x7fd0
leaq 0x1fdf(%rip), %rsi      # 0x5237
movl $0xf, %edx
callq 0x21d0
movq 0x4d67(%rip), %rdi      # 0x7fd0
leaq 0x1fd7(%rip), %rsi      # 0x5247
movl $0x29, %edx
callq 0x21d0
movq 0x4d4f(%rip), %rdi      # 0x7fd0
leaq 0x1fe9(%rip), %rsi      # 0x5271
movl $0x15, %edx
callq 0x21d0
movq 0x4d37(%rip), %rdi      # 0x7fd0
leaq 0x1fe7(%rip), %rsi      # 0x5287
movl $0x29, %edx
callq 0x21d0
movq 0x4d1f(%rip), %rdi      # 0x7fd0
leaq 0x1ff9(%rip), %rsi      # 0x52b1
movl $0x13, %edx
callq 0x21d0
movq 0x4d07(%rip), %rdi      # 0x7fd0
leaq 0x1ff5(%rip), %rsi      # 0x52c5
movl $0x2f, %edx
callq 0x21d0
movq 0x4cef(%rip), %rdi      # 0x7fd0
leaq 0x200d(%rip), %rsi      # 0x52f5
movl $0x1f, %edx
callq 0x21d0
movq 0x4cd7(%rip), %rdi      # 0x7fd0
leaq 0x2015(%rip), %rsi      # 0x5315
movl $0x46, %edx
callq 0x21d0
movq 0x4cbf(%rip), %rdi      # 0x7fd0
leaq 0x2044(%rip), %rsi      # 0x535c
movl $0x3d, %edx
callq 0x21d0
movq 0x4ca7(%rip), %rdi      # 0x7fd0
leaq 0x206a(%rip), %rsi      # 0x539a
movl $0x35, %edx
callq 0x21d0
movq 0x4c8f(%rip), %rdi      # 0x7fd0
leaq 0x2088(%rip), %rsi      # 0x53d0
movl $0x20, %edx
callq 0x21d0
movq 0x4c77(%rip), %rdi      # 0x7fd0
leaq 0x2091(%rip), %rsi      # 0x53f1
movl $0x2f, %edx
callq 0x21d0
movq 0x4c5f(%rip), %rdi      # 0x7fd0
leaq 0x20a9(%rip), %rsi      # 0x5421
movl $0x2b, %edx
callq 0x21d0
xorl %r14d, %r14d
movq 0x4c44(%rip), %rdi      # 0x7fd0
leaq 0x20ba(%rip), %rsi      # 0x544d
movl $0x27, %edx
callq 0x21d0
jmp 0x38cd
leaq -0x68(%rbp), %rdx
movq $0x1, (%rdx)
leaq 0x1e33(%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 0x3ac6
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x33fe
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x48(%rbp), %rdx
movq $0x1, (%rdx)
leaq 0x2133(%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 0x3ac6
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x3457
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0xa0(%rbp), %rdx
testq %rdx, %rdx
je 0x3468
xorl %r14d, %r14d
jmp 0x3493
movq -0xe0(%rbp), %rax
cmpq %rax, -0xd8(%rbp)
je 0x3463
movq (%rax), %r8
movq 0x8(%rax), %rcx
movl $0x1, %r14d
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
callq 0x2290
movq -0x80(%rbp), %rdx
testq %rdx, %rdx
jne 0x34d1
movq -0xe0(%rbp), %rax
movq -0xd8(%rbp), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq %r14, %rcx
jbe 0x34d1
shll $0x4, %r14d
movq (%rax,%r14), %r8
movq 0x8(%rax,%r14), %rcx
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x2290
cmpq $0x0, -0x80(%rbp)
jne 0x352c
leaq -0x68(%rbp), %rdi
movq %r12, (%rdi)
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
addq %rsi, %rdx
callq 0x44bc
leaq 0x1f79(%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 0x352c
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
cmpq $0x0, -0xa0(%rbp)
je 0x3785
cmpq $0x0, -0x80(%rbp)
je 0x37c0
leaq -0xc8(%rbp), %rdx
movq $0x4, (%rdx)
leaq 0x1f67(%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 0x3ac6
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x359c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
cmpq $0x0, -0x60(%rbp)
jne 0x3684
leaq -0x48(%rbp), %rdi
movq %r13, (%rdi)
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
addq %rsi, %rdx
callq 0x44bc
leaq 0x1efb(%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 0x35f8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x68(%rbp), %rdi
callq 0x26ee
leaq -0x48(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x1ebd(%rip), %rsi      # 0x54cc
leaq 0x1eb7(%rip), %rdx      # 0x54cd
callq 0x4556
leaq -0xb8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1ea1(%rip), %rsi      # 0x54ce
leaq 0x1e9b(%rip), %rdx      # 0x54cf
leaq -0xc8(%rbp), %rdi
callq 0x4556
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
callq 0x267e
movq -0xc8(%rbp), %rdi
cmpq %r14, %rdi
je 0x366f
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x3684
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2190
cmpq $0x0, -0x60(%rbp)
je 0x37fb
leaq -0x48(%rbp), %rsi
movq $0x4, (%rsi)
leaq 0x1e4d(%rip), %rax      # 0x54ee
movq %rax, 0x8(%rsi)
movq %rbx, %rdi
callq 0x4692
btq $0x20, %rax
movl $0x8, %r14d
cmovbl %eax, %r14d
leal -0x8(%r14), %eax
roll $0x1d, %eax
cmpl $0x7, %eax
ja 0x3833
movl $0x8b, %ecx
btl %eax, %ecx
jae 0x3833
leaq -0x48(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2732
leaq -0x48(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movl %r14d, %ecx
callq 0x291d
movq 0x48c8(%rip), %rdi      # 0x7fd0
leaq 0x1e1c(%rip), %rsi      # 0x552b
movl $0x14, %edx
callq 0x21d0
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x48a8(%rip), %rdi      # 0x7fd0
callq 0x21d0
movq %rax, %r14
leaq 0x19cc(%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 0x1991(%rip), %rsi      # 0x50ec
movl $0x7, %edx
movq %rax, %rdi
callq 0x21d0
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x377d
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x2190
xorl %r14d, %r14d
jmp 0x3881
movq 0x4844(%rip), %rdi      # 0x7fd0
leaq 0x1ce5(%rip), %rsi      # 0x5478
movl $0x1d, %edx
callq 0x21d0
movl $0x2, %r14d
movq 0x4826(%rip), %rdi      # 0x7fd0
leaq 0x1ce5(%rip), %rsi      # 0x5496
movl $0x10, %edx
callq 0x21d0
jmp 0x3896
movq 0x4809(%rip), %rdi      # 0x7fd0
leaq 0x1cd9(%rip), %rsi      # 0x54a7
movl $0x19, %edx
callq 0x21d0
movl $0x3, %r14d
movq 0x47eb(%rip), %rdi      # 0x7fd0
leaq 0x1caa(%rip), %rsi      # 0x5496
movl $0x10, %edx
callq 0x21d0
jmp 0x3896
movq 0x47ce(%rip), %rdi      # 0x7fd0
leaq 0x1cc7(%rip), %rsi      # 0x54d0
movl $0x1d, %edx
callq 0x21d0
movl $0x4, %r14d
movq 0x47b0(%rip), %rdi      # 0x7fd0
leaq 0x1c6f(%rip), %rsi      # 0x5496
movl $0x10, %edx
callq 0x21d0
jmp 0x3881
movq 0x4796(%rip), %rdi      # 0x7fd0
leaq 0x1cb2(%rip), %rsi      # 0x54f3
movl $0x17, %edx
callq 0x21d0
movq 0x477e(%rip), %rdi      # 0x7fd0
leaq 0x1cb2(%rip), %rsi      # 0x550b
movl $0x1f, %edx
callq 0x21d0
movl $0x5, %r14d
movq 0x4760(%rip), %rdi      # 0x7fd0
leaq 0x1c1f(%rip), %rsi      # 0x5496
movl $0x10, %edx
callq 0x21d0
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x3896
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x38ae
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38cd
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2190
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x38e8
movq -0xd0(%rbp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x4434
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 0x392e
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x392e
jmp 0x395c
jmp 0x392b
jmp 0x395c
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x39a0
movq -0x38(%rbp), %rsi
incq %rsi
jmp 0x399b
jmp 0x395c
jmp 0x395c
jmp 0x395c
jmp 0x395c
jmp 0x39b7
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x39ba
movq -0x38(%rbp), %rsi
jmp 0x39ad
movq %rax, %rbx
jmp 0x39a0
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x39d2
movq -0x58(%rbp), %rsi
jmp 0x39ca
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x39f8
movq -0x78(%rbp), %rsi
jmp 0x39e9
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x39a0
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x2190
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x39ba
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x39ba
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x39d2
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2190
leaq -0x98(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39f8
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2190
jmp 0x39f8
jmp 0x39f5
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x3b46
movq %rbx, %rdi
callq 0x2320