#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*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int call_dgesvd(char jobu, char jobvt, int m, int n, double *a, int lda,
                double *s, double *u, int ldu, double *vt, int ldvt) {
  int info = 0;
  double wkopt;
  int lwork = -1;
  double *work = NULL;
  dgesvd_(&jobu, &jobvt, &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, &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_dgesvd\n", stderr);
    return -999;
  }
  dgesvd_(&jobu, &jobvt, &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work, &lwork,
          &info);
  free(work);
  return info;
}


x86 assembly (clang, -O0):
<call_dgesvd>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %sil,%al
mov    %dil,%sil
mov    0x30(%rbp),%edi
mov    0x28(%rbp),%rdi
mov    0x20(%rbp),%edi
mov    0x18(%rbp),%rdi
mov    0x10(%rbp),%rdi
mov    %sil,-0x2d(%rbp)
mov    %al,-0x2e(%rbp)
mov    %edx,-0x34(%rbp)
mov    %ecx,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
mov    %r9d,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0xffffffff,-0x54(%rbp)
movq   $0x0,-0x60(%rbp)
mov    -0x40(%rbp),%r8
mov    0x10(%rbp),%r13
mov    0x18(%rbp),%r12
mov    0x28(%rbp),%r14
lea    -0x2d(%rbp),%rdi
lea    -0x2e(%rbp),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x44(%rbp),%r9
lea    0x20(%rbp),%r15
lea    0x30(%rbp),%rbx
lea    -0x50(%rbp),%r11
lea    -0x54(%rbp),%r10
lea    -0x48(%rbp),%rax
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   1060 <dgesvd_@plt>
cmpl   $0x0,-0x48(%rbp)
je     120d <call_dgesvd+0xcd>
mov    -0x48(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    12c7 <call_dgesvd+0x187>
cvttsd2si -0x50(%rbp),%eax
mov    %eax,-0x54(%rbp)
movslq -0x54(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1254 <call_dgesvd+0x114>
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
lea    0xdbd(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xfffffc19,-0x2c(%rbp)
jmp    12c7 <call_dgesvd+0x187>
mov    -0x40(%rbp),%r8
mov    0x10(%rbp),%r13
mov    0x18(%rbp),%r12
mov    0x28(%rbp),%r14
mov    -0x60(%rbp),%r11
lea    -0x2d(%rbp),%rdi
lea    -0x2e(%rbp),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x44(%rbp),%r9
lea    0x20(%rbp),%r15
lea    0x30(%rbp),%rbx
lea    -0x54(%rbp),%r10
lea    -0x48(%rbp),%rax
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   1060 <dgesvd_@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_dgesvd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%rbx
mov    0x60(%rsp),%rbp
mov    %dil,0xb(%rsp)
mov    %sil,0xa(%rsp)
mov    %edx,0x1c(%rsp)
mov    %ecx,0x18(%rsp)
mov    %r9d,0x14(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0xffffffff,0x10(%rsp)
ff
lea    0xc(%rsp),%r13
lea    0x10(%rsp),%r12
lea    0x20(%rsp),%rax
lea    0x80(%rsp),%r15
lea    0x70(%rsp),%r10
lea    0xb(%rsp),%rdi
lea    0xa(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r9
push   %r13
push   %r12
push   %rax
push   %r15
push   0x98(%rsp)
push   %r10
push   0x98(%rsp)
push   %rbp
call   1060 <dgesvd_@plt>
add    $0x40,%rsp
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    1265 <call_dgesvd+0x125>
cvttsd2si 0x20(%rsp),%edi
mov    %edi,0x10(%rsp)
shl    $0x3,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     124b <call_dgesvd+0x10b>
mov    %rax,%r14
lea    0xb(%rsp),%rdi
lea    0xa(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r9
mov    %rbx,%r8
push   %r13
push   %r12
push   %rax
push   %r15
push   0x98(%rsp)
lea    0x98(%rsp),%rax
push   %rax
push   0x98(%rsp)
push   %rbp
call   1060 <dgesvd_@plt>
add    $0x40,%rsp
mov    %r14,%rdi
call   1030 <free@plt>
mov    0xc(%rsp),%eax
jmp    1265 <call_dgesvd+0x125>
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
lea    0xda5(%rip),%rdi
call   1040 <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_dgesvd\0A\00"
@stderr = global i32 0
define i32 @call_dgesvd(i8 signext %0, i8 signext %1, i32 %2, i32 %3, double* %4, i32 %5, double* %6, double* %7, i32 %8, double* %9, i32 %10) {
%12 = alloca i32
%13 = alloca i8
%14 = alloca i8
%15 = alloca i32
%16 = alloca i32
%17 = alloca double*
%18 = alloca i32
%19 = alloca double*
%20 = alloca double*
%21 = alloca i32
%22 = alloca double*
%23 = alloca i32
%24 = alloca i32
%25 = alloca double
%26 = alloca i32
%27 = alloca double*
store i8 %0, i8* %13
store i8 %1, i8* %14
store i32 %2, i32* %15
store i32 %3, i32* %16
store double* %4, double** %17
store i32 %5, i32* %18
store double* %6, double** %19
store double* %7, double** %20
store i32 %8, i32* %21
store double* %9, double** %22
store i32 %10, i32* %23
store i32 0, i32* %24
store i32 -1, i32* %26
store double* null, double** %27
%28 = load double*, double** %17
%29 = load double*, double** %19
%30 = load double*, double** %20
%31 = load double*, double** %22
%32 = call i32 @dgesvd_(i8* %13, i8* %14, i32* %15, i32* %16, double* %28, i32* %18, double* %29, double* %30, i32* %21, double* %31, i32* %23, double* %25, i32* %26, i32* %24)
%33 = load i32, i32* %24
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %11
%36 = load i32, i32* %24
store i32 %36, i32* %12
br label %61
37: ; preds = %11
%38 = load double, double* %25
%39 = fptosi double %38 to i32
store i32 %39, i32* %26
%40 = load i32, i32* %26
%41 = sext i32 %40 to i64
%42 = mul i64 8, %41
%43 = trunc i64 %42 to i32
%44 = call i64 @malloc(i32 %43)
%45 = inttoptr i64 %44 to double*
store double* %45, double** %27
%46 = load double*, double** %27
%47 = icmp eq double* %46, null
br i1 %47, label %48, label %51
48: ; preds = %37
%49 = load i32, i32* @stderr
%50 = call i32 @fputs(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %49)
store i32 -999, i32* %12
br label %61
51: ; preds = %37
%52 = load double*, double** %17
%53 = load double*, double** %19
%54 = load double*, double** %20
%55 = load double*, double** %22
%56 = load double*, double** %27
%57 = call i32 @dgesvd_(i8* %13, i8* %14, i32* %15, i32* %16, double* %52, i32* %18, double* %53, double* %54, i32* %21, double* %55, i32* %23, double* %56, i32* %26, i32* %24)
%58 = load double*, double** %27
%59 = call i32 @free(double* %58)
%60 = load i32, i32* %24
store i32 %60, i32* %12
br label %61
61: ; preds = %51, %48, %35
%62 = load i32, i32* %12
ret i32 %62
}

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