// File: /workspace/github_c_makefile_star2_O2/zpole[P]IICV/vl/aib.c
// Function: vl_aib_merge_nodes
void
vl_aib_merge_nodes (VlAIB * aib, vl_uint i, vl_uint j, vl_uint new)
{
  vl_uint last_entry = aib->nentries - 1 ;
  vl_uint c, n ;

  /* clear the list of nodes to update */
  aib->nwhich = 0;

  /* make sure that i is smaller than j */
  if(i > j) { vl_uint tmp = j; j = i; i = tmp; }

  /* -----------------------------------------------------------------
   *                    Merge entries i and j, storing the result in i
   * -------------------------------------------------------------- */

  aib-> Px   [i] += aib->Px[j] ;
  aib-> beta [i]  = BETA_MAX ;
  aib-> nodes[i]  = new ;

  for (c = 0; c < aib->nlabels; c++)
    aib-> Pcx [i*aib->nlabels + c] += aib-> Pcx [j*aib->nlabels + c] ;

  /* -----------------------------------------------------------------
   *                                              Move last entry to j
   * -------------------------------------------------------------- */

  aib-> Px    [j]  = aib-> Px    [last_entry];
  aib-> beta  [j]  = aib-> beta  [last_entry];
  aib-> bidx  [j]  = aib-> bidx  [last_entry];
  aib-> nodes [j]  = aib-> nodes [last_entry];

  for (c = 0 ;  c < aib->nlabels ; c++)
    aib-> Pcx[j*aib->nlabels + c] = aib-> Pcx [last_entry*aib->nlabels + c] ;

  /* delete last entry */
  aib-> nentries -- ;

  /* -----------------------------------------------------------------
   *                                        Scan for entries to update
   * -------------------------------------------------------------- */

  /*
   * After mergin entries i and j, we need to update all other entries
   * that had one of these two as closest match. We also need to
   * update the renewend entry i. This is added by the loop below
   * since bidx [i] = j exactly because i was merged.
   *
   * Additionaly, since we moved the last entry back to the entry j,
   * we need to adjust the valeus of bidx to reflect this.
   */

  for (n = 0 ; n < aib->nentries; n++) {
    if(aib->bidx[n] == i || aib->bidx[n] == j) {
        aib->bidx  [n] = 0;
        aib->beta  [n] = BETA_MAX;
        aib->which [aib->nwhich++] = n ;
      }
    else if(aib->bidx[n] == last_entry) {
      aib->bidx[n] = j ;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0x8(%rdi), %eax
andl $0x0, 0x28(%rdi)
cmpl %edx, %esi
movl %edx, %r8d
cmoval %esi, %r8d
cmovbl %esi, %edx
movq 0x38(%rdi), %r10
movsd (%r10,%r8,8), %xmm0
addsd (%r10,%rdx,8), %xmm0
movsd %xmm0, (%r10,%rdx,8)
movq 0x10(%rdi), %rsi
movabsq $0x7fefffffffffffff, %r9 # imm = 0x7FEFFFFFFFFFFFFF
movq %r9, (%rsi,%rdx,8)
movq (%rdi), %r11
movl %ecx, (%r11,%rdx,4)
movl 0x4c(%rdi), %ecx
movl %ecx, %ebx
imull %r8d, %ebx
movl %ecx, %r14d
imull %edx, %r14d
xorl %r15d, %r15d
cmpq %rcx, %r15
jae 0x9dfa
movq 0x30(%rdi), %r12
leal (%rbx,%r15), %r13d
movsd (%r12,%r13,8), %xmm0
leal (%r14,%r15), %r13d
addsd (%r12,%r13,8), %xmm0
movsd %xmm0, (%r12,%r13,8)
incq %r15
jmp 0x9dd2
decl %eax
movsd (%r10,%rax,8), %xmm0
movsd %xmm0, (%r10,%r8,8)
movsd (%rsi,%rax,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
movq 0x18(%rdi), %rcx
movl (%rcx,%rax,4), %r10d
movl %r10d, (%rcx,%r8,4)
movl (%r11,%rax,4), %r10d
movl %r10d, (%r11,%r8,4)
movl 0x4c(%rdi), %r10d
movl %r10d, %r11d
imull %eax, %r11d
movl %r10d, %ebx
imull %r8d, %ebx
xorl %r14d, %r14d
cmpq %r10, %r14
jae 0x9e5e
movq 0x30(%rdi), %r15
leal (%r11,%r14), %r12d
movsd (%r15,%r12,8), %xmm0
leal (%rbx,%r14), %r12d
movsd %xmm0, (%r15,%r12,8)
incq %r14
jmp 0x9e3c
movl 0x8(%rdi), %r11d
decl %r11d
movl %r11d, 0x8(%rdi)
xorl %r10d, %r10d
movl %r11d, %r11d
cmpq %r11, %r10
jae 0x9eb8
movl (%rcx,%r10,4), %r11d
cmpl %edx, %r11d
setne %bl
cmpl %r8d, %r11d
setne %bpl
testb %bpl, %bl
jne 0x9ea6
andl $0x0, (%rcx,%r10,4)
movq %r9, (%rsi,%r10,8)
movq 0x20(%rdi), %r11
movl 0x28(%rdi), %ebx
leal 0x1(%rbx), %ebp
movl %ebp, 0x28(%rdi)
movl %r10d, (%r11,%rbx,4)
jmp 0x9eaf
cmpl %eax, %r11d
jne 0x9eaf
movl %r8d, (%rcx,%r10,4)
incq %r10
movl 0x8(%rdi), %r11d
jmp 0x9e6c
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq