// File: /workspace/github_c_makefile_star2_O2/archer1357[P]Offline-Raytracer/sobol.c
// Function: sobol_init
int sobol_init(void * state, unsigned int dimension)
{
  sobol_state_t * s_state = (sobol_state_t *) state;
  unsigned int i_dim;
  int j, k;
  int ell;

  if(dimension < 1 || dimension > SOBOL_MAX_DIMENSION) {
    return GSL_EINVAL;
  }

  /* Initialize direction table in dimension 0. */
  for(k=0; k<SOBOL_BIT_COUNT; k++) s_state->v_direction[k][0] = 1;

  /* Initialize in remaining dimensions. */
  for(i_dim=1; i_dim<dimension; i_dim++) {

    const int poly_index = i_dim;
    const int degree_i = degree_table[poly_index];
    int includ[8];

    /* Expand the polynomial bit pattern to separate
     * components of the logical array includ[].
     */
    int p_i = primitive_polynomials[poly_index];
    for(k = degree_i-1; k >= 0; k--) {
      includ[k] = ((p_i % 2) == 1);
      p_i /= 2;
    }

    /* Leading elements for dimension i come from v_init[][]. */
    for(j=0; j<degree_i; j++) s_state->v_direction[j][i_dim] = v_init[j][i_dim];

    /* Calculate remaining elements for this dimension,
     * as explained in Bratley+Fox, section 2.
     */
    for(j=degree_i; j<SOBOL_BIT_COUNT; j++) {
      int newv = s_state->v_direction[j-degree_i][i_dim];
      ell = 1;
      for(k=0; k<degree_i; k++) {
        ell *= 2;
        if(includ[k]) newv ^= (ell * s_state->v_direction[j-k-1][i_dim]);
      }
      s_state->v_direction[j][i_dim] = newv;
    }
  }

  /* Multiply columns of v by appropriate power of 2. */
  ell = 1;
  for(j=SOBOL_BIT_COUNT-1-1; j>=0; j--) {
    ell *= 2;
    for(i_dim=0; i_dim<dimension; i_dim++) {
      s_state->v_direction[j][i_dim] *= ell;
    }
  }

  /* 1/(common denominator of the elements in v_direction) */
  s_state->last_denominator_inv = 1.0 /(2.0 * ell);

  /* final setup */
  s_state->sequence_count = 0;
  for(i_dim=0; i_dim<dimension; i_dim++) s_state->last_numerator_vec[i_dim] = 0;

  return GSL_SUCCESS;
}

// Assembly:
leal -0x29(%rsi), %eax
cmpl $-0x28, %eax
jae 0x409192
movl $0x4, %eax
retq
leaq 0xb0(%rdi), %r8
movl $0xb0, %eax
cmpq $0x1370, %rax           # imm = 0x1370
je 0x4091b5
movl $0x1, (%rdi,%rax)
addq $0xa0, %rax
jmp 0x40919e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movabsq $-0x100000000, %r9      # imm = 0xFFFFFFFF00000000
movl %esi, %ecx
movq %rdi, -0x30(%rsp)
leaq 0xb4(%rdi), %rsi
movabsq $0x1, %r10
leaq 0xcabfc(%rip), %r11     # 0x4d3de4
cmpq %rcx, %r10
je 0x4092f3
leaq 0xcaaa8(%rip), %rax     # 0x4d3ca0
movl (%rax,%r10,4), %r12d
leaq 0xcab3d(%rip), %rax     # 0x4d3d40
movl (%rax,%r10,4), %eax
movq %r12, %rdx
testl %edx, %edx
jle 0x409233
movl %eax, %edi
andl $0x80000001, %edi       # imm = 0x80000001
xorl %ebx, %ebx
cmpl $0x1, %edi
sete %bl
movl %ebx, -0x2c(%rsp,%rdx,4)
leaq -0x1(%rdx), %rdi
cltd
movl $0x2, %ebx
idivl %ebx
movq %rdi, %rdx
jmp 0x40920a
testl %r12d, %r12d
movl $0x0, %eax
cmovgl %r12d, %eax
imulq $0xa0, %rax, %rdx
xorl %edi, %edi
cmpq %rdi, %rdx
je 0x40925d
movl (%r11,%rdi), %ebx
movl %ebx, (%rsi,%rdi)
addq $0xa0, %rdi
jmp 0x409248
movslq %r12d, %rbx
shlq $0x20, %r12
addq %r9, %r12
movq %rbx, %rdx
cmpq $0x1d, %rdx
jg 0x4092e3
movq %rdx, %rdi
subq %rbx, %rdi
imulq $0xa0, %rdi, %rdi
addq %r8, %rdi
movl (%rdi,%r10,4), %r14d
movq %r12, %rbp
xorl %edi, %edi
movl $0x1, %r15d
cmpq %rdi, %rax
je 0x4092c3
addl %r15d, %r15d
cmpl $0x0, -0x28(%rsp,%rdi,4)
je 0x4092bb
movq %rbp, %r13
sarq $0x20, %r13
imulq $0xa0, %r13, %r13
addq %r8, %r13
movl (%r13,%r10,4), %r13d
imull %r15d, %r13d
xorl %r13d, %r14d
incq %rdi
addq %r9, %rbp
jmp 0x40928f
imulq $0xa0, %rdx, %rdi
addq %r8, %rdi
movl %r14d, (%rdi,%r10,4)
incq %rdx
movabsq $0x100000000, %rdi      # imm = 0x100000000
addq %rdi, %r12
jmp 0x40926a
incq %r10
addq $0x4, %r11
addq $0x4, %rsi
jmp 0x4091e8
movl $0x1, %eax
movl $0x1c, %edx
movq -0x30(%rsp), %r10
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
testl %edx, %edx
js 0x40933a
movl %edx, %esi
imulq $0xa0, %rsi, %rsi
addq %r8, %rsi
addl %eax, %eax
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x409336
movl (%rsi,%rdi,4), %r9d
imull %eax, %r9d
movl %r9d, (%rsi,%rdi,4)
incq %rdi
jmp 0x409320
decl %edx
jmp 0x40930c
movabsq $0x3e10000000000000, %rax # imm = 0x3E10000000000000
movq %rax, 0x8(%r10)
andl $0x0, (%r10)
xorl %eax, %eax
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x409191
andl $0x0, 0x10(%r10,%rdx,4)
incq %rdx
jmp 0x409350