#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 */
float *calloc(int, int);
int /*<<< orphan*/ cpuCalculation(float *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ memCalculation(float *, float *);
int /*<<< orphan*/ stderr;
int main() {
  float *pCpuArray = calloc(1000000, sizeof(float));
  float *pMemArray = calloc(1000000, sizeof(float));
  if (!pCpuArray || !pMemArray) {
    fprintf(stderr, "Fail to alloc array for the test\n");
    free(pCpuArray);
    free(pMemArray);
    return -1;
  }
  unsigned int i = 0;
  for (i = 0; i < 1000; i++) {
    cpuCalculation(pCpuArray);
    memCalculation(pCpuArray, pMemArray);
  }
  free(pCpuArray);
  free(pMemArray);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xf4240,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0xf4240,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119b <main+0x4b>
cmpq   $0x0,-0x18(%rbp)
jne    11ce <main+0x7e>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1226 <main+0xd6>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jae    120d <main+0xbd>
mov    -0x10(%rbp),%rdi
call   1070 <cpuCalculation@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <memCalculation@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11dc <main+0x8c>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0xf4240,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    $0xf4240,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     11bc <main+0x6c>
test   %r14,%r14
je     11bc <main+0x6c>
mov    $0x3e8,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <cpuCalculation@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <memCalculation@plt>
add    $0xffffffff,%ebp
jne    1190 <main+0x40>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11e6 <main+0x96>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Fail to alloc array for the test\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float*
%3 = alloca float*
%4 = alloca i32
store i32 0, i32* %1
%5 = call float* @calloc(i32 1000000, i32 4)
store float* %5, float** %2
%6 = call float* @calloc(i32 1000000, i32 4)
store float* %6, float** %3
%7 = load float*, float** %2
%8 = icmp ne float* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load float*, float** %3
%11 = icmp ne float* %10, null
br i1 %11, label %19, label %12
12: ; preds = %9, %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%15 = load float*, float** %2
%16 = call i32 @free(float* %15)
%17 = load float*, float** %3
%18 = call i32 @free(float* %17)
store i32 -1, i32* %1
br label %37
19: ; preds = %9
store i32 0, i32* %4
store i32 0, i32* %4
br label %20
20: ; preds = %29, %19
%21 = load i32, i32* %4
%22 = icmp ult i32 %21, 1000
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load float*, float** %2
%25 = call i32 @cpuCalculation(float* %24)
%26 = load float*, float** %2
%27 = load float*, float** %3
%28 = call i32 @memCalculation(float* %26, float* %27)
br label %29
29: ; preds = %23
%30 = load i32, i32* %4
%31 = add i32 %30, 1
store i32 %31, i32* %4
br label %20
32: ; preds = %20
%33 = load float*, float** %2
%34 = call i32 @free(float* %33)
%35 = load float*, float** %3
%36 = call i32 @free(float* %35)
store i32 0, i32* %1
br label %37
37: ; preds = %32, %12
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Fail to alloc array for the test\0A\00"
define i32 @main() {
%1 = tail call float* @calloc(i32 1000000, i32 4)
%2 = tail call float* @calloc(i32 1000000, i32 4)
%3 = icmp ne float* %1, null
%4 = icmp ne float* %2, null
%5 = and i1 %3, %4
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @free(float* %1)
%10 = tail call i32 @free(float* %2)
br label %20
11: ; preds = %0, %11
%12 = phi i32 [ %15, %11 ], [ 0, %0 ]
%13 = tail call i32 @cpuCalculation(float* %1)
%14 = tail call i32 @memCalculation(float* %1, float* %2)
%15 = add nuw nsw i32 %12, 1
%16 = icmp eq i32 %15, 1000
br i1 %16, label %17, label %11
17: ; preds = %11
%18 = tail call i32 @free(float* %1)
%19 = tail call i32 @free(float* %2)
br label %20
20: ; preds = %17, %6
%21 = phi i32 [ 0, %17 ], [ -1, %6 ]
ret i32 %21
}