#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
float *allocate_1d_float(int N, char zero) {
  float *arr;
  if (!zero)
    arr = (float *)malloc(N * sizeof(float));
  else
    arr = (float *)calloc(N, sizeof(float));
  if ((arr) == NULL) {
    printf("%10s: NULL pointer\n", (char *)("allocate_1d_float"));
    perror((char *)("allocate_1d_float"));
    exit(1);
  };
  return (arr);
}


x86 assembly (clang, -O0):
<allocate_1d_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
cmpb   $0x0,-0x5(%rbp)
jne    1183 <allocate_1d_float+0x33>
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
jmp    1194 <allocate_1d_float+0x44>
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c8 <allocate_1d_float+0x78>
lea    0xe5a(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1030 <printf@plt>
lea    0xe5b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_1d_float>:
push   %rbx
test   %sil,%sil
je     1167 <allocate_1d_float+0x17>
mov    $0x4,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1174 <allocate_1d_float+0x24>
pop    %rbx
ret
shl    $0x2,%edi
call   1050 <malloc@plt>
test   %rax,%rax
jne    1165 <allocate_1d_float+0x15>
lea    0xe85(%rip),%rdi
lea    0xe92(%rip),%rbx
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"%10s: NULL pointer\0A\00"
@.str.1 = [18 x i8] c"allocate_1d_float\00"
define float* @allocate_1d_float(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca float*
store i32 %0, i32* %3
store i8 %1, i8* %4
%6 = load i8, i8* %4
%7 = icmp ne i8 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to float*
store float* %14, float** %5
br label %19
15: ; preds = %2
%16 = load i32, i32* %3
%17 = call i64 @calloc(i32 %16, i32 4)
%18 = inttoptr i64 %17 to float*
store float* %18, float** %5
br label %19
19: ; preds = %15, %8
%20 = load float*, float** %5
%21 = icmp eq float* %20, null
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = load float*, float** %5
ret float* %27
}

LLVM IR (-O2):
@.str = [20 x i8] c"%10s: NULL pointer\0A\00"
@.str.1 = [18 x i8] c"allocate_1d_float\00"
define float* @allocate_1d_float(i32 %0, i8 signext %1) {
%3 = icmp eq i8 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = shl i32 %0, 2
%6 = tail call i64 @malloc(i32 %5)
br label %9
7: ; preds = %2
%8 = tail call i64 @calloc(i32 %0, i32 4)
br label %9
9: ; preds = %7, %4
%10 = phi i64 [ %8, %7 ], [ %6, %4 ]
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = inttoptr i64 %10 to float*
ret float* %17
}