#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*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(double *);
double *malloc(int);
int /*<<< orphan*/ stderr;
int svd(double *, double *, double *, int, double *, int);
int svd_double(double *d, double *a, double *u, int m, double *v, int n) {
  assert(m >= n);
  double *dd = malloc(n * sizeof(double));
  double *da = malloc(n * m * sizeof(double));
  double *du = malloc(m * m * sizeof(double));
  double *dv = malloc(n * n * sizeof(double));
  if (!(dd && da && du && dv))
    exit(fprintf(stderr, "out of mem"));
  for (int i = 0; i < n * m; i++)
    da[i] = a[i];
  int r = svd(dd, da, du, m, dv, n);
  if (d)
    for (int i = 0; i < n; i++)
      d[i] = dd[i];
  if (u)
    for (int i = 0; i < m * m; i++)
      u[i] = du[i];
  if (v)
    for (int i = 0; i < n * n; i++)
      v[i] = dv[i];
  free(du);
  free(dv);
  free(da);
  free(dd);
  return r;
}


x86 assembly (clang, -O0):
<svd_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
imul   -0x2c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1219 <svd_double+0xb9>
cmpq   $0x0,-0x40(%rbp)
je     1219 <svd_double+0xb9>
cmpq   $0x0,-0x48(%rbp)
je     1219 <svd_double+0xb9>
cmpq   $0x0,-0x50(%rbp)
jne    1235 <svd_double+0xd5>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1060 <fprintf@plt>
mov    %eax,%edi
call   1080 <exit@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    -0x2c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    1276 <svd_double+0x116>
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    123c <svd_double+0xdc>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x50(%rbp),%r8
mov    -0x2c(%rbp),%r9d
call   1040 <svd@plt>
mov    %eax,-0x58(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     12e0 <svd_double+0x180>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12db <svd_double+0x17b>
mov    -0x38(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    12a7 <svd_double+0x147>
jmp    12e0 <svd_double+0x180>
cmpq   $0x0,-0x18(%rbp)
je     1331 <svd_double+0x1d1>
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    132c <svd_double+0x1cc>
mov    -0x48(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    12f2 <svd_double+0x192>
jmp    1331 <svd_double+0x1d1>
cmpq   $0x0,-0x28(%rbp)
je     1382 <svd_double+0x222>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    -0x2c(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
cmp    %ecx,%eax
jge    137d <svd_double+0x21d>
mov    -0x50(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1343 <svd_double+0x1e3>
jmp    1382 <svd_double+0x222>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svd_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%r15d
mov    %r8,0x30(%rsp)
mov    %ecx,%ebx
mov    %rdx,0x20(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdi,0x18(%rsp)
xor    %edi,%edi
cmp    %r9d,%ecx
setge  %dil
call   1050 <assert@plt>
lea    0x0(,%r15,8),%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %r15d,%r12d
imul   %ebx,%r12d
lea    0x0(,%r12,8),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %ebx,0x4(%rsp)
mov    %ebx,%r13d
imul   %r13d,%r13d
lea    0x0(,%r13,8),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %r15d,%eax
imul   %eax,%eax
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,8),%edi
call   1080 <malloc@plt>
mov    %rbp,0x28(%rsp)
test   %rbp,%rbp
je     12fa <svd_double+0x18a>
test   %r14,%r14
je     12fa <svd_double+0x18a>
test   %rbx,%rbx
je     12fa <svd_double+0x18a>
test   %rax,%rax
je     12fa <svd_double+0x18a>
test   %r12d,%r12d
jle    1246 <svd_double+0xd6>
mov    %r12d,%edx
shl    $0x3,%rdx
mov    %r14,%rdi
mov    0x8(%rsp),%rsi
mov    %rax,%rbp
call   1070 <memcpy@plt>
mov    %rbp,%rax
mov    0x28(%rsp),%r12
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    0x4(%rsp),%ecx
mov    %rax,%rbp
mov    %rax,%r8
mov    %r15d,%r9d
call   1040 <svd@plt>
mov    %eax,0x4(%rsp)
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     1288 <svd_double+0x118>
test   %r15d,%r15d
jle    1288 <svd_double+0x118>
mov    %r15d,%edx
shl    $0x3,%rdx
mov    %r12,%rsi
call   1070 <memcpy@plt>
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     12a6 <svd_double+0x136>
test   %r13d,%r13d
je     12a6 <svd_double+0x136>
mov    %r13d,%edx
shl    $0x3,%rdx
mov    %rbx,%rsi
call   1070 <memcpy@plt>
mov    0x30(%rsp),%rdi
test   %rdi,%rdi
mov    0x10(%rsp),%rax
je     12c7 <svd_double+0x157>
test   %eax,%eax
je     12c7 <svd_double+0x157>
mov    %eax,%edx
shl    $0x3,%rdx
mov    %rbp,%rsi
call   1070 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
lea    0xcf6(%rip),%rsi
call   1060 <fprintf@plt>
mov    %eax,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"out of mem\00"
define i32 @svd_double(double* %0, double* %1, double* %2, i32 %3, double* %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca double*
%12 = alloca i32
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store i32 %3, i32* %10
store double* %4, double** %11
store i32 %5, i32* %12
%22 = load i32, i32* %10
%23 = load i32, i32* %12
%24 = icmp sge i32 %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 8
%30 = trunc i64 %29 to i32
%31 = call double* @malloc(i32 %30)
store double* %31, double** %13
%32 = load i32, i32* %12
%33 = load i32, i32* %10
%34 = mul nsw i32 %32, %33
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 8
%37 = trunc i64 %36 to i32
%38 = call double* @malloc(i32 %37)
store double* %38, double** %14
%39 = load i32, i32* %10
%40 = load i32, i32* %10
%41 = mul nsw i32 %39, %40
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 8
%44 = trunc i64 %43 to i32
%45 = call double* @malloc(i32 %44)
store double* %45, double** %15
%46 = load i32, i32* %12
%47 = load i32, i32* %12
%48 = mul nsw i32 %46, %47
%49 = sext i32 %48 to i64
%50 = mul i64 %49, 8
%51 = trunc i64 %50 to i32
%52 = call double* @malloc(i32 %51)
store double* %52, double** %16
%53 = load double*, double** %13
%54 = icmp ne double* %53, null
br i1 %54, label %55, label %64
55: ; preds = %6
%56 = load double*, double** %14
%57 = icmp ne double* %56, null
br i1 %57, label %58, label %64
58: ; preds = %55
%59 = load double*, double** %15
%60 = icmp ne double* %59, null
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load double*, double** %16
%63 = icmp ne double* %62, null
br i1 %63, label %68, label %64
64: ; preds = %61, %58, %55, %6
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %61
store i32 0, i32* %17
br label %69
69: ; preds = %85, %68
%70 = load i32, i32* %17
%71 = load i32, i32* %12
%72 = load i32, i32* %10
%73 = mul nsw i32 %71, %72
%74 = icmp slt i32 %70, %73
br i1 %74, label %75, label %88
75: ; preds = %69
%76 = load double*, double** %8
%77 = load i32, i32* %17
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %76, i64 %78
%80 = load double, double* %79
%81 = load double*, double** %14
%82 = load i32, i32* %17
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double, double* %81, i64 %83
store double %80, double* %84
br label %85
85: ; preds = %75
%86 = load i32, i32* %17
%87 = add nsw i32 %86, 1
store i32 %87, i32* %17
br label %69
88: ; preds = %69
%89 = load double*, double** %13
%90 = load double*, double** %14
%91 = load double*, double** %15
%92 = load i32, i32* %10
%93 = load double*, double** %16
%94 = load i32, i32* %12
%95 = call i32 @svd(double* %89, double* %90, double* %91, i32 %92, double* %93, i32 %94)
store i32 %95, i32* %18
%96 = load double*, double** %7
%97 = icmp ne double* %96, null
br i1 %97, label %98, label %117
98: ; preds = %88
store i32 0, i32* %19
br label %99
99: ; preds = %113, %98
%100 = load i32, i32* %19
%101 = load i32, i32* %12
%102 = icmp slt i32 %100, %101
br i1 %102, label %103, label %116
103: ; preds = %99
%104 = load double*, double** %13
%105 = load i32, i32* %19
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds double, double* %104, i64 %106
%108 = load double, double* %107
%109 = load double*, double** %7
%110 = load i32, i32* %19
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds double, double* %109, i64 %111
store double %108, double* %112
br label %113
113: ; preds = %103
%114 = load i32, i32* %19
%115 = add nsw i32 %114, 1
store i32 %115, i32* %19
br label %99
116: ; preds = %99
br label %117
117: ; preds = %116, %88
%118 = load double*, double** %9
%119 = icmp ne double* %118, null
br i1 %119, label %120, label %141
120: ; preds = %117
store i32 0, i32* %20
br label %121
121: ; preds = %137, %120
%122 = load i32, i32* %20
%123 = load i32, i32* %10
%124 = load i32, i32* %10
%125 = mul nsw i32 %123, %124
%126 = icmp slt i32 %122, %125
br i1 %126, label %127, label %140
127: ; preds = %121
%128 = load double*, double** %15
%129 = load i32, i32* %20
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds double, double* %128, i64 %130
%132 = load double, double* %131
%133 = load double*, double** %9
%134 = load i32, i32* %20
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds double, double* %133, i64 %135
store double %132, double* %136
br label %137
137: ; preds = %127
%138 = load i32, i32* %20
%139 = add nsw i32 %138, 1
store i32 %139, i32* %20
br label %121
140: ; preds = %121
br label %141
141: ; preds = %140, %117
%142 = load double*, double** %11
%143 = icmp ne double* %142, null
br i1 %143, label %144, label %165
144: ; preds = %141
store i32 0, i32* %21
br label %145
145: ; preds = %161, %144
%146 = load i32, i32* %21
%147 = load i32, i32* %12
%148 = load i32, i32* %12
%149 = mul nsw i32 %147, %148
%150 = icmp slt i32 %146, %149
br i1 %150, label %151, label %164
151: ; preds = %145
%152 = load double*, double** %16
%153 = load i32, i32* %21
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds double, double* %152, i64 %154
%156 = load double, double* %155
%157 = load double*, double** %11
%158 = load i32, i32* %21
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds double, double* %157, i64 %159
store double %156, double* %160
br label %161
161: ; preds = %151
%162 = load i32, i32* %21
%163 = add nsw i32 %162, 1
store i32 %163, i32* %21
br label %145
164: ; preds = %145
br label %165
165: ; preds = %164, %141
%166 = load double*, double** %15
%167 = call i32 @free(double* %166)
%168 = load double*, double** %16
%169 = call i32 @free(double* %168)
%170 = load double*, double** %14
%171 = call i32 @free(double* %170)
%172 = load double*, double** %13
%173 = call i32 @free(double* %172)
%174 = load i32, i32* %18
ret i32 %174
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"out of mem\00"
define i32 @svd_double(double* writeonly %0, double* nocapture %1, double* writeonly %2, i32 %3, double* writeonly %4, i32 %5) {
%7 = bitcast double* %1 to i8*
%8 = bitcast double* %0 to i8*
%9 = bitcast double* %2 to i8*
%10 = bitcast double* %4 to i8*
%11 = icmp sge i32 %3, %5
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = shl i32 %5, 3
%15 = tail call double* @malloc(i32 %14)
%16 = bitcast double* %15 to i8*
%17 = mul nsw i32 %5, %3
%18 = shl i32 %17, 3
%19 = tail call double* @malloc(i32 %18)
%20 = bitcast double* %19 to i8*
%21 = mul nsw i32 %3, %3
%22 = shl i32 %21, 3
%23 = tail call double* @malloc(i32 %22)
%24 = bitcast double* %23 to i8*
%25 = mul nsw i32 %5, %5
%26 = shl i32 %25, 3
%27 = tail call double* @malloc(i32 %26)
%28 = bitcast double* %27 to i8*
%29 = icmp ne double* %15, null
%30 = icmp ne double* %19, null
%31 = and i1 %29, %30
%32 = icmp ne double* %23, null
%33 = and i1 %31, %32
%34 = icmp ne double* %27, null
%35 = and i1 %33, %34
br i1 %35, label %36, label %41
36: ; preds = %6
%37 = icmp sgt i32 %17, 0
br i1 %37, label %38, label %45
38: ; preds = %36
%39 = zext i32 %17 to i64
%40 = shl nuw nsw i64 %39, 3
br label %45
41: ; preds = %6
%42 = load i32, i32* @stderr
%43 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%44 = tail call i32 @exit(i32 %43)
unreachable
45: ; preds = %38, %36
%46 = tail call i32 @svd(double* %15, double* %19, double* %23, i32 %3, double* %27, i32 %5)
%47 = icmp ne double* %0, null
%48 = icmp sgt i32 %5, 0
%49 = and i1 %47, %48
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = zext i32 %5 to i64
%52 = shl nuw nsw i64 %51, 3
br label %53
53: ; preds = %50, %45
%54 = icmp ne double* %2, null
%55 = icmp ne i32 %21, 0
%56 = select i1 %54, i1 %55, i1 false
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = zext i32 %21 to i64
%59 = shl nuw nsw i64 %58, 3
br label %60
60: ; preds = %57, %53
%61 = icmp ne double* %4, null
%62 = icmp ne i32 %25, 0
%63 = select i1 %61, i1 %62, i1 false
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = zext i32 %25 to i64
%66 = shl nuw nsw i64 %65, 3
br label %67
67: ; preds = %64, %60
%68 = tail call i32 @free(double* %23)
%69 = tail call i32 @free(double* %27)
%70 = tail call i32 @free(double* %19)
%71 = tail call i32 @free(double* %15)
ret i32 %46
}