#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*/ dgelsy_(int *, int *, int *, double *, int *, double *,
                           int *, 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_dgelsy(int m, int n, int nrhs, double *a, int lda, double *b, int ldb,
                int *jpvt, double rcond, int *rank) {
  int info = 0;
  double wkopt;
  int lwork = -1;
  double *work = NULL;
  dgelsy_(&m, &n, &nrhs, a, &lda, b, &ldb, jpvt, &rcond, rank, &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_dgelsy\n", stderr);
    return -999;
  }
  dgelsy_(&m, &n, &nrhs, a, &lda, b, &ldb, jpvt, &rcond, rank, work, &lwork,
          &info);
  free(work);
  return info;
}


x86 assembly (clang, -O0):
<call_dgelsy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
mov    %edx,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r8d,-0x3c(%rbp)
mov    %r9,-0x48(%rbp)
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0xffffffff,-0x64(%rbp)
movq   $0x0,-0x70(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x48(%rbp),%r9
mov    0x18(%rbp),%r15
mov    0x20(%rbp),%rbx
lea    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x3c(%rbp),%r8
lea    0x10(%rbp),%r12
lea    -0x50(%rbp),%r14
lea    -0x60(%rbp),%r11
lea    -0x64(%rbp),%r10
lea    -0x54(%rbp),%rax
mov    %r12,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1040 <dgelsy_@plt>
cmpl   $0x0,-0x54(%rbp)
je     11fd <call_dgelsy+0xbd>
mov    -0x54(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    12ae <call_dgelsy+0x16e>
cvttsd2si -0x60(%rbp),%eax
mov    %eax,-0x64(%rbp)
movslq -0x64(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    1244 <call_dgelsy+0x104>
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
lea    0xdcd(%rip),%rdi
call   1050 <fputs@plt>
movl   $0xfffffc19,-0x24(%rbp)
jmp    12ae <call_dgelsy+0x16e>
mov    -0x38(%rbp),%rcx
mov    -0x48(%rbp),%r9
mov    0x18(%rbp),%r15
mov    0x20(%rbp),%rbx
mov    -0x70(%rbp),%r11
lea    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x3c(%rbp),%r8
lea    0x10(%rbp),%r12
lea    -0x50(%rbp),%r14
lea    -0x64(%rbp),%r10
lea    -0x54(%rbp),%rax
mov    %r12,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1040 <dgelsy_@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_dgelsy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r14
mov    %rcx,%rbx
mov    0x68(%rsp),%rbp
mov    %edi,0x14(%rsp)
mov    %esi,0x10(%rsp)
mov    %edx,0xc(%rsp)
mov    %r8d,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
movl   $0x0,(%rsp)
movl   $0xffffffff,0x4(%rsp)
ff
sub    $0x8,%rsp
lea    0x8(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0x28(%rsp),%rax
lea    0x20(%rsp),%r11
lea    0x68(%rsp),%r10
lea    0x1c(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%r8
push   %r12
push   %r13
push   %rax
push   0x90(%rsp)
push   %r11
push   %rbp
push   %r10
call   1040 <dgelsy_@plt>
add    $0x40,%rsp
mov    (%rsp),%eax
test   %eax,%eax
jne    1259 <call_dgelsy+0x119>
cvttsd2si 0x20(%rsp),%edi
mov    %edi,0x4(%rsp)
shl    $0x3,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     123f <call_dgelsy+0xff>
mov    %rax,%r15
sub    $0x8,%rsp
lea    0x1c(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%r8
mov    %rbx,%rcx
mov    %r14,%r9
push   %r12
push   %r13
push   %rax
push   0x90(%rsp)
lea    0x40(%rsp),%rax
push   %rax
push   %rbp
lea    0x98(%rsp),%rax
push   %rax
call   1040 <dgelsy_@plt>
add    $0x40,%rsp
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%rsp),%eax
jmp    1259 <call_dgelsy+0x119>
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
lea    0xdb1(%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 = [57 x i8] c"ERROR: memory allocation (malloc) failed in call_dgelsy\0A\00"
@stderr = global i32 0
define i32 @call_dgelsy(i32 %0, i32 %1, i32 %2, double* %3, i32 %4, double* %5, i32 %6, i32* %7, double %8, i32* %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double*
%16 = alloca i32
%17 = alloca double*
%18 = alloca i32
%19 = alloca i32*
%20 = alloca double
%21 = alloca i32*
%22 = alloca i32
%23 = alloca double
%24 = alloca i32
%25 = alloca double*
store i32 %0, i32* %12
store i32 %1, i32* %13
store i32 %2, i32* %14
store double* %3, double** %15
store i32 %4, i32* %16
store double* %5, double** %17
store i32 %6, i32* %18
store i32* %7, i32** %19
store double %8, double* %20
store i32* %9, i32** %21
store i32 0, i32* %22
store i32 -1, i32* %24
store double* null, double** %25
%26 = load double*, double** %15
%27 = load double*, double** %17
%28 = load i32*, i32** %19
%29 = load i32*, i32** %21
%30 = call i32 @dgelsy_(i32* %12, i32* %13, i32* %14, double* %26, i32* %16, double* %27, i32* %18, i32* %28, double* %20, i32* %29, double* %23, i32* %24, i32* %22)
%31 = load i32, i32* %22
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %10
%34 = load i32, i32* %22
store i32 %34, i32* %11
br label %59
35: ; preds = %10
%36 = load double, double* %23
%37 = fptosi double %36 to i32
store i32 %37, i32* %24
%38 = load i32, i32* %24
%39 = sext i32 %38 to i64
%40 = mul i64 8, %39
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to double*
store double* %43, double** %25
%44 = load double*, double** %25
%45 = icmp eq double* %44, null
br i1 %45, label %46, label %49
46: ; preds = %35
%47 = load i32, i32* @stderr
%48 = call i32 @fputs(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %47)
store i32 -999, i32* %11
br label %59
49: ; preds = %35
%50 = load double*, double** %15
%51 = load double*, double** %17
%52 = load i32*, i32** %19
%53 = load i32*, i32** %21
%54 = load double*, double** %25
%55 = call i32 @dgelsy_(i32* %12, i32* %13, i32* %14, double* %50, i32* %16, double* %51, i32* %18, i32* %52, double* %20, i32* %53, double* %54, i32* %24, i32* %22)
%56 = load double*, double** %25
%57 = call i32 @free(double* %56)
%58 = load i32, i32* %22
store i32 %58, i32* %11
br label %59
59: ; preds = %49, %46, %33
%60 = load i32, i32* %11
ret i32 %60
}

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