// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x88d0
movl 0x8(%rbx), %eax
cmpq $0x5, %rax
ja 0x62dd
leaq 0xdfa2(%rip), %rcx      # 0x14008
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0x28(%rbx)
jle 0x640f
movq 0x16f70(%rip), %rbx     # 0x1cff0
leaq 0xe225(%rip), %rsi      # 0x142ac
movl $0x42, %edx
jmp 0x673e
movl 0x28(%rbx), %eax
testl %eax, %eax
je 0x6328
cmpl $-0x1, %eax
jne 0x6385
movq 0x16f04(%rip), %r14     # 0x1cfb0
leaq 0xe127(%rip), %rsi      # 0x141da
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 0x67ca
testb %al, %al
je 0x6334
leaq 0xe177(%rip), %rsi      # 0x14275
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 0x62ce
movq 0x16e72(%rip), %r15     # 0x1cfb0
leaq 0xdfd8(%rip), %rsi      # 0x1411d
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 0x67ca
testb %al, %al
je 0x62f5
movq %r12, 0x28(%rsp)
leaq 0x10(%rsp), %r12
movq 0x16e3e(%rip), %r13     # 0x1cfd8
movq %rsp, %rbp
movq %r12, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
movl $0x22, %edx
movq %r15, %rdi
leaq 0xdf95(%rip), %rsi      # 0x14153
callq 0x5450
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x53b0
movsbl %al, %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x5670
movq %rbp, %rdi
leaq 0xfec6(%rip), %rsi      # 0x160b6
callq 0x50f0
testl %eax, %eax
je 0x6267
movq %rbp, %rdi
leaq 0xdf73(%rip), %rsi      # 0x14176
callq 0x50f0
testl %eax, %eax
je 0x6267
movq %rbp, %rdi
leaq 0xdf63(%rip), %rsi      # 0x14179
callq 0x50f0
testl %eax, %eax
je 0x6267
movq %rbp, %rdi
leaq 0xdfa9(%rip), %rsi      # 0x141d2
callq 0x50f0
movl $0x3, %r14d
testl %eax, %eax
je 0x62a8
movq %rbp, %rdi
leaq 0xdf92(%rip), %rsi      # 0x141d4
callq 0x50f0
testl %eax, %eax
je 0x62a8
movq %rbp, %rdi
leaq 0xdf83(%rip), %rsi      # 0x141d8
callq 0x50f0
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leal (%rcx,%rcx,2), %r14d
jmp 0x62a8
movl $0x56, %edx
movq %r15, %rdi
leaq 0xdf05(%rip), %rsi      # 0x1417b
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, %r14d
movq %rax, %rdi
callq 0x5260
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x62b6
callq 0x5390
testl %r14d, %r14d
je 0x619d
cmpl $0x3, %r14d
movq 0x28(%rsp), %r12
jne 0x676d
cmpl $0x3, 0x8(%rbx)
je 0x638c
jmp 0x640f
movq 0x16d0c(%rip), %rbx     # 0x1cff0
leaq 0xe004(%rip), %rsi      # 0x142ef
movl $0x2a, %edx
jmp 0x673e
leaq 0xde3b(%rip), %rsi      # 0x14137
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 0x6760
movl $0x4, 0x8(%rbx)
jmp 0x640f
cmpl $0x1, 0x8(%rbx)
jne 0x6362
movq 0x16caf(%rip), %rbx     # 0x1cff0
leaq 0xdeda(%rip), %rsi      # 0x14222
movl $0x2a, %edx
movq %rbx, %rdi
callq 0x5450
movq %rbx, %rdi
callq 0x5190
jmp 0x676d
movq 0x16c47(%rip), %r14     # 0x1cfb0
leaq 0xdedd(%rip), %rsi      # 0x1424d
movl $0x27, %edx
movq %r14, %rdi
callq 0x5450
movq %r14, %rdi
callq 0x5190
movl $0x3, 0x8(%rbx)
movq 0x16c1d(%rip), %r14     # 0x1cfb0
leaq 0xdf80(%rip), %rsi      # 0x1431a
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 0x5bf8
movq (%rbx), %r14
movq %r14, %rdi
callq 0x897c
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x121fe
movq %r14, %rdi
movq %r15, %rsi
callq 0x8982
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x640f
callq 0x5390
cmpl $-0x1, 0xc(%rbx)
je 0x6459
movq 0x16b94(%rip), %r14     # 0x1cfb0
leaq 0xdf79(%rip), %rsi      # 0x1439c
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
jmp 0x64af
movq 0x16b50(%rip), %r14     # 0x1cfb0
leaq 0xdef8(%rip), %rsi      # 0x1435f
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 0x8bea
cmpl $-0x1, %eax
je 0x672b
movl %eax, 0xc(%rbx)
movq 0x16afa(%rip), %r15     # 0x1cfb0
leaq 0xdf03(%rip), %rsi      # 0x143c0
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 0xdee0(%rip), %rsi      # 0x143cd
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 0x88d0
leaq 0xdefb(%rip), %rsi      # 0x1442f
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 0x6585
movq (%rbx), %rsi
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movl $0x1, %edx
jmp 0x659a
testl %eax, %eax
jne 0x66eb
movq (%rbx), %rsi
leaq 0x70(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
callq 0x9750
movq 0x20(%rbx), %rax
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x20(%rbx)
movups 0x10(%rbx), %xmm1
movups %xmm0, 0x10(%rbx)
movq %rsp, %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x7dda
movq %r14, %rdi
callq 0x7dda
movq 0x18(%rbx), %rax
cmpq 0x10(%rbx), %rax
setne %cl
movl 0x8(%rbx), %eax
cmpl $0x1, %eax
sete %dl
orb %cl, %dl
je 0x66d6
cmpl $0x1, %eax
je 0x6675
leaq 0xdeb6(%rip), %rsi      # 0x144bb
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 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x7f0e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x708e
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x6675
callq 0x5390
movq %rbx, %rdi
callq 0x768a
movq (%rbx), %rdi
callq 0x8916
movq %rsp, %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7e20
movq (%rbx), %rdi
cmpq %rdi, 0x8(%rbx)
je 0x66c5
movl $0x1, %ebx
xorl %eax, %eax
movq (%rdi,%rax,8), %rdi
callq 0x10c7c
movl %ebx, %eax
movq (%rsp), %rdi
movq 0x8(%rsp), %rcx
subq %rdi, %rcx
sarq $0x3, %rcx
incl %ebx
cmpq %rax, %rcx
ja 0x66a3
testq %rdi, %rdi
je 0x66cf
callq 0x5390
movb $0x1, %al
jmp 0x676f
movq 0x16913(%rip), %rbx     # 0x1cff0
leaq 0xdda5(%rip), %rsi      # 0x14489
movl $0x31, %edx
jmp 0x673e
leaq 0xdd5f(%rip), %rsi      # 0x14451
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
jmp 0x65dd
movq 0x168be(%rip), %rbx     # 0x1cff0
leaq 0xdc97(%rip), %rsi      # 0x143d0
movl $0x5e, %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 %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
jne 0x67bd
jmp 0x67c2
movq %rax, %rbx
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x67bd
jmp 0x67c2
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
jne 0x67bd
jmp 0x67c2
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x67c2
callq 0x5390
movq %rbx, %rdi
callq 0x5650