#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*/ EightPerLoop(int *, long);
int /*<<< orphan*/ OnePerLoop(int *, long);
int /*<<< orphan*/ SixteenPerLoop(int *, long);
int /*<<< orphan*/ abort();
int *calloc(long, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ time_end();
int /*<<< orphan*/ time_start();
int /*<<< orphan*/ verify_and_zero(int *, long);
int main() {
  long len = 1024 * 1024 * 1;
  int *int_field = calloc(len, sizeof(int));
  if (int_field == NULL) {
    printf("Could not allocate memory.  Aborting.");
    abort();
  }
  verify_and_zero(int_field, len);
  printf("Incrementing one at a time.\n");
  time_start();
  OnePerLoop(int_field, len);
  time_end();
  verify_and_zero(int_field, len);
  printf("Incrementing eight at a time.\n");
  time_start();
  EightPerLoop(int_field, len);
  time_end();
  verify_and_zero(int_field, len);
  printf("Incrementing sixteen at a time.\n");
  time_start();
  SixteenPerLoop(int_field, len);
  time_end();
  verify_and_zero(int_field, len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x100000,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1090 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d7 <main+0x47>
lea    0xe35(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   1050 <abort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <verify_and_zero@plt>
lea    0xe3b(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   10a0 <time_start@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <OnePerLoop@plt>
mov    $0x0,%al
call   1080 <time_end@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <verify_and_zero@plt>
lea    0xe24(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   10a0 <time_start@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <EightPerLoop@plt>
mov    $0x0,%al
call   1080 <time_end@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <verify_and_zero@plt>
lea    0xe0f(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   10a0 <time_start@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <SixteenPerLoop@plt>
mov    $0x0,%al
call   1080 <time_end@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <verify_and_zero@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x100000,%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
test   %rax,%rax
je     1269 <main+0xc9>
mov    %rax,%rbx
mov    $0x100000,%esi
mov    %rax,%rdi
call   1030 <verify_and_zero@plt>
lea    0xe56(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   10b0 <time_start@plt>
mov    $0x100000,%esi
mov    %rbx,%rdi
call   1040 <OnePerLoop@plt>
xor    %eax,%eax
call   1090 <time_end@plt>
mov    $0x100000,%esi
mov    %rbx,%rdi
call   1030 <verify_and_zero@plt>
lea    0xe3e(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   10b0 <time_start@plt>
mov    $0x100000,%esi
mov    %rbx,%rdi
call   1070 <EightPerLoop@plt>
xor    %eax,%eax
call   1090 <time_end@plt>
mov    $0x100000,%esi
mov    %rbx,%rdi
call   1030 <verify_and_zero@plt>
lea    0xe28(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   10b0 <time_start@plt>
mov    $0x100000,%esi
mov    %rbx,%rdi
call   10c0 <SixteenPerLoop@plt>
xor    %eax,%eax
call   1090 <time_end@plt>
mov    $0x100000,%esi
mov    %rbx,%rdi
call   1030 <verify_and_zero@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xd90(%rip),%rdi
call   1080 <printf@plt>
xor    %eax,%eax
call   1050 <abort@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Could not allocate memory. Aborting.\00"
@.str.1 = [29 x i8] c"Incrementing one at a time.\0A\00"
@.str.2 = [31 x i8] c"Incrementing eight at a time.\0A\00"
@.str.3 = [33 x i8] c"Incrementing sixteen at a time.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32*
store i32 0, i32* %1
store i64 1048576, i64* %2
%4 = load i64, i64* %2
%5 = call i32* @calloc(i64 %4, i32 4)
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %0
%12 = load i32*, i32** %3
%13 = load i64, i64* %2
%14 = call i32 @verify_and_zero(i32* %12, i64 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (...) @time_start()
%17 = load i32*, i32** %3
%18 = load i64, i64* %2
%19 = call i32 @OnePerLoop(i32* %17, i64 %18)
%20 = call i32 (...) @time_end()
%21 = load i32*, i32** %3
%22 = load i64, i64* %2
%23 = call i32 @verify_and_zero(i32* %21, i64 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 (...) @time_start()
%26 = load i32*, i32** %3
%27 = load i64, i64* %2
%28 = call i32 @EightPerLoop(i32* %26, i64 %27)
%29 = call i32 (...) @time_end()
%30 = load i32*, i32** %3
%31 = load i64, i64* %2
%32 = call i32 @verify_and_zero(i32* %30, i64 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 (...) @time_start()
%35 = load i32*, i32** %3
%36 = load i64, i64* %2
%37 = call i32 @SixteenPerLoop(i32* %35, i64 %36)
%38 = call i32 (...) @time_end()
%39 = load i32*, i32** %3
%40 = load i64, i64* %2
%41 = call i32 @verify_and_zero(i32* %39, i64 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"Could not allocate memory. Aborting.\00"
@str = [28 x i8] c"Incrementing one at a time.\00"
@str.4 = [30 x i8] c"Incrementing eight at a time.\00"
@str.5 = [32 x i8] c"Incrementing sixteen at a time.\00"
define i32 @main() {
%1 = tail call i32* @calloc(i64 1048576, i32 4)
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (...) @abort()
unreachable
6: ; preds = %0
%7 = tail call i32 @verify_and_zero(i32* %1, i64 1048576)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (...) @time_start()
%10 = tail call i32 @OnePerLoop(i32* %1, i64 1048576)
%11 = tail call i32 (...) @time_end()
%12 = tail call i32 @verify_and_zero(i32* %1, i64 1048576)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
%14 = tail call i32 (...) @time_start()
%15 = tail call i32 @EightPerLoop(i32* %1, i64 1048576)
%16 = tail call i32 (...) @time_end()
%17 = tail call i32 @verify_and_zero(i32* %1, i64 1048576)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
%19 = tail call i32 (...) @time_start()
%20 = tail call i32 @SixteenPerLoop(i32* %1, i64 1048576)
%21 = tail call i32 (...) @time_end()
%22 = tail call i32 @verify_and_zero(i32* %1, i64 1048576)
ret i32 0
}