#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 unsigned int uint8_t;

/* Variables and functions */
uint8_t checksum(uint8_t *base) {
  int i = 255, c = 0;
  unsigned sum = 255;
  while (--i >= 0) {
    sum += base[i] + c;
    c = 0;
    if (sum >= 256) {
      sum &= 0xff;
      c = 1;
    }
  }
  return sum;
}


x86 assembly (clang, -O0):
<checksum>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0xff,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0xff,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     116e <checksum+0x6e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x100,-0x14(%rbp)
jb     1169 <checksum+0x69>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    111d <checksum+0x1d>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<checksum>:
xor    %edx,%edx
mov    $0xff,%eax
mov    $0xfc,%ecx
nopl   0x0(%rax)
add    %edx,%eax
add    0x8(%rdi,%rcx,4),%eax
cmp    $0x100,%eax
movzbl %al,%eax
sbb    $0xffffffff,%eax
add    0x4(%rdi,%rcx,4),%eax
cmp    $0x100,%eax
movzbl %al,%eax
sbb    $0xffffffff,%eax
add    (%rdi,%rcx,4),%eax
xor    %edx,%edx
cmp    $0x100,%eax
setae  %dl
movzbl %al,%eax
add    $0xfffffffffffffffd,%rcx
cmp    $0xfffffffffffffffd,%rcx
jne    1110 <checksum+0x10>
ret

LLVM IR (-O0):
define i32 @checksum(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 255, i32* %3
store i32 0, i32* %4
store i32 255, i32* %5
br label %6
6: ; preds = %25, %1
%7 = load i32, i32* %3
%8 = add nsw i32 %7, -1
store i32 %8, i32* %3
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %6
%11 = load i32*, i32** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = load i32, i32* %14
%16 = load i32, i32* %4
%17 = add i32 %15, %16
%18 = load i32, i32* %5
%19 = add i32 %18, %17
store i32 %19, i32* %5
store i32 0, i32* %4
%20 = load i32, i32* %5
%21 = icmp uge i32 %20, 256
br i1 %21, label %22, label %25
22: ; preds = %10
%23 = load i32, i32* %5
%24 = and i32 %23, 255
store i32 %24, i32* %5
store i32 1, i32* %4
br label %25
25: ; preds = %22, %10
br label %6
26: ; preds = %6
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
define i32 @checksum(i32* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ 254, %1 ], [ %29, %2 ]
%4 = phi i32 [ 255, %1 ], [ %27, %2 ]
%5 = phi i32 [ 0, %1 ], [ %28, %2 ]
%6 = getelementptr inbounds i32, i32* %0, i64 %3
%7 = load i32, i32* %6
%8 = add nuw nsw i32 %4, %5
%9 = add i32 %8, %7
%10 = icmp ugt i32 %9, 255
%11 = and i32 %9, 255
%12 = zext i1 %10 to i32
%13 = add nsw i64 %3, -1
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = add nuw nsw i32 %11, %12
%17 = add i32 %16, %15
%18 = icmp ugt i32 %17, 255
%19 = and i32 %17, 255
%20 = zext i1 %18 to i32
%21 = add nsw i64 %3, -2
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = add nuw nsw i32 %19, %20
%25 = add i32 %24, %23
%26 = icmp ugt i32 %25, 255
%27 = and i32 %25, 255
%28 = zext i1 %26 to i32
%29 = add nsw i64 %3, -3
%30 = icmp eq i64 %21, 0
br i1 %30, label %31, label %2
31: ; preds = %2
ret i32 %27
}