// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x68
popq %rdi
pushq $0x1
popq %rsi
callq 0x9960
movq %rax, %rbx
movl %r15d, (%rax)
movl %ebp, 0x4(%rax)
movss 0x8(%rsp), %xmm0
movss %xmm0, 0x40(%rax)
movl $0xbca0a0a1, 0x8(%rax)  # imm = 0xBCA0A0A1
movl %r15d, %edi
callq 0x20079
imull %ebp, %eax
cltq
movq %rax, 0x10(%rbx)
andq $0x0, 0x20(%rbx)
movq %r14, %rdi
imulq %r14, %rdi
shlq $0x3, %rdi
callq 0x95e0
movq %rax, 0x28(%rbx)
leaq -0x1(%r14), %r15
shrq %r15
cvtsi2ss %r15, %xmm0
subss 0x8(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0xd342(%rip), %xmm0     # 0x2d1b0
mulsd %xmm0, %xmm0
cvttsd2si %xmm0, %rcx
movslq %r14d, %rdx
xorl %esi, %esi
testq %rdx, %rdx
movl $0x0, %edi
cmovgq %rdx, %rdi
movq %r14, 0x18(%rbx)
movq %r15, %r8
negq %r8
xorl %r9d, %r9d
cmpq %rdi, %r9
je 0x1fee5
movq %r9, %r10
subq %r15, %r10
imulq %r10, %r10
xorl %r11d, %r11d
cmpq %r11, %rdx
je 0x1fedd
movq %r11, %r12
orq %r9, %r12
je 0x1fed8
leaq (%r8,%r11), %r12
imulq %r12, %r12
addq %r10, %r12
cmpq %rcx, %r12
jg 0x1fed8
leaq (%rsi,%r11), %r12
movq 0x20(%rbx), %r13
leaq 0x1(%r13), %rbp
movq %rbp, 0x20(%rbx)
movq %r12, (%rax,%r13,8)
incq %r11
jmp 0x1fea7
incq %r9
addq %r14, %rsi
jmp 0x1fe95
movq 0x20(%rbx), %rdi
shlq $0x3, %rdi
callq 0x95e0
movq %rax, 0x30(%rbx)
movq 0x20(%rbx), %rdi
shlq $0x3, %rdi
callq 0x95e0
movq %rax, 0x38(%rbx)
movslq (%rbx), %rdi
shlq $0x3, %rdi
callq 0x95e0
movq %rax, 0x50(%rbx)
movslq (%rbx), %rdi
shlq $0x2, %rdi
callq 0x95e0
movq %rax, 0x48(%rbx)
movslq (%rbx), %rsi
imulq 0x20(%rbx), %rsi
pushq $0x8
popq %r14
movq %r14, %rdi
callq 0x9960
movq %rax, 0x58(%rbx)
movslq (%rbx), %rsi
imulq 0x20(%rbx), %rsi
movq %r14, %rdi
callq 0x9960
movq %rax, 0x60(%rbx)
cvtsi2sd %r15, %xmm0
movsd %xmm0, 0x10(%rsp)
cvtss2sd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r14d, %r14d
xorl %r12d, %r12d
movslq 0x20(%rbx), %rax
cmpq %rax, %r12
jge 0x20067
cvtsi2sdl (%rbx), %xmm0
movq 0x28(%rbx), %rax
movq (%rax,%r12,8), %rax
movslq 0x18(%rbx), %rcx
cqto
idivq %rcx
movsd 0xd3e6(%rip), %xmm1     # 0x2d380
divsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
subq %r15, %rdx
cvtsi2sd %rdx, %xmm1
subq %r15, %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x28(%rsp)
callq 0x9730
movsd %xmm0, 0x18(%rsp)
movl (%rbx), %eax
xorl %r13d, %r13d
cltq
cmpq %rax, %r13
jge 0x2005b
cvtsi2sd %r13, %xmm0
mulsd 0x30(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
callq 0x9470
mulsd 0x8(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x38(%rsp), %xmm0
callq 0x98d0
mulsd 0x8(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movslq (%rbx), %rax
movq %rax, %rcx
imulq %r14, %rcx
movq 0x58(%rbx), %rdx
addq %rcx, %rdx
movsd 0x40(%rsp), %xmm1
movsd %xmm1, (%rdx,%r13,8)
addq 0x60(%rbx), %rcx
movsd %xmm0, (%rcx,%r13,8)
incq %r13
jmp 0x1ffd0
incq %r12
addq $0x8, %r14
jmp 0x1ff70
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq