// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpl $0x1, -0x14(%rbp)
jb 0x410b8f
cmpl $0x28, -0x14(%rbp)
jbe 0x410b9b
movl $0x4, -0x4(%rbp)
jmp 0x410e49
movl $0x0, -0x2c(%rbp)
cmpl $0x1e, -0x2c(%rbp)
jge 0x410bd1
movq -0x20(%rbp), %rax
addq $0xb0, %rax
movslq -0x2c(%rbp), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x410ba2
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x410d81
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
movslq -0x34(%rbp), %rcx
leaq 0xd403b(%rip), %rax     # 0x4e4c30
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movslq -0x34(%rbp), %rcx
leaq 0xd40ca(%rip), %rax     # 0x4e4cd0
movl (%rax,%rcx,4), %eax
movl %eax, -0x64(%rbp)
movl -0x38(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0x410c52
movl -0x64(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
sete %al
andb $0x1, %al
movzbl %al, %ecx
movslq -0x2c(%rbp), %rax
movl %ecx, -0x60(%rbp,%rax,4)
movl -0x64(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x64(%rbp)
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x410c15
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x410ca5
movslq -0x28(%rbp), %rcx
leaq 0xd4104(%rip), %rax     # 0x4e4d70
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %edx
movq -0x20(%rbp), %rax
addq $0xb0, %rax
movslq -0x28(%rbp), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x410c59
movl -0x38(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x1e, -0x28(%rbp)
jge 0x410d71
movq -0x20(%rbp), %rax
addq $0xb0, %rax
movl -0x28(%rbp), %ecx
subl -0x38(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rbp)
movl $0x1, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x410d42
movl -0x30(%rbp), %eax
shll %eax
movl %eax, -0x30(%rbp)
movslq -0x2c(%rbp), %rax
cmpl $0x0, -0x60(%rbp,%rax,4)
je 0x410d35
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
addq $0xb0, %rcx
movl -0x28(%rbp), %edx
subl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0xa0, %rdx, %rdx
addq %rdx, %rcx
movl -0x24(%rbp), %edx
imull (%rcx,%rdx,4), %eax
xorl -0x68(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x410d37
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x410ce9
movl -0x68(%rbp), %edx
movq -0x20(%rbp), %rax
addq $0xb0, %rax
movslq -0x28(%rbp), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x410cab
jmp 0x410d73
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x410bd8
movl $0x1, -0x30(%rbp)
movl $0x1c, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jl 0x410de9
movl -0x30(%rbp), %eax
shll %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x410ddc
movl -0x30(%rbp), %edx
movq -0x20(%rbp), %rax
addq $0xb0, %rax
movslq -0x28(%rbp), %rcx
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
imull (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x410da4
jmp 0x410dde
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x410d8f
cvtsi2sdl -0x30(%rbp), %xmm0
movsd 0xd3e32(%rip), %xmm1    # 0x4e4c28
mulsd %xmm0, %xmm1
movsd 0xd3e1e(%rip), %xmm0    # 0x4e4c20
divsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x410e42
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movl $0x0, 0x10(%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x410e20
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nop