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


x86 assembly (clang, -O0):
<call_dgeqp3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0xffffffff,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
lea    -0x40(%rbp),%r11
lea    -0x44(%rbp),%r10
lea    -0x34(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <dgeqp3_@plt>
cmpl   $0x0,-0x34(%rbp)
je     11bf <call_dgeqp3+0x7f>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <call_dgeqp3+0x10c>
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    1206 <call_dgeqp3+0xc6>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    0xe0b(%rip),%rdi
call   1050 <fputs@plt>
movl   $0xfffffc19,-0x4(%rbp)
jmp    124c <call_dgeqp3+0x10c>
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x50(%rbp),%r11
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
lea    -0x44(%rbp),%r10
lea    -0x34(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <dgeqp3_@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_dgeqp3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rdx,%rbx
mov    %edi,0x1c(%rsp)
mov    %esi,0x18(%rsp)
mov    %ecx,0x14(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0xffffffff,0x10(%rsp)
ff
sub    $0x8,%rsp
lea    0x14(%rsp),%rbp
lea    0x18(%rsp),%r13
lea    0x28(%rsp),%rax
lea    0x24(%rsp),%rdi
lea    0x20(%rsp),%rsi
lea    0x1c(%rsp),%rcx
push   %rbp
push   %r13
push   %rax
call   1040 <dgeqp3_@plt>
add    $0x20,%rsp
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    1215 <call_dgeqp3+0xd5>
cvttsd2si 0x20(%rsp),%edi
mov    %edi,0x10(%rsp)
shl    $0x3,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11fb <call_dgeqp3+0xbb>
mov    %rax,%r12
sub    $0x8,%rsp
lea    0x24(%rsp),%rdi
lea    0x20(%rsp),%rsi
lea    0x1c(%rsp),%rcx
mov    %rbx,%rdx
mov    %r15,%r8
mov    %r14,%r9
push   %rbp
push   %r13
push   %rax
call   1040 <dgeqp3_@plt>
add    $0x20,%rsp
mov    %r12,%rdi
call   1030 <free@plt>
mov    0xc(%rsp),%eax
jmp    1215 <call_dgeqp3+0xd5>
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
lea    0xdf5(%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_dgeqp3\0A\00"
@stderr = global i32 0
define i32 @call_dgeqp3(i32 %0, i32 %1, double* %2, i32 %3, i32* %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
%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 double* %2, double** %10
store i32 %3, i32* %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** %10
%19 = load i32*, i32** %12
%20 = load double*, double** %13
%21 = call i32 @dgeqp3_(i32* %8, i32* %9, double* %18, i32* %11, i32* %19, double* %20, double* %15, i32* %16, i32* %14)
%22 = load i32, i32* %14
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %6
%25 = load i32, i32* %14
store i32 %25, i32* %7
br label %49
26: ; preds = %6
%27 = load double, double* %15
%28 = fptosi double %27 to i32
store i32 %28, i32* %16
%29 = load i32, i32* %16
%30 = sext i32 %29 to i64
%31 = mul i64 8, %30
%32 = trunc i64 %31 to i32
%33 = call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to double*
store double* %34, double** %17
%35 = load double*, double** %17
%36 = icmp eq double* %35, null
br i1 %36, label %37, label %40
37: ; preds = %26
%38 = load i32, i32* @stderr
%39 = call i32 @fputs(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %38)
store i32 -999, i32* %7
br label %49
40: ; preds = %26
%41 = load double*, double** %10
%42 = load i32*, i32** %12
%43 = load double*, double** %13
%44 = load double*, double** %17
%45 = call i32 @dgeqp3_(i32* %8, i32* %9, double* %41, i32* %11, i32* %42, double* %43, double* %44, i32* %16, i32* %14)
%46 = load double*, double** %17
%47 = call i32 @free(double* %46)
%48 = load i32, i32* %14
store i32 %48, i32* %7
br label %49
49: ; preds = %40, %37, %24
%50 = load i32, i32* %7
ret i32 %50
}

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