#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, long);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ setgmn(double *, double *, long, double *);
int /*<<< orphan*/ stderr;
int psetmn(long p) {
  extern double *fwork, *parm;
  static long oldp = 0L;
  if (p > oldp) {
    if (parm != NULL)
      free(parm);
    parm = (double *)malloc(sizeof(double) * (p * (p + 3L) / 2L + 1L));
    if (parm == NULL) {
      fputs("Out of memory in PSETMN - ABORT", stderr);
      fprintf(stderr, "P = %ld; Requested # of doubles %ld\n", p,
              p * (p + 3L) / 2L + 1L);
      oldp = 0L;
      return 0;
    } else {
      oldp = p;
    }
  }
  setgmn(fwork, fwork + p, p, parm);
  return 1;
}


x86 assembly (clang, -O0):
<psetmn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    0x2ee9(%rip),%rax
jle    1252 <psetmn+0x102>
mov    0x2e5c(%rip),%rax
cmpq   $0x0,(%rax)
je     118d <psetmn+0x3d>
mov    0x2e4b(%rip),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x3,%rcx
imul   %rcx,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
add    $0x1,%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    0x2e10(%rip),%rax
mov    %rcx,(%rax)
mov    0x2e06(%rip),%rax
cmpq   $0x0,(%rax)
jne    1242 <psetmn+0xf2>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    0xe1c(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x3,%rcx
imul   %rcx,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
add    $0x1,%rcx
lea    0xdfa(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,0x2e1a(%rip)
movl   $0x0,-0x4(%rbp)
jmp    128b <psetmn+0x13b>
mov    -0x10(%rbp),%rax
mov    %rax,0x2e03(%rip)
jmp    1252 <psetmn+0x102>
mov    0x2d97(%rip),%rax
mov    (%rax),%rdi
mov    0x2d8d(%rip),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rdx
mov    0x2d54(%rip),%rax
mov    (%rax),%rcx
call   1040 <setgmn@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psetmn>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e71(%rip),%r15
mov    (%r15),%rcx
cmp    %rdi,0x2ee7(%rip)
jge    11af <psetmn+0x5f>
test   %rcx,%rcx
je     1178 <psetmn+0x28>
mov    %rcx,%rdi
call   1030 <free@plt>
lea    0x3(%r14),%rax
imul   %r14,%rax
mov    %rax,%rbx
shr    $0x3f,%rbx
add    %rax,%rbx
sar    %rbx
add    $0x1,%rbx
lea    0x0(,%rbx,8),%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11cc <psetmn+0x7c>
mov    %rax,%rcx
mov    %r14,0x2ea1(%rip)
mov    0x2e3a(%rip),%rax
mov    (%rax),%rdi
lea    (%rdi,%r14,8),%rsi
mov    %r14,%rdx
call   1040 <setgmn@plt>
mov    $0x1,%eax
jmp    1204 <psetmn+0xb4>
mov    0x2e05(%rip),%r15
mov    (%r15),%esi
lea    0xe23(%rip),%rdi
call   1050 <fputs@plt>
mov    (%r15),%edi
lea    0xe34(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <fprintf@plt>
movq   $0x0,0x2e4e(%rip)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@psetmn.oldp = internal global i64 0
@parm = external global double*
@.str = [32 x i8] c"Out of memory in PSETMN - ABORT\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"P = %ld; Requested # of doubles %ld\0A\00"
@fwork = external global double*
define i32 @psetmn(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = load i64, i64* @psetmn.oldp
%6 = icmp sgt i64 %4, %5
br i1 %6, label %7, label %41
7: ; preds = %1
%8 = load double*, double** @parm
%9 = icmp ne double* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load double*, double** @parm
%12 = call i32 @free(double* %11)
br label %13
13: ; preds = %10, %7
%14 = load i64, i64* %3
%15 = load i64, i64* %3
%16 = add nsw i64 %15, 3
%17 = mul nsw i64 %14, %16
%18 = sdiv i64 %17, 2
%19 = add nsw i64 %18, 1
%20 = mul i64 8, %19
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to double*
store double* %23, double** @parm
%24 = load double*, double** @parm
%25 = icmp eq double* %24, null
br i1 %25, label %26, label %38
26: ; preds = %13
%27 = load i32, i32* @stderr
%28 = call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @stderr
%30 = load i64, i64* %3
%31 = load i64, i64* %3
%32 = load i64, i64* %3
%33 = add nsw i64 %32, 3
%34 = mul nsw i64 %31, %33
%35 = sdiv i64 %34, 2
%36 = add nsw i64 %35, 1
%37 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 %30, i64 %36)
store i64 0, i64* @psetmn.oldp
store i32 0, i32* %2
br label %49
38: ; preds = %13
%39 = load i64, i64* %3
store i64 %39, i64* @psetmn.oldp
br label %40
40: ; preds = %38
br label %41
41: ; preds = %40, %1
%42 = load double*, double** @fwork
%43 = load double*, double** @fwork
%44 = load i64, i64* %3
%45 = getelementptr inbounds double, double* %43, i64 %44
%46 = load i64, i64* %3
%47 = load double*, double** @parm
%48 = call i32 @setgmn(double* %42, double* %45, i64 %46, double* %47)
store i32 1, i32* %2
br label %49
49: ; preds = %41, %26
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@psetmn.oldp = internal unnamed_addr global i64 0
@parm = external global double*
@.str = [32 x i8] c"Out of memory in PSETMN - ABORT\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"P = %ld; Requested # of doubles %ld\0A\00"
@fwork = external global double*
define i32 @psetmn(i64 %0) {
%2 = load i64, i64* @psetmn.oldp
%3 = icmp slt i64 %2, %0
%4 = load double*, double** @parm
br i1 %3, label %5, label %25
5: ; preds = %1
%6 = icmp eq double* %4, null
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 @free(double* %4)
br label %9
9: ; preds = %7, %5
%10 = add nsw i64 %0, 3
%11 = mul nsw i64 %10, %0
%12 = sdiv i64 %11, 2
%13 = add nsw i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = shl i32 %14, 3
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to double*
store double* %17, double** @parm
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %24
19: ; preds = %9
%20 = load i32, i32* @stderr
%21 = tail call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 %0, i64 %13)
store i64 0, i64* @psetmn.oldp
br label %30
24: ; preds = %9
store i64 %0, i64* @psetmn.oldp
br label %25
25: ; preds = %1, %24
%26 = phi double* [ %17, %24 ], [ %4, %1 ]
%27 = load double*, double** @fwork
%28 = getelementptr inbounds double, double* %27, i64 %0
%29 = tail call i32 @setgmn(double* %27, double* %28, i64 %0, double* %26)
br label %30
30: ; preds = %25, %19
%31 = phi i32 [ 0, %19 ], [ 1, %25 ]
ret i32 %31
}