#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__ time_t;

/* Variables and functions */
int /*<<< orphan*/ free(void *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned long *);
scalar_t__ time(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  unsigned long bytes = (64 * 1024 * 1024);
  unsigned long volatile *data =
      (unsigned long *)malloc(sizeof(unsigned long) * bytes);
  unsigned long testDuration = 0;
  unsigned long bitFlipsCtr = 0;
  printf("how long do you want this test to go on for? (in min): ");
  scanf("%ld", &testDuration);
  testDuration = testDuration * 60;
  printf("\ninitializing 64 MB size array of integers, setting all values to "
         "0...\n");
  for (unsigned long i = 0; i < bytes; i++) {
    data[i] = 0;
  }
  printf("checking for bitflips now\n");
  time_t startTest = time(0);
  time_t endTest = startTest + testDuration;
  while (time(0) < endTest) {
    for (unsigned long i = 0; i < bytes; i++) {
      if (data[i] != 0) {
        data[i] = 0;
        bitFlipsCtr++;
      }
    }
  }
  printf("\nFinished test with %ld bit flip(s) detected\n", bitFlipsCtr);
  free((void *)data);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x4000000,-0x18(%rbp)
04
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe92(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <scanf@plt>
imul   $0x3c,-0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11fd <main+0xad>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11ce <main+0x7e>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
xor    %edi,%edi
call   1050 <time@plt>
cmp    -0x48(%rbp),%rax
jge    1296 <main+0x146>
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1291 <main+0x141>
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    $0x0,%rax
je     127b <main+0x12b>
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1280 <main+0x130>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    123b <main+0xeb>
jmp    1222 <main+0xd2>
mov    -0x30(%rbp),%rsi
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x20000000,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
movq   $0x0,(%rsp)
lea    0xe7c(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea4(%rip),%rdi
mov    %rsp,%rsi
call   1080 <scanf@plt>
imul   $0x3c,(%rsp),%rax
mov    %rax,(%rsp)
lea    0xebe(%rip),%rdi
call   1040 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movq   $0x0,(%r12,%rbx,8)
movq   $0x0,0x8(%r12,%rbx,8)
movq   $0x0,0x10(%r12,%rbx,8)
movq   $0x0,0x18(%r12,%rbx,8)
movq   $0x0,0x20(%r12,%rbx,8)
movq   $0x0,0x28(%r12,%rbx,8)
movq   $0x0,0x30(%r12,%rbx,8)
movq   $0x0,0x38(%r12,%rbx,8)
add    $0x8,%rbx
cmp    $0x4000000,%rbx
jne    11c0 <main+0x60>
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%r15
add    (%rsp),%r15
xor    %edi,%edi
call   1060 <time@plt>
cmp    %r15,%rax
jge    1281 <main+0x121>
xor    %ecx,%ecx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpq   $0x0,(%r12,%rcx,8)
je     1263 <main+0x103>
movq   $0x0,(%r12,%rcx,8)
add    $0x1,%r14
add    $0x1,%rcx
cmp    $0x4000000,%rcx
jne    1250 <main+0xf0>
xor    %edi,%edi
call   1060 <time@plt>
mov    $0x0,%ecx
cmp    %r15,%rax
jl     1250 <main+0xf0>
lea    0xdb4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [56 x i8] c"how long do you want this test to go on for? (in min): \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [72 x i8] c"\0Ainitializing 64 MB size array of integers, setting all values to 0...\0A\00"
@.str.3 = [27 x i8] c"checking for bitflips now\0A\00"
@.str.4 = [46 x i8] c"\0AFinished test with %ld bit flip(s) detected\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 67108864, i64* %6
%14 = load i64, i64* %6
%15 = mul i64 8, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i64*
store i64* %18, i64** %7
store i64 0, i64* %8
store i64 0, i64* %9
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %8)
%21 = load i64, i64* %8
%22 = mul i64 %21, 60
store i64 %22, i64* %8
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %10
br label %24
24: ; preds = %32, %2
%25 = load i64, i64* %10
%26 = load i64, i64* %6
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = load i64*, i64** %7
%30 = load i64, i64* %10
%31 = getelementptr inbounds i64, i64* %29, i64 %30
store volatile i64 0, i64* %31
br label %32
32: ; preds = %28
%33 = load i64, i64* %10
%34 = add i64 %33, 1
store i64 %34, i64* %10
br label %24
35: ; preds = %24
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%37 = call i64 @time(i32 0)
store i64 %37, i64* %11
%38 = load i64, i64* %11
%39 = load i64, i64* %8
%40 = add i64 %38, %39
store i64 %40, i64* %12
br label %41
41: ; preds = %66, %35
%42 = call i64 @time(i32 0)
%43 = load i64, i64* %12
%44 = icmp slt i64 %42, %43
br i1 %44, label %45, label %67
45: ; preds = %41
store i64 0, i64* %13
br label %46
46: ; preds = %63, %45
%47 = load i64, i64* %13
%48 = load i64, i64* %6
%49 = icmp ult i64 %47, %48
br i1 %49, label %50, label %66
50: ; preds = %46
%51 = load i64*, i64** %7
%52 = load i64, i64* %13
%53 = getelementptr inbounds i64, i64* %51, i64 %52
%54 = load volatile i64, i64* %53
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %50
%57 = load i64*, i64** %7
%58 = load i64, i64* %13
%59 = getelementptr inbounds i64, i64* %57, i64 %58
store volatile i64 0, i64* %59
%60 = load i64, i64* %9
%61 = add i64 %60, 1
store i64 %61, i64* %9
br label %62
62: ; preds = %56, %50
br label %63
63: ; preds = %62
%64 = load i64, i64* %13
%65 = add i64 %64, 1
store i64 %65, i64* %13
br label %46
66: ; preds = %46
br label %41
67: ; preds = %41
%68 = load i64, i64* %9
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i64 %68)
%70 = load i64*, i64** %7
%71 = bitcast i64* %70 to i8*
%72 = call i32 @free(i8* %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [56 x i8] c"how long do you want this test to go on for? (in min): \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.4 = [46 x i8] c"\0AFinished test with %ld bit flip(s) detected\0A\00"
@str = [71 x i8] c"\0Ainitializing 64 MB size array of integers, setting all values to 0...\00"
@str.5 = [26 x i8] c"checking for bitflips now\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = tail call i64 @malloc(i32 536870912)
%5 = inttoptr i64 %4 to i64*
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%9 = load i64, i64* %3
%10 = mul i64 %9, 60
store i64 %10, i64* %3
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str, i64 0, i64 0))
br label %19
12: ; preds = %19
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
%14 = call i64 @time(i32 0)
%15 = load i64, i64* %3
%16 = add i64 %15, %14
%17 = call i64 @time(i32 0)
%18 = icmp slt i64 %17, %16
br i1 %18, label %41, label %55
19: ; preds = %19, %2
%20 = phi i64 [ 0, %2 ], [ %36, %19 ]
%21 = getelementptr inbounds i64, i64* %5, i64 %20
store volatile i64 0, i64* %21
%22 = or i64 %20, 1
%23 = getelementptr inbounds i64, i64* %5, i64 %22
store volatile i64 0, i64* %23
%24 = or i64 %20, 2
%25 = getelementptr inbounds i64, i64* %5, i64 %24
store volatile i64 0, i64* %25
%26 = or i64 %20, 3
%27 = getelementptr inbounds i64, i64* %5, i64 %26
store volatile i64 0, i64* %27
%28 = or i64 %20, 4
%29 = getelementptr inbounds i64, i64* %5, i64 %28
store volatile i64 0, i64* %29
%30 = or i64 %20, 5
%31 = getelementptr inbounds i64, i64* %5, i64 %30
store volatile i64 0, i64* %31
%32 = or i64 %20, 6
%33 = getelementptr inbounds i64, i64* %5, i64 %32
store volatile i64 0, i64* %33
%34 = or i64 %20, 7
%35 = getelementptr inbounds i64, i64* %5, i64 %34
store volatile i64 0, i64* %35
%36 = add nuw nsw i64 %20, 8
%37 = icmp eq i64 %36, 67108864
br i1 %37, label %12, label %19
38: ; preds = %49
%39 = call i64 @time(i32 0)
%40 = icmp slt i64 %39, %16
br i1 %40, label %53, label %55
41: ; preds = %12, %53
%42 = phi i64 [ %54, %53 ], [ 0, %12 ]
%43 = phi i64 [ %50, %53 ], [ 0, %12 ]
%44 = getelementptr inbounds i64, i64* %5, i64 %42
%45 = load volatile i64, i64* %44
%46 = icmp eq i64 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %41
store volatile i64 0, i64* %44
%48 = add i64 %43, 1
br label %49
49: ; preds = %41, %47
%50 = phi i64 [ %48, %47 ], [ %43, %41 ]
%51 = add nuw nsw i64 %42, 1
%52 = icmp eq i64 %51, 67108864
br i1 %52, label %38, label %53
53: ; preds = %49, %38
%54 = phi i64 [ %51, %49 ], [ 0, %38 ]
br label %41
55: ; preds = %38, %12
%56 = phi i64 [ 0, %12 ], [ %50, %38 ]
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i64 %56)
%58 = inttoptr i64 %4 to i8*
%59 = call i32 @free(i8* %58)
ret i32 0
}