#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*/ fprintf(int /*<<< orphan*/, char *, long);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int rsprfw(long size) {
  extern double *fwork;
  static long sfwork = 0L;
  if (size <= sfwork)
    return 1;
  if (fwork != NULL)
    free(fwork);
  fwork = (double *)malloc(sizeof(double) * size);
  if (fwork != NULL) {
    sfwork = size;
    return 1;
  }
  fputs(" Unable to allocate randlib float working array:\n", stderr);
  fprintf(stderr, " Requested number of entries = %ld\n", size);
  fputs(" Out of memory in RSPRFW - ABORT\n", stderr);
  sfwork = 0L;
  return 0;
}


x86 assembly (clang, -O0):
<rsprfw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    0x2ef1(%rip),%rax
jg     1169 <rsprfw+0x29>
movl   $0x1,-0x4(%rbp)
jmp    1222 <rsprfw+0xe2>
mov    0x2e80(%rip),%rax
cmpq   $0x0,(%rax)
je     1189 <rsprfw+0x49>
mov    0x2e6f(%rip),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    0x2e4e(%rip),%rax
mov    %rcx,(%rax)
mov    0x2e44(%rip),%rax
cmpq   $0x0,(%rax)
je     11cd <rsprfw+0x8d>
mov    -0x10(%rbp),%rax
mov    %rax,0x2e87(%rip)
movl   $0x1,-0x4(%rbp)
jmp    1222 <rsprfw+0xe2>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
lea    0xe23(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xe4b(%rip),%rdi
call   1040 <fputs@plt>
movq   $0x0,0x2e2d(%rip)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsprfw>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%eax
cmp    %rdi,0x2ef8(%rip)
jge    11c7 <rsprfw+0x87>
mov    %rdi,%rbx
mov    0x2e94(%rip),%r14
mov    (%r14),%rdi
test   %rdi,%rdi
je     1169 <rsprfw+0x29>
call   1030 <free@plt>
lea    0x0(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    %rax,(%r14)
mov    $0x1,%eax
test   %rcx,%rcx
jne    11c0 <rsprfw+0x80>
mov    0x2e4c(%rip),%r14
mov    (%r14),%esi
lea    0xe6a(%rip),%rdi
call   1040 <fputs@plt>
mov    (%r14),%edi
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    (%r14),%esi
lea    0xe9f(%rip),%rdi
call   1040 <fputs@plt>
xor    %ebx,%ebx
xor    %eax,%eax
mov    %rbx,0x2e81(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@rsprfw.sfwork = internal global i64 0
@fwork = external global double*
@.str = [50 x i8] c" Unable to allocate randlib float working array:\0A\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c" Requested number of entries = %ld\0A\00"
@.str.2 = [34 x i8] c" Out of memory in RSPRFW - ABORT\0A\00"
define i32 @rsprfw(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = load i64, i64* @rsprfw.sfwork
%6 = icmp sle i64 %4, %5
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %32
8: ; preds = %1
%9 = load double*, double** @fwork
%10 = icmp ne double* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load double*, double** @fwork
%13 = call i32 @free(double* %12)
br label %14
14: ; preds = %11, %8
%15 = load i64, i64* %3
%16 = mul i64 8, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** @fwork
%20 = load double*, double** @fwork
%21 = icmp ne double* %20, null
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = load i64, i64* %3
store i64 %23, i64* @rsprfw.sfwork
store i32 1, i32* %2
br label %32
24: ; preds = %14
%25 = load i32, i32* @stderr
%26 = call i32 @fputs(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @stderr
%28 = load i64, i64* %3
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %28)
%30 = load i32, i32* @stderr
%31 = call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %30)
store i64 0, i64* @rsprfw.sfwork
store i32 0, i32* %2
br label %32
32: ; preds = %24, %22, %7
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@rsprfw.sfwork = internal unnamed_addr global i64 0
@fwork = external global double*
@.str = [50 x i8] c" Unable to allocate randlib float working array:\0A\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c" Requested number of entries = %ld\0A\00"
@.str.2 = [34 x i8] c" Out of memory in RSPRFW - ABORT\0A\00"
define i32 @rsprfw(i64 %0) {
%2 = load i64, i64* @rsprfw.sfwork
%3 = icmp slt i64 %2, %0
br i1 %3, label %4, label %25
4: ; preds = %1
%5 = load double*, double** @fwork
%6 = icmp eq double* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @free(double* %5)
br label %9
9: ; preds = %7, %4
%10 = trunc i64 %0 to i32
%11 = shl i32 %10, 3
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double*
store double* %13, double** @fwork
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %22
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = tail call i32 @fputs(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %0)
%20 = load i32, i32* @stderr
%21 = tail call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %9, %15
%23 = phi i64 [ 0, %15 ], [ %0, %9 ]
%24 = phi i32 [ 0, %15 ], [ 1, %9 ]
store i64 %23, i64* @rsprfw.sfwork
br label %25
25: ; preds = %22, %1
%26 = phi i32 [ 1, %1 ], [ %24, %22 ]
ret i32 %26
}