// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/sobol.c
// Function: sobol_get
int sobol_get(void * state, unsigned int dimension, double * v)
{
  sobol_state_t * s_state = (sobol_state_t *) state;

  unsigned int i_dimension;

  /* Find the position of the least-significant zero in count. */
  int ell = 0;
  int c = s_state->sequence_count;
  while(1) {
    ++ell;
    if((c % 2) == 1) c /= 2;
    else break;
  }

  /* Check for exhaustion. */
  if(ell > SOBOL_BIT_COUNT) {
    // return GSL_EFAILED; /* FIXME: good return code here */
    /////////////////
    sobol_init(state, dimension);

    /* Find the position of the least-significant zero in count. */
    int ell = 0;
    int c = s_state->sequence_count;
    while(1) {
      ++ell;
      if((c % 2) == 1) c /= 2;
      else break;
    }
    /////////////////
  }

  for(i_dimension=0; i_dimension<dimension; i_dimension++) {
    const int direction_i     = s_state->v_direction[ell-1][i_dimension];
    const int old_numerator_i = s_state->last_numerator_vec[i_dimension];
    const int new_numerator_i = old_numerator_i ^ direction_i;
    s_state->last_numerator_vec[i_dimension] = new_numerator_i;
    v[i_dimension] = new_numerator_i * s_state->last_denominator_inv;
  }

  s_state->sequence_count++;

  return GSL_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x410ea4
movl -0x2c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
jmp 0x410ea6
jmp 0x410ea8
jmp 0x410e7b
cmpl $0x1e, -0x28(%rbp)
jle 0x410ef9
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x410b70
movl $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x410ef3
movl -0x34(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x34(%rbp)
jmp 0x410ef5
jmp 0x410ef7
jmp 0x410eca
jmp 0x410ef9
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x410f78
movq -0x20(%rbp), %rax
addq $0xb0, %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movl 0x10(%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
xorl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %edx
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %edx, 0x10(%rax,%rcx,4)
cvtsi2sdl -0x40(%rbp), %xmm0
movq -0x20(%rbp), %rax
mulsd 0x8(%rax), %xmm0
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x410f00
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)