#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 */
double fabs(double);
int /*<<< orphan*/ free(double *);
double macheps();
scalar_t__ malloc(int);
int /*<<< orphan*/ mmult(double *, double *, double *, int, int, int);
int svd(double *, int, int, double *, double *, double *);
int lls_svd(double *Ai, double *bi, int M, int N, double *xo) {
  int retcode, i, j, t;
  double *U, *V, *q, *C;
  double eps;
  U = (double *)malloc(sizeof(double) * M * N);
  V = (double *)malloc(sizeof(double) * N * N);
  q = (double *)malloc(sizeof(double) * N);
  C = (double *)malloc(sizeof(double) * N);
  retcode = 0;
  eps = macheps();
  retcode = svd(Ai, M, N, U, V, q);
  ;
  if (retcode != 0) {
    return retcode;
  }
  mmult(bi, U, C, 1, M, N);
  for (i = 0; i < N; ++i) {
    t = i * N;
    for (j = 0; j < N; ++j) {
      if (fabs(q[j]) > eps) {
        V[t + j] /= q[j];
      } else {
        V[t + j] = 0.0;
      }
    }
  }
  mmult(V, C, xo, N, N, 1);
  free(U);
  free(V);
  free(q);
  return retcode;
}


x86 assembly (clang, -O0):
<lls_svd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
movslq -0x20(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
movslq -0x20(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x0,%al
call   1070 <macheps@plt>
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x50(%rbp),%r9
call   1050 <svd@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     120c <lls_svd+0xbc>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1324 <lls_svd+0x1d4>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    $0x1,%ecx
call   1040 <mmult@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12e5 <lls_svd+0x195>
mov    -0x30(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12d2 <lls_svd+0x182>
mov    -0x50(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xd92(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x60(%rbp),%xmm0
jbe    12aa <lls_svd+0x15a>
mov    -0x50(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    12bf <lls_svd+0x16f>
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    12c4 <lls_svd+0x174>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    124e <lls_svd+0xfe>
jmp    12d7 <lls_svd+0x187>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1231 <lls_svd+0xe1>
mov    -0x48(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    $0x1,%r9d
call   1040 <mmult@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lls_svd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x20(%rsp)
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %rsi,0x8(%rsp)
mov    %rdi,(%rsp)
mov    %edx,%edi
imul   %ecx,%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0x0(,%r13,8),%r15d
mov    %r15d,%edi
imul   %r13d,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1070 <macheps@plt>
movsd  %xmm0,0x18(%rsp)
mov    (%rsp),%rdi
mov    %r14d,%esi
mov    %r13d,%edx
mov    %rbp,%rcx
mov    %r12,(%rsp)
mov    %r12,%r8
mov    %rbx,%r9
call   1050 <svd@plt>
mov    %eax,%r12d
test   %eax,%eax
jne    12b7 <lls_svd+0x167>
mov    0x8(%rsp),%rdi
mov    %rbp,0x8(%rsp)
mov    %rbp,%rsi
mov    %r15,0x10(%rsp)
mov    %r15,%rdx
mov    $0x1,%ecx
mov    %r14d,%r8d
mov    %r13d,%r9d
call   1040 <mmult@plt>
test   %r13d,%r13d
mov    0x20(%rsp),%rdx
movsd  0x18(%rsp),%xmm4
jle    1280 <lls_svd+0x130>
mov    %r13d,%eax
lea    0x0(,%rax,8),%rcx
xor    %ebp,%ebp
movapd 0xdd3(%rip),%xmm0
mov    (%rsp),%rsi
jmp    124c <lls_svd+0xfc>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
add    %rcx,%rsi
cmp    %rax,%rbp
je     1280 <lls_svd+0x130>
xor    %edi,%edi
jmp    125e <lls_svd+0x10e>
movsd  %xmm2,(%rsi,%rdi,8)
add    $0x1,%rdi
cmp    %rdi,%rax
je     1240 <lls_svd+0xf0>
movsd  (%rbx,%rdi,8),%xmm1
movapd %xmm1,%xmm3
andpd  %xmm0,%xmm3
xorpd  %xmm2,%xmm2
ucomisd %xmm4,%xmm3
jbe    1250 <lls_svd+0x100>
movsd  (%rsi,%rdi,8),%xmm2
divsd  %xmm1,%xmm2
jmp    1250 <lls_svd+0x100>
mov    (%rsp),%rbp
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    %r13d,%ecx
mov    %r13d,%r8d
mov    $0x1,%r9d
call   1040 <mmult@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lls_svd(double* %0, double* %1, i32 %2, i32 %3, double* %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
%19 = alloca double*
%20 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store double* %4, double** %11
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = mul i64 8, %22
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = mul i64 %23, %25
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to double*
store double* %29, double** %16
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = mul i64 8, %31
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = mul i64 %32, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to double*
store double* %38, double** %17
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = mul i64 8, %40
%42 = trunc i64 %41 to i32
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to double*
store double* %44, double** %18
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = mul i64 8, %46
%48 = trunc i64 %47 to i32
%49 = call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to double*
store double* %50, double** %19
store i32 0, i32* %12
%51 = call double (...) @macheps()
store double %51, double* %20
%52 = load double*, double** %7
%53 = load i32, i32* %9
%54 = load i32, i32* %10
%55 = load double*, double** %16
%56 = load double*, double** %17
%57 = load double*, double** %18
%58 = call i32 @svd(double* %52, i32 %53, i32 %54, double* %55, double* %56, double* %57)
store i32 %58, i32* %12
%59 = load i32, i32* %12
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %5
%62 = load i32, i32* %12
store i32 %62, i32* %6
br label %134
63: ; preds = %5
%64 = load double*, double** %8
%65 = load double*, double** %16
%66 = load double*, double** %19
%67 = load i32, i32* %9
%68 = load i32, i32* %10
%69 = call i32 @mmult(double* %64, double* %65, double* %66, i32 1, i32 %67, i32 %68)
store i32 0, i32* %13
br label %70
70: ; preds = %117, %63
%71 = load i32, i32* %13
%72 = load i32, i32* %10
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %120
74: ; preds = %70
%75 = load i32, i32* %13
%76 = load i32, i32* %10
%77 = mul nsw i32 %75, %76
store i32 %77, i32* %15
store i32 0, i32* %14
br label %78
78: ; preds = %113, %74
%79 = load i32, i32* %14
%80 = load i32, i32* %10
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %116
82: ; preds = %78
%83 = load double*, double** %18
%84 = load i32, i32* %14
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %83, i64 %85
%87 = load double, double* %86
%88 = call double @llvm.fabs.f64(double %87)
%89 = load double, double* %20
%90 = fcmp ogt double %88, %89
br i1 %90, label %91, label %105
91: ; preds = %82
%92 = load double*, double** %18
%93 = load i32, i32* %14
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds double, double* %92, i64 %94
%96 = load double, double* %95
%97 = load double*, double** %17
%98 = load i32, i32* %15
%99 = load i32, i32* %14
%100 = add nsw i32 %98, %99
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds double, double* %97, i64 %101
%103 = load double, double* %102
%104 = fdiv double %103, %96
store double %104, double* %102
br label %112
105: ; preds = %82
%106 = load double*, double** %17
%107 = load i32, i32* %15
%108 = load i32, i32* %14
%109 = add nsw i32 %107, %108
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds double, double* %106, i64 %110
store double 0.000000e+00, double* %111
br label %112
112: ; preds = %105, %91
br label %113
113: ; preds = %112
%114 = load i32, i32* %14
%115 = add nsw i32 %114, 1
store i32 %115, i32* %14
br label %78
116: ; preds = %78
br label %117
117: ; preds = %116
%118 = load i32, i32* %13
%119 = add nsw i32 %118, 1
store i32 %119, i32* %13
br label %70
120: ; preds = %70
%121 = load double*, double** %17
%122 = load double*, double** %19
%123 = load double*, double** %11
%124 = load i32, i32* %10
%125 = load i32, i32* %10
%126 = call i32 @mmult(double* %121, double* %122, double* %123, i32 %124, i32 %125, i32 1)
%127 = load double*, double** %16
%128 = call i32 @free(double* %127)
%129 = load double*, double** %17
%130 = call i32 @free(double* %129)
%131 = load double*, double** %18
%132 = call i32 @free(double* %131)
%133 = load i32, i32* %12
store i32 %133, i32* %6
br label %134
134: ; preds = %120, %61
%135 = load i32, i32* %6
ret i32 %135
}

LLVM IR (-O2):
define i32 @lls_svd(double* %0, double* %1, i32 %2, i32 %3, double* %4) {
%6 = shl i32 %2, 3
%7 = mul i32 %6, %3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = shl i32 %3, 3
%11 = mul i32 %10, %3
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double*
%14 = tail call i64 @malloc(i32 %10)
%15 = inttoptr i64 %14 to double*
%16 = tail call i64 @malloc(i32 %10)
%17 = inttoptr i64 %16 to double*
%18 = tail call double (...) @macheps()
%19 = tail call i32 @svd(double* %0, i32 %2, i32 %3, double* %9, double* %13, double* %15)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %53
21: ; preds = %5
%22 = tail call i32 @mmult(double* %1, double* %9, double* %17, i32 1, i32 %2, i32 %3)
%23 = icmp sgt i32 %3, 0
br i1 %23, label %24, label %48
24: ; preds = %21
%25 = zext i32 %3 to i64
%26 = zext i32 %3 to i64
br label %27
27: ; preds = %45, %24
%28 = phi i64 [ 0, %24 ], [ %46, %45 ]
%29 = mul nsw i64 %28, %25
br label %30
30: ; preds = %27, %41
%31 = phi i64 [ 0, %27 ], [ %43, %41 ]
%32 = getelementptr inbounds double, double* %15, i64 %31
%33 = load double, double* %32
%34 = tail call double @llvm.fabs.f64(double %33)
%35 = fcmp ogt double %34, %18
%36 = add nuw nsw i64 %31, %29
%37 = getelementptr inbounds double, double* %13, i64 %36
br i1 %35, label %38, label %41
38: ; preds = %30
%39 = load double, double* %37
%40 = fdiv double %39, %33
br label %41
41: ; preds = %30, %38
%42 = phi double [ %40, %38 ], [ 0.000000e+00, %30 ]
store double %42, double* %37
%43 = add nuw nsw i64 %31, 1
%44 = icmp eq i64 %43, %26
br i1 %44, label %45, label %30
45: ; preds = %41
%46 = add nuw nsw i64 %28, 1
%47 = icmp eq i64 %46, %26
br i1 %47, label %48, label %27
48: ; preds = %45, %21
%49 = tail call i32 @mmult(double* %13, double* %17, double* %4, i32 %3, i32 %3, i32 1)
%50 = tail call i32 @free(double* %9)
%51 = tail call i32 @free(double* %13)
%52 = tail call i32 @free(double* %15)
br label %53
53: ; preds = %5, %48
ret i32 %19
}