// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leal -0x29(%rsi), %eax
movl $0x4, %ebx
cmpl $-0x28, %eax
jb 0x40a589
leaq 0xb0(%rdi), %rax
movdqa 0xcda6e(%rip), %xmm0    # 0x4d7d30
movdqa 0xcd676(%rip), %xmm1    # 0x4d7940
movl $0x290, %ecx            # imm = 0x290
movdqa 0xcd679(%rip), %xmm2    # 0x4d7950
movdqa 0xcda61(%rip), %xmm3    # 0x4d7d40
pshufd $0xf5, %xmm3, %xmm4     # xmm4 = xmm3[1,1,3,3]
movdqa 0xcda64(%rip), %xmm5    # 0x4d7d50
movdqa %xmm1, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm3, %xmm7
pcmpgtd %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pcmpeqd %xmm4, %xmm6
pand %xmm7, %xmm6
movd %xmm6, %edx
testb $0x1, %dl
je 0x40a31d
movl $0x1, -0x1e0(%rdi,%rcx)
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0x40a332
movl $0x1, -0x140(%rdi,%rcx)
movdqa %xmm0, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm3, %xmm7
pcmpgtd %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pcmpeqd %xmm4, %xmm6
pand %xmm7, %xmm6
pextrw $0x0, %xmm6, %edx
testb $0x1, %dl
je 0x40a364
movl $0x1, -0xa0(%rdi,%rcx)
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0x40a375
movl $0x1, (%rdi,%rcx)
paddq %xmm5, %xmm1
paddq %xmm5, %xmm0
addq $0x280, %rcx            # imm = 0x280
cmpq $0x1690, %rcx           # imm = 0x1690
jne 0x40a2ec
movq %rdi, 0x8(%rsp)
movl %esi, %r11d
movq %rsi, 0x10(%rsp)
cmpl $0x2, %esi
jb 0x40a4fa
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
movq 0x8(%rsp), %rcx
leaq 0xb4(%rcx), %r8
movl $0x1, %r9d
leaq 0xcdada(%rip), %r10     # 0x4d7ea4
movq %r11, 0x18(%rsp)
leaq 0xcd98a(%rip), %rcx     # 0x4d7d60
movslq (%rcx,%r9,4), %rcx
leaq 0xcda1f(%rip), %rdx     # 0x4d7e00
movl (%rdx,%r9,4), %ebx
leal 0x1(%rcx), %edx
leal -0x1(%rcx), %edi
leaq (%rsp,%rdi,4), %rdi
addq $0x20, %rdi
movl %ebx, %r11d
movl %ebx, %ebp
andl $0x80000001, %ebp       # imm = 0x80000001
xorl %r15d, %r15d
cmpl $0x1, %ebp
sete %r15b
movl %r15d, (%rdi)
shrl $0x1f, %r11d
addl %ebx, %r11d
sarl %r11d
decl %edx
addq $-0x4, %rdi
movl %r11d, %ebx
cmpl $0x1, %edx
jg 0x40a3f6
cmpl $0x2, %ecx
movl $0x1, %r12d
cmovgel %ecx, %r12d
movq %r12, %rdx
shlq $0x5, %rdx
leaq (%rdx,%rdx,4), %rdx
xorl %edi, %edi
movl (%r10,%rdi), %r11d
movl %r11d, (%r8,%rdi)
addq $0xa0, %rdi
cmpq %rdi, %rdx
jne 0x40a43d
cmpl $0x1e, %ecx
movl $0x1d, %ebp
cmovgel %ecx, %ebp
incl %ebp
movq %rcx, %r14
shlq $0x20, %r14
addq %rsi, %r14
movq %rcx, %r15
movq %r15, %rdx
subq %rcx, %rdx
leaq (%rdx,%rdx,4), %rdx
shlq $0x5, %rdx
addq %rax, %rdx
movl (%rdx,%r9,4), %ebx
movl $0x1, %edx
movq %r14, %r11
xorl %edi, %edi
addl %edx, %edx
cmpl $0x0, 0x20(%rsp,%rdi,4)
je 0x40a4b2
movq %r11, %r13
sarq $0x20, %r13
leaq (%r13,%r13,4), %r13
shlq $0x5, %r13
addq %rax, %r13
movl (%r13,%r9,4), %r13d
imull %edx, %r13d
xorl %r13d, %ebx
incq %rdi
addq %rsi, %r11
cmpq %rdi, %r12
jne 0x40a48a
leaq (%r15,%r15,4), %rdx
shlq $0x5, %rdx
addq %rax, %rdx
movl %ebx, (%rdx,%r9,4)
incq %r15
movabsq $0x100000000, %rdx      # imm = 0x100000000
addq %rdx, %r14
cmpl %r15d, %ebp
jne 0x40a46b
incq %r9
addq $0x4, %r10
addq $0x4, %r8
movq 0x18(%rsp), %r11
cmpq %r11, %r9
jne 0x40a3cf
movq 0x8(%rsp), %rdi
leaq 0x1230(%rdi), %rax
movl $0x1, %esi
movl $0x1c, %r8d
movq 0x10(%rsp), %rdx
addl %esi, %esi
testl %edx, %edx
je 0x40a539
xorl %r9d, %r9d
movl (%rax,%r9,4), %ecx
imull %esi, %ecx
movl %ecx, (%rax,%r9,4)
incq %r9
cmpq %r9, %r11
jne 0x40a51f
testq %r8, %r8
jne 0x40a53e
jmp 0x40a549
testq %r8, %r8
je 0x40a573
decq %r8
addq $-0xa0, %rax
jmp 0x40a516
movabsq $0x3e10000000000000, %rax # imm = 0x3E10000000000000
movq %rax, 0x8(%rdi)
movl $0x0, (%rdi)
testl %edx, %edx
je 0x40a587
addq $0x10, %rdi
shll $0x2, %edx
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x4010e0
jmp 0x40a589
movabsq $0x3e10000000000000, %rax # imm = 0x3E10000000000000
movq %rax, 0x8(%rdi)
movl $0x0, (%rdi)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq