// File: /workspace/github_c_makefile_star2_O0/felipelouza[P]egap/tools/heap.c
// Function: heapfy_down
void heapfy_down(heap *h, int i) {

  int last = h->size-1;

  // Selects the child s of i with smaller cost:
  int l = 2*i+1;
  int r = l+1;
  int s;
  if (r <= last)
    s = key(l) < key(r) ? l : r;    
  else if (l == last)
    s = l;
  else
    return;

  // Swaps down:
  while (key(i) > key(s)) {   
    
    heap_node *aux = h->heap[i];
    h->heap[i] = h->heap[s];
    h->heap[s] = aux;

    i = s;
    l = 2*i+1;
    r = l+1;

    if (r <= last)
      s = key(l) < key(r) ? l : r;      
    else if (l == last)
      s = l;
    else
      return;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x10(%rbp), %eax
jg 0x3673
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movslq -0x14(%rbp), %rax
movq (%rcx,%rax,8), %rdx
movq (%rdx), %rax
movslq 0x8(%rdx), %rsi
shlq $0x4, %rsi
movq (%rax,%rsi), %rdx
movq 0x8(%rax,%rsi), %rax
movslq -0x18(%rbp), %rsi
movq (%rcx,%rsi,8), %rsi
movq (%rsi), %rcx
movslq 0x8(%rsi), %rdi
shlq $0x4, %rdi
movq (%rcx,%rdi), %rsi
movq 0x8(%rcx,%rdi), %rcx
subq %rsi, %rdx
sbbq %rcx, %rax
jae 0x3665
jmp 0x365d
movl -0x14(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x366b
movl -0x18(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x368a
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jne 0x3683
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x3688
jmp 0x37b7
jmp 0x368a
jmp 0x368c
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq (%rdx), %rcx
movslq 0x8(%rdx), %rdx
shlq $0x4, %rdx
movq (%rcx,%rdx), %rsi
movq 0x8(%rcx,%rdx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rax,%rdx,8), %rdx
movq (%rdx), %rax
movslq 0x8(%rdx), %rdi
shlq $0x4, %rdi
movq (%rax,%rdi), %rdx
movq 0x8(%rax,%rdi), %rax
subq %rsi, %rdx
sbbq %rcx, %rax
jae 0x37b7
jmp 0x36d9
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x10(%rbp), %eax
jg 0x379e
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movslq -0x14(%rbp), %rax
movq (%rcx,%rax,8), %rdx
movq (%rdx), %rax
movslq 0x8(%rdx), %rsi
shlq $0x4, %rsi
movq (%rax,%rsi), %rdx
movq 0x8(%rax,%rsi), %rax
movslq -0x18(%rbp), %rsi
movq (%rcx,%rsi,8), %rsi
movq (%rsi), %rcx
movslq 0x8(%rsi), %rdi
shlq $0x4, %rdi
movq (%rcx,%rdi), %rsi
movq 0x8(%rcx,%rdi), %rcx
subq %rsi, %rdx
sbbq %rcx, %rax
jae 0x3790
jmp 0x3788
movl -0x14(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x3796
movl -0x18(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x37b2
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jne 0x37ae
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x37b0
jmp 0x37b7
jmp 0x37b2
jmp 0x368c
popq %rbp
retq
nopl (%rax)