// File: /workspace/github_c_makefile_star2_O1/zpole[P]IICV/vl/liop.c
// Function: vl_liopdesc_new
VlLiopDesc *
vl_liopdesc_new (vl_int numNeighbours, vl_int numSpatialBins,
                 float radius, vl_size sideLength)
{
  vl_index i, t ;
  VlLiopDesc * self = vl_calloc(sizeof(VlLiopDesc), 1);

  assert(radius <= sideLength/2) ;

  self->numNeighbours = numNeighbours ;
  self->numSpatialBins = numSpatialBins ;
  self->neighRadius = radius ;
  self->intensityThreshold = DEFAULT_INTENSITY_THRESHOLD ;

  self->dimension = factorial(numNeighbours) * numSpatialBins ;

  /*
   Precompute a list of pixels within a circular patch inside
   the square image. Leave a suitable marging for sampling around
   these pixels.
   */

  self->patchSize = 0 ;
  self->patchPixels = vl_malloc(sizeof(vl_uindex)*sideLength*sideLength) ;
  self->patchSideLength = sideLength ;

  {
    vl_index x, y ;
    vl_index center = (sideLength - 1) / 2 ;
    double t = center - radius + 0.6 ;
    vl_index t2 = (vl_index) (t * t) ;
    for (y = 0 ; y < (signed)sideLength ; ++y) {
      for (x = 0 ; x < (signed)sideLength ; ++x) {
        vl_index dx = x - center ;
        vl_index dy = y - center ;
        if (x == 0 && y == 0) continue ;
        if (dx*dx + dy*dy <= t2) {
          self->patchPixels[self->patchSize++] = x + y * sideLength ;
        }
      }
    }
  }

  self->patchIntensities = vl_malloc(sizeof(vl_uindex)*self->patchSize) ;
  self->patchPermutation = vl_malloc(sizeof(vl_uindex)*self->patchSize) ;

  /*
   Precompute the samples in the circular neighbourhood of each
   measurement point.
   */

  self->neighPermutation = vl_malloc(sizeof(vl_uindex) * self->numNeighbours) ;
  self->neighIntensities = vl_malloc(sizeof(float) * self->numNeighbours) ;
  self->neighSamplesX = vl_calloc(sizeof(double), self->numNeighbours * self->patchSize) ;
  self->neighSamplesY = vl_calloc(sizeof(double), self->numNeighbours * self->patchSize) ;

  for (i = 0 ; i < (signed)self->patchSize ; ++i) {
    vl_index pixel ;
    double x, y ;
    double dangle = 2*VL_PI / (double)self->numNeighbours ;
    double angle0 ;
    vl_index center = (sideLength - 1) / 2 ;

    pixel = self->patchPixels[i] ;
    x = (pixel % (signed)self->patchSideLength) - center ;
    y = (pixel / (signed)self->patchSideLength) - center ;

    angle0 = atan2(y,x) ;

    for (t = 0 ; t < (signed)self->numNeighbours ; ++t) {
      double x1 = x + radius * cos(angle0 + dangle * t) + center ;
      double y1 = y + radius * sin(angle0 + dangle * t) + center ;
      self->neighSamplesX[t + (signed)self->numNeighbours * i] = x1 ;
      self->neighSamplesY[t + (signed)self->numNeighbours * i] = y1 ;
    }
  }
  return self ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r14
movss %xmm0, 0x8(%rsp)
movl %esi, %ebp
movl %edi, %r15d
movl $0x68, %edi
movl $0x1, %esi
callq 0x98f0
movq %rax, %rbx
movl %r15d, (%rax)
movl %ebp, 0x4(%rax)
movd 0x8(%rsp), %xmm0
movd %xmm0, 0x40(%rax)
movl $0xbca0a0a1, 0x8(%rax)  # imm = 0xBCA0A0A1
movl $0x1, %eax
cmpl $0x2, %r15d
jl 0x23f06
leal 0x2(%r15), %eax
andl $-0x4, %eax
movd %r15d, %xmm0
addl $-0x2, %r15d
pshufd $0x0, %xmm0, %xmm3      # xmm3 = xmm0[0,0,0,0]
paddd 0x10386(%rip), %xmm3    # 0x341e0
movd %r15d, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa 0x10384(%rip), %xmm1    # 0x341f0
movl $0x4, %ecx
movdqa 0x10387(%rip), %xmm4    # 0x34200
movdqa %xmm1, %xmm2
movdqa %xmm3, %xmm1
pmuludq %xmm2, %xmm1
pshufd $0xe8, %xmm1, %xmm1     # xmm1 = xmm1[0,2,2,3]
pshufd $0xf5, %xmm2, %xmm5     # xmm5 = xmm2[1,1,3,3]
pshufd $0xf5, %xmm3, %xmm6     # xmm6 = xmm3[1,1,3,3]
pmuludq %xmm5, %xmm6
pshufd $0xe8, %xmm6, %xmm5     # xmm5 = xmm6[0,2,2,3]
punpckldq %xmm5, %xmm1    # xmm1 = xmm1[0],xmm5[0],xmm1[1],xmm5[1]
paddd %xmm4, %xmm3
movl %ecx, %edx
addl $-0x4, %ecx
addl %eax, %edx
addl $-0x4, %edx
cmpl $0x4, %edx
jne 0x23e79
negl %ecx
movd %ecx, %xmm3
pshufd $0x0, %xmm3, %xmm3      # xmm3 = xmm3[0,0,0,0]
por 0x10349(%rip), %xmm3    # 0x34210
movdqa 0xf141(%rip), %xmm4     # 0x33010
pxor %xmm4, %xmm0
pxor %xmm4, %xmm3
pcmpgtd %xmm0, %xmm3
pand %xmm3, %xmm2
pandn %xmm1, %xmm3
por %xmm2, %xmm3
pshufd $0xee, %xmm3, %xmm0     # xmm0 = xmm3[2,3,2,3]
pshufd $0xff, %xmm3, %xmm1     # xmm1 = xmm3[3,3,3,3]
pshufd $0xf5, %xmm3, %xmm2     # xmm2 = xmm3[1,1,3,3]
pmuludq %xmm1, %xmm2
pmuludq %xmm3, %xmm0
pmuludq %xmm2, %xmm0
movd %xmm0, %eax
imull %ebp, %eax
cltq
movq %rax, 0x10(%rbx)
movq $0x0, 0x20(%rbx)
movq %r14, %rdi
imulq %r14, %rdi
shlq $0x3, %rdi
callq 0x95b0
movq %rax, 0x28(%rbx)
movq %r14, 0x18(%rbx)
leaq -0x1(%r14), %r15
shrq %r15
movslq %r14d, %rcx
testq %rcx, %rcx
jle 0x23fb9
xorps %xmm0, %xmm0
cvtsi2ss %r15, %xmm0
subss 0x8(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0xf290(%rip), %xmm0     # 0x331e8
mulsd %xmm0, %xmm0
cvttsd2si %xmm0, %rdx
movq %r15, %rsi
negq %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movq %r8, %r9
subq %r15, %r9
imulq %r9, %r9
xorl %r10d, %r10d
movq %r10, %r11
orq %r8, %r11
je 0x23fa6
leaq (%rsi,%r10), %r11
imulq %r11, %r11
addq %r9, %r11
cmpq %rdx, %r11
jg 0x23fa6
leaq (%rdi,%r10), %r11
movq 0x20(%rbx), %r12
leaq 0x1(%r12), %r13
movq %r13, 0x20(%rbx)
movq %r11, (%rax,%r12,8)
incq %r10
cmpq %r10, %rcx
jne 0x23f79
incq %r8
addq %r14, %rdi
cmpq %rcx, %r8
jne 0x23f6c
movq 0x20(%rbx), %rdi
shlq $0x3, %rdi
callq 0x95b0
movq %rax, 0x30(%rbx)
movq 0x20(%rbx), %rdi
shlq $0x3, %rdi
callq 0x95b0
movq %rax, 0x38(%rbx)
movslq (%rbx), %rdi
shlq $0x3, %rdi
callq 0x95b0
movq %rax, 0x50(%rbx)
movslq (%rbx), %rdi
shlq $0x2, %rdi
callq 0x95b0
movq %rax, 0x48(%rbx)
movslq (%rbx), %rsi
imulq 0x20(%rbx), %rsi
movl $0x8, %edi
callq 0x98f0
movq %rax, 0x58(%rbx)
movslq (%rbx), %rsi
imulq 0x20(%rbx), %rsi
movl $0x8, %edi
callq 0x98f0
movq %rax, 0x60(%rbx)
cmpl $0x0, 0x20(%rbx)
jle 0x2416a
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
movsd %xmm0, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r14d, %r14d
xorl %r12d, %r12d
xorps %xmm0, %xmm0
cvtsi2sdl (%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rbx), %rax
movq (%rax,%r12,8), %rax
movslq 0x18(%rbx), %rcx
cqto
idivq %rcx
subq %r15, %rdx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
subq %r15, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd %xmm1, 0x38(%rsp)
callq 0x96e0
cmpl $0x0, (%rbx)
jle 0x24156
movapd %xmm0, %xmm1
movsd 0xf2f2(%rip), %xmm0     # 0x333a0
divsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %r13d, %r13d
movsd %xmm1, 0x28(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
mulsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
callq 0x9450
mulsd 0x8(%rsp), %xmm0
addsd 0x38(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x9860
movsd 0x8(%rsp), %xmm3
movsd 0x18(%rsp), %xmm2
movsd 0x28(%rsp), %xmm1
mulsd %xmm3, %xmm0
addsd 0x30(%rsp), %xmm0
addsd %xmm2, %xmm0
movslq (%rbx), %rax
imulq %r14, %rax
movq 0x58(%rbx), %rcx
addq %rax, %rcx
movq 0x10(%rsp), %xmm4
movq %xmm4, (%rcx,%r13,8)
addq 0x60(%rbx), %rax
movsd %xmm0, (%rax,%r13,8)
incq %r13
movslq (%rbx), %rax
cmpq %rax, %r13
jl 0x240c3
incq %r12
movslq 0x20(%rbx), %rax
addq $0x8, %r14
cmpq %rax, %r12
jl 0x24054
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq