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


x86 assembly (clang, -O0):
<rspriw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    0x2ef1(%rip),%rax
jg     1169 <rspriw+0x29>
movl   $0x1,-0x4(%rbp)
jmp    1222 <rspriw+0xe2>
mov    0x2e70(%rip),%rax
cmpq   $0x0,(%rax)
je     1189 <rspriw+0x49>
mov    0x2e5f(%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    0x2e3e(%rip),%rax
mov    %rcx,(%rax)
mov    0x2e34(%rip),%rax
cmpq   $0x0,(%rax)
je     11cd <rspriw+0x8d>
mov    -0x10(%rbp),%rax
mov    %rax,0x2e87(%rip)
movl   $0x1,-0x4(%rbp)
jmp    1222 <rspriw+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    0xe41(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xe50(%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):
<rspriw>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%eax
cmp    %rdi,0x2ef8(%rip)
jge    11c7 <rspriw+0x87>
mov    %rdi,%rbx
mov    0x2e84(%rip),%r14
mov    (%r14),%rdi
test   %rdi,%rdi
je     1169 <rspriw+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 <rspriw+0x80>
mov    0x2e4c(%rip),%r14
mov    (%r14),%esi
lea    0xe6a(%rip),%rdi
call   1040 <fputs@plt>
mov    (%r14),%edi
lea    0xe92(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    (%r14),%esi
lea    0xea4(%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):
@rspriw.siwork = internal global i64 0
@iwork = external global i64*
@.str = [55 x i8] c" Unable to allocate randlib (long) int 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 RSPRIW - ABORT\0A\00"
define i32 @rspriw(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = load i64, i64* @rspriw.siwork
%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 i64*, i64** @iwork
%10 = icmp ne i64* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i64*, i64** @iwork
%13 = call i32 @free(i64* %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 i64*
store i64* %19, i64** @iwork
%20 = load i64*, i64** @iwork
%21 = icmp ne i64* %20, null
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = load i64, i64* %3
store i64 %23, i64* @rspriw.siwork
store i32 1, i32* %2
br label %32
24: ; preds = %14
%25 = load i32, i32* @stderr
%26 = call i32 @fputs(i8* getelementptr inbounds ([55 x i8], [55 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* @rspriw.siwork
store i32 0, i32* %2
br label %32
32: ; preds = %24, %22, %7
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@rspriw.siwork = internal unnamed_addr global i64 0
@iwork = external global i64*
@.str = [55 x i8] c" Unable to allocate randlib (long) int 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 RSPRIW - ABORT\0A\00"
define i32 @rspriw(i64 %0) {
%2 = load i64, i64* @rspriw.siwork
%3 = icmp slt i64 %2, %0
br i1 %3, label %4, label %25
4: ; preds = %1
%5 = load i64*, i64** @iwork
%6 = icmp eq i64* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @free(i64* %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 i64*
store i64* %13, i64** @iwork
%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 ([55 x i8], [55 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* @rspriw.siwork
br label %25
25: ; preds = %22, %1
%26 = phi i32 [ 1, %1 ], [ %24, %22 ]
ret i32 %26
}