// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x7934
movl 0x8(%rbx), %eax
cmpq $0x5, %rax
ja 0x5e20
leaq 0xd36d(%rip), %rcx      # 0x13008
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0x28(%rbx)
jle 0x5f20
movq 0x1833b(%rip), %rdi     # 0x1dff0
leaq 0xd5b0(%rip), %rsi      # 0x1326c
jmp 0x60f1
movl 0x28(%rbx), %eax
testl %eax, %eax
je 0x5e46
cmpl $-0x1, %eax
jne 0x5ec6
movq 0x182d4(%rip), %rdi     # 0x1dfb0
leaq 0xd4b7(%rip), %rsi      # 0x1319a
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq %rbx, %rdi
callq 0x6166
testb %al, %al
je 0x5e92
movq 0x182a9(%rip), %rdi     # 0x1dfb0
leaq 0xd527(%rip), %rsi      # 0x13235
callq 0x5380
movq %rax, %rdi
callq 0x5180
jmp 0x5e87
movq 0x18289(%rip), %rdi     # 0x1dfb0
leaq 0xd3af(%rip), %rsi      # 0x130dd
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq %rbx, %rdi
callq 0x6166
testb %al, %al
je 0x5e33
movq %r12, 0x20(%rsp)
leaq 0xd3bc(%rip), %r12      # 0x13113
movq 0x1827a(%rip), %r13     # 0x1dfd8
movq %rsp, %rbp
leaq 0xf7dd(%rip), %r14      # 0x15545
leaq 0xd3c7(%rip), %r15      # 0x13136
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
andq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
movq 0x18226(%rip), %rdi     # 0x1dfb0
movq %r12, %rsi
callq 0x5380
movq %r13, %rdi
movq %rbp, %rsi
callq 0x5090
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6f43
testb %al, %al
jne 0x5e52
movq %rbp, %rdi
movq %r15, %rsi
callq 0x6f43
testb %al, %al
jne 0x5e52
movq %rbp, %rdi
leaq 0xd36c(%rip), %rsi      # 0x13139
callq 0x6f43
testb %al, %al
jne 0x5e52
movq %rbp, %rdi
leaq 0xd3b2(%rip), %rsi      # 0x13192
callq 0x6f43
testb %al, %al
jne 0x5e7a
movq %rbp, %rdi
leaq 0xd39d(%rip), %rsi      # 0x13194
callq 0x6f43
testb %al, %al
jne 0x5e7a
movq %rbp, %rdi
leaq 0xd38e(%rip), %rsi      # 0x13198
callq 0x6f43
testb %al, %al
jne 0x5e7a
movq %rbp, %rdi
callq 0x5160
jmp 0x5d6f
movq 0x181c9(%rip), %rdi     # 0x1dff0
leaq 0xd481(%rip), %rsi      # 0x132af
jmp 0x60f1
movq 0x18176(%rip), %rdi     # 0x1dfb0
leaq 0xd2b6(%rip), %rsi      # 0x130f7
jmp 0x60f1
movl $0x4, 0x8(%rbx)
jmp 0x5f20
movq 0x18157(%rip), %rdi     # 0x1dfb0
leaq 0xd2db(%rip), %rsi      # 0x1313b
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq %rsp, %rdi
callq 0x5160
jmp 0x60fe
movq %rsp, %rdi
callq 0x5160
movq 0x20(%rsp), %r12
cmpl $0x3, 0x8(%rbx)
je 0x5ecd
jmp 0x5f20
cmpl $0x1, 0x8(%rbx)
jne 0x5eab
movq 0x18151(%rip), %rdi     # 0x1dff0
leaq 0xd33c(%rip), %rsi      # 0x131e2
jmp 0x60f1
movq 0x180fe(%rip), %rdi     # 0x1dfb0
leaq 0xd354(%rip), %rsi      # 0x1320d
callq 0x5380
movq %rax, %rdi
callq 0x5180
movl $0x3, 0x8(%rbx)
movq 0x180dc(%rip), %rdi     # 0x1dfb0
leaq 0xd3ff(%rip), %rsi      # 0x132da
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq %rbx, %rdi
callq 0x5950
movq (%rbx), %r14
movq %r14, %rdi
callq 0x79cc
leaq 0x48(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x10f2e
movq %r14, %rdi
movq %r15, %rsi
callq 0x79d2
leaq 0x48(%rsp), %rdi
callq 0x5160
cmpl $-0x1, 0xc(%rbx)
je 0x5f43
movq 0x18083(%rip), %rdi     # 0x1dfb0
leaq 0xd428(%rip), %rsi      # 0x1335c
callq 0x5380
movq %rax, %rdi
callq 0x5180
jmp 0x5f6e
movq 0x18066(%rip), %rdi     # 0x1dfb0
leaq 0xd3ce(%rip), %rsi      # 0x1331f
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq %rbx, %rdi
callq 0x6702
testb %al, %al
je 0x60e3
movq 0x1803b(%rip), %r14     # 0x1dfb0
leaq 0xd404(%rip), %rsi      # 0x13380
movq %r14, %rdi
callq 0x5380
movq %rax, %rdi
movl 0xc(%rbx), %eax
movl $0x400, %ecx            # imm = 0x400
cltd
idivl %ecx
movl %eax, %esi
callq 0x55f0
leaq 0xd3ed(%rip), %rsi      # 0x1338d
movq %rax, %rdi
callq 0x5380
movq %rax, %rdi
callq 0x5180
movq (%rbx), %rdi
movslq 0xc(%rbx), %rsi
callq 0x7934
leaq 0xd42c(%rip), %rsi      # 0x133ef
movq %r14, %rdi
callq 0x5380
movq %rax, %rdi
callq 0x5180
movl 0x8(%rbx), %eax
leal -0x2(%rax), %ecx
cmpl $0x3, %ecx
jae 0x5fec
movq (%rbx), %rsi
movq %rsp, %r14
pushq $0x1
popq %rdx
movq %r14, %rdi
jmp 0x5fff
testl %eax, %eax
jne 0x610f
movq (%rbx), %rsi
movq %rsp, %r14
movq %r14, %rdi
xorl %edx, %edx
callq 0x84f8
leaq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x71de
movq %r14, %rdi
callq 0x6eb2
movq 0x18(%rbx), %rax
cmpq 0x10(%rbx), %rax
setne %cl
movl 0x8(%rbx), %eax
cmpl $0x1, %eax
sete %dl
orb %cl, %dl
je 0x60c7
cmpl $0x1, %eax
je 0x6079
movq 0x17f70(%rip), %rdi     # 0x1dfb0
leaq 0xd434(%rip), %rsi      # 0x1347b
callq 0x5380
movq %rax, %rdi
callq 0x5180
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x54b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x671e
leaq 0x28(%rsp), %rdi
callq 0x5160
movq %rbx, %rdi
callq 0x6b2a
movq (%rbx), %rdi
callq 0x7986
movq %rsp, %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6ed4
xorl %r14d, %r14d
movl %r14d, %r14d
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x60d7
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6f22
movq (%rax), %rdi
callq 0xf8f2
incl %r14d
jmp 0x609a
movq 0x17f22(%rip), %rdi     # 0x1dff0
leaq 0xd374(%rip), %rsi      # 0x13449
jmp 0x60f1
movq %rsp, %rdi
callq 0x714e
movb $0x1, %al
jmp 0x6100
movq 0x17f06(%rip), %rdi     # 0x1dff0
leaq 0xd29f(%rip), %rsi      # 0x13390
callq 0x5380
movq %rax, %rdi
callq 0x5180
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x17e9a(%rip), %rdi     # 0x1dfb0
leaq 0xd2f4(%rip), %rsi      # 0x13411
callq 0x5380
movq %rax, %rdi
callq 0x5180
jmp 0x6018
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x614b
jmp 0x6145
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x614b
movq %rax, %rbx
movq %rsp, %rdi
callq 0x5160
jmp 0x615d
movq %rax, %rbx
movq %rsp, %rdi
callq 0x714e
movq %rbx, %rdi
callq 0x5610
nop