// File: /workspace/github_c_makefile_star2_O0/millimat[P]Soft-Heap/softheap.c
// Function: repeated_combine
static void repeated_combine(softheap *Q, int smaller_rank, int r) {
  tree *curr = Q->first;

  while(curr->next != NULL) {
    bool two = (curr->rank == curr->next->rank);
    bool three = (two && curr->next->next != NULL && curr->rank == curr->next->next->rank);

    if(!two) { // only one tree of this rank
      if(curr->rank > smaller_rank) break; // no more combines to do and no carries
      else curr = curr->next;
    } else if(!three) { // exactly two trees of this rank
      // combine them to make a carry, then delete curr->next. 
      // carry may need to be merged with its next tree, so do not advance curr.
      curr->root = combine(curr->root, curr->next->root, r);
      curr->rank = curr->root->rank;
      tree *tofree = curr->next;
      remove_tree(Q, curr->next); // will change what curr->next points to
      free(tofree);
    } else { // exactly three trees of this rank
      // skip the first so that we can combine the second and third to form a carry
      curr = curr->next;
    }
  }

  if(curr->rank > Q->rank) Q->rank = curr->rank; // Q might have a new highest-rank tree
  update_suffix_min(curr); // this is final tree affected by merge, so update sufmin backwds from here
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2028
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x20(%rcx), %eax
sete %al
andb $0x1, %al
movb %al, -0x19(%rbp)
xorl %eax, %eax
testb $0x1, -0x19(%rbp)
movb %al, -0x29(%rbp)
je 0x1f81
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
xorl %eax, %eax
cmpq $0x0, 0x8(%rcx)
movb %al, -0x29(%rbp)
je 0x1f81
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x20(%rcx), %eax
sete %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
andb $0x1, %al
movb %al, -0x1a(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x1fae
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
cmpl -0xc(%rbp), %eax
jle 0x1fa0
jmp 0x2028
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x2023
testb $0x1, -0x1a(%rbp)
jne 0x2015
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rsi
movl -0x10(%rbp), %edx
callq 0x2590
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x24(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x23f0
movq -0x28(%rbp), %rdi
callq 0x1030
jmp 0x2021
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x2023
jmp 0x1f1d
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jle 0x2046
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rdi
callq 0x2380
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)