// File: tomfunkhouser[P]gaps/pkgs/png/trees.c
// Function: pqdownheap
local void pqdownheap(s, tree, k)
    deflate_state *s;
    ct_data *tree;  /* the tree to restore */
    int k;               /* node to move down */
{
    int v = s->heap[k];
    int j = k << 1;  /* left son of k */
    while (j <= s->heap_len) {
        /* Set j to the smallest of the two sons: */
        if (j < s->heap_len &&
            smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
            j++;
        }
        /* Exit if v is smaller than both sons */
        if (smaller(tree, v, s->heap[j], s->depth)) break;

        /* Exchange v with the smallest son */
        s->heap[k] = s->heap[j];  k = j;

        /* And continue down the tree, setting j to the left son of k */
        j <<= 1;
    }
    s->heap[k] = v;
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movl %edx, -0x14(%rsp)
movq -0x8(%rsp), %rax
movslq -0x14(%rsp), %rcx
movl 0xbb0(%rax,%rcx,4), %eax
movl %eax, -0x18(%rsp)
movl -0x14(%rsp), %eax
shll %eax
movl %eax, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x14a4(%rcx), %eax
jg 0x1214f5
movl -0x1c(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x14a4(%rcx), %eax
jge 0x12142b
movq -0x10(%rsp), %rax
movq -0x8(%rsp), %rcx
movl -0x1c(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movslq 0xbb0(%rcx,%rdx,4), %rcx
movzwl (%rax,%rcx,4), %eax
movq -0x10(%rsp), %rcx
movq -0x8(%rsp), %rdx
movslq -0x1c(%rsp), %rsi
movslq 0xbb0(%rdx,%rsi,4), %rdx
movzwl (%rcx,%rdx,4), %ecx
cmpl %ecx, %eax
jl 0x121420
movq -0x10(%rsp), %rax
movq -0x8(%rsp), %rcx
movl -0x1c(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movslq 0xbb0(%rcx,%rdx,4), %rcx
movzwl (%rax,%rcx,4), %eax
movq -0x10(%rsp), %rcx
movq -0x8(%rsp), %rdx
movslq -0x1c(%rsp), %rsi
movslq 0xbb0(%rdx,%rsi,4), %rdx
movzwl (%rcx,%rdx,4), %ecx
cmpl %ecx, %eax
jne 0x12142b
movq -0x8(%rsp), %rax
movq -0x8(%rsp), %rcx
movl -0x1c(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movslq 0xbb0(%rcx,%rdx,4), %rcx
movzbl 0x14ac(%rax,%rcx), %eax
movq -0x8(%rsp), %rcx
movq -0x8(%rsp), %rdx
movslq -0x1c(%rsp), %rsi
movslq 0xbb0(%rdx,%rsi,4), %rdx
movzbl 0x14ac(%rcx,%rdx), %ecx
cmpl %ecx, %eax
jg 0x12142b
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
movq -0x10(%rsp), %rax
movslq -0x18(%rsp), %rcx
movzwl (%rax,%rcx,4), %eax
movq -0x10(%rsp), %rcx
movq -0x8(%rsp), %rdx
movslq -0x1c(%rsp), %rsi
movslq 0xbb0(%rdx,%rsi,4), %rdx
movzwl (%rcx,%rdx,4), %ecx
cmpl %ecx, %eax
jl 0x1214ba
movq -0x10(%rsp), %rax
movslq -0x18(%rsp), %rcx
movzwl (%rax,%rcx,4), %eax
movq -0x10(%rsp), %rcx
movq -0x8(%rsp), %rdx
movslq -0x1c(%rsp), %rsi
movslq 0xbb0(%rdx,%rsi,4), %rdx
movzwl (%rcx,%rdx,4), %ecx
cmpl %ecx, %eax
jne 0x1214bc
movq -0x8(%rsp), %rax
movslq -0x18(%rsp), %rcx
movzbl 0x14ac(%rax,%rcx), %eax
movq -0x8(%rsp), %rcx
movq -0x8(%rsp), %rdx
movslq -0x1c(%rsp), %rsi
movslq 0xbb0(%rdx,%rsi,4), %rdx
movzbl 0x14ac(%rcx,%rdx), %ecx
cmpl %ecx, %eax
jg 0x1214bc
jmp 0x1214f5
movq -0x8(%rsp), %rax
movslq -0x1c(%rsp), %rcx
movl 0xbb0(%rax,%rcx,4), %edx
movq -0x8(%rsp), %rax
movslq -0x14(%rsp), %rcx
movl %edx, 0xbb0(%rax,%rcx,4)
movl -0x1c(%rsp), %eax
movl %eax, -0x14(%rsp)
movl -0x1c(%rsp), %eax
shll %eax
movl %eax, -0x1c(%rsp)
jmp 0x12132d
movl -0x18(%rsp), %edx
movq -0x8(%rsp), %rax
movslq -0x14(%rsp), %rcx
movl %edx, 0xbb0(%rax,%rcx,4)
retq
nopl (%rax,%rax)