// File: sisong[P]ApkDiffPatch/zlib1.3.1/trees.c
// Function: scan_tree
local void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
    int n;                     /* iterates over all tree elements */
    int prevlen = -1;          /* last emitted length */
    int curlen;                /* length of current code */
    int nextlen = tree[0].Len; /* length of next code */
    int count = 0;             /* repeat count of the current code */
    int max_count = 7;         /* max repeat count */
    int min_count = 4;         /* min repeat count */

    if (nextlen == 0) max_count = 138, min_count = 3;
    tree[max_code + 1].Len = (ush)0xffff; /* guard */

    for (n = 0; n <= max_code; n++) {
        curlen = nextlen; nextlen = tree[n + 1].Len;
        if (++count < max_count && curlen == nextlen) {
            continue;
        } else if (count < min_count) {
            s->bl_tree[curlen].Freq += count;
        } else if (curlen != 0) {
            if (curlen != prevlen) s->bl_tree[curlen].Freq++;
            s->bl_tree[REP_3_6].Freq++;
        } else if (count <= 10) {
            s->bl_tree[REPZ_3_10].Freq++;
        } else {
            s->bl_tree[REPZ_11_138].Freq++;
        }
        count = 0; prevlen = curlen;
        if (nextlen == 0) {
            max_count = 138, min_count = 3;
        } else if (curlen == nextlen) {
            max_count = 6, min_count = 3;
        } else {
            max_count = 7, min_count = 4;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movzwl 0x2(%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x7, -0x2c(%rbp)
movl $0x4, -0x30(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0xa13ca
movl $0x8a, -0x2c(%rbp)
movl $0x3, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw $0xffff, 0x2(%rax,%rcx,4) # imm = 0xFFFF
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0xa1525
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzwl 0x2(%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
cmpl -0x2c(%rbp), %eax
jge 0xa1427
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0xa1427
jmp 0xa1517
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0xa144e
movl -0x28(%rbp), %esi
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movzwl 0xabc(%rax,%rcx,4), %edx
addl %esi, %edx
movw %dx, 0xabc(%rax,%rcx,4)
jmp 0xa14c8
cmpl $0x0, -0x20(%rbp)
je 0xa1490
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
je 0xa1478
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movw 0xabc(%rax,%rcx,4), %dx
addw $0x1, %dx
movw %dx, 0xabc(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movw 0xafc(%rax), %cx
addw $0x1, %cx
movw %cx, 0xafc(%rax)
jmp 0xa14c6
cmpl $0xa, -0x28(%rbp)
jg 0xa14ae
movq -0x8(%rbp), %rax
movw 0xb00(%rax), %cx
addw $0x1, %cx
movw %cx, 0xb00(%rax)
jmp 0xa14c4
movq -0x8(%rbp), %rax
movw 0xb04(%rax), %cx
addw $0x1, %cx
movw %cx, 0xb04(%rax)
jmp 0xa14c6
jmp 0xa14c8
jmp 0xa14ca
movl $0x0, -0x28(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0xa14ed
movl $0x8a, -0x2c(%rbp)
movl $0x3, -0x30(%rbp)
jmp 0xa1515
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0xa1505
movl $0x6, -0x2c(%rbp)
movl $0x3, -0x30(%rbp)
jmp 0xa1513
movl $0x7, -0x2c(%rbp)
movl $0x4, -0x30(%rbp)
jmp 0xa1515
jmp 0xa1517
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xa13e5
popq %rbp
retq
nopw (%rax,%rax)