// File: /workspace/github_c_makefile_star2_O0/josch[P]stride/nsc.c
// Function: make_unsp
int make_unsp(int densit, int mode, int * num_dot, int cubus) {
  int ndot, ico_cube_cb, i, j, k, l, ijk, tn, tl, tl2;
  point_double xus;
  point_int    work;
  double x, y, z;

  if (xpunsp) free(xpunsp); if (ico_wk) free(ico_wk);

  k=1; if (mode < 0) { k=0; mode = -mode; }
  if (mode == UNSP_ICO_ARC)      { ndot = ico_dot_arc(densit); }
  else if (mode == UNSP_ICO_DOD)      { ndot = ico_dot_dod(densit); }
  else {
    WARNING("make_unsp: mode %c%d not allowed", (k) ? '+':'-',mode);
    return 1;
    }

  last_n_dot = ndot; last_densit = densit; last_unsp = mode;
  *num_dot=ndot; if (k) return 0;

/* in the following the dots of the unit sphere may be resorted */
  last_unsp = -last_unsp;

/* determine distribution of points in elementary cubes */
  if (cubus) {
    ico_cube = cubus;
    }
  else {
    last_cubus = 0;
    i=1;
    while (i*i*i*2 < ndot) i++;
    ico_cube = MAXIMUM(i-1, 0);
    }
  ico_cube_cb = ico_cube*ico_cube*ico_cube;
  del_cube=2./((double)ico_cube);
  work = (int *) CALLOC(ndot, sizeof(int));
  xus = xpunsp;
  for (l=0; l<ndot; l++) {
    i = MAXIMUM((int) floor((1.+xus[3*l])/del_cube), 0);
    if (i>=ico_cube) i = ico_cube-1;
    j = MAXIMUM((int) floor((1.+xus[1+3*l])/del_cube), 0);
    if (j>=ico_cube) j = ico_cube-1;
    k = MAXIMUM((int) floor((1.+xus[2+3*l])/del_cube), 0);
    if (k>=ico_cube) k = ico_cube-1;
    ijk = i+j*ico_cube+k*ico_cube*ico_cube;
    work[l] = ijk;
    }

  ico_wk = (int *) CALLOC(2*ico_cube_cb+1, sizeof(int));
  ico_pt = ico_wk+ico_cube_cb;
  for (l=0; l<ndot; l++) {
    ico_wk[work[l]]++;   /* dots per elementary cube */
    }

/* reordering of the coordinate array in accordance with box number */
  tn=0;
  for (i=0; i<ico_cube; i++) {
    for (j=0; j<ico_cube; j++) {
      for (k=0; k<ico_cube; k++) {
        tl=0;
        tl2 = tn;
        ijk = i+ico_cube*j+ico_cube*ico_cube*k;
        *(ico_pt+ijk) = tn;
        for (l=tl2; l<ndot; l++) {
          if (ijk == work[l]) {
            x = xus[3*l]; y = xus[1+3*l]; z = xus[2+3*l];
            xus[3*l] = xus[3*tn];
            xus[1+3*l] = xus[1+3*tn]; xus[2+3*l] = xus[2+3*tn];
            xus[3*tn] = x; xus[1+3*tn] = y; xus[2+3*tn] = z;
            ijk = work[l]; work[l]=work[tn]; work[tn]=ijk;
            tn++; tl++;
            }
          }
        *(ico_wk+ijk) = tl;
        }		/* cycle k */
      }			/* cycle j */
    }			/* cycle i */
  free(work); return 0;
  }

