// File: /workspace/github_cpp_makefile_star2_O1/lrq3000[P]rfrb/./src/raidSystem.cpp
// Function: RaidSystem::raidCheck(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool RaidSystem::raidCheck(std::string path)
{
	bool found = false;
	//No RAID level is chosen from the user
	handle->setBlockSize(CHECKSIZE);
	if (raidSystem == Raid_unknown)
	{
		std::cout << "Starting with Raid check." << std::endl;
		//Calling easyCheck() to estimate RAID level
		found = easyCheck();
		if (found == false)
		{
			//Something went wrong
			std::cout << "No valid Raid system found!" << std::endl;
			return false;
		}
		else
		{
			while (true)
			{
				//RAID level found
				std::string answer;
				std::cout << "Do you want to accept this? [y/n] ";
				std::getline(std::cin, answer);
				if (answer == "n" || answer == "No" || answer == "N")
				{
					std::cout << "Raid system can not be estimated automatically. Must be handed with the program start." << std::endl;
					return false;
				}
				else if (answer == "y" || answer == "Yes" || answer == "Y")
				{
					break;
				}
			}
		}
	}
	else if (raidSystem == Raid5_user)
	{
		//RAID5 was chosen

		//It was not set, if an image is lost
		if (lostImages == -1)
		{
			std::cout << "User input: Raid 5! Checking for lost discs or if it's a Raid 1 system." << std::endl;
			//Check if user was right
			found = easyCheck();
			if (found == false)
			{
				if (raidSystem == Raid1)
				{
					//User was wrong, we think it's RAID1.
					std::cerr << "User input wrong. Estimated Raid 1 system!" << std::endl;
					return false;
				}
				else
				{
					//User was right with RAID5, but an image is lost.
					std::cout << "Discs missing. Will recover disc later!" << std::endl;
					raidSystem = Raid5_incomplete;
				}
				found = true;
			}
			else
			{
				//Complete RAID5 was found. No image must be recovered
				std::cout << "Raid 5 system is complete. No missing discs indicated!" << std::endl;
			}
		}
		else if (lostImages == 0)
		{
			//User says that no image is missing
			raidSystem = Raid5_complete;
			found = true;
		}
		else
		{
			//User says that at least one image is missing
			raidSystem = Raid5_incomplete;
			found = true;
		}
	}
	else if (raidSystem == Raid1)
	{
		//User says it's RAID1
		found = true;
	}
	else if (raidSystem == Raid0)
	{
		//User says it's RAID0

		if (lostImages > 0)
		{
			//User says an image is missing. That can't be recovered. We have to abort.
			std::cerr << "User specifies Raid 0 system with lost discs. Cannot be recovered!" << std::endl;
			return false;
		}
		found = true;
	}

	//Few final checks
	if (found == false)
	{
		//We haven't found one fitting RAID-level.
		std::cerr << "No valid Raid system found! Have to abort!" << std::endl;
		return false;
	}
	if (raidSystem == Raid5_incomplete)
	{
		//RAID5 was found with a missing image. Is recovered here.
		std::cout << "Incomplete Raid 5 system. Will recover disc and mount it internally." << std::endl;
		recoverLostImage();
		handle->addImage(handle->getFileWriter()->getPath());
	}

	//Stripesize estimation
	if (stripeSize == -1)
	{
		//User hasn't specified a stripesize. We has to determine it on our own.
		std::cout << "No Stripesize specified! Trying to calculate Stripesize now." << std::endl;
		found = calculateStripeSize();
	}
	else
	{
		//User specified stripesize
		std::cout << "Using Stripesize specified by user!" << std::endl;
		found = true;
	}

	//Output if stripesize estimation went fine.
	if (found == true)
	{
		std::cout << "Stripesize: " << stripeSize/1024 << "KB" << std::endl;
	}
	else
	{
		std::cerr << "No valid Stripesize found. User should estimate it on its own, or disc could not be recovered." << std::endl;
		return false;
	}
	//For further operations, set blocksize to stripesize.
	handle->setBlockSize(stripeSize);

	//Stripemap estimation
	std::cout << "Trying to estimate the Stripemap." << std::endl;
	if (raidSystem == Raid5_user || raidSystem == Raid5_incomplete || raidSystem == Raid5_complete)
	{
		//RAID5 needs a stripemap and has parity information. That's the call with 'true'
		stripeMap = handle->estimateStripeMap(true);
	}
	else if (raidSystem == Raid0)
	{
		//RAID0 needs a stripemap and has no parity information. That's the call with 'false'
		stripeMap = handle->estimateStripeMap(false);
	}
	else
	{
		//RAID1 needs no stripemap. We're done here.
		std::cout << "No need to estimate Stripemap because of Raid 1 system." << std::endl;
		found = true;
	}

	//Final checks if stripemap estimation went fine
	if (stripeMap.size() == 0 && !(raidSystem == Raid1))
	{
		std::cerr << "No valid Stripemap found. Have to abort Recovery." << std::endl;
		return false;
	}
	else if (raidSystem == Raid1)
	{}
	else
	{
		//If everything went fine, the whole imagefile is created
		std::cout << "Rebuild the imagefile out of the Raid discs." << std::endl;
		found = buildDataImage(path);
	}

	//If nothing bad has happened, the results are printed.
	if (found == true)
	{
		printAllInfos();
	}
	std::vector<FileReader *> inFiles = handle->getInFiles();
	for (unsigned int j = 0; j < inFiles.size(); ++j)
	{
		inFiles.at(j)->closeFile();
	}
	return found;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x8906
movl 0x8(%rbx), %eax
cmpq $0x5, %rax
ja 0x62f7
leaq 0xef8c(%rip), %rcx      # 0x15008
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0x28(%rbx)
jle 0x63a2
movq 0x18f5a(%rip), %rbx     # 0x1eff0
leaq 0xf20f(%rip), %rsi      # 0x152ac
movl $0x42, %edx
jmp 0x674c
movl 0x28(%rbx), %eax
testl %eax, %eax
je 0x6342
cmpl $-0x1, %eax
jne 0x639a
movq 0x18eee(%rip), %r14     # 0x1efb0
leaq 0xf111(%rip), %rsi      # 0x151da
movl $0x47, %edx
movq %r14, %rdi
callq 0x5450
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
movq %rbx, %rdi
callq 0x6820
testb %al, %al
je 0x6349
movl %eax, %ebp
leaq 0xf15f(%rip), %rsi      # 0x15275
movl $0x36, %edx
movq %r14, %rdi
callq 0x5450
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
jmp 0x62ee
movq 0x18e5a(%rip), %r15     # 0x1efb0
leaq 0xefc0(%rip), %rsi      # 0x1511d
movl $0x19, %edx
movq %r15, %rdi
callq 0x5450
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
movq %rbx, %rdi
callq 0x6820
testb %al, %al
je 0x630f
movb %al, 0xf(%rsp)
movq %r12, 0x38(%rsp)
leaq 0x20(%rsp), %r12
movq 0x18e22(%rip), %r13     # 0x1efd8
leaq 0x10(%rsp), %r14
movq %r12, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movl $0x22, %edx
movq %r15, %rdi
leaq 0xef76(%rip), %rsi      # 0x15153
callq 0x5450
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x5670
movq %r14, %rdi
leaq 0x11396(%rip), %rsi     # 0x175a5
callq 0x50f0
testl %eax, %eax
je 0x6284
movq %r14, %rdi
leaq 0xef54(%rip), %rsi      # 0x15176
callq 0x50f0
testl %eax, %eax
je 0x6284
movq %r14, %rdi
leaq 0xef44(%rip), %rsi      # 0x15179
callq 0x50f0
testl %eax, %eax
je 0x6284
movq %r14, %rdi
leaq 0xef8a(%rip), %rsi      # 0x151d2
callq 0x50f0
movl $0x3, %ebp
testl %eax, %eax
je 0x62c4
movq %r14, %rdi
leaq 0xef74(%rip), %rsi      # 0x151d4
callq 0x50f0
testl %eax, %eax
je 0x62c4
movq %r14, %rdi
leaq 0xef65(%rip), %rsi      # 0x151d8
callq 0x50f0
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leal (%rcx,%rcx,2), %ebp
jmp 0x62c4
movl $0x56, %edx
movq %r15, %rdi
leaq 0xeee8(%rip), %rsi      # 0x1517b
callq 0x5450
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x5260
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x62d3
callq 0x5390
testl %ebp, %ebp
je 0x61bb
cmpl $0x3, %ebp
jne 0x677b
movq 0x38(%rsp), %r12
movb 0xf(%rsp), %bpl
testb %bpl, %bpl
jne 0x63a2
movq 0x18cf2(%rip), %rbx     # 0x1eff0
leaq 0xefea(%rip), %rsi      # 0x152ef
movl $0x2a, %edx
jmp 0x674c
leaq 0xee21(%rip), %rsi      # 0x15137
movl $0x1b, %edx
movq %r15, %rdi
callq 0x5450
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r15, %rdi
jmp 0x676e
movl $0x4, %eax
jmp 0x639f
cmpl $0x1, 0x8(%rbx)
jne 0x6377
movq 0x18c9a(%rip), %rbx     # 0x1eff0
leaq 0xeec5(%rip), %rsi      # 0x15222
movl $0x2a, %edx
movq %rbx, %rdi
callq 0x5450
movq %rbx, %rdi
callq 0x5190
jmp 0x677b
movq 0x18c32(%rip), %r14     # 0x1efb0
leaq 0xeec8(%rip), %rsi      # 0x1524d
movl $0x27, %edx
movq %r14, %rdi
callq 0x5450
movq %r14, %rdi
callq 0x5190
movl $0x3, %eax
movl %eax, 0x8(%rbx)
cmpl $0x3, 0x8(%rbx)
jne 0x642f
movq 0x18bfd(%rip), %r14     # 0x1efb0
leaq 0xef60(%rip), %rsi      # 0x1531a
movl $0x44, %edx
movq %r14, %rdi
callq 0x5450
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
movq %rbx, %rdi
callq 0x5c08
movq (%rbx), %r14
movq %r14, %rdi
callq 0x89b2
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x12f3a
movq %r14, %rdi
movq %r15, %rsi
callq 0x89b8
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x642f
callq 0x5390
cmpl $-0x1, 0xc(%rbx)
je 0x647c
movq 0x18b74(%rip), %r14     # 0x1efb0
leaq 0xef59(%rip), %rsi      # 0x1539c
movl $0x23, %edx
movq %r14, %rdi
callq 0x5450
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
movb $0x1, %bpl
jmp 0x64d5
movq 0x18b2d(%rip), %r14     # 0x1efb0
leaq 0xeed5(%rip), %rsi      # 0x1535f
movl $0x3c, %edx
movq %r14, %rdi
callq 0x5450
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
movq (%rbx), %rdi
callq 0x8c34
cmpl $-0x1, %eax
je 0x64ce
movl %eax, 0xc(%rbx)
cmpl $-0x1, %eax
setne %bpl
testb %bpl, %bpl
je 0x65b7
movq 0x18acb(%rip), %r15     # 0x1efb0
leaq 0xeed4(%rip), %rsi      # 0x153c0
movl $0xc, %edx
movq %r15, %rdi
callq 0x5450
movl 0xc(%rbx), %eax
leal 0x3ff(%rax), %esi
testl %eax, %eax
cmovnsl %eax, %esi
sarl $0xa, %esi
movq %r15, %rdi
callq 0x5630
movq %rax, %r14
leaq 0xeeb1(%rip), %rsi      # 0x153cd
movl $0x2, %edx
movq %rax, %rdi
callq 0x5450
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
movq (%rbx), %rdi
movslq 0xc(%rbx), %rsi
callq 0x8906
leaq 0xeecc(%rip), %rsi      # 0x1542f
movl $0x21, %edx
movq %r15, %rdi
callq 0x5450
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
movl 0x8(%rbx), %eax
leal -0x2(%rax), %ecx
cmpl $0x3, %ecx
jae 0x65cf
movq (%rbx), %rsi
leaq 0x80(%rsp), %r14
movq %r14, %rdi
movl $0x1, %edx
jmp 0x65e7
movq 0x18a32(%rip), %rbx     # 0x1eff0
leaq 0xee0b(%rip), %rsi      # 0x153d0
movl $0x5e, %edx
jmp 0x674c
testl %eax, %eax
jne 0x6791
movq (%rbx), %rsi
leaq 0x80(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
callq 0x9892
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x10(%rbx), %xmm0
movq 0x20(%rbx), %rax
movaps (%r14), %xmm1
movups %xmm1, 0x10(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x20(%rbx)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%r14)
movq %rcx, 0x10(%r14)
callq 0x7e18
movq %r14, %rdi
callq 0x7e18
movq 0x18(%rbx), %rax
cmpq 0x10(%rbx), %rax
setne %cl
movl 0x8(%rbx), %eax
cmpl $0x1, %eax
sete %dl
orb %cl, %dl
je 0x6739
cmpl $0x1, %eax
je 0x66d5
leaq 0xee59(%rip), %rsi      # 0x154bb
movl $0x2c, %edx
movq %r15, %rdi
callq 0x5450
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x7f46
movq %rbx, %rdi
movq %r14, %rsi
callq 0x70e4
movq 0x40(%rsp), %rdi
movb $0x1, %bpl
cmpq %r15, %rdi
je 0x66d5
callq 0x5390
testb %bpl, %bpl
je 0x66e2
movq %rbx, %rdi
callq 0x76ca
movq (%rbx), %rdi
callq 0x894c
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7e58
movq (%rbx), %rdi
cmpq %rdi, 0x8(%rbx)
je 0x672d
movl $0x1, %ebx
xorl %eax, %eax
movq (%rdi,%rax,8), %rdi
callq 0x116b6
movl %ebx, %eax
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
subq %rdi, %rcx
sarq $0x3, %rcx
incl %ebx
cmpq %rax, %rcx
ja 0x670a
testq %rdi, %rdi
je 0x677d
callq 0x5390
jmp 0x677d
movq 0x188b0(%rip), %rbx     # 0x1eff0
leaq 0xed42(%rip), %rsi      # 0x15489
movl $0x31, %edx
movq %rbx, %rdi
callq 0x5450
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xecb9(%rip), %rsi      # 0x15451
movl $0x37, %edx
movq %r15, %rdi
callq 0x5450
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5260
movb $0x1, %bpl
jmp 0x663a
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
jne 0x6812
jmp 0x6817
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x6812
jmp 0x6817
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
jne 0x6812
jmp 0x6817
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x6817
callq 0x5390
movq %rbx, %rdi
callq 0x5650
nop