// File: /workspace/github_c_makefile_star2_O1/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 %rbx
movl 0x8(%rdi), %eax
decl %eax
cmpl %edx, %esi
movl %edx, %r8d
cmoval %esi, %r8d
movl $0x0, 0x28(%rdi)
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
testq %rcx, %rcx
je 0x9e2f
movq 0x30(%rdi), %rbx
movl %ecx, %ebp
imull %r8d, %ebp
movl %ecx, %r14d
imull %edx, %r14d
movl %ebp, %r15d
movsd (%rbx,%r15,8), %xmm0
movl %r14d, %r15d
addsd (%rbx,%r15,8), %xmm0
movsd %xmm0, (%rbx,%r15,8)
incl %r14d
incl %ebp
decq %rcx
jne 0x9e0d
movl %eax, %ebx
movsd (%r10,%rbx,8), %xmm0
movsd %xmm0, (%r10,%r8,8)
movsd (%rsi,%rbx,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
movq 0x18(%rdi), %rcx
movl (%rcx,%rbx,4), %r10d
movl %r10d, (%rcx,%r8,4)
movl (%r11,%rbx,4), %r10d
movl %r10d, (%r11,%r8,4)
movl 0x4c(%rdi), %r10d
testq %r10, %r10
je 0x9e91
movq 0x30(%rdi), %r11
movl %r10d, %ebx
imull %eax, %ebx
movl %r10d, %ebp
imull %r8d, %ebp
movl %ebx, %r14d
movsd (%r11,%r14,8), %xmm0
movl %ebp, %r14d
movsd %xmm0, (%r11,%r14,8)
incl %ebp
incl %ebx
decq %r10
jne 0x9e76
decl 0x8(%rdi)
je 0x9ee3
xorl %r10d, %r10d
movl (%rcx,%r10,4), %r11d
cmpl %edx, %r11d
setne %bl
cmpl %r8d, %r11d
setne %bpl
testb %bpl, %bl
jne 0x9ece
movl $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 0x9ed7
cmpl %eax, %r11d
jne 0x9ed7
movl %r8d, (%rcx,%r10,4)
incq %r10
movl 0x8(%rdi), %r11d
cmpq %r11, %r10
jb 0x9e99
popq %rbx
popq %r14
popq %r15
popq %rbp
retq