// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movq %rsi, %rdx
movl %edi, %esi
leaq -0x120(%rbp), %rbx
movq %rbx, %rdi
callq 0x39f2
leaq -0x98(%rbp), %rsi
movq $0x4, (%rsi)
leaq 0x23eb(%rip), %rax      # 0x51e9
movq %rax, 0x8(%rsi)
leaq -0x78(%rbp), %rdx
movb $0x0, (%rdx)
movq %rbx, %rdi
callq 0x35d8
testb %al, %al
je 0x2f3d
movq 0x51b0(%rip), %rdi      # 0x7fd0
leaq 0x23c7(%rip), %rsi      # 0x51ee
callq 0x21b0
movq 0x519d(%rip), %rdi      # 0x7fd0
leaq 0x23fd(%rip), %rsi      # 0x5237
callq 0x21b0
movq 0x518a(%rip), %rdi      # 0x7fd0
leaq 0x23fa(%rip), %rsi      # 0x5247
callq 0x21b0
movq 0x5177(%rip), %rdi      # 0x7fd0
leaq 0x2411(%rip), %rsi      # 0x5271
callq 0x21b0
movq 0x5164(%rip), %rdi      # 0x7fd0
leaq 0x2414(%rip), %rsi      # 0x5287
callq 0x21b0
movq 0x5151(%rip), %rdi      # 0x7fd0
leaq 0x242b(%rip), %rsi      # 0x52b1
callq 0x21b0
movq 0x513e(%rip), %rdi      # 0x7fd0
leaq 0x242c(%rip), %rsi      # 0x52c5
callq 0x21b0
movq 0x512b(%rip), %rdi      # 0x7fd0
leaq 0x2449(%rip), %rsi      # 0x52f5
callq 0x21b0
movq 0x5118(%rip), %rdi      # 0x7fd0
leaq 0x2456(%rip), %rsi      # 0x5315
callq 0x21b0
movq 0x5105(%rip), %rdi      # 0x7fd0
leaq 0x248a(%rip), %rsi      # 0x535c
callq 0x21b0
movq 0x50f2(%rip), %rdi      # 0x7fd0
leaq 0x24b5(%rip), %rsi      # 0x539a
callq 0x21b0
movq 0x50df(%rip), %rdi      # 0x7fd0
leaq 0x24d8(%rip), %rsi      # 0x53d0
callq 0x21b0
movq 0x50cc(%rip), %rdi      # 0x7fd0
leaq 0x24e6(%rip), %rsi      # 0x53f1
callq 0x21b0
movq 0x50b9(%rip), %rdi      # 0x7fd0
leaq 0x2503(%rip), %rsi      # 0x5421
callq 0x21b0
xorl %ebx, %ebx
movq 0x50a4(%rip), %rdi      # 0x7fd0
leaq 0x251a(%rip), %rsi      # 0x544d
callq 0x21b0
jmp 0x3303
leaq -0x58(%rbp), %rdx
movq $0x1, (%rdx)
leaq 0x2298(%rip), %rax      # 0x51e7
movq %rax, 0x8(%rdx)
leaq -0x68(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x98(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x78(%rbp), %rcx
callq 0x35fe
leaq -0x78(%rbp), %rdi
callq 0x2100
leaq -0x38(%rbp), %rdx
movq $0x1, (%rdx)
leaq 0x25ae(%rip), %rax      # 0x5543
movq %rax, 0x8(%rdx)
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x78(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x58(%rbp), %rcx
callq 0x35fe
leaq -0x58(%rbp), %rdi
callq 0x2100
cmpq $0x0, -0x90(%rbp)
je 0x2fd4
xorl %eax, %eax
jmp 0x2ff3
movq -0xd0(%rbp), %rsi
cmpq %rsi, -0xc8(%rbp)
je 0x2fd0
leaq -0x98(%rbp), %rdi
callq 0x44d6
pushq $0x1
popq %rax
cmpq $0x0, -0x70(%rbp)
jne 0x3059
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rcx
subq %rsi, %rcx
sarq $0x4, %rcx
cmpq %rax, %rcx
jbe 0x302a
shll $0x4, %eax
addq %rax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x44d6
cmpq $0x0, -0x70(%rbp)
jne 0x3059
leaq 0x2444(%rip), %rdx      # 0x5475
leaq -0x58(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x365a
leaq -0x78(%rbp), %rdi
leaq -0x58(%rbp), %rbx
movq %rbx, %rsi
callq 0x2210
movq %rbx, %rdi
callq 0x2100
cmpq $0x0, -0x90(%rbp)
je 0x322a
cmpq $0x0, -0x70(%rbp)
je 0x3254
leaq -0xb8(%rbp), %rdx
movq $0x4, (%rdx)
leaq 0x243a(%rip), %rax      # 0x54c1
movq %rax, 0x8(%rdx)
leaq -0x28(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x58(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x38(%rbp), %rcx
callq 0x35fe
leaq -0x38(%rbp), %rdi
callq 0x2100
cmpq $0x0, -0x50(%rbp)
jne 0x315c
leaq 0x23fc(%rip), %rdx      # 0x54c6
leaq -0x38(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x365a
leaq -0x58(%rbp), %rbx
leaq -0x38(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2210
movq %r14, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x26cc
leaq 0x23c8(%rip), %rsi      # 0x54cc
leaq -0x38(%rbp), %rdi
leaq -0x12(%rbp), %rdx
callq 0x359c
leaq 0x23b6(%rip), %rsi      # 0x54ce
leaq -0xb8(%rbp), %rdi
leaq -0x11(%rbp), %rdx
callq 0x359c
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
callq 0x2676
leaq -0xb8(%rbp), %rdi
callq 0x2100
leaq -0x38(%rbp), %rdi
callq 0x2100
cmpq $0x0, -0x50(%rbp)
je 0x32bc
leaq -0x38(%rbp), %rsi
movq $0x4, (%rsi)
leaq 0x2380(%rip), %rax      # 0x54ee
movq %rax, 0x8(%rsi)
leaq -0xb8(%rbp), %rdx
movl $0x8, (%rdx)
leaq -0x120(%rbp), %rdi
callq 0x3692
movl %eax, %ebx
leal -0x8(%rbx), %eax
roll $0x1d, %eax
cmpl $0x7, %eax
ja 0x327f
movl $0x8b, %ecx
btl %eax, %ecx
jae 0x327f
leaq -0x38(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2707
leaq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x58(%rbp), %rdx
movl %ebx, %ecx
callq 0x28af
movq 0x4dfc(%rip), %rdi      # 0x7fd0
leaq 0x2350(%rip), %rsi      # 0x552b
callq 0x21b0
leaq -0x58(%rbp), %rsi
movq %rax, %rdi
callq 0x2190
leaq 0x1f10(%rip), %rsi      # 0x5103
movq %rax, %rdi
callq 0x21b0
movq -0x30(%rbp), %rsi
subq -0x38(%rbp), %rsi
movq %rax, %rdi
callq 0x2140
leaq 0x1eda(%rip), %rsi      # 0x50ec
movq %rax, %rdi
callq 0x21b0
leaq -0x38(%rbp), %rdi
callq 0x43f6
xorl %ebx, %ebx
jmp 0x32e5
movq 0x4d9f(%rip), %rdi      # 0x7fd0
leaq 0x2240(%rip), %rsi      # 0x5478
callq 0x21b0
movq 0x4d8c(%rip), %rdi      # 0x7fd0
leaq 0x224b(%rip), %rsi      # 0x5496
callq 0x21b0
pushq $0x2
jmp 0x327c
movq 0x4d75(%rip), %rdi      # 0x7fd0
leaq 0x2245(%rip), %rsi      # 0x54a7
callq 0x21b0
movq 0x4d62(%rip), %rdi      # 0x7fd0
leaq 0x2221(%rip), %rsi      # 0x5496
callq 0x21b0
pushq $0x3
popq %rbx
jmp 0x32ee
movq 0x4d4a(%rip), %rdi      # 0x7fd0
leaq 0x2266(%rip), %rsi      # 0x54f3
callq 0x21b0
movq 0x4d37(%rip), %rdi      # 0x7fd0
leaq 0x226b(%rip), %rsi      # 0x550b
callq 0x21b0
movq 0x4d24(%rip), %rdi      # 0x7fd0
leaq 0x21e3(%rip), %rsi      # 0x5496
callq 0x21b0
pushq $0x5
jmp 0x32e4
movq 0x4d0d(%rip), %rdi      # 0x7fd0
leaq 0x2206(%rip), %rsi      # 0x54d0
callq 0x21b0
movq 0x4cfa(%rip), %rdi      # 0x7fd0
leaq 0x21b9(%rip), %rsi      # 0x5496
callq 0x21b0
pushq $0x4
popq %rbx
leaq -0x58(%rbp), %rdi
callq 0x2100
leaq -0x78(%rbp), %rdi
callq 0x2100
leaq -0x98(%rbp), %rdi
callq 0x2100
leaq -0x120(%rbp), %rdi
callq 0x42aa
movl %ebx, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x2100
jmp 0x3331
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x2100
jmp 0x3374
jmp 0x3348
jmp 0x3348
jmp 0x3348
jmp 0x3348
jmp 0x337f
jmp 0x3348
movq %rax, %rbx
jmp 0x3374
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
jmp 0x3378
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
jmp 0x3386
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
jmp 0x3392
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x43f6
leaq -0x58(%rbp), %rdi
callq 0x2100
jmp 0x3382
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x2100
leaq -0x98(%rbp), %rdi
callq 0x2100
jmp 0x339e
jmp 0x339b
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x42aa
movq %rbx, %rdi
callq 0x2330