// File: /workspace/github_c_makefile_star2_O1/fabiovila[P]fs2ch/fs2ch.cpp
// Function: main
int main(int argc, char *argv[])
{
	
  std::vector <stFile> Files;
  stFile tFiles;
  char chBuffer[100];
  string path;
  string outputname;
  MIMELIST = mime();
  
  if (argc <= 1) {
	  boost::filesystem::path cpath(boost::filesystem::current_path());	
	  path = cpath.string();
	} else {
		path = argv[1];
	}

   if (argc == 3){
	   outputname = argv[2];
	   
   } else outputname = "out.h";
  cout << "Input directory \e[92m" << path << "\e[0m\n";
  cout << "Output file as \e[92m" << outputname << "\e[0m\n";
  cout << "\e[1mMounting the filesystem ..." << "\e[0m\n";
  listfolder(path);
  
  for (std::vector<std::string>::const_iterator i = List.begin(); i != List.end(); ++i){
	if (!boost::filesystem::is_regular_file(*i)) continue; // Opened files return undefined length 
		std::ifstream file(*i, std::ios::binary );
		if (file) {
					// Get file size
					std::uintmax_t  length = boost::filesystem::file_size(*i);
					// Alloc buffer
					//cout << *i << " " << length << " " << boost::filesystem::is_regular_file(*i) << " " << boost::filesystem::file_size(*i);
					char * buffer = new char [length];
					// Read and store name and size
					file.read(buffer,length);
						tFiles.name = *i;
						// clear path
						tFiles.name = tFiles.name.substr(path.size(),tFiles.name.size());
						tFiles.mime = getmime(tFiles.name);
						tFiles.bytes = buffer;
						tFiles.size = length;					  
						Files.push_back(tFiles);
					file.close();
		} else exit(1);
	} 

	// Create out.h 
	 std::ofstream out(outputname);
	 int index = 0, a = 0;
	 cout << " Creating \e[92m"<< outputname << "\e[0m file ... \n";
	 out << "typedef struct { const char *name; const char *mime; int size; const unsigned char *data; } stFile;\n";
	 out << "#define FS_FILES	" << Files.size() << "\n";

	 
	 index = 0;
	 for (std::vector<stFile>::iterator i = Files.begin(); i != Files.end(); ++i) {
		 out << "// " << index << " : " << i->name  << " " << i->mime << " " << i->size << "\n";
		 index++;
	 }
	 
	 
	 out << "\n\nconst volatile stFile fsFiles[" << Files.size() <<"] = { "; 
	 

	 for (std::vector<stFile>::iterator i = Files.begin(); i != Files.end(); ++i){
		 cout << " " << i->name << "\n";
		 
		 out << "{\"" << i->name << "\" , ";
		 out << "\"" << i->mime << "\" , ";
		 out << i->size << ", ";
		 out << "(const unsigned char*)\""; 
			for (a = 0; a < i->size; a++) {
				out << dec2hex[(unsigned char) i->bytes[a]];	
			}
		if ( Files.end() - i == 1 ) out << "\"}"; else out << "\"}, "; 		
		 
	 }
	out << "};"; 
	out.close();
	cout << "\n\e[1mFiles embedded: " << Files.size() <<  " in struct: \e[0m\n";
	cout << " \e[96mstruct {\n  const char *name; \n  const char *mime; \n  int size; \n  const unsigned char *data;\n };\e[0m\n";
	cout << "\n\e[1mInclude \e[92m" << outputname <<  "\e[0m in your application and use fsFiles["<< Files.size() << "]\n\n\n\e[0m";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rsi, %rbx
movl %edi, %r14d
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
xorl %eax, %eax
movq %rax, -0x30(%rbp)
leaq -0x110(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xe0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x90(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x50(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x328(%rbp), %rdi
callq 0x5873
leaq 0xe3dc(%rip), %rdi      # 0x131e0
callq 0xb9e8
movq -0x318(%rbp), %rax
testq %rax, %rax
je 0x4e5e
leaq -0x320(%rbp), %rcx
movl (%rcx), %edx
movl %edx, 0xe3c4(%rip)      # 0x131e8
leaq 0xe3bd(%rip), %rdx      # 0x131e8
movq %rax, 0xe3be(%rip)      # 0x131f0
movups 0x10(%rcx), %xmm0
movups %xmm0, 0xe3bb(%rip)     # 0x131f8
movq %rdx, 0x8(%rax)
movq 0x20(%rcx), %rax
movq %rax, 0xe3bc(%rip)      # 0x13208
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0x328(%rbp), %rdi
callq 0xb840
cmpl $0x1, %r14d
jg 0x4eb2
leaq -0x328(%rbp), %rdi
xorl %esi, %esi
callq 0x21c0
leaq -0xa0(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x2110
leaq -0x318(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4edd
movq -0x318(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x4edd
movq 0x8(%rbx), %r15
leaq -0xa0(%rbp), %r12
movq 0x8(%r12), %r13
movq %r15, %rdi
callq 0x20e0
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %rax, %r8
callq 0x22a0
cmpl $0x3, %r14d
jne 0x4f0c
movq 0x10(%rbx), %rbx
leaq -0x60(%rbp), %r14
movq 0x8(%r14), %r15
movq %rbx, %rdi
callq 0x20e0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x22a0
jmp 0x4f28
leaq -0x60(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x8142(%rip), %rcx      # 0xd05d
movl $0x5, %r8d
xorl %esi, %esi
callq 0x22a0
movq 0xe0a9(%rip), %rdi      # 0x12fd8
leaq 0x812d(%rip), %rsi      # 0xd063
movl $0x15, %edx
callq 0x2200
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq 0xe083(%rip), %rdi      # 0x12fd8
callq 0x2200
leaq 0x8261(%rip), %rsi      # 0xd1c2
movl $0x5, %edx
movq %rax, %rdi
callq 0x2200
movq 0xe063(%rip), %rdi      # 0x12fd8
leaq 0x80fd(%rip), %rsi      # 0xd079
movl $0x14, %edx
callq 0x2200
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0xe043(%rip), %rdi      # 0x12fd8
callq 0x2200
leaq 0x8221(%rip), %rsi      # 0xd1c2
movl $0x5, %edx
movq %rax, %rdi
callq 0x2200
movq 0xe023(%rip), %rdi      # 0x12fd8
leaq 0x80d2(%rip), %rsi      # 0xd08e
movl $0x1f, %edx
callq 0x2200
movq 0xe00b(%rip), %rdi      # 0x12fd8
leaq 0x81ee(%rip), %rsi      # 0xd1c2
movl $0x5, %edx
callq 0x2200
leaq -0xa0(%rbp), %rdi
callq 0x4c2b
movq 0xe1d7(%rip), %rbx      # 0x131c8
cmpq 0xe1d8(%rip), %rbx      # 0x131d0
je 0x522c
leaq -0x328(%rbp), %r15
leaq -0x80(%rbp), %r13
leaq -0xc8(%rbp), %r14
leaq -0x318(%rbp), %rax
movq %rax, -0x328(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0xba20
movq %r14, %r12
movq %r13, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2280
movl -0x80(%rbp), %r14d
movq -0x328(%rbp), %rdi
leaq -0x318(%rbp), %rax
cmpq %rax, %rdi
je 0x5066
movq -0x318(%rbp), %rsi
incq %rsi
callq 0x21d0
cmpl $0x2, %r14d
movq %r12, %r14
jne 0x521b
movq %r15, %rdi
movq %rbx, %rsi
movl $0x4, %edx
callq 0x22b0
movq -0x328(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x308(%rbp,%rax)
jne 0x5762
leaq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xba20
movq %r13, %rdi
xorl %esi, %esi
callq 0x2240
movq %rax, %r14
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x50dc
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x21d0
movq %r14, %rdi
callq 0x2030
movq %rax, -0xa8(%rbp)
movq %r15, %rdi
movq -0xa8(%rbp), %rsi
movq %r14, %rdx
callq 0x2230
leaq -0x120(%rbp), %rdi
movq %rbx, %rsi
callq 0x2110
movq %r14, -0xd0(%rbp)
movq %r15, %r14
movq -0x98(%rbp), %rdx
movq -0x118(%rbp), %rcx
movq %r13, %rdi
leaq -0x120(%rbp), %r15
movq %r15, %rsi
callq 0x21e0
movq %r15, %rdi
movq %r13, %rsi
callq 0x2220
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x515a
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0xba20
movq %r14, %r15
leaq -0x80(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x4b2c
movq %r12, %r14
leaq -0xf0(%rbp), %rdi
movq %r13, %rsi
callq 0x2220
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x51be
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x51e0
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0xa8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xd0(%rbp), %rax
movl %eax, -0xf8(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x8d64
movq %r15, %rdi
callq 0x2060
movq %r15, %rdi
callq 0x2070
addq $0x20, %rbx
cmpq 0xdfaa(%rip), %rbx      # 0x131d0
jne 0x5010
leaq -0x328(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x10, %edx
callq 0x2300
movq 0xdd90(%rip), %rdi      # 0x12fd8
leaq 0x7e5f(%rip), %rsi      # 0xd0ae
movl $0xf, %edx
callq 0x2200
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0xdd70(%rip), %rdi      # 0x12fd8
callq 0x2200
leaq 0x7e4a(%rip), %rsi      # 0xd0be
movl $0xf, %edx
movq %rax, %rdi
callq 0x2200
leaq 0x7e46(%rip), %rsi      # 0xd0ce
leaq -0x328(%rbp), %rdi
movl $0x64, %edx
callq 0x2200
leaq 0x7e93(%rip), %rsi      # 0xd133
leaq -0x328(%rbp), %rdi
movl $0x11, %edx
callq 0x2200
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x4, %rsi
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rsi
leaq -0x328(%rbp), %rdi
callq 0x2140
leaq 0x7dee(%rip), %rsi      # 0xd0cc
movl $0x1, %edx
movq %rax, %rdi
callq 0x2200
movq -0x40(%rbp), %r14
cmpq -0x38(%rbp), %r14
je 0x53b3
xorl %ebx, %ebx
leaq -0x328(%rbp), %r15
leaq 0x7e72(%rip), %r13      # 0xd17b
movl $0x3, %edx
movq %r15, %rdi
leaq 0x7e2d(%rip), %rsi      # 0xd145
callq 0x2200
movq %r15, %rdi
movl %ebx, %esi
callq 0x22d0
movq %rax, %r12
movl $0x3, %edx
movq %rax, %rdi
leaq 0x7e10(%rip), %rsi      # 0xd149
callq 0x2200
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r12, %rdi
callq 0x2200
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2200
movq 0x30(%r14), %rsi
movq 0x38(%r14), %rdx
movq %r12, %rdi
callq 0x2200
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2200
movl 0x28(%r14), %esi
movq %r12, %rdi
callq 0x22d0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7d2e(%rip), %rsi      # 0xd0cc
callq 0x2200
incl %ebx
addq $0x50, %r14
cmpq -0x38(%rbp), %r14
jne 0x5309
leaq 0x7d93(%rip), %rsi      # 0xd14d
leaq -0x328(%rbp), %rdi
movl $0x20, %edx
callq 0x2200
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x4, %rsi
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rsi
leaq -0x328(%rbp), %rdi
callq 0x2140
leaq 0x7d76(%rip), %rsi      # 0xd16e
movl $0x6, %edx
movq %rax, %rdi
callq 0x2200
movq -0x40(%rbp), %r12
cmpq -0x38(%rbp), %r12
je 0x5589
movq 0xdbbe(%rip), %rbx      # 0x12fd8
leaq -0x328(%rbp), %r13
leaq 0x7d50(%rip), %r14      # 0xd178
leaq 0xdde1(%rip), %r15      # 0x13210
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x7d3d(%rip), %rsi      # 0xd17b
callq 0x2200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %rbx, %rdi
callq 0x2200
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7c69(%rip), %rsi      # 0xd0cc
callq 0x2200
movl $0x2, %edx
movq %r13, %rdi
leaq 0x7cfe(%rip), %rsi      # 0xd175
callq 0x2200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r13, %rdi
callq 0x2200
movl $0x4, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2200
movl $0x1, %edx
movq %r13, %rdi
leaq 0x7ce7(%rip), %rsi      # 0xd193
callq 0x2200
movq 0x30(%r12), %rsi
movq 0x38(%r12), %rdx
movq %r13, %rdi
callq 0x2200
movl $0x4, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2200
movl 0x28(%r12), %esi
movq %r13, %rdi
callq 0x22d0
movl $0x2, %edx
movq %rax, %rdi
leaq 0x7c8b(%rip), %rsi      # 0xd17a
callq 0x2200
movl $0x17, %edx
movq %r13, %rdi
leaq 0x7c7a(%rip), %rsi      # 0xd17d
callq 0x2200
movq %rbx, %r14
cmpl $0x0, 0x28(%r12)
jle 0x553f
xorl %ebx, %ebx
movq 0x20(%r12), %rax
movzbl (%rax,%rbx), %eax
shll $0x5, %eax
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq %r13, %rdi
callq 0x2200
incq %rbx
movslq 0x28(%r12), %rax
cmpq %rax, %rbx
jl 0x5515
movq -0x38(%rbp), %rax
subq %r12, %rax
xorl %ecx, %ecx
cmpq $0x50, %rax
setne %cl
leaq 0x7c42(%rip), %rsi      # 0xd198
leaq 0x7c38(%rip), %rax      # 0xd195
cmoveq %rax, %rsi
leaq 0x2(,%rcx,2), %rdx
movq %r13, %rdi
callq 0x2200
movq %r14, %rbx
leaq 0x7bfd(%rip), %r14      # 0xd178
addq $0x50, %r12
cmpq -0x38(%rbp), %r12
jne 0x542f
leaq 0x7c0d(%rip), %rsi      # 0xd19d
leaq -0x328(%rbp), %rdi
movl $0x2, %edx
callq 0x2200
leaq -0x328(%rbp), %rdi
callq 0x2250
movq 0xda24(%rip), %rdi      # 0x12fd8
leaq 0x7be5(%rip), %rsi      # 0xd1a0
movl $0x15, %edx
callq 0x2200
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x4, %rsi
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rsi
movq 0xd9f2(%rip), %rdi      # 0x12fd8
callq 0x2140
leaq 0x7bc4(%rip), %rsi      # 0xd1b6
movl $0x11, %edx
movq %rax, %rdi
callq 0x2200
movq 0xd9d2(%rip), %rdi      # 0x12fd8
leaq 0x7bbb(%rip), %rsi      # 0xd1c8
movl $0x6b, %edx
callq 0x2200
movq 0xd9ba(%rip), %rdi      # 0x12fd8
leaq 0x7c0f(%rip), %rsi      # 0xd234
movl $0x12, %edx
callq 0x2200
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0xd99a(%rip), %rdi      # 0x12fd8
callq 0x2200
movq %rax, %rbx
leaq 0x7bfa(%rip), %rsi      # 0xd247
movl $0x29, %edx
movq %rax, %rdi
callq 0x2200
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x4, %rsi
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rsi
movq %rbx, %rdi
callq 0x2140
leaq 0x7bee(%rip), %rsi      # 0xd271
movl $0x8, %edx
movq %rax, %rdi
callq 0x2200
movq 0xd939(%rip), %rax      # 0x12fd0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x320(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x328(%rbp,%rcx)
callq 0x2190
leaq -0x230(%rbp), %rdi
callq 0x20b0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x56df
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x5701
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x5723
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x5745
movq -0x110(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x40(%rbp), %rdi
callq 0x8de2
xorl %eax, %eax
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x2210
movq %rax, %rbx
leaq -0x318(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x57df
jmp 0x57c9
jmp 0x57c9
jmp 0x57c9
jmp 0x57c9
jmp 0x57f7
jmp 0x57f7
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x57fa
movq -0xb8(%rbp), %rsi
jmp 0x57bb
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x57fa
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x57fa
jmp 0x57f7
jmp 0x57c9
movq %rax, %rbx
jmp 0x581b
movq %rax, %rbx
movq -0x328(%rbp), %rdi
leaq -0x318(%rbp), %rax
cmpq %rax, %rdi
je 0x581b
movq -0x318(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x581b
jmp 0x580c
movq %rax, %rbx
leaq -0x328(%rbp), %rdi
callq 0x2070
jmp 0x581b
jmp 0x580c
jmp 0x580c
movq %rax, %rbx
leaq -0x328(%rbp), %rdi
callq 0x2270
leaq -0x50(%rbp), %rax
movq -0x60(%rbp), %rdi
cmpq %rax, %rdi
je 0x5834
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x21d0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x5856
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x120(%rbp), %rdi
callq 0x8d9c
leaq -0x40(%rbp), %rdi
callq 0x8de2
movq %rbx, %rdi
callq 0x22e0