// File: /workspace/github_cpp_makefile_star2_O1/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 0x4a127
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 0x4a3f8
testq %rsi, %rsi
je 0x4a18e
movq %rdx, %r8
cmpq $0x10, %rdx
jae 0x4a198
testq %r8, %r8
je 0x4a14e
xorl %eax, %eax
movzbl (%rsi,%rax), %edx
addq %rdx, %rdi
addq %rdi, %rcx
incq %rax
cmpq %rax, %r8
jne 0x4a13c
leaq -0xfff1(%rdi), %rsi
cmpq $0xfff1, %rdi           # imm = 0xFFF1
cmovbq %rdi, %rsi
movabsq $0xf00e10d2fc5cd, %rdx  # imm = 0xF00E10D2FC5CD
movq %rcx, %rax
mulq %rdx
movl %ecx, %eax
subl %edx, %eax
shrl %eax
addl %edx, %eax
shrl $0xf, %eax
imull $0xfff1, %eax, %eax     # imm = 0xFFF1
subl %eax, %ecx
shll $0x10, %ecx
orq %rsi, %rcx
jmp 0x4a3f8
movl $0x1, %ecx
jmp 0x4a3f8
cmpq $0x15b0, %r8            # imm = 0x15B0
jb 0x4a2ca
movabsq $0xf00e10d2fc5cd, %r9   # imm = 0xF00E10D2FC5CD
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 0x4a1b8
addq $0x15b0, %rsi           # imm = 0x15B0
movq %rdi, %rax
mulq %r9
movq %rdi, %rax
subq %rdx, %rax
shrq %rax
addq %rdx, %rax
shrq $0xf, %rax
imulq $0xfff1, %rax, %rax     # imm = 0xFFF1
subq %rax, %rdi
movq %rcx, %rax
mulq %r9
movq %rcx, %rax
subq %rdx, %rax
shrq %rax
addq %rdx, %rax
shrq $0xf, %rax
imulq $0xfff1, %rax, %rax     # imm = 0xFFF1
subq %rax, %rcx
cmpq $0x15af, %r8            # imm = 0x15AF
ja 0x4a1af
testq %r8, %r8
je 0x4a3f1
cmpq $0x10, %r8
jb 0x4a38e
addq $-0x10, %r8
movzbl (%rsi), %eax
addq %rdi, %rax
addq %rax, %rcx
movzbl 0x1(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x2(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x3(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x4(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x5(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x6(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x7(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x8(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x9(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0xa(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0xb(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0xc(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0xd(%rsi), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0xe(%rsi), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0xf(%rsi), %edi
addq %rax, %rdi
addq %rdi, %rcx
addq $0x10, %rsi
cmpq $0xf, %r8
ja 0x4a2dd
testq %r8, %r8
je 0x4a3a7
xorl %eax, %eax
movzbl (%rsi,%rax), %edx
addq %rdx, %rdi
addq %rdi, %rcx
incq %rax
cmpq %rax, %r8
jne 0x4a395
movabsq $0xf00e10d2fc5cd, %rsi  # imm = 0xF00E10D2FC5CD
movq %rdi, %rax
mulq %rsi
movq %rdi, %rax
subq %rdx, %rax
shrq %rax
addq %rdx, %rax
shrq $0xf, %rax
imulq $0xfff1, %rax, %rax     # imm = 0xFFF1
subq %rax, %rdi
movq %rcx, %rax
mulq %rsi
movq %rcx, %rax
subq %rdx, %rax
shrq %rax
addq %rdx, %rax
shrq $0xf, %rax
imulq $0xfff1, %rax, %rax     # imm = 0xFFF1
subq %rax, %rcx
shlq $0x10, %rcx
orq %rdi, %rcx
movq %rcx, %rax
retq