// File: /workspace/github_c_makefile_star2_O3/sheneman[P]clearcut/clearcut.c
// Function: NJ_neighbor_joining
NJ_TREE *
NJ_neighbor_joining(NJ_ARGS *nj_args,
		    DMAT *dmat) {

  
  NJ_TREE   *tree = NULL;
  NJ_VERTEX *vertex = NULL;

  long int a, b;
  float min;
    

  /* initialize the r and r2 vectors */
  NJ_init_r(dmat);

  /* allocate and initialize our vertex vector used for tree construction */
  vertex = NJ_init_vertex(dmat);
  if(!vertex) {
    fprintf(stderr, "Clearcut:  Could not initialize vertex in NJ_neighbor_joining()\n");
    return(NULL);
  }
  
  /* we iterate until the working distance matrix has only 2 entries */
  while(vertex->nactive > 2) {
 
    /* 
     * Find the global minimum transformed distance from the distance matrix
     */
    min = NJ_min_transform(dmat, &a, &b);

    /* 
     * Build the tree by removing nodes a and b from the vertex array
     * and inserting a new internal node which joins a and b.  Collapse
     * the vertex array similarly to how the distance matrix and r and r2 
     * are compacted. 
     */
    NJ_decompose(dmat, vertex, a, b, 0);

    /* decrement the r and r2 vectors by the distances corresponding to a, b */
    NJ_compute_r(dmat, a, b);

    /* compact the distance matrix and the r and r2 vectors */
    NJ_collapse(dmat, vertex, a, b);
  }
  
  /* Properly join the last two nodes on the vertex list */
  tree = NJ_decompose(dmat, vertex, 0, 1, NJ_LAST);

  /* return the computed tree to the calling function */
  return(tree);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rsi, %rdi
callq 0x3eaf
movq %rbx, %rdi
callq 0x3f26
testq %rax, %rax
je 0x334e
movq %rax, %r14
cmpq $0x3, 0x10(%rax)
jl 0x3303
leaq 0x10(%rsp), %r15
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3f9b
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rbp
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x4028
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rdx
movq 0x28(%rbx), %rcx
leaq 0x1(%r13), %rsi
cmpq %rax, %rsi
jge 0x328b
movq %rbp, %rdi
notq %rdi
leaq (%rdi,%rax,2), %rdi
imulq %rbp, %rdi
movq %rdi, %r8
shrq $0x3f, %r8
addq %rdi, %r8
andq $-0x2, %r8
leaq (%rdx,%r8,2), %rdi
leaq (%rdi,%rbp,4), %rdi
addq $0x4, %rdi
movq %r13, %r8
notq %r8
leaq (%r8,%rax,2), %r8
imulq %r13, %r8
movq %r8, %r9
shrq $0x3f, %r9
addq %r8, %r9
andq $-0x2, %r9
leaq (%rdx,%r9,2), %r8
movss (%rcx,%rsi,4), %xmm0
subss (%r8,%rsi,4), %xmm0
movss %xmm0, (%rcx,%rsi,4)
cmpq %rbp, %rsi
jle 0x3283
subss (%rdi), %xmm0
addq $0x4, %rdi
movss %xmm0, (%rcx,%rsi,4)
incq %rsi
cmpq %rsi, %rax
jne 0x3261
testq %rbp, %rbp
jle 0x32ea
leaq (%rdx,%rbp,4), %rsi
leaq (%rdx,%r13,4), %rdx
leaq -0x1(%rax), %rdi
leaq -0x4(,%rax,4), %r8
xorl %r9d, %r9d
movss (%rcx,%r9,4), %xmm0
cmpq %r13, %r9
jge 0x32c4
subss (%rdx), %xmm0
movss %xmm0, (%rcx,%r9,4)
addq %r8, %rdx
movq %rdi, %r10
jmp 0x32cd
movq %r9, %r10
notq %r10
addq %rax, %r10
subss (%rsi), %xmm0
movss %xmm0, (%rcx,%r9,4)
leaq (%rsi,%r10,4), %rsi
incq %r9
decq %rdi
addq $-0x4, %r8
cmpq %r9, %rbp
jne 0x32a7
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x4122
cmpq $0x2, 0x10(%r14)
jg 0x31d8
movq 0x18(%rbx), %rax
movss 0x4(%rax), %xmm0
movq (%r14), %rax
movq (%rax), %rbx
movss %xmm0, 0x10(%rbx)
movq 0x8(%rax), %r14
movss %xmm0, 0x10(%r14)
movl $0x1, %edi
movl $0x20, %esi
callq 0x2160
movq %rbx, (%rax)
movq %r14, 0x8(%rax)
movq $-0x1, 0x18(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x22ae
xorl %eax, %eax
jmp 0x333f