// File: chinmayachaudhry[P]Branch-Predictor/hybrid.cpp
// Function: hybrid::update_chooser_table(long long, int, char)
void hybrid :: update_chooser_table(ll address, int chooser_table_prediction, char actual_branch)
{
	//ll index = calc_Index(address);

	if(actual_branch == 't')
	{
		if(gshare_prediction == 1 && bimodal_prediction == 0)
		{
			if(chooser_table.at(chooser_table_index) < 3)
				chooser_table.at(chooser_table_index) = chooser_table.at(chooser_table_index) + 1;
		}
		else if(bimodal_prediction == 1 && gshare_prediction == 0)
		{
			if(chooser_table.at(chooser_table_index) > 0)
				chooser_table.at(chooser_table_index) = chooser_table.at(chooser_table_index) - 1;

		}
		if(chooser_table_prediction == 0)
			mispredictions++;
		else
			true_predictions++;
	}		
	else if(actual_branch == 'n')
	{	
		if(gshare_prediction == 0 && bimodal_prediction == 1)
		{
			if(chooser_table.at(chooser_table_index) < 3)
				chooser_table.at(chooser_table_index) = chooser_table.at(chooser_table_index) + 1;
		}
		else if(bimodal_prediction == 0 && gshare_prediction == 1)
		{
			if(chooser_table.at(chooser_table_index) > 0)
				chooser_table.at(chooser_table_index) = chooser_table.at(chooser_table_index) - 1;

		}	

		if(chooser_table_prediction == 1)
			mispredictions++;
		else
			true_predictions++;
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movb %al, -0x15(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movsbl -0x15(%rbp), %eax
cmpl $0x74, %eax
jne 0x6dba
movq -0x20(%rbp), %rax
cmpl $0x1, 0x2c(%rax)
jne 0x6d24
movq -0x20(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x6d24
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
cmpl $0x3, (%rax)
jge 0x6d22
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movl (%rcx), %ecx
addl $0x1, %ecx
movl %ecx, -0x24(%rbp)
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
movl -0x24(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x6d8d
movq -0x20(%rbp), %rax
cmpl $0x1, 0x28(%rax)
jne 0x6d8b
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jne 0x6d8b
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
cmpl $0x0, (%rax)
jle 0x6d89
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movl (%rcx), %ecx
subl $0x1, %ecx
movl %ecx, -0x28(%rbp)
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
movl -0x28(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x6d8b
jmp 0x6d8d
cmpl $0x0, -0x14(%rbp)
jne 0x6da5
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
jmp 0x6db5
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
jmp 0x6ec3
movsbl -0x15(%rbp), %eax
cmpl $0x6e, %eax
jne 0x6ec1
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jne 0x6e2e
movq -0x20(%rbp), %rax
cmpl $0x1, 0x28(%rax)
jne 0x6e2e
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
cmpl $0x3, (%rax)
jge 0x6e2c
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movl (%rcx), %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x6e97
movq -0x20(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x6e95
movq -0x20(%rbp), %rax
cmpl $0x1, 0x2c(%rax)
jne 0x6e95
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
cmpl $0x0, (%rax)
jle 0x6e93
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movl (%rcx), %ecx
subl $0x1, %ecx
movl %ecx, -0x30(%rbp)
movq %rax, %rdi
addq $0x40, %rdi
movslq 0x20(%rax), %rsi
callq 0x52f0
movl -0x30(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x6e95
jmp 0x6e97
cmpl $0x1, -0x14(%rbp)
jne 0x6eaf
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
jmp 0x6ebf
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
jmp 0x6ec1
jmp 0x6ec3
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)