// Assembly:
subq $0x88, %rsp
movl %edi, 0x80(%rsp)
movl %esi, 0x7c(%rsp)
movq %rdx, 0x70(%rsp)
movl %ecx, 0x6c(%rsp)
cmpq $0x0, 0x111cd(%rip)     # 0x31e70
je 0x20cb1
movq 0x111c4(%rip), %rdi     # 0x31e70
callq 0x2030
cmpq $0x0, 0x111bf(%rip)     # 0x31e78
je 0x20cc7
movq 0x111b6(%rip), %rdi     # 0x31e78
callq 0x2030
movl $0x1, 0x58(%rsp)
cmpl $0x0, 0x7c(%rsp)
jge 0x20ce8
movl $0x0, 0x58(%rsp)
xorl %eax, %eax
subl 0x7c(%rsp), %eax
movl %eax, 0x7c(%rsp)
cmpl $0xa, 0x7c(%rsp)
jne 0x20d01
movl 0x80(%rsp), %edi
callq 0x1e4f0
movl %eax, 0x68(%rsp)
jmp 0x20d6a
cmpl $0x9, 0x7c(%rsp)
jne 0x20d1a
movl 0x80(%rsp), %edi
callq 0x1f4e0
movl %eax, 0x68(%rsp)
jmp 0x20d68
leaq 0xba20(%rip), %rax      # 0x2c741
movq %rax, 0x11178(%rip)     # 0x31ea0
movl $0x1bc, 0x11166(%rip)   # imm = 0x1BC
movl 0x58(%rsp), %ecx
movl $0x2d, %esi
movl $0x2b, %eax
cmpl $0x0, %ecx
cmovnel %eax, %esi
movl 0x7c(%rsp), %edx
leaq 0xbb8f(%rip), %rdi      # 0x2c8e0
movb $0x0, %al
callq 0x1d5c0
movl $0x1, 0x84(%rsp)
jmp 0x213b5
jmp 0x20d6a
movl 0x68(%rsp), %eax
movl %eax, 0x11114(%rip)     # 0x31e88
movl 0x80(%rsp), %eax
movl %eax, 0x1110b(%rip)     # 0x31e8c
movl 0x7c(%rsp), %eax
movl %eax, 0x11105(%rip)     # 0x31e90
movl 0x68(%rsp), %ecx
movq 0x70(%rsp), %rax
movl %ecx, (%rax)
cmpl $0x0, 0x58(%rsp)
je 0x20dad
movl $0x0, 0x84(%rsp)
jmp 0x213b5
xorl %eax, %eax
subl 0x110db(%rip), %eax     # 0x31e90
movl %eax, 0x110d5(%rip)     # 0x31e90
cmpl $0x0, 0x6c(%rsp)
je 0x20dce
movl 0x6c(%rsp), %eax
movl %eax, 0x110f0(%rip)     # 0x31ebc
jmp 0x20e2e
movl $0x0, 0x110bc(%rip)     # 0x31e94
movl $0x1, 0x60(%rsp)
movl 0x60(%rsp), %eax
imull 0x60(%rsp), %eax
imull 0x60(%rsp), %eax
shll %eax
cmpl 0x68(%rsp), %eax
jge 0x20e03
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x20de0
movl 0x60(%rsp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jle 0x20e1c
movl 0x60(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x20e24
xorl %eax, %eax
movl %eax, 0x14(%rsp)
jmp 0x20e24
movl 0x14(%rsp), %eax
movl %eax, 0x1108e(%rip)     # 0x31ebc
movl 0x11088(%rip), %eax     # 0x31ebc
imull 0x11081(%rip), %eax     # 0x31ebc
imull 0x1107a(%rip), %eax     # 0x31ebc
movl %eax, 0x64(%rsp)
cvtsi2sdl 0x1106e(%rip), %xmm1 # 0x31ebc
movsd 0xac62(%rip), %xmm0     # 0x2bab8
divsd %xmm1, %xmm0
movsd %xmm0, 0x1105e(%rip)    # 0x31ec0
movslq 0x68(%rsp), %rdx
leaq 0xb8d3(%rip), %rdi      # 0x2c741
movl $0x1d2, %esi            # imm = 0x1D2
movl $0x4, %ecx
callq 0x1d7a0
movq %rax, 0x30(%rsp)
movq 0x10fe7(%rip), %rax     # 0x31e70
movq %rax, 0x38(%rsp)
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x68(%rsp), %eax
jge 0x21098
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
movslq %ecx, %rcx
movsd 0xa93f(%rip), %xmm0     # 0x2b7f8
addsd (%rax,%rcx,8), %xmm0
divsd 0x10ffa(%rip), %xmm0    # 0x31ec0
callq 0x21c0
cvttsd2si %xmm0, %eax
cmpl $0x0, %eax
jle 0x20f05
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
movslq %ecx, %rcx
movsd 0xa90f(%rip), %xmm0     # 0x2b7f8
addsd (%rax,%rcx,8), %xmm0
divsd 0x10fca(%rip), %xmm0    # 0x31ec0
callq 0x21c0
cvttsd2si %xmm0, %eax
movl %eax, 0x10(%rsp)
jmp 0x20f0d
xorl %eax, %eax
movl %eax, 0x10(%rsp)
jmp 0x20f0d
movl 0x10(%rsp), %eax
movl %eax, 0x60(%rsp)
movl 0x60(%rsp), %eax
cmpl 0x10f9d(%rip), %eax     # 0x31ebc
jl 0x20f2e
movl 0x10f95(%rip), %eax     # 0x31ebc
subl $0x1, %eax
movl %eax, 0x60(%rsp)
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd 0xa8b2(%rip), %xmm0     # 0x2b7f8
addsd (%rax,%rcx,8), %xmm0
divsd 0x10f6d(%rip), %xmm0    # 0x31ec0
callq 0x21c0
cvttsd2si %xmm0, %eax
cmpl $0x0, %eax
jle 0x20f95
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd 0xa87f(%rip), %xmm0     # 0x2b7f8
addsd (%rax,%rcx,8), %xmm0
divsd 0x10f3a(%rip), %xmm0    # 0x31ec0
callq 0x21c0
cvttsd2si %xmm0, %eax
movl %eax, 0xc(%rsp)
jmp 0x20f9d
xorl %eax, %eax
movl %eax, 0xc(%rsp)
jmp 0x20f9d
movl 0xc(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x10f0d(%rip), %eax     # 0x31ebc
jl 0x20fbe
movl 0x10f05(%rip), %eax     # 0x31ebc
subl $0x1, %eax
movl %eax, 0x5c(%rsp)
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movsd 0xa822(%rip), %xmm0     # 0x2b7f8
addsd (%rax,%rcx,8), %xmm0
divsd 0x10edd(%rip), %xmm0    # 0x31ec0
callq 0x21c0
cvttsd2si %xmm0, %eax
cmpl $0x0, %eax
jle 0x21025
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movsd 0xa7ef(%rip), %xmm0     # 0x2b7f8
addsd (%rax,%rcx,8), %xmm0
divsd 0x10eaa(%rip), %xmm0    # 0x31ec0
callq 0x21c0
cvttsd2si %xmm0, %eax
movl %eax, 0x8(%rsp)
jmp 0x2102d
xorl %eax, %eax
movl %eax, 0x8(%rsp)
jmp 0x2102d
movl 0x8(%rsp), %eax
movl %eax, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x10e7d(%rip), %eax     # 0x31ebc
jl 0x2104e
movl 0x10e75(%rip), %eax     # 0x31ebc
subl $0x1, %eax
movl %eax, 0x58(%rsp)
movl 0x60(%rsp), %eax
movl 0x5c(%rsp), %ecx
imull 0x10e5f(%rip), %ecx     # 0x31ebc
addl %ecx, %eax
movl 0x58(%rsp), %ecx
imull 0x10e52(%rip), %ecx     # 0x31ebc
imull 0x10e4b(%rip), %ecx     # 0x31ebc
addl %ecx, %eax
movl %eax, 0x50(%rsp)
movl 0x50(%rsp), %edx
movq 0x30(%rsp), %rax
movslq 0x54(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x20e96
movl 0x64(%rsp), %eax
shll %eax
addl $0x1, %eax
movslq %eax, %rdx
leaq 0xb696(%rip), %rdi      # 0x2c741
movl $0x1df, %esi            # imm = 0x1DF
movl $0x4, %ecx
callq 0x1d7a0
movq %rax, 0x10db7(%rip)     # 0x31e78
movq 0x10db0(%rip), %rax     # 0x31e78
movslq 0x64(%rsp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x10da5(%rip)     # 0x31e80
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x68(%rsp), %eax
jge 0x21118
movq 0x10d84(%rip), %rax     # 0x31e78
movq 0x30(%rsp), %rcx
movslq 0x54(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x210e3
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
cmpl 0x10d8a(%rip), %eax     # 0x31ebc
jge 0x213a0
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x10d72(%rip), %eax     # 0x31ebc
jge 0x2138e
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x10d5a(%rip), %eax     # 0x31ebc
jge 0x2137c
movl $0x0, 0x48(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x60(%rsp), %eax
movl 0x10d3a(%rip), %ecx     # 0x31ebc
imull 0x5c(%rsp), %ecx
addl %ecx, %eax
movl 0x10d2d(%rip), %ecx     # 0x31ebc
imull 0x10d26(%rip), %ecx     # 0x31ebc
imull 0x58(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x50(%rsp)
movl 0x4c(%rsp), %edx
movq 0x10cd4(%rip), %rax     # 0x31e80
movslq 0x50(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x44(%rsp), %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x68(%rsp), %eax
jge 0x21359
movl 0x50(%rsp), %eax
movq 0x30(%rsp), %rcx
movslq 0x54(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x21347
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x38(%rsp), %rax
imull $0x3, 0x4c(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x38(%rsp), %rax
imull $0x3, 0x4c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x38(%rsp), %rax
imull $0x3, 0x4c(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rax
imull $0x3, 0x54(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x28(%rsp), %xmm0
movq 0x38(%rsp), %rax
imull $0x3, 0x4c(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x20(%rsp), %xmm0
movq 0x38(%rsp), %rax
imull $0x3, 0x4c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x18(%rsp), %xmm0
movq 0x38(%rsp), %rax
imull $0x3, 0x4c(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x30(%rsp), %rax
movslq 0x54(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x50(%rsp)
movq 0x30(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x30(%rsp), %rax
movslq 0x54(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x50(%rsp), %edx
movq 0x30(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x21349
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x211bc
movl 0x48(%rsp), %edx
movq 0x10b14(%rip), %rax     # 0x31e78
movslq 0x50(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x21158
jmp 0x2137e
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x21140
jmp 0x21390
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x21128
movq 0x30(%rsp), %rdi
callq 0x2030
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)