// File: biotomas[P]ipasir/sat/picosat961/picosat-961/picosat.c
// Function: hdown
static void
hdown (PS * ps, Rnk * r)
{
  unsigned end, rpos, cpos, opos;
  Rnk *child, *other;

  assert (r->pos > 0);
  assert (ps->heap[r->pos] == r);

  end = ps->hhead - ps->heap;
  rpos = r->pos;

  for (;;)
    {
      cpos = 2 * rpos;
      if (cpos >= end)
	break;

      opos = cpos + 1;
      child = ps->heap[cpos];

      if (cmp_rnk (r, child) < 0)
	{
	  if (opos < end)
	    {
	      other = ps->heap[opos];

	      if (cmp_rnk (child, other) < 0)
		{
		  child = other;
		  cpos = opos;
		}
	    }
	}
      else if (opos < end)
	{
	  child = ps->heap[opos];

	  if (cmp_rnk (r, child) >= 0)
	    break;

	  cpos = opos;
	}
      else
	break;

      ps->heap[rpos] = child;
      child->pos = rpos;
      rpos = cpos;
    }

  r->pos = rpos;
  ps->heap[rpos] = r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpl $0x0, %eax
jle 0xd463
jmp 0xd482
leaq 0x1270b(%rip), %rdi     # 0x1fb75
leaq 0xfe33(%rip), %rsi      # 0x1d2a4
movl $0xa81, %edx            # imm = 0xA81
leaq 0x12703(%rip), %rcx     # 0x1fb80
callq 0x10b0
movq -0x8(%rbp), %rax
movq 0x1c8(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
cmpq -0x10(%rbp), %rax
jne 0xd4a8
jmp 0xd4c7
leaq 0x126e9(%rip), %rdi     # 0x1fb98
leaq 0xfdee(%rip), %rsi      # 0x1d2a4
movl $0xa82, %edx            # imm = 0xA82
leaq 0x126be(%rip), %rcx     # 0x1fb80
callq 0x10b0
movq -0x8(%rbp), %rax
movq 0x1d0(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x1c8(%rcx), %rcx
subq %rcx, %rax
sarq $0x3, %rax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jb 0xd50b
jmp 0xd5f8
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x1c8(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x129a0
cmpl $0x0, %eax
jge 0xd57e
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0xd57c
movq -0x8(%rbp), %rax
movq 0x1c8(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x129a0
cmpl $0x0, %eax
jge 0xd57a
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0xd57c
jmp 0xd5bc
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0xd5b8
movq -0x8(%rbp), %rax
movq 0x1c8(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x129a0
cmpl $0x0, %eax
jl 0xd5b0
jmp 0xd5f8
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0xd5ba
jmp 0xd5f8
jmp 0xd5bc
movq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x1c8(%rax), %rax
movl -0x18(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x18(%rbp), %edx
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x4(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0xd4f6
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x1c8(%rax), %rax
movl -0x18(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
addq $0x30, %rsp
popq %rbp
retq
nop