#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ adler32_short(unsigned char *, unsigned int, int *, int *);
uint32_t adler32(unsigned char *buffer, unsigned int size) {
  uint32_t a = 1;
  uint32_t b = 0;
  while (size >= 5552) {
    adler32_short(buffer, 5552, &a, &b);
    buffer += 5552;
    size -= 5552;
  }
  adler32_short(buffer, size, &a, &b);
  return (b << 16) + a;
}


x86 assembly (clang, -O0):
<adler32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x15b0,-0xc(%rbp)
jb     116e <adler32+0x5e>
mov    -0x8(%rbp),%rdi
mov    $0x15b0,%esi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1030 <adler32_short@plt>
mov    -0x8(%rbp),%rax
add    $0x15b0,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x15b0,%eax
mov    %eax,-0xc(%rbp)
jmp    112d <adler32+0x1d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1030 <adler32_short@plt>
mov    -0x14(%rbp),%eax
shl    $0x10,%eax
add    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adler32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
movl   $0x1,0x4(%rsp)
movl   $0x0,(%rsp)
cmp    $0x15b0,%esi
jb     1168 <adler32+0x58>
lea    0x4(%rsp),%r14
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x15b0,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1030 <adler32_short@plt>
add    $0x15b0,%rbx
add    $0xffffea50,%ebp
cmp    $0x15af,%ebp
ja     1140 <adler32+0x30>
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <adler32_short@plt>
mov    (%rsp),%eax
shl    $0x10,%eax
add    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @adler32(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %10, %2
%8 = load i32, i32* %4
%9 = icmp uge i32 %8, 5552
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = call i32 @adler32_short(i8* %11, i32 5552, i32* %5, i32* %6)
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 5552
store i8* %14, i8** %3
%15 = load i32, i32* %4
%16 = sub i32 %15, 5552
store i32 %16, i32* %4
br label %7
17: ; preds = %7
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = call i32 @adler32_short(i8* %18, i32 %19, i32* %5, i32* %6)
%21 = load i32, i32* %6
%22 = shl i32 %21, 16
%23 = load i32, i32* %5
%24 = add nsw i32 %22, %23
ret i32 %24
}

LLVM IR (-O2):
define i32 @adler32(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = icmp ugt i32 %1, 5551
br i1 %7, label %8, label %15
8: ; preds = %2, %8
%9 = phi i32 [ %13, %8 ], [ %1, %2 ]
%10 = phi i8* [ %12, %8 ], [ %0, %2 ]
%11 = call i32 @adler32_short(i8* %10, i32 5552, i32* %3, i32* %4)
%12 = getelementptr inbounds i8, i8* %10, i64 5552
%13 = add i32 %9, -5552
%14 = icmp ugt i32 %13, 5551
br i1 %14, label %8, label %15
15: ; preds = %8, %2
%16 = phi i8* [ %0, %2 ], [ %12, %8 ]
%17 = phi i32 [ %1, %2 ], [ %13, %8 ]
%18 = call i32 @adler32_short(i8* %16, i32 %17, i32* %3, i32* %4)
%19 = load i32, i32* %4
%20 = shl i32 %19, 16
%21 = load i32, i32* %3
%22 = add nsw i32 %20, %21
ret i32 %22
}