// File: /workspace/github_cpp_makefile_star2_O2/lrq3000[P]rfrb/./src/main.cpp
// Function: main
int main(int argc, char *argv[])
{
	//Check the Parameters
	std::string inPath;
	std::vector<std::string> paths;
	std::string outPath;
	int raidVersion = 6, stripeSize = -1, lostImages = -1;

	//Too few arguments
	if (argc < 5)
	{
		std::cout << "\"Raid faster - recover better\"(v0.8.0) will recover/rebuild a damaged raidsystem " << std::endl;
		std::cout << "from remaining images. It handles Raid-0, Raid-1 and Raid-5." << std::endl;
		std::cout << "Copyright (C) 2014 crisbi - Christian Zoubek, Sabine Seufert" << std::endl << std::endl;
		std::cerr << "Try: './rfrb [-P PathToImageFolder] [-o PathToOutputFolder] ([-r #RaidVersion] [-s #Stripesize] [-n #NumberOfLostImages])'" << std::endl;
		std::cerr << "or './rfrb [-p PathToImage1] [-p PathToImage2] ... [-o PathToOutputFolder] ([-r #RaidVersion] [-s #Stripesize] [-n #NumberOfLostImages])'" << std::endl;
		return 1;
	}

	bool in = false;
	bool out = false;
	for (int i = 1; i < argc-1; i=i+1)
	{
		std::string input = argv[i];
		if (input.compare("-h") == 0)
		{
			std::cout << "\"Raid faster - recover better\"(v0.8.0) will recover/rebuild a damaged raidsystem " << std::endl;
			std::cout << "from remaining images. It handles Raid-0, Raid-1 and Raid-5." << std::endl;
			std::cout << "Copyright (C) 2014 crisbi - Christian Zoubek, Sabine Seufert" << std::endl << std::endl;
			std::cerr << "Usage 1: './rfrb [-P PathToImageFolder] [-o PathToOutputFolder] ([-r #RaidVersion] [-s #Stripesize] [-n #NumberOfLostImages])'" << std::endl;
			std::cerr << "Usage 2: './rfrb [-p PathToImage1] [-p PathToImage2] ... [-o PathToOutputFolder] ([-r #RaidVersion] [-s #Stripesize] [-n #NumberOfLostImages])'" << std::endl;
			return 1;
		}
		if (input.compare("-P") == 0)
		{
			inPath = argv[i+1];
			in = true;
			std::cout << "Input Folder: " << inPath << std::endl;
		}
		else if (input.compare("-p") == 0)
		{
			paths.push_back(argv[i+1]);
			in = true;
			std::cout << "image: " << argv[i+1] << std::endl;
		}
		else if (input.compare("-o") == 0)
		{
			outPath = argv[i+1];
			out = true;
			std::cout << "Output Folder: " << outPath << std::endl;
		}
		else if (input.compare("-r") == 0)
		{
			raidVersion = atoi(argv[i+1]);
			std::cout << "RaidVersion: " << raidVersion << std::endl;
		}
		else if (input.compare("-s") == 0)
		{
			stripeSize = atoi(argv[i+1]);
			std::cout << "Stripesize: " << stripeSize << std::endl;
		}
		else if (input.compare("-n") == 0)
		{
			lostImages = atoi(argv[i+1]);
			std::cout << "Lost discs: " << lostImages << std::endl;
		}
		else
		{
			continue;
		}
	}

	//Check if input is valid
	if (in == true && out == true && ((inPath.size() > 0 && paths.empty()) || (paths.size()>0 && inPath == "")))
	{
		std::cout << "Valid Input" << std::endl;
	} else
	{
		std::cout << "Not a valid Input. Please try again." << std::endl;
		std::cout << "Please use: './rfrb [-P PathToImageFolder] [-o PathToOutput-Folder]'" << std::endl;
		std::cout << "or: './rfrb [-p PathToImage1] [-p PathToImage2] [-o PathToOutput-Folder]'" << std::endl;
		return 1;
	}

	RaidRecover *raidR;
	if (paths.empty())
	{
		if (!(inPath.at(inPath.size()-1) == '/'))
			inPath+="/";
		if (!(outPath.at(outPath.size()-1) == '/'))
			outPath += "/";
		raidR = new RaidRecover(inPath, outPath);
	}
	else
	{
		raidR = new RaidRecover(paths, outPath);
	}

	//Check if a valid RAID-level was set
	if (raidVersion != 0 && raidVersion != 1 && raidVersion != 5)
	{}
	else
	{
		raidR->setRaid(raidVersion);
	}

	//Stripesize was set
	if (stripeSize >= 0)
	{
		raidR->setStripeSize(stripeSize);
	}

	//Number of lost Images was set
	if (lostImages >= 0)
	{
		raidR->setLostImages(lostImages);
	}

	std::cout << "Interpreted parameters. Now starting to analyse the Raid system." << std::endl;

	//Call the RAID-recovery
	raidR->run();

	return  0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
andq $0x0, 0x30(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movb %cl, (%rax)
cmpl $0x5, %edi
jge 0x1189a
movq 0xc7a3(%rip), %rdi      # 0x1dfb0
leaq 0x3a09(%rip), %rsi      # 0x1521d
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq 0xc788(%rip), %rdi      # 0x1dfb0
leaq 0x3a40(%rip), %rsi      # 0x1526f
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq 0xc76d(%rip), %rdi      # 0x1dfb0
leaq 0x3a62(%rip), %rsi      # 0x152ac
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq %rax, %rdi
callq 0x5180
movq 0xc78a(%rip), %rdi      # 0x1dff0
leaq 0x3a7c(%rip), %rsi      # 0x152e9
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq 0xc76f(%rip), %rdi      # 0x1dff0
leaq 0x3adc(%rip), %rsi      # 0x15364
callq 0x5380
movq %rax, %rdi
callq 0x5180
jmp 0x11cea
movq %rsi, %r15
movl %edi, %r12d
decl %r12d
pushq $-0x1
popq %rax
pushq $0x6
popq %rcx
movl %ecx, 0xc(%rsp)
pushq $0x1
popq %rbp
xorl %ebx, %ebx
leaq 0xf8(%rsp), %r13
leaq 0x118(%rsp), %r14
movl %eax, 0x14(%rsp)
movl %eax, 0x10(%rsp)
movl $0x0, 0x1c(%rsp)
cmpq %rbp, %r12
je 0x11b0a
movq (%r15,%rbp,8), %rsi
movq %r13, %rdi
movq %r14, %rdx
callq 0x5130
movq %r13, %rdi
leaq 0x3afa(%rip), %rsi      # 0x153ee
callq 0x5100
testl %eax, %eax
je 0x11b3b
movq %r13, %rdi
leaq 0x3bf5(%rip), %rsi      # 0x15500
callq 0x5100
testl %eax, %eax
je 0x119c5
movq %r13, %rdi
leaq 0x3bf0(%rip), %rsi      # 0x15512
callq 0x5100
testl %eax, %eax
je 0x119f6
movq %r13, %rdi
leaq 0x3be4(%rip), %rsi      # 0x1551d
callq 0x5100
testl %eax, %eax
je 0x11a57
movq %r13, %rdi
leaq 0x3be0(%rip), %rsi      # 0x15530
callq 0x5100
testl %eax, %eax
je 0x11a96
movq %r13, %rdi
leaq 0x3bda(%rip), %rsi      # 0x15541
callq 0x5100
testl %eax, %eax
je 0x11ad0
movq %r13, %rdi
leaq 0x3bc6(%rip), %rsi      # 0x15544
callq 0x5100
testl %eax, %eax
jne 0x11a47
movq 0x8(%r15,%rbp,8), %rdi
callq 0x5560
movl %eax, 0x10(%rsp)
movq 0xc610(%rip), %rdi      # 0x1dfb0
leaq 0x3ba0(%rip), %rsi      # 0x15547
callq 0x5380
movq %rax, %rdi
movl 0x10(%rsp), %esi
callq 0x55f0
movq %rax, %rdi
callq 0x5180
jmp 0x11a47
movq 0x8(%r15,%rbp,8), %rsi
leaq 0x40(%rsp), %rdi
callq 0x5640
movq 0xc5d5(%rip), %rdi      # 0x1dfb0
leaq 0x3b21(%rip), %rsi      # 0x15503
callq 0x5380
movq %rax, %rdi
leaq 0x40(%rsp), %rsi
callq 0x52f0
jmp 0x11a3d
movq 0x8(%r15,%rbp,8), %rsi
movq %r14, %rdi
leaq 0x1b(%rsp), %rdx
callq 0x5130
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x11f40
movq %r14, %rdi
callq 0x5160
movq 0xc58c(%rip), %rdi      # 0x1dfb0
leaq 0x3aea(%rip), %rsi      # 0x15515
callq 0x5380
movq 0x8(%r15,%rbp,8), %rsi
movq %rax, %rdi
callq 0x5380
movb $0x1, %bl
movq %rax, %rdi
callq 0x5180
movq %r13, %rdi
callq 0x5160
incq %rbp
jmp 0x118d2
movq 0x8(%r15,%rbp,8), %rsi
leaq 0x60(%rsp), %rdi
callq 0x5640
movq 0xc543(%rip), %rdi      # 0x1dfb0
leaq 0x3aac(%rip), %rsi      # 0x15520
callq 0x5380
movq %rax, %rdi
leaq 0x60(%rsp), %rsi
callq 0x52f0
movb $0x1, %cl
movl %ecx, 0x1c(%rsp)
movq %rax, %rdi
callq 0x5180
jmp 0x11a47
movq 0x8(%r15,%rbp,8), %rdi
callq 0x5560
movl %eax, 0xc(%rsp)
movq 0xc505(%rip), %rdi      # 0x1dfb0
leaq 0x3a81(%rip), %rsi      # 0x15533
callq 0x5380
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x55f0
movq %rax, %rdi
callq 0x5180
jmp 0x11a47
movq 0x8(%r15,%rbp,8), %rdi
callq 0x5560
movl %eax, 0x14(%rsp)
movq 0xc4cb(%rip), %rdi      # 0x1dfb0
leaq 0x1894(%rip), %rsi      # 0x13380
callq 0x5380
movq %rax, %rdi
movl 0x14(%rsp), %esi
callq 0x55f0
movq %rax, %rdi
callq 0x5180
jmp 0x11a47
andb 0x1c(%rsp), %bl
testb $0x1, %bl
je 0x11c99
cmpq $0x0, 0x48(%rsp)
je 0x11bdc
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq %rcx, %rax
jne 0x11be6
jmp 0x11c08
movq 0xc46e(%rip), %rdi      # 0x1dfb0
leaq 0x36d4(%rip), %rsi      # 0x1521d
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq 0xc453(%rip), %rdi      # 0x1dfb0
leaq 0x370b(%rip), %rsi      # 0x1526f
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq 0xc438(%rip), %rdi      # 0x1dfb0
leaq 0x372d(%rip), %rsi      # 0x152ac
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq %rax, %rdi
callq 0x5180
movq 0xc455(%rip), %rdi      # 0x1dff0
leaq 0x384f(%rip), %rsi      # 0x153f1
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq 0xc43a(%rip), %rdi      # 0x1dff0
leaq 0x38b3(%rip), %rsi      # 0x15470
callq 0x5380
movq %rax, %rdi
callq 0x5180
leaq 0xf8(%rsp), %rdi
callq 0x5160
jmp 0x11cea
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq %rax, %rcx
je 0x11c99
leaq 0x2dae(%rip), %rsi      # 0x149a4
leaq 0x40(%rsp), %rdi
callq 0x6f43
testb %al, %al
je 0x11c99
movq 0xc3a1(%rip), %rdi      # 0x1dfb0
leaq 0x393e(%rip), %rsi      # 0x15554
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq 0x20(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x11d1f
pushq $0x50
popq %rdi
callq 0x5390
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11eec
leaq 0x98(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x54b0
leaq 0x80(%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %rbx, %rdi
callq 0x115c0
leaq 0x98(%rsp), %rdi
callq 0x5160
leaq 0x80(%rsp), %rdi
callq 0xb920
jmp 0x11dce
movq 0xc310(%rip), %rdi      # 0x1dfb0
leaq 0x38b9(%rip), %rsi      # 0x15560
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq 0xc2f5(%rip), %rdi      # 0x1dfb0
leaq 0x38c3(%rip), %rsi      # 0x15585
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq 0xc2da(%rip), %rdi      # 0x1dfb0
leaq 0x38ed(%rip), %rsi      # 0x155ca
callq 0x5380
movq %rax, %rdi
callq 0x5180
pushq $0x1
popq %rbp
leaq 0x60(%rsp), %rdi
callq 0x5160
leaq 0x20(%rsp), %rdi
callq 0xb920
leaq 0x40(%rsp), %rdi
callq 0x5160
movl %ebp, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%rsp), %rdi
movq 0x8(%rdi), %rsi
decq %rsi
callq 0x5650
cmpb $0x2f, (%rax)
je 0x11d46
leaq 0x38d8(%rip), %rsi      # 0x15614
leaq 0x40(%rsp), %rdi
callq 0x5630
leaq 0x60(%rsp), %rdi
movq 0x8(%rdi), %rsi
decq %rsi
callq 0x5650
cmpb $0x2f, (%rax)
je 0x11d6d
leaq 0x38b1(%rip), %rsi      # 0x15614
leaq 0x60(%rsp), %rdi
callq 0x5630
pushq $0x50
popq %rdi
callq 0x5390
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x54b0
leaq 0xb8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x54b0
leaq 0xd8(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
movq %rbx, %rdi
callq 0x114ba
leaq 0xb8(%rsp), %rdi
callq 0x5160
leaq 0xd8(%rsp), %rdi
callq 0x5160
cmpl $0x5, 0xc(%rsp)
ja 0x11ded
pushq $0x23
popq %rax
movl 0xc(%rsp), %ecx
btl %ecx, %eax
jae 0x11ded
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x116fc
cmpl $0x0, 0x14(%rsp)
js 0x11e00
movq %rbx, %rdi
movl 0x14(%rsp), %esi
callq 0x116e8
cmpl $0x0, 0x10(%rsp)
js 0x11e13
movq %rbx, %rdi
movl 0x10(%rsp), %esi
callq 0x116f2
movq 0xc196(%rip), %rdi      # 0x1dfb0
leaq 0x37f5(%rip), %rsi      # 0x15616
callq 0x5380
movq %rax, %rdi
callq 0x5180
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x11706
jmp 0x11ced
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
callq 0x5160
jmp 0x11e52
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x5160
jmp 0x11e8a
jmp 0x11e87
movq %rax, %r14
leaq 0x98(%rsp), %rdi
callq 0x5160
jmp 0x11e78
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0xb920
jmp 0x11e8a
movq %rax, %r14
movq %rbx, %rdi
callq 0x5360
jmp 0x11ec5
jmp 0x11eb0
jmp 0x11eb0
movq %rax, %r14
leaq 0x118(%rsp), %rdi
callq 0x5160
jmp 0x11eb8
jmp 0x11eb5
jmp 0x11eb5
jmp 0x11eb0
movq %rax, %r14
jmp 0x11ec5
movq %rax, %r14
leaq 0xf8(%rsp), %rdi
callq 0x5160
leaq 0x60(%rsp), %rdi
callq 0x5160
leaq 0x20(%rsp), %rdi
callq 0xb920
leaq 0x40(%rsp), %rdi
callq 0x5160
movq %r14, %rdi
callq 0x5610
nop