// File: /workspace/github_c_makefile_star2_O0/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
subq $0x7d0, %rsp            # imm = 0x7D0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xf660
leaq -0x78(%rbp), %rdi
callq 0xf680
leaq -0x100(%rbp), %rdi
callq 0x3370
leaq -0x120(%rbp), %rdi
callq 0x3370
leaq -0x150(%rbp), %rdi
callq 0xac60
jmp 0xa071
leaq 0x1c218(%rip), %rdi     # 0x26290
leaq -0x150(%rbp), %rsi
callq 0xf6b0
leaq -0x150(%rbp), %rdi
callq 0xf2e0
cmpl $0x1, -0x8(%rbp)
jg 0xa11a
leaq -0x180(%rbp), %rdi
callq 0xf6e0
jmp 0xa0a8
leaq -0x180(%rbp), %rdi
callq 0xf5e0
movq %rax, -0x688(%rbp)
jmp 0xa0bd
movq -0x688(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x3050
jmp 0xa0d2
leaq -0x180(%rbp), %rdi
callq 0xf5f0
jmp 0xa132
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xac21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0xf5f0
jmp 0xac21
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x100(%rbp), %rdi
callq 0x3330
jmp 0xa130
jmp 0xa132
cmpl $0x3, -0x8(%rbp)
jne 0xa150
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x120(%rbp), %rdi
callq 0x3330
jmp 0xa14e
jmp 0xa167
leaq 0x113db(%rip), %rsi     # 0x1b532
leaq -0x120(%rbp), %rdi
callq 0x3330
jmp 0xa165
jmp 0xa167
movq 0x1be6a(%rip), %rdi     # 0x25fd8
leaq 0x113c3(%rip), %rsi     # 0x1b538
callq 0x3250
movq %rax, -0x690(%rbp)
jmp 0xa183
movq -0x690(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x3220
movq %rax, -0x698(%rbp)
jmp 0xa19f
movq -0x698(%rbp), %rdi
leaq 0x114ea(%rip), %rsi     # 0x1b697
callq 0x3250
jmp 0xa1b4
movq 0x1be1d(%rip), %rdi     # 0x25fd8
leaq 0x1138c(%rip), %rsi     # 0x1b54e
callq 0x3250
movq %rax, -0x6a0(%rbp)
jmp 0xa1d0
movq -0x6a0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3220
movq %rax, -0x6a8(%rbp)
jmp 0xa1ec
movq -0x6a8(%rbp), %rdi
leaq 0x1149d(%rip), %rsi     # 0x1b697
callq 0x3250
jmp 0xa201
movq 0x1bdd0(%rip), %rdi     # 0x25fd8
leaq 0x11354(%rip), %rsi     # 0x1b563
callq 0x3250
movq %rax, -0x6b0(%rbp)
jmp 0xa21d
movq -0x6b0(%rbp), %rdi
leaq 0x1146c(%rip), %rsi     # 0x1b697
callq 0x3250
jmp 0xa232
leaq -0x100(%rbp), %rdi
callq 0x9ec0
jmp 0xa240
leaq 0x1c031(%rip), %rdi     # 0x26278
callq 0xf710
movq %rax, -0x190(%rbp)
leaq -0x188(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xf740
leaq 0x1c00b(%rip), %rdi     # 0x26278
callq 0xf7c0
movq %rax, -0x198(%rbp)
leaq -0x188(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0xf780
testb $0x1, %al
jne 0xa295
jmp 0xa58e
leaq -0x188(%rbp), %rdi
callq 0xf820
movq %rax, %rsi
leaq -0x1b8(%rbp), %rdi
callq 0xf410
jmp 0xa2b2
leaq -0x1b8(%rbp), %rdi
callq 0xf7f0
movb %al, -0x6b1(%rbp)
jmp 0xa2c6
movb -0x6b1(%rbp), %al
xorb $-0x1, %al
movb %al, -0x6b2(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0xf5f0
movb -0x6b2(%rbp), %al
testb $0x1, %al
jne 0xa2ec
jmp 0xa314
jmp 0xa56c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0xf5f0
jmp 0xac21
leaq -0x188(%rbp), %rdi
callq 0xf820
movq %rax, %rsi
leaq -0x3c0(%rbp), %rdi
movl $0x4, %edx
callq 0x33e0
jmp 0xa336
movq -0x3c0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x3c0(%rbp,%rax), %rdi
callq 0x3300
movb %al, -0x6b3(%rbp)
jmp 0xa356
movb -0x6b3(%rbp), %al
testb $0x1, %al
jne 0xa365
jmp 0xa556
leaq -0x188(%rbp), %rdi
callq 0xf820
movq %rax, %rsi
leaq -0x3e8(%rbp), %rdi
callq 0xf410
jmp 0xa382
leaq -0x3e8(%rbp), %rdi
callq 0xf840
movq %rax, -0x6c0(%rbp)
jmp 0xa397
leaq -0x3e8(%rbp), %rdi
callq 0xf5f0
movq -0x6c0(%rbp), %rax
movq %rax, -0x3c8(%rbp)
movq -0x3c8(%rbp), %rdi
callq 0x3030
movq %rax, -0x6c8(%rbp)
jmp 0xa3c6
movq -0x6c8(%rbp), %rax
movq %rax, -0x3f0(%rbp)
movq -0x3f0(%rbp), %rsi
movq -0x3c8(%rbp), %rdx
leaq -0x3c0(%rbp), %rdi
callq 0x3310
jmp 0xa3f0
leaq -0x188(%rbp), %rdi
callq 0xf820
movq %rax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x3050
jmp 0xa40a
leaq -0x100(%rbp), %rdi
callq 0x31e0
movq %rax, -0x6d0(%rbp)
leaq -0x78(%rbp), %rdi
movq %rdi, -0x6d8(%rbp)
callq 0x31e0
movq -0x6d8(%rbp), %rsi
movq -0x6d0(%rbp), %rdx
movq %rax, %rcx
leaq -0x410(%rbp), %rdi
callq 0x3290
jmp 0xa44c
leaq -0x78(%rbp), %rdi
movq %rdi, -0x6e0(%rbp)
leaq -0x410(%rbp), %rsi
movq %rsi, -0x6e8(%rbp)
callq 0x32f0
movq -0x6e8(%rbp), %rdi
callq 0x3180
movq -0x6e0(%rbp), %rsi
leaq -0x450(%rbp), %rdi
callq 0x3110
jmp 0xa48b
leaq -0x430(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0x9d70
jmp 0xa4a0
leaq -0x48(%rbp), %rdi
leaq -0x430(%rbp), %rsi
movq %rsi, -0x6f0(%rbp)
callq 0x32f0
movq -0x6f0(%rbp), %rdi
callq 0x3180
leaq -0x450(%rbp), %rdi
callq 0x3180
movq -0x3f0(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x3c8(%rbp), %eax
movl %eax, -0x50(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xf860
jmp 0xa4f2
leaq -0x3c0(%rbp), %rdi
callq 0x3070
jmp 0xa500
jmp 0xa560
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xa57d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x3e8(%rbp), %rdi
callq 0xf5f0
jmp 0xa57d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x3180
jmp 0xa57d
movl $0x1, %edi
callq 0x32e0
leaq -0x3c0(%rbp), %rdi
callq 0x3090
leaq -0x188(%rbp), %rdi
callq 0xf8d0
jmp 0xa266
leaq -0x3c0(%rbp), %rdi
callq 0x3090
jmp 0xac21
leaq -0x650(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movl $0x10, %edx
callq 0x3460
jmp 0xa5a8
movl $0x0, -0x654(%rbp)
movl $0x0, -0x658(%rbp)
movq 0x1ba15(%rip), %rdi     # 0x25fd8
leaq 0x10fb9(%rip), %rsi     # 0x1b583
callq 0x3250
movq %rax, -0x6f8(%rbp)
jmp 0xa5d8
movq -0x6f8(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3220
movq %rax, -0x700(%rbp)
jmp 0xa5f4
movq -0x700(%rbp), %rdi
leaq 0x10f91(%rip), %rsi     # 0x1b593
callq 0x3250
jmp 0xa609
leaq 0x10f93(%rip), %rsi     # 0x1b5a3
leaq -0x650(%rbp), %rdi
callq 0x3250
jmp 0xa61e
leaq 0x10fe3(%rip), %rsi     # 0x1b608
leaq -0x650(%rbp), %rdi
callq 0x3250
movq %rax, -0x708(%rbp)
jmp 0xa63a
leaq -0x28(%rbp), %rdi
callq 0xf8f0
movq -0x708(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, -0x710(%rbp)
jmp 0xa65b
movq -0x710(%rbp), %rdi
leaq 0x10f38(%rip), %rsi     # 0x1b5a1
callq 0x3250
jmp 0xa670
movl $0x0, -0x654(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xf920
movq %rax, -0x660(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xf990
movq %rax, -0x668(%rbp)
leaq -0x660(%rbp), %rdi
leaq -0x668(%rbp), %rsi
callq 0xf950
testb $0x1, %al
jne 0xa6b6
jmp 0xa809
leaq 0x10f5d(%rip), %rsi     # 0x1b61a
leaq -0x650(%rbp), %rdi
callq 0x3250
movq %rax, -0x718(%rbp)
jmp 0xa6d2
movq -0x718(%rbp), %rdi
movl -0x654(%rbp), %esi
callq 0x3420
movq %rax, -0x720(%rbp)
jmp 0xa6ed
movq -0x720(%rbp), %rdi
leaq 0x10f23(%rip), %rsi     # 0x1b61e
callq 0x3250
movq %rax, -0x728(%rbp)
jmp 0xa709
leaq -0x660(%rbp), %rdi
callq 0xf9c0
movq -0x728(%rbp), %rdi
movq %rax, %rsi
callq 0x3220
movq %rax, -0x730(%rbp)
jmp 0xa72d
movq -0x730(%rbp), %rdi
leaq 0x10f15(%rip), %rsi     # 0x1b650
callq 0x3250
movq %rax, -0x738(%rbp)
jmp 0xa749
leaq -0x660(%rbp), %rdi
callq 0xf9c0
movq -0x738(%rbp), %rdi
movq %rax, %rsi
addq $0x30, %rsi
callq 0x3220
movq %rax, -0x740(%rbp)
jmp 0xa771
movq -0x740(%rbp), %rdi
leaq 0x10ed1(%rip), %rsi     # 0x1b650
callq 0x3250
movq %rax, -0x748(%rbp)
jmp 0xa78d
leaq -0x660(%rbp), %rdi
callq 0xf9c0
movq -0x748(%rbp), %rdi
movl 0x28(%rax), %esi
callq 0x3420
movq %rax, -0x750(%rbp)
jmp 0xa7b1
movq -0x750(%rbp), %rdi
leaq 0x10de2(%rip), %rsi     # 0x1b5a1
callq 0x3250
jmp 0xa7c6
movl -0x654(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x654(%rbp)
leaq -0x660(%rbp), %rdi
callq 0xf9e0
jmp 0xa68a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x650(%rbp), %rdi
callq 0x33b0
jmp 0xac21
leaq 0x10e12(%rip), %rsi     # 0x1b622
leaq -0x650(%rbp), %rdi
callq 0x3250
movq %rax, -0x758(%rbp)
jmp 0xa825
leaq -0x28(%rbp), %rdi
callq 0xf8f0
movq -0x758(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, -0x760(%rbp)
jmp 0xa846
movq -0x760(%rbp), %rdi
leaq 0x10def(%rip), %rsi     # 0x1b643
callq 0x3250
jmp 0xa85b
leaq -0x28(%rbp), %rdi
callq 0xf920
movq %rax, -0x670(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xf990
movq %rax, -0x678(%rbp)
leaq -0x670(%rbp), %rdi
leaq -0x678(%rbp), %rsi
callq 0xf950
testb $0x1, %al
jne 0xa897
jmp 0xaacb
movq 0x1b73a(%rip), %rdi     # 0x25fd8
leaq 0x10dab(%rip), %rsi     # 0x1b650
callq 0x3250
movq %rax, -0x768(%rbp)
jmp 0xa8b3
leaq -0x670(%rbp), %rdi
callq 0xf9c0
movq -0x768(%rbp), %rdi
movq %rax, %rsi
callq 0x3220
movq %rax, -0x770(%rbp)
jmp 0xa8d7
movq -0x770(%rbp), %rdi
leaq 0x10cbc(%rip), %rsi     # 0x1b5a1
callq 0x3250
jmp 0xa8ec
leaq 0x10d57(%rip), %rsi     # 0x1b64a
leaq -0x650(%rbp), %rdi
callq 0x3250
movq %rax, -0x778(%rbp)
jmp 0xa908
leaq -0x670(%rbp), %rdi
callq 0xf9c0
movq -0x778(%rbp), %rdi
movq %rax, %rsi
callq 0x3220
movq %rax, -0x780(%rbp)
jmp 0xa92c
movq -0x780(%rbp), %rdi
leaq 0x10d13(%rip), %rsi     # 0x1b64d
callq 0x3250
jmp 0xa941
leaq 0x10d20(%rip), %rsi     # 0x1b668
leaq -0x650(%rbp), %rdi
callq 0x3250
movq %rax, -0x788(%rbp)
jmp 0xa95d
leaq -0x670(%rbp), %rdi
callq 0xf9c0
movq -0x788(%rbp), %rdi
movq %rax, %rsi
addq $0x30, %rsi
callq 0x3220
movq %rax, -0x790(%rbp)
jmp 0xa985
movq -0x790(%rbp), %rdi
leaq 0x10cba(%rip), %rsi     # 0x1b64d
callq 0x3250
jmp 0xa99a
leaq -0x670(%rbp), %rdi
callq 0xf9c0
movl 0x28(%rax), %esi
leaq -0x650(%rbp), %rdi
callq 0x3420
movq %rax, -0x798(%rbp)
jmp 0xa9be
movq -0x798(%rbp), %rdi
leaq 0x10c83(%rip), %rsi     # 0x1b64f
callq 0x3250
jmp 0xa9d3
leaq 0x10c78(%rip), %rsi     # 0x1b652
leaq -0x650(%rbp), %rdi
callq 0x3250
jmp 0xa9e8
movl $0x0, -0x658(%rbp)
movl -0x658(%rbp), %eax
movl %eax, -0x79c(%rbp)
leaq -0x670(%rbp), %rdi
callq 0xf9c0
movq %rax, %rcx
movl -0x79c(%rbp), %eax
cmpl 0x28(%rcx), %eax
jge 0xaa61
leaq -0x670(%rbp), %rdi
callq 0xf9c0
movq 0x20(%rax), %rax
movslq -0x658(%rbp), %rcx
movzbl (%rax,%rcx), %eax
shll $0x5, %eax
leaq 0x1b883(%rip), %rsi     # 0x262c0
addq %rax, %rsi
leaq -0x650(%rbp), %rdi
callq 0x3220
jmp 0xaa4e
jmp 0xaa50
movl -0x658(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x658(%rbp)
jmp 0xa9f2
leaq -0x28(%rbp), %rdi
callq 0xf990
movq %rax, -0x680(%rbp)
leaq -0x680(%rbp), %rdi
leaq -0x670(%rbp), %rsi
callq 0xfa00
cmpq $0x1, %rax
jne 0xaaa1
leaq 0x10bd9(%rip), %rsi     # 0x1b66a
leaq -0x650(%rbp), %rdi
callq 0x3250
jmp 0xaa9f
jmp 0xaab8
leaq 0x10bc5(%rip), %rsi     # 0x1b66d
leaq -0x650(%rbp), %rdi
callq 0x3250
jmp 0xaab6
jmp 0xaab8
jmp 0xaaba
leaq -0x670(%rbp), %rdi
callq 0xf9e0
jmp 0xa86b
leaq 0x10ba0(%rip), %rsi     # 0x1b672
leaq -0x650(%rbp), %rdi
callq 0x3250
jmp 0xaae0
leaq -0x650(%rbp), %rdi
callq 0x3380
jmp 0xaaee
movq 0x1b4e3(%rip), %rdi     # 0x25fd8
leaq 0x10b79(%rip), %rsi     # 0x1b675
callq 0x3250
movq %rax, -0x7a8(%rbp)
jmp 0xab0a
leaq -0x28(%rbp), %rdi
callq 0xf8f0
movq -0x7a8(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, -0x7b0(%rbp)
jmp 0xab2b
movq -0x7b0(%rbp), %rdi
leaq 0x10b52(%rip), %rsi     # 0x1b68b
callq 0x3250
jmp 0xab40
movq 0x1b491(%rip), %rdi     # 0x25fd8
leaq 0x10b4f(%rip), %rsi     # 0x1b69d
callq 0x3250
jmp 0xab55
movq 0x1b47c(%rip), %rdi     # 0x25fd8
leaq 0x10ba6(%rip), %rsi     # 0x1b709
callq 0x3250
movq %rax, -0x7b8(%rbp)
jmp 0xab71
movq -0x7b8(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3220
movq %rax, -0x7c0(%rbp)
jmp 0xab8d
movq -0x7c0(%rbp), %rdi
leaq 0x10b81(%rip), %rsi     # 0x1b71c
callq 0x3250
movq %rax, -0x7c8(%rbp)
jmp 0xaba9
leaq -0x28(%rbp), %rdi
callq 0xf8f0
movq -0x7c8(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, -0x7d0(%rbp)
jmp 0xabca
movq -0x7d0(%rbp), %rdi
leaq 0x10b6e(%rip), %rsi     # 0x1b746
callq 0x3250
jmp 0xabdf
leaq -0x650(%rbp), %rdi
callq 0x33b0
leaq -0x120(%rbp), %rdi
callq 0x3180
leaq -0x100(%rbp), %rdi
callq 0x3180
leaq -0x78(%rbp), %rdi
callq 0xfa50
leaq -0x28(%rbp), %rdi
callq 0xfa80
movl -0x4(%rbp), %eax
addq $0x7d0, %rsp            # imm = 0x7D0
popq %rbp
retq
leaq -0x120(%rbp), %rdi
callq 0x3180
leaq -0x100(%rbp), %rdi
callq 0x3180
leaq -0x78(%rbp), %rdi
callq 0xfa50
leaq -0x28(%rbp), %rdi
callq 0xfa80
movq -0x158(%rbp), %rdi
callq 0x3430
nopw (%rax,%rax)