// File: uclaopt[P]AsyncQVI/include/algo.h
// Function: QVI::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{
				init_state = (iter/params->len_action) % params->len_state;
				init_action = iter % params->len_action;
			}
			
			S = 0.;
			for (int i = 0; i < params->max_inner_iter; i++){
				// call sample oracle
				s.SO(init_state, init_action, next_state, r);
				S += r + params->gamma * V->at(next_state);
			}
			// averaged reward
			S = S / params->max_inner_iter;
			double newQ = S - (1-params->gamma)*params->epsilon/4.;
			
			// update shared memory
			pthread_mutex_lock(&writelock);
			if (newQ > V->at(init_state)){
				V->at(init_state) = newQ;
				pi->at(init_state) = init_action;
			}
			pthread_mutex_unlock(&writelock);
		}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq 0x14e8(%rax), %rax
cmpl $0x0, 0x2c(%rax)
jne 0x4ef2
movq -0x20(%rbp), %rax
movq 0x14e8(%rax), %rax
movl (%rax), %esi
subl $0x1, %esi
xorl %edi, %edi
callq 0x37a0
movl %eax, %ecx
movq -0x20(%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 -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x4f25
movq -0x20(%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 -0x20(%rbp), %rax
movl %edx, 0x4(%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rax)
movl $0x0, -0x10(%rbp)
movq -0x20(%rbp), %rcx
movl -0x10(%rbp), %eax
movq 0x14e8(%rcx), %rcx
cmpl 0x38(%rcx), %eax
jge 0x4fd5
movq -0x20(%rbp), %r8
movq %r8, %rdi
addq $0x20, %rdi
movl (%r8), %esi
movl 0x4(%r8), %edx
movq %r8, %rcx
addq $0x8, %rcx
addq $0x10, %r8
callq 0x4dd0
movq -0x20(%rbp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movq 0x14e8(%rax), %rcx
movsd 0x18(%rcx), %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x14d8(%rax), %rdi
movslq 0x8(%rax), %rsi
callq 0x7780
movsd -0x30(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movq %rax, %rcx
movq -0x20(%rbp), %rax
movsd (%rcx), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd 0x18(%rax), %xmm0
movsd %xmm0, 0x18(%rax)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4f38
movq -0x20(%rbp), %rax
movsd 0x18(%rax), %xmm0
movq 0x14e8(%rax), %rcx
cvtsi2sdl 0x38(%rcx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rax)
movsd 0x18(%rax), %xmm0
movq 0x14e8(%rax), %rcx
movsd 0x8011(%rip), %xmm1     # 0xd018
subsd 0x18(%rcx), %xmm1
movq 0x14e8(%rax), %rax
mulsd 0x60(%rax), %xmm1
movsd 0x8000(%rip), %xmm2     # 0xd020
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
leaq 0xf59c(%rip), %rdi      # 0x145d0
callq 0x22d0
movq -0x20(%rbp), %rax
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x14d8(%rax), %rdi
movslq (%rax), %rsi
callq 0x7780
movsd -0x38(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x50a8
movq -0x20(%rbp), %rax
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movq 0x14d8(%rax), %rdi
movslq (%rax), %rsi
callq 0x7780
movsd -0x48(%rbp), %xmm0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movsd %xmm0, (%rcx)
movl 0x4(%rax), %ecx
movl %ecx, -0x3c(%rbp)
movq 0x14e0(%rax), %rdi
movslq (%rax), %rsi
callq 0x77c0
movl -0x3c(%rbp), %ecx
movl %ecx, (%rax)
leaq 0xf521(%rip), %rdi      # 0x145d0
callq 0x2110
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)