#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*/ dgesvd_(char *, char *, int *, int *, double *, int *,
                           double *, double *, int *, double *, int *, double *,
                           int *, int *);
int /*<<< orphan*/ free(double *);
int make_int(int *, long);
scalar_t__ malloc(int);
double max(int, int);
int min(int, int);
int lapack_svd(double *U, double *S, double *Vt, long m_long, long n_long,
               double *A) {
  int m, n;
  int info = make_int(&m, m_long);
  if (info != 0)
    return 1;
  info = make_int(&n, n_long);
  if (info != 0)
    return 1;
  char job = 'A';
  int min_mn = min(m, n);
  int max_mn = max(m, n);
  int lwork = 2.0 * max(3 * min_mn + max_mn, 5 * min_mn);
  double *work = (double *)malloc(lwork * sizeof(double));
  dgesvd_(&job, &job, &m, &n, A, &m, S, U, &m, Vt, &n, work, &lwork, &info);
  free(work);
  if (info != 0) {
    return 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<lapack_svd>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rdi,-0x38(%rbp)
mov    %rsi,-0x40(%rbp)
mov    %rdx,-0x48(%rbp)
mov    %rcx,-0x50(%rbp)
mov    %r8,-0x58(%rbp)
mov    %r9,-0x60(%rbp)
mov    -0x50(%rbp),%rsi
lea    -0x64(%rbp),%rdi
call   1060 <make_int@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
je     11b2 <lapack_svd+0x52>
movl   $0x1,-0x2c(%rbp)
jmp    12c4 <lapack_svd+0x164>
mov    -0x58(%rbp),%rsi
lea    -0x68(%rbp),%rdi
call   1060 <make_int@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
je     11d8 <lapack_svd+0x78>
movl   $0x1,-0x2c(%rbp)
jmp    12c4 <lapack_svd+0x164>
movb   $0x41,-0x6d(%rbp)
mov    -0x64(%rbp),%edi
mov    -0x68(%rbp),%esi
call   1040 <min@plt>
mov    %eax,-0x74(%rbp)
mov    -0x64(%rbp),%edi
mov    -0x68(%rbp),%esi
call   1050 <max@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x78(%rbp)
imul   $0x3,-0x74(%rbp),%edi
add    -0x78(%rbp),%edi
imul   $0x5,-0x74(%rbp),%esi
call   1050 <max@plt>
movaps %xmm0,%xmm1
movsd  0xde9(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x7c(%rbp)
movslq -0x7c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x88(%rbp)
mov    -0x60(%rbp),%r8
mov    -0x40(%rbp),%r13
mov    -0x38(%rbp),%r12
mov    -0x48(%rbp),%r14
mov    -0x88(%rbp),%r11
lea    -0x6d(%rbp),%rsi
lea    -0x64(%rbp),%r15
lea    -0x68(%rbp),%rbx
lea    -0x7c(%rbp),%r10
lea    -0x6c(%rbp),%rax
mov    %rsi,%rdi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %r15,%r9
mov    %r13,(%rsp)
mov    %r12,0x8(%rsp)
mov    %r15,0x10(%rsp)
mov    %r14,0x18(%rsp)
mov    %rbx,0x20(%rsp)
mov    %r11,0x28(%rsp)
mov    %r10,0x30(%rsp)
mov    %rax,0x38(%rsp)
call   1080 <dgesvd_@plt>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x6c(%rbp)
je     12bd <lapack_svd+0x15d>
movl   $0x2,-0x2c(%rbp)
jmp    12c4 <lapack_svd+0x164>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<lapack_svd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbx
mov    %r8,0x20(%rsp)
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rcx,%rsi
call   1060 <make_int@plt>
mov    $0x1,%ebp
test   %eax,%eax
jne    1255 <lapack_svd+0xf5>
mov    %rbx,0x18(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    0x20(%rsp),%rsi
call   1060 <make_int@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
jne    1255 <lapack_svd+0xf5>
movb   $0x41,0x7(%rsp)
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
call   1040 <min@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
call   1050 <max@plt>
cvttsd2si %xmm0,%eax
lea    0x0(%rbp,%rbp,2),%edi
add    %eax,%edi
lea    0x0(%rbp,%rbp,4),%esi
call   1050 <max@plt>
addsd  %xmm0,%xmm0
cvttsd2si %xmm0,%edi
mov    %edi,0x14(%rsp)
shl    $0x3,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0x8(%rsp),%rax
lea    0x14(%rsp),%r10
lea    0x7(%rsp),%rdi
mov    %rdi,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    0x18(%rsp),%r8
mov    %r14,%r9
push   %rax
push   %r10
push   %rbp
push   %rbx
push   %r13
push   %r14
push   %r12
push   %r15
call   1080 <dgesvd_@plt>
add    $0x40,%rsp
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
cmpl   $0x0,0x8(%rsp)
setne  %bpl
add    %ebp,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lapack_svd(double* %0, double* %1, double* %2, i64 %3, i64 %4, double* %5) {
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i64
%12 = alloca i64
%13 = alloca double*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca double*
store double* %0, double** %8
store double* %1, double** %9
store double* %2, double** %10
store i64 %3, i64* %11
store i64 %4, i64* %12
store double* %5, double** %13
%22 = load i64, i64* %11
%23 = call i32 @make_int(i32* %14, i64 %22)
store i32 %23, i32* %16
%24 = load i32, i32* %16
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %6
store i32 1, i32* %7
br label %68
27: ; preds = %6
%28 = load i64, i64* %12
%29 = call i32 @make_int(i32* %15, i64 %28)
store i32 %29, i32* %16
%30 = load i32, i32* %16
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 1, i32* %7
br label %68
33: ; preds = %27
store i8 65, i8* %17
%34 = load i32, i32* %14
%35 = load i32, i32* %15
%36 = call i32 @min(i32 %34, i32 %35)
store i32 %36, i32* %18
%37 = load i32, i32* %14
%38 = load i32, i32* %15
%39 = call double @max(i32 %37, i32 %38)
%40 = fptosi double %39 to i32
store i32 %40, i32* %19
%41 = load i32, i32* %18
%42 = mul nsw i32 3, %41
%43 = load i32, i32* %19
%44 = add nsw i32 %42, %43
%45 = load i32, i32* %18
%46 = mul nsw i32 5, %45
%47 = call double @max(i32 %44, i32 %46)
%48 = fmul double 2.000000e+00, %47
%49 = fptosi double %48 to i32
store i32 %49, i32* %20
%50 = load i32, i32* %20
%51 = sext i32 %50 to i64
%52 = mul i64 %51, 8
%53 = trunc i64 %52 to i32
%54 = call i64 @malloc(i32 %53)
%55 = inttoptr i64 %54 to double*
store double* %55, double** %21
%56 = load double*, double** %13
%57 = load double*, double** %9
%58 = load double*, double** %8
%59 = load double*, double** %10
%60 = load double*, double** %21
%61 = call i32 @dgesvd_(i8* %17, i8* %17, i32* %14, i32* %15, double* %56, i32* %14, double* %57, double* %58, i32* %14, double* %59, i32* %15, double* %60, i32* %20, i32* %16)
%62 = load double*, double** %21
%63 = call i32 @free(double* %62)
%64 = load i32, i32* %16
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %33
store i32 2, i32* %7
br label %68
67: ; preds = %33
store i32 0, i32* %7
br label %68
68: ; preds = %67, %66, %32, %26
%69 = load i32, i32* %7
ret i32 %69
}

LLVM IR (-O2):
define i32 @lapack_svd(double* %0, double* %1, double* %2, i64 %3, i64 %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
%12 = bitcast i32* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = bitcast i32* %9 to i8*
%15 = call i32 @make_int(i32* %7, i64 %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %43
17: ; preds = %6
%18 = call i32 @make_int(i32* %8, i64 %4)
store i32 %18, i32* %9
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %43
20: ; preds = %17
store i8 65, i8* %10
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = call i32 @min(i32 %21, i32 %22)
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = call double @max(i32 %24, i32 %25)
%27 = fptosi double %26 to i32
%28 = bitcast i32* %11 to i8*
%29 = mul nsw i32 %23, 3
%30 = add nsw i32 %29, %27
%31 = mul nsw i32 %23, 5
%32 = call double @max(i32 %30, i32 %31)
%33 = fmul double %32, 2.000000e+00
%34 = fptosi double %33 to i32
store i32 %34, i32* %11
%35 = shl i32 %34, 3
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to double*
%38 = call i32 @dgesvd_(i8* %10, i8* %10, i32* %7, i32* %8, double* %5, i32* %7, double* %1, double* %0, i32* %7, double* %2, i32* %8, double* %37, i32* %11, i32* %9)
%39 = call i32 @free(double* %37)
%40 = load i32, i32* %9
%41 = icmp eq i32 %40, 0
%42 = select i1 %41, i32 0, i32 2
br label %43
43: ; preds = %17, %6, %20
%44 = phi i32 [ %42, %20 ], [ 1, %6 ], [ 1, %17 ]
ret i32 %44
}