// File: uclaopt[P]AsyncQVI/include/algo.h
// Function: Qlearning::update(int)
void update(int iter){
			
			// select (state, action) uniformly random
			if(params->style == 0){
				init_state = uniformInt(0, params->len_state-1); 
				init_action = uniformInt(0, params->len_action-1);
			}
			// select (state, action) globally cyclic 
			else if(params->style == 1){
				init_state = (iter/params->len_action) % params->len_state;
				init_action = iter % params->len_action;
			}
			// select (state, action) following a Markovian trajectory with some exploration
			else{
				init_state = next_state;
				init_action = (*pi)[next_state];
				if(uniformDouble(0.,1.) < params->explore)
					init_action = uniformInt(0, params->len_action-1);
			}
			
			// call sample oracle
			s.SO(init_state, init_action, next_state, r);
			
			// update global variables with mutex
			pthread_mutex_lock(&writelock);
			
			// learning rate of Q-learning
			//params->alpha = 1./pow(iter,0.51);
			(*Q)[init_state][init_action] = (1-params->alpha) * (*Q)[init_state][init_action]
											+ params->alpha * (r + params->gamma*(*V)[next_state]);
			if((*Q)[init_state][init_action] > (*V)[init_state]){
				(*V)[init_state] = (*Q)[init_state][init_action];
				(*pi)[init_state] = init_action;
			}
			pthread_mutex_unlock(&writelock);			
		}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq 0x14e8(%rax), %rax
cmpl $0x0, 0x2c(%rax)
jne 0x5295
movq -0x18(%rbp), %rax
movq 0x14e8(%rax), %rax
movl (%rax), %esi
subl $0x1, %esi
xorl %edi, %edi
callq 0x37a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq 0x14e8(%rax), %rax
movl 0x4(%rax), %esi
subl $0x1, %esi
xorl %edi, %edi
callq 0x37a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x534e
movq -0x18(%rbp), %rax
movq 0x14e8(%rax), %rax
cmpl $0x1, 0x2c(%rax)
jne 0x52db
movq -0x18(%rbp), %rcx
movl -0xc(%rbp), %eax
movq 0x14e8(%rcx), %rsi
cltd
idivl 0x4(%rsi)
movq 0x14e8(%rcx), %rsi
cltd
idivl (%rsi)
movl %edx, (%rcx)
movl -0xc(%rbp), %eax
movq 0x14e8(%rcx), %rcx
cltd
idivl 0x4(%rcx)
movq -0x18(%rbp), %rax
movl %edx, 0x4(%rax)
jmp 0x534c
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movl %ecx, (%rax)
movq 0x14e0(%rax), %rdi
movslq 0x8(%rax), %rsi
callq 0x4e40
movq %rax, %rcx
movq -0x18(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, 0x4(%rax)
xorps %xmm0, %xmm0
movsd 0x7d0d(%rip), %xmm1     # 0xd018
callq 0x37e0
movq -0x18(%rbp), %rax
movaps %xmm0, %xmm1
movq 0x14e8(%rax), %rax
movsd 0x48(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x534a
movq -0x18(%rbp), %rax
movq 0x14e8(%rax), %rax
movl 0x4(%rax), %esi
subl $0x1, %esi
xorl %edi, %edi
callq 0x37a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x534c
jmp 0x534e
movq -0x18(%rbp), %r8
movq %r8, %rdi
addq $0x18, %rdi
movl (%r8), %esi
movl 0x4(%r8), %edx
movq %r8, %rcx
addq $0x8, %rcx
addq $0x10, %r8
callq 0x4dd0
leaq 0xf259(%rip), %rdi      # 0x145d0
callq 0x22d0
movq -0x18(%rbp), %rax
movq 0x14e8(%rax), %rcx
movsd 0x7c89(%rip), %xmm0     # 0xd018
subsd 0x50(%rcx), %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x14d0(%rax), %rdi
movslq (%rax), %rsi
callq 0x7920
movq %rax, %rdi
movq -0x18(%rbp), %rax
movslq 0x4(%rax), %rsi
callq 0x7860
movq %rax, %rcx
movq -0x18(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x14e8(%rax), %rcx
movsd 0x50(%rcx), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq 0x14e8(%rax), %rcx
movsd 0x18(%rcx), %xmm0
movsd %xmm0, -0x50(%rbp)
movq 0x14d8(%rax), %rdi
movslq 0x8(%rax), %rsi
callq 0x7860
movsd -0x50(%rbp), %xmm3
movsd -0x48(%rbp), %xmm4
movsd -0x40(%rbp), %xmm1
movsd -0x38(%rbp), %xmm0
movsd -0x30(%rbp), %xmm2
movq %rax, %rcx
movq -0x18(%rbp), %rax
movsd (%rcx), %xmm5
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq 0x14d0(%rax), %rdi
movslq (%rax), %rsi
callq 0x7920
movq %rax, %rdi
movq -0x18(%rbp), %rax
movslq 0x4(%rax), %rsi
callq 0x7860
movsd -0x28(%rbp), %xmm0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movsd %xmm0, (%rcx)
movq 0x14d0(%rax), %rdi
movslq (%rax), %rsi
callq 0x7920
movq %rax, %rdi
movq -0x18(%rbp), %rax
movslq 0x4(%rax), %rsi
callq 0x7860
movq %rax, %rcx
movq -0x18(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x20(%rbp)
movq 0x14d8(%rax), %rdi
movslq (%rax), %rsi
callq 0x7860
movsd -0x20(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x5525
movq -0x18(%rbp), %rax
movq 0x14d0(%rax), %rdi
movslq (%rax), %rsi
callq 0x7920
movq %rax, %rdi
movq -0x18(%rbp), %rax
movslq 0x4(%rax), %rsi
callq 0x7860
movq %rax, %rcx
movq -0x18(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x60(%rbp)
movq 0x14d8(%rax), %rdi
movslq (%rax), %rsi
callq 0x7860
movsd -0x60(%rbp), %xmm0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movsd %xmm0, (%rcx)
movl 0x4(%rax), %ecx
movl %ecx, -0x54(%rbp)
movq 0x14e0(%rax), %rdi
movslq (%rax), %rsi
callq 0x4e40
movl -0x54(%rbp), %ecx
movl %ecx, (%rax)
leaq 0xf0a4(%rip), %rdi      # 0x145d0
callq 0x2110
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)