// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/adler32.c
// Function: adler32
uLong ZEXPORT adler32(adler, buf, len)
    uLong adler;
    const Bytef *buf;
    uInt 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;
        MOD4(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
cmpl $0x1, %edx
jne 0x92312
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 0x925ad
testq %rsi, %rsi
je 0x9233c
movl %edx, %r8d
cmpl $0x10, %edx
jae 0x9234b
movl %r8d, %eax
xorl %edx, %edx
cmpl %edx, %eax
je 0x92467
movzbl (%rsi,%rdx), %r8d
addq %r8, %rdi
addq %rdi, %rcx
incq %rdx
jmp 0x92324
movabsq $0x1, %rcx
jmp 0x925ad
pushq %r14
pushq %rbx
xorl %r9d, %r9d
movl $0x15b0, %r11d          # imm = 0x15B0
movl $0xfff1, %ebx           # imm = 0xFFF1
movq %rsi, %r14
movl %r8d, %r10d
cmpl $0x15b0, %r10d          # imm = 0x15B0
jb 0x92491
addl $0xffffea50, %r10d      # imm = 0xFFFFEA50
xorl %eax, %eax
movzbl (%r14,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x1(%r14,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0x2(%r14,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x3(%r14,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0x4(%r14,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x5(%r14,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0x6(%r14,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x7(%r14,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0x8(%r14,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0x9(%r14,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0xa(%r14,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0xb(%r14,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0xc(%r14,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0xd(%r14,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
movzbl 0xe(%r14,%rax), %edx
addq %rdi, %rdx
addq %rdx, %rcx
movzbl 0xf(%r14,%rax), %edi
addq %rdx, %rdi
addq %rdi, %rcx
addq $0x10, %rax
cmpl $0x15b0, %eax           # imm = 0x15B0
jne 0x92378
addq %r11, %r14
movq %rdi, %rax
xorl %edx, %edx
divq %rbx
movq %rdx, %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rbx
addq %r11, %r9
movq %rdx, %rcx
jmp 0x92362
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 0x925ad
testl %r10d, %r10d
popq %rbx
popq %r14
je 0x925a6
cmpl $0xf, %r10d
jbe 0x92573
addl $-0x10, %r10d
movzbl (%rsi,%r9), %eax
addq %rax, %rdi
addq %rdi, %rcx
movzbl 0x1(%rsi,%r9), %eax
addq %rdi, %rax
addq %rax, %rcx
movzbl 0x2(%rsi,%r9), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x3(%rsi,%r9), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x4(%rsi,%r9), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x5(%rsi,%r9), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x6(%rsi,%r9), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x7(%rsi,%r9), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0x8(%rsi,%r9), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0x9(%rsi,%r9), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0xa(%rsi,%r9), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0xb(%rsi,%r9), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0xc(%rsi,%r9), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0xd(%rsi,%r9), %eax
addq %rdx, %rax
addq %rax, %rcx
movzbl 0xe(%rsi,%r9), %edx
addq %rax, %rdx
addq %rdx, %rcx
movzbl 0xf(%rsi,%r9), %edi
addq %rdx, %rdi
addq %rdi, %rcx
addq $0x10, %r9
jmp 0x9249d
movl %r8d, %eax
cmpl %r9d, %eax
je 0x9258b
movzbl (%rsi,%r9), %edx
addq %rdx, %rdi
addq %rdi, %rcx
incq %r9
jmp 0x92576
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