// File: /workspace/github_c_makefile_star2_O1/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 0x3cc9
movq %rbx, %rdi
callq 0x3d40
testq %rax, %rax
je 0x3282
movq %rax, %r14
cmpq $0x3, 0x10(%rax)
jl 0x325c
leaq 0x10(%rsp), %r15
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3dbb
movq 0x10(%rsp), %r13
movq 0x8(%rsp), %rbp
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x3e48
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rdx
movq 0x28(%rbx), %rcx
leaq 0x1(%r13), %rsi
cmpq %rax, %rsi
jge 0x31ed
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 0x31e5
subss (%rdi), %xmm0
addq $0x4, %rdi
movss %xmm0, (%rcx,%rsi,4)
incq %rsi
cmpq %rsi, %rax
jne 0x31c3
testq %rbp, %rbp
jle 0x3243
leaq (%rdx,%rbp,4), %rsi
leaq (%rdx,%r13,4), %rdx
leaq -0x4(,%rax,4), %rdi
decq %rax
xorl %r8d, %r8d
cmpq %r13, %r8
jge 0x3220
movss (%rcx,%r8,4), %xmm0
subss (%rdx), %xmm0
movss %xmm0, (%rcx,%r8,4)
addq %rdi, %rdx
movss (%rcx,%r8,4), %xmm0
subss (%rsi), %xmm0
movss %xmm0, (%rcx,%r8,4)
leaq (%rsi,%rax,4), %rsi
incq %r8
addq $-0x4, %rdi
decq %rax
cmpq %r8, %rbp
jne 0x3208
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3f65
cmpq $0x2, 0x10(%r14)
jg 0x313a
movl $0x1, %ecx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movl $0x65, %r8d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3e48
callq 0x22ae
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq