// File: 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
subq $0x350, %rsp            # imm = 0x350
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5400
cmpq $0x1, %rax
jbe 0x3330
movq 0xa143(%rip), %rdi      # 0xcfd0
movq 0xa12c(%rip), %rsi      # 0xcfc0
callq 0x2220
movq %rax, %rdi
leaq 0x61e3(%rip), %rsi      # 0x9086
callq 0x21f0
movq %rax, -0x2d0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5400
movq -0x2d0(%rbp), %rdi
movq %rax, %rsi
callq 0x2070
movq %rax, %rdi
leaq 0x61c0(%rip), %rsi      # 0x9091
callq 0x21f0
movq %rax, %rdi
movq 0xa0e0(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0xa0e4(%rip), %rdi      # 0xcfd0
leaq 0x61ae(%rip), %rsi      # 0x90a1
callq 0x21f0
movq %rax, %rdi
movq 0xa0be(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0xa0d2(%rip), %rdi      # 0xcfe0
leaq -0x11(%rbp), %rsi
callq 0x22b0
movsbl -0x11(%rbp), %edi
callq 0x2390
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x59, %ecx
movb %al, -0x2d1(%rbp)
je 0x2f44
movsbl -0x11(%rbp), %edi
callq 0x2390
cmpl $0x4e, %eax
setne %al
movb %al, -0x2d1(%rbp)
movb -0x2d1(%rbp), %al
testb $0x1, %al
jne 0x2f53
jmp 0x2fde
movq 0xa086(%rip), %rax      # 0xcfe0
movq (%rax), %rax
movq 0xa07c(%rip), %rdi      # 0xcfe0
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x2320
movq 0xa06a(%rip), %rdi      # 0xcfe0
movl $0x2710, %esi           # imm = 0x2710
movl $0xa, %edx
callq 0x2160
movq 0xa044(%rip), %rdi      # 0xcfd0
leaq 0x614c(%rip), %rsi      # 0x90df
callq 0x21f0
movq %rax, %rdi
movq 0xa01e(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0xa022(%rip), %rdi      # 0xcfd0
leaq 0x6162(%rip), %rsi      # 0x9117
callq 0x21f0
movq %rax, %rdi
movq 0x9ffc(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0xa010(%rip), %rdi      # 0xcfe0
leaq -0x11(%rbp), %rsi
callq 0x22b0
jmp 0x2f17
movsbl -0x11(%rbp), %edi
callq 0x2390
cmpl $0x59, %eax
jne 0x32c9
movl $0x0, -0x18(%rbp)
movq 0x9fd2(%rip), %rdi      # 0xcfd0
leaq 0x6136(%rip), %rsi      # 0x913b
callq 0x21f0
movq %rax, %rdi
movq 0x9fac(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0x9fb0(%rip), %rdi      # 0xcfd0
leaq 0x6149(%rip), %rsi      # 0x9170
callq 0x21f0
movq %rax, %rdi
movq 0x9f8a(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0x9f9e(%rip), %rax      # 0xcfe0
movq (%rax), %rax
movq 0x9f94(%rip), %rdi      # 0xcfe0
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x2320
movq 0x9f82(%rip), %rdi      # 0xcfe0
movl $0x3e8, %esi            # imm = 0x3E8
movl $0xa, %edx
callq 0x2160
movq 0x9f6c(%rip), %rdi      # 0xcfe0
leaq -0x18(%rbp), %rsi
callq 0x2140
cmpl $0x1, -0x18(%rbp)
jl 0x30aa
movslq -0x18(%rbp), %rax
movq %rax, -0x2e0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5400
movq %rax, %rcx
movq -0x2e0(%rbp), %rax
cmpq %rcx, %rax
jbe 0x3132
movq 0x9f1f(%rip), %rdi      # 0xcfd0
leaq 0x60fb(%rip), %rsi      # 0x91b3
callq 0x21f0
movq %rax, -0x2e8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5400
movq -0x2e8(%rbp), %rdi
movq %rax, %rsi
callq 0x2070
movq %rax, %rdi
movq 0x9eda(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0x9eee(%rip), %rax      # 0xcfe0
movq (%rax), %rax
movq 0x9ee4(%rip), %rdi      # 0xcfe0
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x2320
movq 0x9ed2(%rip), %rdi      # 0xcfe0
movl $0x3e8, %esi            # imm = 0x3E8
movl $0xa, %edx
callq 0x2160
movq 0x9ebc(%rip), %rdi      # 0xcfe0
leaq -0x18(%rbp), %rsi
callq 0x2140
jmp 0x32c7
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x5430
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x5450
movq -0x2f8(%rbp), %rsi
movq -0x8(%rbp), %rax
movq %rax, -0x2f0(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x5450
jmp 0x3179
movq -0x2f0(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x8250
jmp 0x318e
leaq -0x148(%rbp), %rdi
callq 0x2900
movq 0x9e3f(%rip), %rdi      # 0xcfe0
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
xorl %esi, %esi
callq 0x2320
jmp 0x31b4
movq 0x9e25(%rip), %rdi      # 0xcfe0
movl $0x3e8, %esi            # imm = 0x3E8
movl $0xa, %edx
callq 0x2160
jmp 0x31cc
movq 0x9dfd(%rip), %rdi      # 0xcfd0
movq 0x9de6(%rip), %rsi      # 0xcfc0
callq 0x2220
movq %rax, -0x300(%rbp)
jmp 0x31e8
leaq -0x178(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x7cc0
jmp 0x31fd
movq -0x300(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x21e0
movq %rax, -0x308(%rbp)
jmp 0x3219
movq -0x308(%rbp), %rdi
leaq 0x5fad(%rip), %rsi      # 0x91d4
callq 0x21f0
movq %rax, -0x310(%rbp)
jmp 0x3235
movq -0x310(%rbp), %rdi
movq 0x9d7d(%rip), %rsi      # 0xcfc0
callq 0x2220
jmp 0x324a
leaq -0x178(%rbp), %rdi
callq 0x2150
leaq -0xb0(%rbp), %rdi
callq 0x2900
jmp 0x32c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0x32b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x2900
jmp 0x32b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x2150
leaq -0xb0(%rbp), %rdi
callq 0x2900
jmp 0x362f
jmp 0x32c9
movsbl -0x11(%rbp), %edi
callq 0x2390
cmpl $0x4e, %eax
jne 0x332b
movq 0x9d02(%rip), %rax      # 0xcfe0
movq (%rax), %rax
movq 0x9cf8(%rip), %rdi      # 0xcfe0
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x2320
movq 0x9ce6(%rip), %rdi      # 0xcfe0
movl $0x3e8, %esi            # imm = 0x3E8
movl $0xa, %edx
callq 0x2160
movq 0x9cc0(%rip), %rdi      # 0xcfd0
leaq 0x5ed6(%rip), %rsi      # 0x91ed
callq 0x21f0
movq %rax, %rdi
movq 0x9c9a(%rip), %rsi      # 0xcfc0
callq 0x2220
jmp 0x3626
movq -0x10(%rbp), %rdi
callq 0x5400
cmpq $0x1, %rax
jne 0x3624
movq 0x9c86(%rip), %rdi      # 0xcfd0
leaq 0x5eb9(%rip), %rsi      # 0x920a
callq 0x21f0
movq %rax, %rdi
movq 0x9c60(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0x9c74(%rip), %rdi      # 0xcfe0
leaq -0x11(%rbp), %rsi
callq 0x22b0
movsbl -0x11(%rbp), %edi
callq 0x2390
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x59, %ecx
movb %al, -0x311(%rbp)
je 0x33a2
movsbl -0x11(%rbp), %edi
callq 0x2390
cmpl $0x4e, %eax
setne %al
movb %al, -0x311(%rbp)
movb -0x311(%rbp), %al
testb $0x1, %al
jne 0x33ae
jmp 0x3407
movq 0x9c1b(%rip), %rdi      # 0xcfd0
leaq 0x5d23(%rip), %rsi      # 0x90df
callq 0x21f0
movq %rax, %rdi
movq 0x9bf5(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0x9bf9(%rip), %rdi      # 0xcfd0
leaq 0x5d39(%rip), %rsi      # 0x9117
callq 0x21f0
movq %rax, %rdi
movq 0x9bd3(%rip), %rsi      # 0xcfc0
callq 0x2220
movq 0x9be7(%rip), %rdi      # 0xcfe0
leaq -0x11(%rbp), %rsi
callq 0x22b0
jmp 0x3375
movsbl -0x11(%rbp), %edi
callq 0x2390
cmpl $0x59, %eax
jne 0x35be
movq 0x9bc0(%rip), %rdi      # 0xcfe0
movq %rdi, -0x338(%rbp)
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
xorl %esi, %esi
movl %esi, -0x32c(%rbp)
callq 0x2320
movq -0x338(%rbp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
movl $0xa, %edx
callq 0x2160
movl -0x32c(%rbp), %eax
movq -0x10(%rbp), %rdi
movl %eax, %esi
callq 0x5430
movq %rax, %rsi
leaq -0x210(%rbp), %rdi
movq %rdi, -0x328(%rbp)
callq 0x5450
movq -0x328(%rbp), %rsi
movq -0x8(%rbp), %rax
movq %rax, -0x320(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x5450
jmp 0x349b
movq -0x320(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x8250
jmp 0x34b0
leaq -0x2a8(%rbp), %rdi
callq 0x2900
callq 0x2de0
jmp 0x34c3
leaq -0x2c8(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x7cc0
jmp 0x34d8
movq 0x9af1(%rip), %rdi      # 0xcfd0
leaq -0x2c8(%rbp), %rsi
callq 0x21e0
movq %rax, -0x340(%rbp)
jmp 0x34f4
movq -0x340(%rbp), %rdi
leaq 0x5cd2(%rip), %rsi      # 0x91d4
callq 0x21f0
movq %rax, -0x348(%rbp)
jmp 0x3510
movq -0x348(%rbp), %rdi
movq 0x9aa2(%rip), %rsi      # 0xcfc0
callq 0x2220
movq %rax, -0x350(%rbp)
jmp 0x352c
movq -0x350(%rbp), %rdi
movq 0x9a86(%rip), %rsi      # 0xcfc0
callq 0x2220
jmp 0x3541
leaq -0x2c8(%rbp), %rdi
callq 0x2150
leaq -0x210(%rbp), %rdi
callq 0x2900
jmp 0x3622
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0x35b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x2900
jmp 0x35b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x2150
leaq -0x210(%rbp), %rdi
callq 0x2900
jmp 0x362f
movsbl -0x11(%rbp), %edi
callq 0x2390
cmpl $0x4e, %eax
jne 0x3620
movq 0x9a0d(%rip), %rax      # 0xcfe0
movq (%rax), %rax
movq 0x9a03(%rip), %rdi      # 0xcfe0
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x2320
movq 0x99f1(%rip), %rdi      # 0xcfe0
movl $0x3e8, %esi            # imm = 0x3E8
movl $0xa, %edx
callq 0x2160
movq 0x99cb(%rip), %rdi      # 0xcfd0
leaq 0x5be1(%rip), %rsi      # 0x91ed
callq 0x21f0
movq %rax, %rdi
movq 0x99a5(%rip), %rsi      # 0xcfc0
callq 0x2220
jmp 0x3622
jmp 0x3624
jmp 0x3626
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
movq -0x150(%rbp), %rdi
callq 0x2340
nopl (%rax,%rax)