// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/zlib1.3.1/adler32.c
// Function: adler32_z
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
    unsigned long sum2;
    unsigned n;

    /* split Adler-32 into component sums */
    sum2 = (adler >> 16) & 0xffff;
    adler &= 0xffff;

    /* in case user likes doing a byte at a time, keep it fast */
    if (len == 1) {
        adler += buf[0];
        if (adler >= BASE)
            adler -= BASE;
        sum2 += adler;
        if (sum2 >= BASE)
            sum2 -= BASE;
        return adler | (sum2 << 16);
    }

    /* initial Adler-32 value (deferred check for len == 1 speed) */
    if (buf == Z_NULL)
        return 1L;

    /* in case short lengths are provided, keep it somewhat fast */
    if (len < 16) {
        while (len--) {
            adler += *buf++;
            sum2 += adler;
        }
        if (adler >= BASE)
            adler -= BASE;
        MOD28(sum2);            /* only added so many BASE's */
        return adler | (sum2 << 16);
    }

    /* do length NMAX blocks -- requires just one modulo operation */
    while (len >= NMAX) {
        len -= NMAX;
        n = NMAX / 16;          /* NMAX is divisible by 16 */
        do {
            DO16(buf);          /* 16 sums unrolled */
            buf += 16;
        } while (--n);
        MOD(adler);
        MOD(sum2);
    }

    /* do remaining bytes (less than NMAX, still just one modulo) */
    if (len) {                  /* avoid modulos if none remaining */
        while (len >= 16) {
            len -= 16;
            DO16(buf);
            buf += 16;
        }
        while (len--) {
            adler += *buf++;
            sum2 += adler;
        }
        MOD(adler);
        MOD(sum2);
    }

    /* return recombined sums */
    return adler | (sum2 << 16);
}

// Assembly:
movq %rdi, %rcx
movzwl %cx, %edi
shrl $0x10, %ecx
cmpq $0x1, %rdx
jne 0x3fe77
movzbl (%rsi), %eax
leaq (%rdi,%rax), %rdx
movl $0xfff1, %esi           # imm = 0xFFF1
cmpq %rsi, %rdx
leaq -0xfff1(%rdi,%rax), %rax
cmovbq %rdx, %rax
addq %rax, %rcx
movq %rcx, %rdx
shlq $0x10, %rdx
movabsq $-0xfff10000, %rdi      # imm = 0xFFFFFFFF000F0000
addq %rdx, %rdi
cmpq %rsi, %rcx
cmovbq %rdx, %rdi
orq %rax, %rdi
movq %rdi, %rcx
jmp 0x400c4
testq %rsi, %rsi
je 0x3fe9f
movq %rdx, %r8
cmpq $0x10, %rdx
jae 0x3fea7
xorl %eax, %eax
cmpq %rax, %r8
je 0x3ffa3
movzbl (%rsi,%rax), %edx
addq %rdx, %rdi
addq %rdi, %rcx
incq %rax
jmp 0x3fe87
pushq $0x1
popq %rcx
jmp 0x400c4
movl $0xfff1, %r9d           # imm = 0xFFF1
cmpq $0x15b0, %r8            # imm = 0x15B0
jb 0x3ffcd
addq $-0x15b0, %r8           # imm = 0xEA50
xorl %eax, %eax
movzbl (%rsi,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x1(%rsi,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0x2(%rsi,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x3(%rsi,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0x4(%rsi,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x5(%rsi,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0x6(%rsi,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x7(%rsi,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0x8(%rsi,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x9(%rsi,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0xa(%rsi,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0xb(%rsi,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0xc(%rsi,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0xd(%rsi,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0xe(%rsi,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0xf(%rsi,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
addq $0x10, %rax
cmpl $0x15b0, %eax           # imm = 0x15B0
jne 0x3fec3
addq $0x15b0, %rsi           # imm = 0x15B0
movq %rdi, %rax
xorl %edx, %edx
divq %r9
movq %rdx, %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %r9
movq %rdx, %rcx
jmp 0x3fead
leaq -0xfff1(%rdi), %rsi
movl $0xfff1, %r8d           # imm = 0xFFF1
cmpq %r8, %rdi
cmovbq %rdi, %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %rcx
shll $0x10, %ecx
orq %rsi, %rcx
jmp 0x400c4
testq %r8, %r8
je 0x400bd
cmpq $0xf, %r8
jbe 0x4008c
addq $-0x10, %r8
movzbl (%rsi), %eax
addq %rax, %rdi
addq %rdi, %rcx
movzbl 0x1(%rsi), %eax
addq %rdi, %rax
addq %rax, %rcx
movzbl 0x2(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x3(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x4(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x5(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x6(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x7(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x8(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x9(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0xa(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0xb(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0xc(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0xd(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0xe(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0xf(%rsi), %edi
addq %rdx, %rdi
addq %rdi, %rcx
addq $0x10, %rsi
jmp 0x3ffd6
xorl %eax, %eax
cmpq %rax, %r8
je 0x400a2
movzbl (%rsi,%rax), %edx
addq %rdx, %rdi
addq %rdi, %rcx
incq %rax
jmp 0x4008e
movl $0xfff1, %esi           # imm = 0xFFF1
movq %rdi, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
movq %rdx, %rcx
shlq $0x10, %rcx
orq %rdi, %rcx
movq %rcx, %rax
retq