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


x86 assembly (clang, -O0):
<call_dorgqr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r9
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x1c(%rbp),%r8
lea    -0x38(%rbp),%r11
lea    -0x3c(%rbp),%r10
lea    -0x2c(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <dorgqr_@plt>
cmpl   $0x0,-0x2c(%rbp)
je     11bf <call_dorgqr+0x7f>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <call_dorgqr+0x10c>
cvttsd2si -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1206 <call_dorgqr+0xc6>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    0xe0b(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xfffffc19,-0x4(%rbp)
jmp    124c <call_dorgqr+0x10c>
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r9
mov    -0x48(%rbp),%r11
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x1c(%rbp),%r8
lea    -0x3c(%rbp),%r10
lea    -0x2c(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <dorgqr_@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_dorgqr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r9,%r14
mov    %rcx,%rbx
mov    %edi,0x14(%rsp)
mov    %esi,0x10(%rsp)
mov    %edx,0xc(%rsp)
mov    %r8d,0x8(%rsp)
movl   $0x0,(%rsp)
movl   $0xffffffff,0x4(%rsp)
ff
sub    $0x8,%rsp
lea    0x8(%rsp),%r13
lea    0xc(%rsp),%r12
lea    0x20(%rsp),%rax
lea    0x1c(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%r8
push   %r13
push   %r12
push   %rax
call   1060 <dorgqr_@plt>
add    $0x20,%rsp
mov    (%rsp),%eax
test   %eax,%eax
jne    121c <call_dorgqr+0xdc>
cvttsd2si 0x18(%rsp),%edi
mov    %edi,0x4(%rsp)
shl    $0x3,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1202 <call_dorgqr+0xc2>
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   %r13
push   %r12
push   %rax
call   1060 <dorgqr_@plt>
add    $0x20,%rsp
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%rsp),%eax
jmp    121c <call_dorgqr+0xdc>
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
lea    0xdee(%rip),%rdi
call   1040 <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_dorgqr\0A\00"
@stderr = global i32 0
define i32 @call_dorgqr(i32 %0, i32 %1, i32 %2, double* %3, i32 %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
%12 = alloca i32
%13 = alloca double*
%14 = alloca i32
%15 = alloca double
%16 = alloca i32
%17 = alloca double*
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store double* %3, double** %11
store i32 %4, i32* %12
store double* %5, double** %13
store i32 0, i32* %14
store i32 -1, i32* %16
store double* null, double** %17
%18 = load double*, double** %11
%19 = load double*, double** %13
%20 = call i32 @dorgqr_(i32* %8, i32* %9, i32* %10, double* %18, i32* %12, double* %19, double* %15, i32* %16, i32* %14)
%21 = load i32, i32* %14
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %6
%24 = load i32, i32* %14
store i32 %24, i32* %7
br label %47
25: ; preds = %6
%26 = load double, double* %15
%27 = fptosi double %26 to i32
store i32 %27, i32* %16
%28 = load i32, i32* %16
%29 = sext i32 %28 to i64
%30 = mul i64 8, %29
%31 = trunc i64 %30 to i32
%32 = call i64 @malloc(i32 %31)
%33 = inttoptr i64 %32 to double*
store double* %33, double** %17
%34 = load double*, double** %17
%35 = icmp eq double* %34, null
br i1 %35, label %36, label %39
36: ; preds = %25
%37 = load i32, i32* @stderr
%38 = call i32 @fputs(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %37)
store i32 -999, i32* %7
br label %47
39: ; preds = %25
%40 = load double*, double** %11
%41 = load double*, double** %13
%42 = load double*, double** %17
%43 = call i32 @dorgqr_(i32* %8, i32* %9, i32* %10, double* %40, i32* %12, double* %41, double* %42, i32* %16, i32* %14)
%44 = load double*, double** %17
%45 = call i32 @free(double* %44)
%46 = load i32, i32* %14
store i32 %46, i32* %7
br label %47
47: ; preds = %39, %36, %23
%48 = load i32, i32* %7
ret i32 %48
}

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