// File: /workspace/github_c_makefile_star2_O0/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:
movq %rdi, -0x8(%rsp)
movl %esi, -0xc(%rsp)
movl %edx, -0x10(%rsp)
movl %ecx, -0x14(%rsp)
movq -0x8(%rsp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x18(%rsp)
movq -0x8(%rsp), %rax
movl $0x0, 0x28(%rax)
movl -0xc(%rsp), %eax
cmpl -0x10(%rsp), %eax
jbe 0xa0be
movl -0x10(%rsp), %eax
movl %eax, -0x24(%rsp)
movl -0xc(%rsp), %eax
movl %eax, -0x10(%rsp)
movl -0x24(%rsp), %eax
movl %eax, -0xc(%rsp)
movq -0x8(%rsp), %rax
movq 0x38(%rax), %rax
movl -0x10(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rsp), %rax
movq 0x38(%rax), %rax
movl -0xc(%rsp), %ecx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rsp), %ecx
movsd 0x4ef04(%rip), %xmm0    # 0x59000
movsd %xmm0, (%rax,%rcx,8)
movl -0x14(%rsp), %edx
movq -0x8(%rsp), %rax
movq (%rax), %rax
movl -0xc(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x4c(%rcx), %eax
jae 0xa17e
movq -0x8(%rsp), %rax
movq 0x30(%rax), %rax
movl -0x10(%rsp), %ecx
movq -0x8(%rsp), %rdx
imull 0x4c(%rdx), %ecx
addl -0x1c(%rsp), %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rsp), %rax
movq 0x30(%rax), %rax
movl -0xc(%rsp), %ecx
movq -0x8(%rsp), %rdx
imull 0x4c(%rdx), %ecx
addl -0x1c(%rsp), %ecx
movl %ecx, %ecx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0xa11c
movq -0x8(%rsp), %rax
movq 0x38(%rax), %rax
movl -0x18(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rsp), %rax
movq 0x38(%rax), %rax
movl -0x10(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rsp), %ecx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl -0x10(%rsp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl -0x18(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl -0x10(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rsp), %rax
movq (%rax), %rax
movl -0x18(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movq -0x8(%rsp), %rax
movq (%rax), %rax
movl -0x10(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x4c(%rcx), %eax
jae 0xa269
movq -0x8(%rsp), %rax
movq 0x30(%rax), %rax
movl -0x18(%rsp), %ecx
movq -0x8(%rsp), %rdx
imull 0x4c(%rdx), %ecx
addl -0x1c(%rsp), %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rsp), %rax
movq 0x30(%rax), %rax
movl -0x10(%rsp), %ecx
movq -0x8(%rsp), %rdx
imull 0x4c(%rdx), %ecx
addl -0x1c(%rsp), %ecx
movl %ecx, %ecx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0xa20c
movq -0x8(%rsp), %rax
movl 0x8(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x8(%rax)
movl $0x0, -0x20(%rsp)
movl -0x20(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xa34d
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl -0x20(%rsp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0xc(%rsp), %eax
je 0xa2bd
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl -0x20(%rsp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x10(%rsp), %eax
jne 0xa30f
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl -0x20(%rsp), %ecx
movl $0x0, (%rax,%rcx,4)
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl -0x20(%rsp), %ecx
movsd 0x4ed1a(%rip), %xmm0    # 0x59000
movsd %xmm0, (%rax,%rcx,8)
movl -0x20(%rsp), %edx
movq -0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
jmp 0xa33b
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl -0x20(%rsp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x18(%rsp), %eax
jne 0xa339
movl -0x10(%rsp), %edx
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl -0x20(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0xa33b
jmp 0xa33d
movl -0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rsp)
jmp 0xa27f
retq
nop