#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int checksum(int *a, int size) {
  int check = 0, i;
  for (i = 0; i < size; i++) {
    if (i == 0) {
      fprintf(stderr, "check: %d, &a: %p, a[0]: %d\n", check, a, a[0]);
    }
    if (i % 1024 == 0)
      fprintf(stderr, "it:%p\n", &a[i]);
    check += a[i];
    if (i == size - 1)
      fprintf(stderr, "Checksum invitro: %d\n", check);
  }
  return check;
}


x86 assembly (clang, -O0):
<checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f1 <checksum+0xe1>
cmpl   $0x0,-0x14(%rbp)
jne    1168 <checksum+0x58>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    (%rax),%r8d
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a2 <checksum+0x92>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11de <checksum+0xce>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e3 <checksum+0xd3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <checksum+0x1d>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checksum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11d5 <checksum+0xc5>
mov    %esi,%r14d
mov    %rdi,%rbx
lea    -0x1(%r14),%r13d
mov    0x2eac(%rip),%r15
mov    (%r15),%edi
mov    (%rbx),%r8d
lea    0xebf(%rip),%rsi
xor    %edx,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
lea    0xec6(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%ebp
test   %r13d,%r13d
je     11d9 <checksum+0xc9>
mov    %r14d,%r14d
mov    $0x1,%r15d
mov    $0x4,%r12d
jmp    118d <checksum+0x7d>
nopl   0x0(%rax)
add    $0x1,%r15
add    $0x4,%r12
cmp    %r15,%r14
je     11ec <checksum+0xdc>
test   $0x3ff,%r15d
jne    11b1 <checksum+0xa1>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    (%rbx,%r12,1),%rdx
lea    0xe73(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    (%rbx,%r15,4),%ebp
cmp    %r15,%r13
jne    1180 <checksum+0x70>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1180 <checksum+0x70>
xor    %ebp,%ebp
jmp    11ec <checksum+0xdc>
mov    (%r15),%edi
lea    0xe41(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"check: %d, &a: %p, a[0]: %d\0A\00"
@.str.1 = [7 x i8] c"it:%p\0A\00"
@.str.2 = [22 x i8] c"Checksum invitro: %d\0A\00"
define i32 @checksum(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %50, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %53
11: ; preds = %7
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i32, i32* %5
%17 = load i32*, i32** %3
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %16, i32* %17, i32 %20)
br label %22
22: ; preds = %14, %11
%23 = load i32, i32* %6
%24 = srem i32 %23, 1024
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i32*, i32** %3
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %31)
br label %33
33: ; preds = %26, %22
%34 = load i32*, i32** %3
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = load i32, i32* %5
%40 = add nsw i32 %39, %38
store i32 %40, i32* %5
%41 = load i32, i32* %6
%42 = load i32, i32* %4
%43 = sub nsw i32 %42, 1
%44 = icmp eq i32 %41, %43
br i1 %44, label %45, label %49
45: ; preds = %33
%46 = load i32, i32* @stderr
%47 = load i32, i32* %5
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %45, %33
br label %50
50: ; preds = %49
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %7
53: ; preds = %7
%54 = load i32, i32* %5
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"check: %d, &a: %p, a[0]: %d\0A\00"
@.str.1 = [7 x i8] c"it:%p\0A\00"
@.str.2 = [22 x i8] c"Checksum invitro: %d\0A\00"
define i32 @checksum(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %38
4: ; preds = %2
%5 = add nsw i32 %1, -1
%6 = zext i32 %5 to i64
%7 = zext i32 %1 to i64
%8 = load i32, i32* @stderr
%9 = load i32, i32* %0
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 0, i32* %0, i32 %9)
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %0)
%13 = load i32, i32* %0
%14 = icmp eq i32 %5, 0
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %38
18: ; preds = %4, %35
%19 = phi i64 [ %36, %35 ], [ 1, %4 ]
%20 = phi i32 [ %30, %35 ], [ %13, %4 ]
%21 = and i64 %19, 1023
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = getelementptr inbounds i32, i32* %0, i64 %19
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %25)
br label %27
27: ; preds = %23, %18
%28 = getelementptr inbounds i32, i32* %0, i64 %19
%29 = load i32, i32* %28
%30 = add nsw i32 %29, %20
%31 = icmp eq i64 %19, %6
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %35
35: ; preds = %27, %32
%36 = add nuw nsw i64 %19, 1
%37 = icmp eq i64 %36, %7
br i1 %37, label %38, label %18
38: ; preds = %35, %15, %2
%39 = phi i32 [ 0, %2 ], [ %13, %15 ], [ %30, %35 ]
ret i32 %39
}