#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*/ abort();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
double *paw_alloc_1d_array(int n) {
  double *array;
  int i;
  array = (double *)malloc(n * sizeof(double));
  if (array == 0) {
    printf("memory allocation problem in alloc_1d_array\n");
    abort();
  }
  for (i = 0; i < n; i++)
    array[i] = 0;
  return array;
}


x86 assembly (clang, -O0):
<paw_alloc_1d_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116c <paw_alloc_1d_array+0x3c>
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119d <paw_alloc_1d_array+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1173 <paw_alloc_1d_array+0x43>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paw_alloc_1d_array>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x0(,%rbx,8),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1179 <paw_alloc_1d_array+0x39>
mov    %rax,%r14
test   %ebx,%ebx
jle    116e <paw_alloc_1d_array+0x2e>
mov    %ebx,%edx
shl    $0x3,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"memory allocation problem in alloc_1d_array\0A\00"
define double* @paw_alloc_1d_array(i32 %0) {
%2 = alloca i32
%3 = alloca double*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = mul i64 %6, 8
%8 = trunc i64 %7 to i32
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to double*
store double* %10, double** %3
%11 = load double*, double** %3
%12 = icmp eq double* %11, null
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %1
store i32 0, i32* %4
br label %17
17: ; preds = %26, %16
%18 = load i32, i32* %4
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load double*, double** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
store double 0.000000e+00, double* %25
br label %26
26: ; preds = %21
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %17
29: ; preds = %17
%30 = load double*, double** %3
ret double* %30
}

LLVM IR (-O2):
@str = [44 x i8] c"memory allocation problem in alloc_1d_array\00"
define double* @paw_alloc_1d_array(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %14
8: ; preds = %6
%9 = zext i32 %0 to i64
%10 = shl nuw nsw i64 %9, 3
br label %14
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %8, %6
%15 = inttoptr i64 %3 to double*
ret double* %15
}