#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*/ dgeqrf_(int *, int *, double *, int *, double *, double *,
                           int *, int *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int call_dgeqrf(int m, int n, double *a, int lda, double *tau) {
  int info = 0;
  double wkopt;
  int lwork = -1;
  double *work = NULL;
  dgeqrf_(&m, &n, a, &lda, tau, &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_dgeqrf\n", stderr);
    return -999;
  }
  dgeqrf_(&m, &n, a, &lda, tau, work, &lwork, &info);
  free(work);
  return info;
}


x86 assembly (clang, -O0):
<call_dgeqrf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%r8
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
lea    -0x38(%rbp),%r9
lea    -0x3c(%rbp),%r10
lea    -0x2c(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <dgeqrf_@plt>
cmpl   $0x0,-0x2c(%rbp)
je     11b2 <call_dgeqrf+0x72>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1236 <call_dgeqrf+0xf6>
cvttsd2si -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11f9 <call_dgeqrf+0xb9>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    0xe18(%rip),%rdi
call   1050 <fputs@plt>
movl   $0xfffffc19,-0x4(%rbp)
jmp    1236 <call_dgeqrf+0xf6>
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%r8
mov    -0x48(%rbp),%r9
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
lea    -0x3c(%rbp),%r10
lea    -0x2c(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <dgeqrf_@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_dgeqrf>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r8,%r14
mov    %rdx,%rbx
mov    %edi,0x14(%rsp)
mov    %esi,0x10(%rsp)
mov    %ecx,0xc(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
lea    0x4(%rsp),%r13
lea    0x8(%rsp),%r12
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rcx
lea    0x18(%rsp),%r9
push   %r13
push   %r12
call   1040 <dgeqrf_@plt>
add    $0x10,%rsp
mov    0x4(%rsp),%eax
test   %eax,%eax
jne    1209 <call_dgeqrf+0xc9>
cvttsd2si 0x18(%rsp),%edi
mov    %edi,0x8(%rsp)
shl    $0x3,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ef <call_dgeqrf+0xaf>
mov    %rax,%r15
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rcx
mov    %rbx,%rdx
mov    %r14,%r8
mov    %rax,%r9
push   %r13
push   %r12
call   1040 <dgeqrf_@plt>
add    $0x10,%rsp
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%eax
jmp    1209 <call_dgeqrf+0xc9>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
lea    0xe01(%rip),%rdi
call   1050 <fputs@plt>
mov    $0xfffffc19,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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