#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double *malloc(int);
int const max(int, int);
int /*<<< orphan*/ stderr;
int dgels(char TRANS, int M, int N, int NRHS, double *A, int LDA, double *B,
          int LDB) {
  const int NB = 1024;
  int LWORK;
  LWORK = M * N + max(M * N, NRHS) * NB;
  double *WORK;
  WORK = malloc(LWORK * sizeof(double));
  if (WORK == NULL) {
    fprintf(stderr, "Error -- out of memory\n");
    exit(1);
  }
  int INFO;
  dgels_(&TRANS, &M, &N, &NRHS, A, &LDA, B, &LDB, WORK, &LWORK, &INFO);
  return INFO;
}


x86 assembly (clang, -O0):
<dgels>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %dil,%al
mov    0x18(%rbp),%edi
mov    0x10(%rbp),%rdi
mov    %al,-0x11(%rbp)
mov    %esi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x400,-0x30(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%edi
imul   -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <max@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
shl    $0xa,%ecx
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11e3 <dgels+0x93>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%r8
mov    0x10(%rbp),%r14
mov    -0x40(%rbp),%r11
lea    -0x11(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x2c(%rbp),%r9
lea    0x18(%rbp),%rbx
lea    -0x34(%rbp),%r10
lea    -0x44(%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    -0x44(%rbp),%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<dgels>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %r8,%rbx
mov    %edx,%ebp
mov    %dil,0xf(%rsp)
mov    %esi,0x24(%rsp)
mov    %edx,0x20(%rsp)
mov    %ecx,0x1c(%rsp)
mov    %r9d,0x18(%rsp)
imul   %esi,%ebp
mov    %ebp,%edi
mov    %ecx,%esi
call   1030 <max@plt>
shl    $0xa,%eax
add    %eax,%ebp
mov    %ebp,0x14(%rsp)
shl    $0x3,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11e2 <dgels+0x92>
sub    $0x8,%rsp
lea    0x18(%rsp),%rbp
lea    0x1c(%rsp),%r10
lea    0x50(%rsp),%r11
lea    0x17(%rsp),%rdi
lea    0x2c(%rsp),%rsi
lea    0x28(%rsp),%rdx
lea    0x24(%rsp),%rcx
lea    0x20(%rsp),%r9
mov    %rbx,%r8
push   %rbp
push   %r10
push   %rax
push   %r11
push   0x68(%rsp)
call   1040 <dgels_@plt>
add    $0x30,%rsp
mov    0x10(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Error -- out of memory\0A\00"
define i32 @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 double*
%14 = alloca i32
%15 = alloca double*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca double*
%20 = alloca i32
store i8 %0, i8* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store double* %4, double** %13
store i32 %5, i32* %14
store double* %6, double** %15
store i32 %7, i32* %16
store i32 1024, i32* %17
%21 = load i32, i32* %10
%22 = load i32, i32* %11
%23 = mul nsw i32 %21, %22
%24 = load i32, i32* %10
%25 = load i32, i32* %11
%26 = mul nsw i32 %24, %25
%27 = load i32, i32* %12
%28 = call i32 @max(i32 %26, i32 %27)
%29 = mul nsw i32 %28, 1024
%30 = add nsw i32 %23, %29
store i32 %30, i32* %18
%31 = load i32, i32* %18
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 8
%34 = trunc i64 %33 to i32
%35 = call double* @malloc(i32 %34)
store double* %35, double** %19
%36 = load double*, double** %19
%37 = icmp eq double* %36, null
br i1 %37, label %38, label %42
38: ; preds = %8
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %8
%43 = load double*, double** %13
%44 = load double*, double** %15
%45 = load double*, double** %19
%46 = call i32 @dgels_(i8* %9, i32* %10, i32* %11, i32* %12, double* %43, i32* %14, double* %44, i32* %16, double* %45, i32* %18, i32* %20)
%47 = load i32, i32* %20
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Error -- out of memory\0A\00"
define i32 @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 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
%17 = bitcast i32* %15 to i8*
%18 = mul nsw i32 %2, %1
%19 = tail call i32 @max(i32 %18, i32 %3)
%20 = shl nsw i32 %19, 10
%21 = add nsw i32 %20, %18
store i32 %21, i32* %15
%22 = shl i32 %21, 3
%23 = tail call double* @malloc(i32 %22)
%24 = icmp eq double* %23, null
br i1 %24, label %25, label %29
25: ; preds = %8
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %8
%30 = bitcast i32* %16 to i8*
%31 = call i32 @dgels_(i8* %9, i32* %10, i32* %11, i32* %12, double* %4, i32* %13, double* %6, i32* %14, double* %23, i32* %15, i32* %16)
%32 = load i32, i32* %16
ret i32 %32
}