#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;
typedef int /*<<< orphan*/ curDWord;

/* Variables and functions */
int /*<<< orphan*/ flipEndian(unsigned char *, int);
uint32_t MKBlockChecksum(uint32_t *ckSum, const unsigned char *data,
                         size_t len) {
  uint32_t *curDWordPtr;
  uint32_t curDWord;
  uint32_t myCkSum;
  myCkSum = *ckSum;
  if (data) {
    curDWordPtr = (uint32_t *)data;
    while (curDWordPtr < (uint32_t *)(&data[len & 0xFFFFFFFC])) {
      curDWord = *curDWordPtr;
      flipEndian((unsigned char *)(&(curDWord)), sizeof(curDWord));
      myCkSum = curDWord + ((myCkSum >> 31) | (myCkSum << 1));
      curDWordPtr++;
    }
  }
  *ckSum = myCkSum;
  return myCkSum;
}


x86 assembly (clang, -O0):
<MKBlockChecksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a5 <MKBlockChecksum+0x95>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movabs $0xfffffffc,%rdx
and    -0x18(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11a0 <MKBlockChecksum+0x90>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
call   1030 <flipEndian@plt>
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
sar    $0x1f,%ecx
mov    -0x28(%rbp),%edx
shl    $0x1,%edx
or     %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    1140 <MKBlockChecksum+0x30>
jmp    11a5 <MKBlockChecksum+0x95>
mov    -0x28(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MKBlockChecksum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    (%rdi),%ebp
test   %rsi,%rsi
je     1169 <MKBlockChecksum+0x59>
mov    %rdx,%r15
and    $0xfffffffc,%r15d
test   %r15,%r15
je     1169 <MKBlockChecksum+0x59>
mov    %rsi,%rbx
add    %rsi,%r15
lea    0xc(%rsp),%r12
nopl   (%rax)
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    %r12,%rdi
mov    $0x4,%esi
call   1030 <flipEndian@plt>
mov    %ebp,%eax
sar    $0x1f,%eax
add    %ebp,%ebp
or     %eax,%ebp
add    0xc(%rsp),%ebp
add    $0x4,%rbx
cmp    %r15,%rbx
jb     1140 <MKBlockChecksum+0x30>
mov    %ebp,(%r14)
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @MKBlockChecksum(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i32*, i32** %4
%11 = load i32, i32* %10
store i32 %11, i32* %9
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %40
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %7
br label %17
17: ; preds = %25, %14
%18 = load i32*, i32** %7
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = and i64 %20, 4294967292
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = bitcast i8* %22 to i32*
%24 = icmp ult i32* %18, %23
br i1 %24, label %25, label %39
25: ; preds = %17
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
store i32 %27, i32* %8
%28 = bitcast i32* %8 to i8*
%29 = call i32 @flipEndian(i8* %28, i32 4)
%30 = load i32, i32* %8
%31 = load i32, i32* %9
%32 = ashr i32 %31, 31
%33 = load i32, i32* %9
%34 = shl i32 %33, 1
%35 = or i32 %32, %34
%36 = add nsw i32 %30, %35
store i32 %36, i32* %9
%37 = load i32*, i32** %7
%38 = getelementptr inbounds i32, i32* %37, i32 1
store i32* %38, i32** %7
br label %17
39: ; preds = %17
br label %40
40: ; preds = %39, %3
%41 = load i32, i32* %9
%42 = load i32*, i32** %4
store i32 %41, i32* %42
%43 = load i32, i32* %9
ret i32 %43
}

LLVM IR (-O2):
define i32 @MKBlockChecksum(i32* nocapture %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* %0
%7 = icmp eq i8* %1, null
br i1 %7, label %27, label %8
8: ; preds = %3
%9 = and i64 %2, 4294967292
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = bitcast i8* %10 to i32*
%12 = icmp eq i64 %9, 0
br i1 %12, label %27, label %13
13: ; preds = %8
%14 = bitcast i8* %1 to i32*
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ %24, %15 ], [ %6, %13 ]
%17 = phi i32* [ %25, %15 ], [ %14, %13 ]
%18 = load i32, i32* %17
store i32 %18, i32* %4
%19 = call i32 @flipEndian(i8* %5, i32 4)
%20 = load i32, i32* %4
%21 = ashr i32 %16, 31
%22 = shl i32 %16, 1
%23 = or i32 %21, %22
%24 = add nsw i32 %20, %23
%25 = getelementptr inbounds i32, i32* %17, i64 1
%26 = icmp ult i32* %25, %11
br i1 %26, label %15, label %27
27: ; preds = %15, %8, %3
%28 = phi i32 [ %6, %3 ], [ %6, %8 ], [ %24, %15 ]
store i32 %28, i32* %0
ret i32 %28
}