#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__ malloc(size_t);
int /*<<< orphan*/ nrerror(char *);
float *vector(long nl, long nh) {
  float *v;
  v = (float *)malloc((size_t)((nh - nl + 1 + 0) * sizeof(float)));
  if (!v)
    nrerror("allocation failure in vector()");
  if (!v)
    return NULL;
  return v - nl + 0;
}


x86 assembly (clang, -O0):
<vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
sub    -0x10(%rbp),%rdi
add    $0x1,%rdi
add    $0x0,%rdi
shl    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1164 <vector+0x44>
lea    0xea1(%rip),%rdi
call   1030 <nrerror@plt>
cmpq   $0x0,-0x20(%rbp)
jne    117c <vector+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    1191 <vector+0x71>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
sub    -0x10(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector>:
push   %rbx
mov    %rdi,%rbx
sub    %rdi,%rsi
lea    0x4(,%rsi,4),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1142 <vector+0x22>
shl    $0x2,%rbx
sub    %rbx,%rax
pop    %rbx
ret
lea    0xeb7(%rip),%rdi
call   1030 <nrerror@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"allocation failure in vector()\00"
define float* @vector(i64 %0, i64 %1) {
%3 = alloca float*
%4 = alloca i64
%5 = alloca i64
%6 = alloca float*
store i64 %0, i64* %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = load i64, i64* %4
%9 = sub nsw i64 %7, %8
%10 = add nsw i64 %9, 1
%11 = add nsw i64 %10, 0
%12 = mul i64 %11, 4
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to float*
store float* %14, float** %6
%15 = load float*, float** %6
%16 = icmp ne float* %15, null
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = call i32 @nrerror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = load float*, float** %6
%21 = icmp ne float* %20, null
br i1 %21, label %23, label %22
22: ; preds = %19
store float* null, float** %3
br label %29
23: ; preds = %19
%24 = load float*, float** %6
%25 = load i64, i64* %4
%26 = sub i64 0, %25
%27 = getelementptr inbounds float, float* %24, i64 %26
%28 = getelementptr inbounds float, float* %27, i64 0
store float* %28, float** %3
br label %29
29: ; preds = %23, %22
%30 = load float*, float** %3
ret float* %30
}

LLVM IR (-O2):
@.str = [31 x i8] c"allocation failure in vector()\00"
define float* @vector(i64 %0, i64 %1) {
%3 = sub nsw i64 %1, %0
%4 = shl i64 %3, 2
%5 = add i64 %4, 4
%6 = tail call i64 @malloc(i64 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @nrerror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %14
10: ; preds = %2
%11 = inttoptr i64 %6 to float*
%12 = sub i64 0, %0
%13 = getelementptr inbounds float, float* %11, i64 %12
br label %14
14: ; preds = %8, %10
%15 = phi float* [ %13, %10 ], [ null, %8 ]
ret float* %15
}