#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 const *, int const *, double *, int const *,
                           double *, double *, int const *, int *);
int /*<<< orphan*/ dorgqr_(int const *, int const *, int const *, double *,
                           int const *, double *, double *, int const *, int *);
int get_qr(const int m, const int n, double *x, double *tau, double *work,
           const int lwork) {
  int info = 0;
  const int rank = m < n ? m : n;
  dgeqrf_(&m, &n, x, &m, tau, work, &lwork, &info);
  if (info != 0)
    return info;
  dorgqr_(&m, &n, &rank, x, &m, tau, work, &lwork, &info);
  return info;
}


x86 assembly (clang, -O0):
<get_qr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    115c <get_qr+0x3c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1162 <get_qr+0x42>
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%rsi
lea    -0x2c(%rbp),%r10
lea    -0x30(%rbp),%rax
mov    %rcx,%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <dgeqrf_@plt>
cmpl   $0x0,-0x30(%rbp)
je     11aa <get_qr+0x8a>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e6 <get_qr+0xc6>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%r11
lea    -0x8(%rbp),%r8
lea    -0xc(%rbp),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x2c(%rbp),%r10
lea    -0x30(%rbp),%rax
mov    %r8,%rdi
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <dorgqr_@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_qr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %edi,0x14(%rsp)
mov    %esi,0x10(%rsp)
mov    %r9d,0x1c(%rsp)
movl   $0x0,0xc(%rsp)
cmp    %esi,%edi
cmovl  %edi,%esi
mov    %esi,0x18(%rsp)
lea    0xc(%rsp),%r13
lea    0x1c(%rsp),%r12
lea    0x10(%rsp),%rsi
lea    0x14(%rsp),%rcx
mov    %rcx,%rdi
mov    %r15,%r8
mov    %r14,%r9
push   %r13
push   %r12
call   1030 <dgeqrf_@plt>
add    $0x10,%rsp
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    11b5 <get_qr+0x95>
sub    $0x8,%rsp
lea    0x18(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x1c(%rsp),%rdi
mov    %rbx,%rcx
mov    %rdi,%r8
mov    %r15,%r9
push   %r13
push   %r12
push   %r14
call   1040 <dorgqr_@plt>
add    $0x20,%rsp
mov    0xc(%rsp),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @get_qr(i32 %0, i32 %1, double* %2, double* %3, double* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store double* %2, double** %10
store double* %3, double** %11
store double* %4, double** %12
store i32 %5, i32* %13
store i32 0, i32* %14
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %6
%20 = load i32, i32* %8
br label %23
21: ; preds = %6
%22 = load i32, i32* %9
br label %23
23: ; preds = %21, %19
%24 = phi i32 [ %20, %19 ], [ %22, %21 ]
store i32 %24, i32* %15
%25 = load double*, double** %10
%26 = load double*, double** %11
%27 = load double*, double** %12
%28 = call i32 @dgeqrf_(i32* %8, i32* %9, double* %25, i32* %8, double* %26, double* %27, i32* %13, i32* %14)
%29 = load i32, i32* %14
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = load i32, i32* %14
store i32 %32, i32* %7
br label %39
33: ; preds = %23
%34 = load double*, double** %10
%35 = load double*, double** %11
%36 = load double*, double** %12
%37 = call i32 @dorgqr_(i32* %8, i32* %9, i32* %15, double* %34, i32* %8, double* %35, double* %36, i32* %13, i32* %14)
%38 = load i32, i32* %14
store i32 %38, i32* %7
br label %39
39: ; preds = %33, %31
%40 = load i32, i32* %7
ret i32 %40
}

LLVM IR (-O2):
define i32 @get_qr(i32 %0, i32 %1, double* %2, double* %3, double* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %5, i32* %9
%12 = bitcast i32* %10 to i8*
store i32 0, i32* %10
%13 = bitcast i32* %11 to i8*
%14 = icmp slt i32 %0, %1
%15 = select i1 %14, i32 %0, i32 %1
store i32 %15, i32* %11
%16 = call i32 @dgeqrf_(i32* %7, i32* %8, double* %2, i32* %7, double* %3, double* %4, i32* %9, i32* %10)
%17 = load i32, i32* %10
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %6
%20 = call i32 @dorgqr_(i32* %7, i32* %8, i32* %11, double* %2, i32* %7, double* %3, double* %4, i32* %9, i32* %10)
%21 = load i32, i32* %10
br label %22
22: ; preds = %6, %19
%23 = phi i32 [ %21, %19 ], [ %17, %6 ]
ret i32 %23
}