// File: chinmayachaudhry[P]Branch-Predictor/yehpatt.cpp
// Function: yehpatt::update(int, char)
void yehpatt :: update(int predicted_branch, char actual_branch)
{
//	ll index = calc_Index(address);
	history_table.at(history_table_index) = history_table.at(history_table_index) >> 1;
	if(actual_branch == 't')
	{
		if(predictor_table.at(predictor_table_index) < 3)
			predictor_table.at(predictor_table_index) = predictor_table.at(predictor_table_index) + 1;
		if(predicted_branch == 0)
			mispredictions++;
		else
			true_predictions++;
		history_table.at(history_table_index) |= (1U << (predictor_index_bits -1));
	}		
	else if(actual_branch == 'n')
	{	
		if(predictor_table.at(predictor_table_index) > 0)
			predictor_table.at(predictor_table_index) = predictor_table.at(predictor_table_index) - 1;
		if(predicted_branch == 1)
			mispredictions++;
		else
			true_predictions++;
		history_table.at(history_table_index) &= ~(1U << (predictor_index_bits -1));
	}


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movb %al, -0xd(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq %rax, %rdi
addq $0x70, %rdi
movslq 0x38(%rax), %rsi
callq 0x52f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movl (%rcx), %ecx
sarl %ecx
movl %ecx, -0x14(%rbp)
movq %rax, %rdi
addq $0x70, %rdi
movslq 0x38(%rax), %rsi
callq 0x52f0
movl -0x14(%rbp), %ecx
movl %ecx, (%rax)
movsbl -0xd(%rbp), %eax
cmpl $0x74, %eax
jne 0x7857
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x58, %rdi
movslq 0x34(%rax), %rsi
callq 0x52f0
cmpl $0x3, (%rax)
jge 0x77fd
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x58, %rdi
movslq 0x34(%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 $0x58, %rdi
movslq 0x34(%rax), %rsi
callq 0x52f0
movl -0x24(%rbp), %ecx
movl %ecx, (%rax)
cmpl $0x0, -0xc(%rbp)
jne 0x7815
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
jmp 0x7825
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
subq $0x1, %rcx
movl $0x1, %edx
shll %cl, %edx
movl %edx, -0x28(%rbp)
movq %rax, %rdi
addq $0x70, %rdi
movslq 0x38(%rax), %rsi
callq 0x52f0
movl -0x28(%rbp), %ecx
orl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x7911
movsbl -0xd(%rbp), %eax
cmpl $0x6e, %eax
jne 0x790f
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x58, %rdi
movslq 0x34(%rax), %rsi
callq 0x52f0
cmpl $0x0, (%rax)
jle 0x78b5
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x58, %rdi
movslq 0x34(%rax), %rsi
callq 0x52f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movl (%rcx), %ecx
subl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movq %rax, %rdi
addq $0x58, %rdi
movslq 0x34(%rax), %rsi
callq 0x52f0
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
cmpl $0x1, -0xc(%rbp)
jne 0x78cd
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
jmp 0x78dd
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
subq $0x1, %rcx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
xorl $-0x1, %ecx
movl %ecx, -0x30(%rbp)
movq %rax, %rdi
addq $0x70, %rdi
movslq 0x38(%rax), %rsi
callq 0x52f0
movl -0x30(%rbp), %ecx
andl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x7911
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)