// File: /workspace/github_cpp_makefile_star2_O2/KitchMKelly[P]Team-9-OSU-Hackathon-Winter-2018/BawkBusterFunctions.cpp
// Function: addToCart(Cart&, std::vector<Video, std::allocator<Video>>&)
void addToCart(Cart &newCart, std::vector<Video> &results)
{
	char addDecision;		//variable to hold user choice
	if(results.size() > 1)
	{
		cout << endl << "There are " << results.size() << " search results" << endl;
		cout << "Would you like to add one of these movies to your cart? (Y/N)" << endl;
		cin >> addDecision;
		//Verify user input
		while ((toupper(addDecision) != 'Y' && toupper(addDecision) != 'N'))
		{	
			cin.clear();	//Clear bad input flag
			cin.ignore(10000, '\n');	//Discard input
			cout << "Please enter either 'Y' to add the movie to your cart, " << endl;
			cout << "or enter 'N' to start a new search." << endl;
			cin >> addDecision;
		}
		//Action based on user input
		if (toupper(addDecision) == 'Y')
		{
			int movieNumber = 0;
			cout << "Please enter the movie number you would like to add." << endl;
			cout << "For example, if you wish to add result \"1. Avatar\", please type 1:" << endl;
			cin.clear();
			cin.ignore(1000, '\n');
			cin >> movieNumber;
			if(movieNumber < 1 || movieNumber > results.size())
			{
				cout << "Try again, options are 1 though " << results.size()  << endl;
				cin.clear();
				cin.ignore(1000, '\n');
				cin >> movieNumber;
			}
			else
			{
				Video vid = results[(movieNumber - 1)];
				//cout << "video title is " << vid.getTitle() << endl;
				newCart.addVidToCart(vid);
				cin.clear();
				cin.ignore(1000, '\n');
				cout << endl << vid.getTitle() << " was added to your cart!" << endl;
				//systemPause();
			}
		}	
		if(toupper(addDecision) == 'N')
		{
			cin.clear();
			cin.ignore(1000, '\n');
			cout << "No movies added to your cart" << endl;			
		}
				
	}
	else if (results.size() == 1)
	{
		cout << "Would you like to add this movie to your cart? (Y/N)" <<endl;
		cin >> addDecision;
	
		//Verify user input
		while ((toupper(addDecision) != 'Y' && toupper(addDecision) != 'N'))
		{
			//cin.clear();	//Clear bad input flag
			//cin.ignore(10000, '\n');	//Discard input
			cout << "Please enter either 'Y' to add the movie to your cart, " << endl;
			cout << "or enter 'N' to start a new search." << endl;
			cin >> addDecision;
		}		

		//Action based on user input
		if (toupper(addDecision) == 'Y')
		{
			cin.clear();
			cin.ignore(1000,'\n');
			Video vid = results[0];
			newCart.addVidToCart(vid);
			clearScreen();
			cout << vid.getTitle() << " was added to your cart!" << endl <<endl;
			//TODO send back to main menu?
		}
		else if (toupper(addDecision) == 'N')
		{
			cin.clear();
			cin.ignore(1000, '\n');
			cout << "No movies added to your cart" << endl;			
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rsi, %r14
movq 0x8(%rsi), %rcx
subq (%rsi), %rcx
movl $0x98, %ebx
movq %rcx, %rax
cqto
idivq %rbx
cmpq $0x2, %rax
jb 0x2a37
movq %rdi, -0x38(%rbp)
movq 0x7688(%rip), %r12      # 0x9fd0
movq %r12, %rdi
callq 0x20d0
leaq 0x3733(%rip), %rsi      # 0x608a
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movq 0x8(%r14), %rax
movq %r14, -0x40(%rbp)
subq (%r14), %rax
cqto
idivq %rbx
movq %rax, %rsi
callq 0x2120
leaq 0x3714(%rip), %rsi      # 0x6095
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
leaq 0x370d(%rip), %rsi      # 0x60a5
movq %r12, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movq 0x7631(%rip), %r14      # 0x9fe0
leaq -0x29(%rbp), %r13
leaq 0x3761(%rip), %r15      # 0x611b
movq %r14, %rbx
movq %r14, %rdi
movq %r13, %rsi
callq 0x21d0
movsbl -0x29(%rbp), %r14d
movl %r14d, %edi
callq 0x2290
cmpl $0x4e, %eax
je 0x2d5b
cmpl $0x59, %eax
je 0x2ad1
movq %rbx, %r14
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x2230
movl $0x2710, %esi           # imm = 0x2710
movq %rbx, %rdi
pushq $0xa
popq %rdx
callq 0x2110
movq %r12, %rdi
leaq 0x36ce(%rip), %rsi      # 0x60e3
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movq %r12, %rdi
movq %r15, %rsi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
jmp 0x29ba
cmpq $0x98, %rcx
jne 0x2da4
movq %r14, -0x40(%rbp)
movq %rdi, -0x38(%rbp)
movq 0x757d(%rip), %r14      # 0x9fd0
leaq 0x37b4(%rip), %rsi      # 0x620e
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movq 0x756f(%rip), %rbx      # 0x9fe0
leaq -0x29(%rbp), %r15
leaq 0x3667(%rip), %r12      # 0x60e3
leaq 0x3698(%rip), %r13      # 0x611b
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21d0
movsbl -0x29(%rbp), %edi
callq 0x2290
cmpl $0x4e, %eax
je 0x2d68
cmpl $0x59, %eax
je 0x2bcf
movq %r14, %rdi
movq %r12, %rsi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movq %r14, %rdi
movq %r13, %rsi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
jmp 0x2a83
leaq -0x44(%rbp), %r15
andl $0x0, (%r15)
movq 0x74f0(%rip), %r14      # 0x9fd0
leaq 0x3658(%rip), %rsi      # 0x613f
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
leaq 0x3676(%rip), %rsi      # 0x6174
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movq %rbx, %r14
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x2230
pushq $0xa
popq %rdx
movl $0x3e8, %esi            # imm = 0x3E8
movq %rbx, %rdi
callq 0x2110
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2100
movslq (%r15), %rcx
testq %rcx, %rcx
movq -0x40(%rbp), %r15
jle 0x2b66
movq (%r15), %rsi
movq 0x8(%r15), %rax
subq %rsi, %rax
movl $0x98, %edi
cqto
idivq %rdi
cmpq %rcx, %rax
jae 0x2c8f
movq 0x7463(%rip), %rdi      # 0x9fd0
leaq 0x3643(%rip), %rsi      # 0x61b7
callq 0x2180
movq %rax, %rdi
movq 0x8(%r15), %rax
subq (%r15), %rax
movl $0x98, %ecx
cqto
idivq %rcx
movq %rax, %rsi
callq 0x2120
movq %rax, %rdi
callq 0x20d0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
xorl %esi, %esi
callq 0x2230
pushq $0xa
popq %rdx
movl $0x3e8, %esi            # imm = 0x3E8
movq %r14, %rdi
callq 0x2110
leaq -0x44(%rbp), %rsi
movq %r14, %rdi
callq 0x2100
jmp 0x2d56
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x2230
pushq $0xa
popq %rdx
movl $0x3e8, %esi            # imm = 0x3E8
movq %rbx, %rdi
callq 0x2110
movq -0x40(%rbp), %rax
movq (%rax), %rsi
leaq -0x100(%rbp), %rbx
movq %rbx, %rdi
callq 0x4266
leaq -0x198(%rbp), %rdi
movq %rbx, %rsi
callq 0x4266
leaq -0x198(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x5180
leaq -0x198(%rbp), %rdi
callq 0x258e
callq 0x28a1
leaq -0x68(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4e74
movq 0x7383(%rip), %rdi      # 0x9fd0
leaq -0x68(%rbp), %rsi
callq 0x2170
leaq 0x357b(%rip), %rsi      # 0x61d8
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x20d0
leaq -0x68(%rbp), %rdi
callq 0x20c0
leaq -0x100(%rbp), %rdi
callq 0x258e
jmp 0x2da4
imulq $0x98, %rcx, %rax
addq %rax, %rsi
addq $-0x98, %rsi
leaq -0x100(%rbp), %r15
movq %r15, %rdi
callq 0x4266
leaq -0x230(%rbp), %rdi
movq %r15, %rsi
callq 0x4266
leaq -0x230(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x5180
leaq -0x230(%rbp), %rdi
callq 0x258e
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
xorl %esi, %esi
callq 0x2230
movq 0x72ee(%rip), %rdi      # 0x9fe0
pushq $0xa
popq %rdx
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x2110
movq 0x72ca(%rip), %rdi      # 0x9fd0
callq 0x20d0
movq %rax, %r14
leaq -0x68(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4e74
leaq -0x68(%rbp), %rsi
movq %r14, %rdi
callq 0x2170
leaq 0x34a7(%rip), %rsi      # 0x61d8
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
leaq -0x68(%rbp), %rdi
callq 0x20c0
leaq -0x100(%rbp), %rdi
callq 0x258e
movsbl -0x29(%rbp), %r14d
movl %r14d, %edi
callq 0x2290
cmpl $0x4e, %eax
jne 0x2da4
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x2230
pushq $0xa
popq %rdx
movl $0x3e8, %esi            # imm = 0x3E8
movq %rbx, %rdi
callq 0x2110
movq 0x7240(%rip), %rdi      # 0x9fd0
leaq 0x345a(%rip), %rsi      # 0x61f1
callq 0x2180
movq %rax, %rdi
callq 0x20d0
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ddb
movq %rax, %rbx
leaq -0x230(%rbp), %rdi
jmp 0x2dd0
jmp 0x2ddb
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
callq 0x258e
jmp 0x2dec
jmp 0x2de0
jmp 0x2ddb
movq %rax, %rbx
jmp 0x2dec
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x20c0
leaq -0x100(%rbp), %rdi
callq 0x258e
movq %rbx, %rdi
callq 0x2250