// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/aib.c
// Function: vl_aib_update_beta
void
vl_aib_update_beta (VlAIB * aib)
{

#define PLOGP(x) ((x)*log((x)))

  vl_uint i;
  double * Px  = aib->Px;
  double * Pcx = aib->Pcx;
  double * tmp = vl_malloc(sizeof(double)*aib->nentries);
  vl_uint a, b, c ;

  /*
   * T1 = I(x,c) - I([x]_ij) = A + B - C
   *
   * A  = \sum_c p(xa,c)           \log ( p(xa,c)          /  p(xa)       )
   * B  = \sum_c p(xb,c)           \log ( p(xb,c)          /  p(xb)       )
   * C  = \sum_c (p(xa,c)+p(xb,c)) \log ((p(xa,c)+p(xb,c)) / (p(xa)+p(xb)))
   *
   * C  = C1 + C2
   * C1 = \sum_c (p(xa,c)+p(xb,c)) \log (p(xa,c)+p(xb,c))
   * C2 = - (p(xa)+p(xb) \log (p(xa)+p(xb))
   */

  /* precalculate A and B */
  for (a = 0; a < aib->nentries; a++) {
    tmp[a] = 0;
    for (c = 0; c < aib->nlabels; c++) {
        double Pac = Pcx [a*aib->nlabels + c] ;
        if(Pac != 0) tmp[a] += Pac * log (Pac / Px[a]) ;
    }
  }

  /* for each entry listed in which */
  for (i = 0 ; i < aib->nwhich; i++) {
    a = aib->which[i];

    /* for each other entry */
    for(b = 0 ; b < aib->nentries ; b++) {
      double T1 = 0 ;

      if (a == b || Px [a] == 0 || Px [b] == 0) continue ;


      T1 = PLOGP ((Px[a] + Px[b])) ;                  /* - C2 */
      T1 += tmp[a] + tmp[b] ;                         /* + A + B */

      for (c = 0 ; c < aib->nlabels; ++ c) {
        double Pac = Pcx [a*aib->nlabels + c] ;
        double Pbc = Pcx [b*aib->nlabels + c] ;
        if (Pac == 0 && Pbc == 0) continue;
        T1 += - PLOGP ((Pac + Pbc)) ;                 /* - C1 */
      }

      /*
       * Now we have beta(a,b). We check wether this is the best beta
       * for entries a and b.
       */
      {
        double beta = T1 ;

        if (beta < aib->beta[a])
          {
            aib->beta[a] = beta;
            aib->bidx[a] = b;
          }
        if (beta < aib->beta[b])
          {
            aib->beta[b] = beta;
            aib->bidx[b] = a;
          }
      }
    }
  }
  vl_free(tmp);
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x70(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x70(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x9660
movq %rax, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movq 0x70(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xa475
movq 0x50(%rsp), %rax
movl 0x4c(%rsp), %ecx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x70(%rsp), %rcx
cmpl 0x4c(%rcx), %eax
jae 0xa463
movq 0x58(%rsp), %rax
movl 0x4c(%rsp), %ecx
movq 0x70(%rsp), %rdx
imull 0x4c(%rdx), %ecx
addl 0x44(%rsp), %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xa408
jp 0xa408
jmp 0xa451
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x38(%rsp), %xmm0
movq 0x60(%rsp), %rax
movl 0x4c(%rsp), %ecx
divsd (%rax,%rcx,8), %xmm0
callq 0x94c0
movaps %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
movq 0x50(%rsp), %rax
movl 0x4c(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0xa453
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xa3c0
jmp 0xa465
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xa395
movl $0x0, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
movq 0x70(%rsp), %rcx
cmpl 0x28(%rcx), %eax
jae 0xa734
movq 0x70(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x6c(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, 0x4c(%rsp)
movl $0x0, 0x48(%rsp)
movl 0x48(%rsp), %eax
movq 0x70(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xa722
xorps %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x48(%rsp), %eax
je 0xa504
movq 0x60(%rsp), %rax
movl 0x4c(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xa4eb
jp 0xa4eb
jmp 0xa504
movq 0x60(%rsp), %rax
movl 0x48(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xa509
jp 0xa509
jmp 0xa712
movq 0x60(%rsp), %rax
movl 0x4c(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
movq 0x60(%rsp), %rax
movl 0x48(%rsp), %ecx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x60(%rsp), %rax
movl 0x4c(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
movq 0x60(%rsp), %rax
movl 0x48(%rsp), %ecx
addsd (%rax,%rcx,8), %xmm0
callq 0x94c0
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x50(%rsp), %rax
movl 0x4c(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
movq 0x50(%rsp), %rax
movl 0x48(%rsp), %ecx
addsd (%rax,%rcx,8), %xmm0
addsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x70(%rsp), %rcx
cmpl 0x4c(%rcx), %eax
jae 0xa670
movq 0x58(%rsp), %rax
movl 0x4c(%rsp), %ecx
movq 0x70(%rsp), %rdx
imull 0x4c(%rdx), %ecx
addl 0x44(%rsp), %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x58(%rsp), %rax
movl 0x48(%rsp), %ecx
movq 0x70(%rsp), %rdx
imull 0x4c(%rdx), %ecx
addl 0x44(%rsp), %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xa60b
jp 0xa60b
movsd 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xa60b
jp 0xa60b
jmp 0xa660
movsd 0x28(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x28(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
callq 0x94c0
movaps %xmm0, %xmm2
movsd (%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xa58f
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rsp), %xmm1
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x4c(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa6c6
movsd 0x18(%rsp), %xmm0
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x4c(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movl 0x48(%rsp), %edx
movq 0x70(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x4c(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movsd 0x18(%rsp), %xmm1
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x48(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa710
movsd 0x18(%rsp), %xmm0
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x48(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movl 0x4c(%rsp), %edx
movq 0x70(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x48(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0xa712
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0xa4ab
jmp 0xa724
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0xa47d
movq 0x50(%rsp), %rdi
callq 0x9620
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)