#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*/ free(double *);
scalar_t__ malloc(unsigned long);
void benchAllocator_core(unsigned long bufferSize) {
  double *buffer = NULL;
  unsigned int i;
  unsigned long j;
  if (bufferSize == 0)
    return;
  for (i = 0; i < 50; i++) {
    buffer = (double *)malloc(bufferSize * sizeof(double));
    for (j = 0; j < bufferSize; j++)
      buffer[j] = 0.0;
    free(buffer);
  }
}


x86 assembly (clang, -O0):
<benchAllocator_core>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1144 <benchAllocator_core+0x24>
jmp    11b4 <benchAllocator_core+0x94>
movl   $0x0,-0x14(%rbp)
cmpl   $0x32,-0x14(%rbp)
jae    11b4 <benchAllocator_core+0x94>
mov    -0x8(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    119d <benchAllocator_core+0x7d>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116e <benchAllocator_core+0x4e>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <benchAllocator_core+0x2b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchAllocator_core>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1175 <benchAllocator_core+0x45>
mov    %rdi,%r14
shl    $0x3,%r14
mov    $0x32,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebp
jne    1150 <benchAllocator_core+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @benchAllocator_core(i64 %0) {
%2 = alloca i64
%3 = alloca double*
%4 = alloca i32
%5 = alloca i64
store i64 %0, i64* %2
store double* null, double** %3
%6 = load i64, i64* %2
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %35
9: ; preds = %1
store i32 0, i32* %4
br label %10
10: ; preds = %32, %9
%11 = load i32, i32* %4
%12 = icmp ult i32 %11, 50
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = load i64, i64* %2
%15 = mul i64 %14, 8
%16 = call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to double*
store double* %17, double** %3
store i64 0, i64* %5
br label %18
18: ; preds = %26, %13
%19 = load i64, i64* %5
%20 = load i64, i64* %2
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = load double*, double** %3
%24 = load i64, i64* %5
%25 = getelementptr inbounds double, double* %23, i64 %24
store double 0.000000e+00, double* %25
br label %26
26: ; preds = %22
%27 = load i64, i64* %5
%28 = add i64 %27, 1
store i64 %28, i64* %5
br label %18
29: ; preds = %18
%30 = load double*, double** %3
%31 = call i32 @free(double* %30)
br label %32
32: ; preds = %29
%33 = load i32, i32* %4
%34 = add i32 %33, 1
store i32 %34, i32* %4
br label %10
35: ; preds = %8, %10
ret void
}

LLVM IR (-O2):
define void @benchAllocator_core(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = shl i64 %0, 3
br label %5
5: ; preds = %3, %5
%6 = phi i32 [ 0, %3 ], [ %11, %5 ]
%7 = tail call i64 @malloc(i64 %4)
%8 = inttoptr i64 %7 to double*
%9 = inttoptr i64 %7 to i8*
%10 = tail call i32 @free(double* %8)
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, 50
br i1 %12, label %13, label %5
13: ; preds = %5, %1
ret void
}