#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 scalar_t__ uint8_t;
typedef int uint64_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
uint16_t checksum_simple(const void *ptr, uint32_t nbytes) {
  const uint16_t *__attribute__((__may_alias__)) hptr = ptr;
  uint64_t sum = 0;
  for (uint32_t nhalfs = nbytes >> 1; nhalfs != 0; nhalfs--) {
    sum += *hptr++;
  }
  if ((nbytes & 0x01) != 0) {
    sum += *(uint8_t *)hptr;
  }
  sum = (sum & 0xffffffff) + (sum >> 32);
  sum = (sum & 0xffffffff) + (sum >> 32);
  (void)(sum == (uint32_t)sum);
  sum = (sum & 0xffff) + (sum >> 16);
  sum = (sum & 0xffff) + (sum >> 16);
  (void)(sum == (uint16_t)sum);
  return (uint16_t)sum;
}


x86 assembly (clang, -O0):
<checksum_simple>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1152 <checksum_simple+0x52>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1123 <checksum_simple+0x23>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1172 <checksum_simple+0x72>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xffffffff,%eax
mov    -0x1c(%rbp),%edx
mov    $0x20,%ecx
sar    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xffffffff,%eax
mov    -0x1c(%rbp),%edx
mov    $0x20,%ecx
sar    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xffff,%eax
mov    -0x1c(%rbp),%ecx
sar    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xffff,%eax
mov    -0x1c(%rbp),%ecx
sar    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<checksum_simple>:
ret

LLVM IR (-O0):
define i32 @checksum_simple(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to i32*
store i32* %9, i32** %5
store i32 0, i32* %6
%10 = load i32, i32* %4
%11 = ashr i32 %10, 1
store i32 %11, i32* %7
br label %12
12: ; preds = %21, %2
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i32*, i32** %5
%17 = getelementptr inbounds i32, i32* %16, i32 1
store i32* %17, i32** %5
%18 = load i32, i32* %16
%19 = load i32, i32* %6
%20 = add nsw i32 %19, %18
store i32 %20, i32* %6
br label %21
21: ; preds = %15
%22 = load i32, i32* %7
%23 = add nsw i32 %22, -1
store i32 %23, i32* %7
br label %12
24: ; preds = %12
%25 = load i32, i32* %4
%26 = and i32 %25, 1
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %24
%29 = load i32*, i32** %5
%30 = bitcast i32* %29 to i64*
%31 = load i64, i64* %30
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = add nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %6
br label %36
36: ; preds = %28, %24
%37 = load i32, i32* %6
%38 = and i32 %37, -1
%39 = load i32, i32* %6
%40 = ashr i32 %39, 32
%41 = add i32 %38, %40
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = and i32 %42, -1
%44 = load i32, i32* %6
%45 = ashr i32 %44, 32
%46 = add i32 %43, %45
store i32 %46, i32* %6
%47 = load i32, i32* %6
%48 = load i32, i32* %6
%49 = icmp eq i32 %47, %48
%50 = zext i1 %49 to i32
%51 = load i32, i32* %6
%52 = and i32 %51, 65535
%53 = load i32, i32* %6
%54 = ashr i32 %53, 16
%55 = add nsw i32 %52, %54
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = and i32 %56, 65535
%58 = load i32, i32* %6
%59 = ashr i32 %58, 16
%60 = add nsw i32 %57, %59
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = load i32, i32* %6
%63 = icmp eq i32 %61, %62
%64 = zext i1 %63 to i32
%65 = load i32, i32* %6
ret i32 %65
}

LLVM IR (-O2):
define i32 @checksum_simple(i8* nocapture readnone %0, i32 %1) {
ret i32 poison
}