#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*/ dgels_(char *, int *, int *, int *, double *, int *,
                          double *, int *, double *, int *, int *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int call_dgels(char trans, int m, int n, int nrhs, double *a, int lda,
               double *b, int ldb) {
  int info = 0;
  double wkopt;
  int lwork = -1;
  double *work = NULL;
  dgels_(&trans, &m, &n, &nrhs, a, &lda, b, &ldb, &wkopt, &lwork, &info);
  if (info != 0)
    return info;
  lwork = (int)wkopt;
  work = (double *)malloc(sizeof(double) * lwork);
  if (work == NULL) {
    fputs("ERROR: memory allocation (malloc) failed in call_dgels\n", stderr);
    return -999;
  }
  dgels_(&trans, &m, &n, &nrhs, a, &lda, b, &ldb, work, &lwork, &info);
  free(work);
  return info;
}


x86 assembly (clang, -O0):
<call_dgels>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %dil,%al
mov    0x18(%rbp),%edi
mov    0x10(%rbp),%rdi
mov    %al,-0x15(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0xffffffff,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x30(%rbp),%r8
mov    0x10(%rbp),%r14
lea    -0x15(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x34(%rbp),%r9
lea    0x18(%rbp),%rbx
lea    -0x40(%rbp),%r11
lea    -0x44(%rbp),%r10
lea    -0x38(%rbp),%rax
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1040 <dgels_@plt>
cmpl   $0x0,-0x38(%rbp)
je     11dd <call_dgels+0x9d>
mov    -0x38(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    127c <call_dgels+0x13c>
cvttsd2si -0x40(%rbp),%eax
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1224 <call_dgels+0xe4>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xded(%rip),%rdi
call   1050 <fputs@plt>
movl   $0xfffffc19,-0x14(%rbp)
jmp    127c <call_dgels+0x13c>
mov    -0x30(%rbp),%r8
mov    0x10(%rbp),%r14
mov    -0x50(%rbp),%r11
lea    -0x15(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x34(%rbp),%r9
lea    0x18(%rbp),%rbx
lea    -0x44(%rbp),%r10
lea    -0x38(%rbp),%rax
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1040 <dgels_@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_dgels>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%rbx
mov    0x60(%rsp),%r15
mov    %dil,0x7(%rsp)
mov    %esi,0x1c(%rsp)
mov    %edx,0x18(%rsp)
mov    %ecx,0x14(%rsp)
mov    %r9d,0x10(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
sub    $0x8,%rsp
lea    0x10(%rsp),%rbp
lea    0x14(%rsp),%r13
lea    0x28(%rsp),%rax
lea    0x70(%rsp),%r12
lea    0xf(%rsp),%rdi
lea    0x24(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x18(%rsp),%r9
push   %rbp
push   %r13
push   %rax
push   %r12
push   %r15
call   1040 <dgels_@plt>
add    $0x30,%rsp
mov    0x8(%rsp),%eax
test   %eax,%eax
jne    1239 <call_dgels+0xf9>
cvttsd2si 0x20(%rsp),%edi
mov    %edi,0xc(%rsp)
shl    $0x3,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     121f <call_dgels+0xdf>
mov    %rax,%r14
sub    $0x8,%rsp
lea    0xf(%rsp),%rdi
lea    0x24(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x18(%rsp),%r9
mov    %rbx,%r8
push   %rbp
push   %r13
push   %rax
push   %r12
push   %r15
call   1040 <dgels_@plt>
add    $0x30,%rsp
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%eax
jmp    1239 <call_dgels+0xf9>
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
lea    0xdd1(%rip),%rdi
call   1050 <fputs@plt>
mov    $0xfffffc19,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"ERROR: memory allocation (malloc) failed in call_dgels\0A\00"
@stderr = global i32 0
define i32 @call_dgels(i8 signext %0, i32 %1, i32 %2, i32 %3, double* %4, i32 %5, double* %6, i32 %7) {
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double*
%15 = alloca i32
%16 = alloca double*
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
%20 = alloca i32
%21 = alloca double*
store i8 %0, i8* %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store double* %4, double** %14
store i32 %5, i32* %15
store double* %6, double** %16
store i32 %7, i32* %17
store i32 0, i32* %18
store i32 -1, i32* %20
store double* null, double** %21
%22 = load double*, double** %14
%23 = load double*, double** %16
%24 = call i32 @dgels_(i8* %10, i32* %11, i32* %12, i32* %13, double* %22, i32* %15, double* %23, i32* %17, double* %19, i32* %20, i32* %18)
%25 = load i32, i32* %18
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %8
%28 = load i32, i32* %18
store i32 %28, i32* %9
br label %51
29: ; preds = %8
%30 = load double, double* %19
%31 = fptosi double %30 to i32
store i32 %31, i32* %20
%32 = load i32, i32* %20
%33 = sext i32 %32 to i64
%34 = mul i64 8, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to double*
store double* %37, double** %21
%38 = load double*, double** %21
%39 = icmp eq double* %38, null
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = load i32, i32* @stderr
%42 = call i32 @fputs(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %41)
store i32 -999, i32* %9
br label %51
43: ; preds = %29
%44 = load double*, double** %14
%45 = load double*, double** %16
%46 = load double*, double** %21
%47 = call i32 @dgels_(i8* %10, i32* %11, i32* %12, i32* %13, double* %44, i32* %15, double* %45, i32* %17, double* %46, i32* %20, i32* %18)
%48 = load double*, double** %21
%49 = call i32 @free(double* %48)
%50 = load i32, i32* %18
store i32 %50, i32* %9
br label %51
51: ; preds = %43, %40, %27
%52 = load i32, i32* %9
ret i32 %52
}

LLVM IR (-O2):
@.str = [56 x i8] c"ERROR: memory allocation (malloc) failed in call_dgels\0A\00"
@stderr = global i32 0
define i32 @call_dgels(i8 signext %0, i32 %1, i32 %2, i32 %3, double* %4, i32 %5, double* %6, i32 %7) {
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca i32
store i8 %0, i8* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %5, i32* %13
store i32 %7, i32* %14
%18 = bitcast i32* %15 to i8*
store i32 0, i32* %15
%19 = bitcast double* %16 to i8*
%20 = bitcast i32* %17 to i8*
store i32 -1, i32* %17
%21 = call i32 @dgels_(i8* %9, i32* %10, i32* %11, i32* %12, double* %4, i32* %13, double* %6, i32* %14, double* %16, i32* %17, i32* %15)
%22 = load i32, i32* %15
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %8
%25 = load double, double* %16
%26 = fptosi double %25 to i32
store i32 %26, i32* %17
%27 = shl i32 %26, 3
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to double*
%30 = icmp eq i64 %28, 0
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = call i32 @fputs(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %38
34: ; preds = %24
%35 = call i32 @dgels_(i8* %9, i32* %10, i32* %11, i32* %12, double* %4, i32* %13, double* %6, i32* %14, double* %29, i32* %17, i32* %15)
%36 = call i32 @free(double* %29)
%37 = load i32, i32* %15
br label %38
38: ; preds = %8, %34, %31
%39 = phi i32 [ -999, %31 ], [ %37, %34 ], [ %22, %8 ]
ret i32 %39
}