#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*/ BackSubstitution(double *, double *, int, double **, int);
int /*<<< orphan*/ LUDecomposition(double *, int, double **, double **);
int /*<<< orphan*/ mult(double *, double *, int, int, int, int, double **);
int /*<<< orphan*/ print(double *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ zeros(int, int, double **);
void testLU() {
  double *mat;
  zeros(2, 2, &mat);
  mat[0] = 1;
  mat[1] = 2;
  mat[1 * 2] = 3;
  mat[1 * 2 + 1] = 4;
  double *b;
  zeros(2, 1, &b);
  b[0] = 1;
  b[1] = 2;
  double *L, *U, *z, *x;
  zeros(2, 2, &L);
  zeros(2, 2, &U);
  zeros(2, 1, &z);
  zeros(2, 1, &x);
  printf("A\n");
  print(mat, 2, 2);
  printf("B\n");
  print(b, 2, 1);
  LUDecomposition(mat, 2, &L, &U);
  printf("L\n");
  print(L, 2, 2);
  printf("U\n");
  print(U, 2, 2);
  BackSubstitution(L, b, 2, &z, 1);
  BackSubstitution(U, z, 2, &x, 0);
  printf("x\n");
  print(x, 2, 1);
  double *bstar;
  zeros(2, 1, &bstar);
  mult(mat, x, 2, 2, 2, 1, &bstar);
  print(bstar, 2, 1);
}


x86 assembly (clang, -O0):
<testLU>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x2,%esi
lea    -0x8(%rbp),%rdx
mov    %esi,%edi
call   1080 <zeros@plt>
mov    -0x8(%rbp),%rax
movsd  0xe84(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe6c(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe73(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe5a(%rip),%xmm0
movsd  %xmm0,0x18(%rax)
mov    $0x2,%edi
mov    $0x1,%esi
lea    -0x10(%rbp),%rdx
call   1080 <zeros@plt>
mov    -0x10(%rbp),%rax
movsd  0xe2e(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe16(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    $0x2,%esi
lea    -0x18(%rbp),%rdx
mov    %esi,%edi
call   1080 <zeros@plt>
mov    $0x2,%esi
lea    -0x20(%rbp),%rdx
mov    %esi,%edi
call   1080 <zeros@plt>
mov    $0x2,%edi
mov    $0x1,%esi
lea    -0x28(%rbp),%rdx
call   1080 <zeros@plt>
mov    $0x2,%edi
mov    $0x1,%esi
lea    -0x30(%rbp),%rdx
call   1080 <zeros@plt>
lea    0xde4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%edx
mov    %edx,%esi
call   1050 <print@plt>
lea    0xdcb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <LUDecomposition@plt>
lea    0xd99(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2,%edx
mov    %edx,%esi
call   1050 <print@plt>
lea    0xd80(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2,%edx
mov    %edx,%esi
call   1050 <print@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
lea    -0x28(%rbp),%rcx
mov    $0x1,%r8d
call   1040 <BackSubstitution@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x2,%edx
lea    -0x30(%rbp),%rcx
xor    %r8d,%r8d
call   1040 <BackSubstitution@plt>
lea    0xd32(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
mov    $0x2,%edi
mov    $0x1,%esi
lea    -0x38(%rbp),%rdx
call   1080 <zeros@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x2,%r8d
mov    $0x1,%r9d
lea    -0x38(%rbp),%rax
mov    %r8d,%edx
mov    %r8d,%ecx
mov    %rax,(%rsp)
call   1070 <mult@plt>
mov    -0x38(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testLU>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0x10(%rsp),%rdx
mov    $0x2,%edi
mov    $0x2,%esi
call   1080 <zeros@plt>
mov    0x10(%rsp),%rax
movaps 0xe75(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe7b(%rip),%xmm0
movups %xmm0,0x10(%rax)
lea    0x18(%rsp),%rdx
mov    $0x2,%edi
mov    $0x1,%esi
call   1080 <zeros@plt>
mov    0x18(%rsp),%rax
movaps 0xe47(%rip),%xmm0
movups %xmm0,(%rax)
lea    0x30(%rsp),%r12
mov    $0x2,%edi
mov    $0x2,%esi
mov    %r12,%rdx
call   1080 <zeros@plt>
lea    0x28(%rsp),%rbx
mov    $0x2,%edi
mov    $0x2,%esi
mov    %rbx,%rdx
call   1080 <zeros@plt>
lea    0x40(%rsp),%r15
mov    $0x2,%edi
mov    $0x1,%esi
mov    %r15,%rdx
call   1080 <zeros@plt>
lea    0x20(%rsp),%r14
mov    $0x2,%edi
mov    $0x1,%esi
mov    %r14,%rdx
call   1080 <zeros@plt>
lea    0xe01(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%rdi
mov    $0x2,%esi
mov    $0x2,%edx
call   1050 <print@plt>
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
mov    0x10(%rsp),%rdi
mov    $0x2,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1060 <LUDecomposition@plt>
lea    0xdb0(%rip),%rdi
call   1030 <puts@plt>
mov    0x30(%rsp),%rdi
mov    $0x2,%esi
mov    $0x2,%edx
call   1050 <print@plt>
lea    0xd92(%rip),%rdi
call   1030 <puts@plt>
mov    0x28(%rsp),%rdi
mov    $0x2,%esi
mov    $0x2,%edx
call   1050 <print@plt>
mov    0x30(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    $0x2,%edx
mov    %r15,%rcx
mov    $0x1,%r8d
call   1040 <BackSubstitution@plt>
mov    0x28(%rsp),%rdi
mov    0x40(%rsp),%rsi
mov    $0x2,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1040 <BackSubstitution@plt>
lea    0xd3d(%rip),%rdi
call   1030 <puts@plt>
mov    0x20(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
lea    0x38(%rsp),%rbx
mov    $0x2,%edi
mov    $0x1,%esi
mov    %rbx,%rdx
call   1080 <zeros@plt>
mov    0x10(%rsp),%rdi
mov    0x20(%rsp),%rsi
mov    %rbx,(%rsp)
mov    $0x2,%edx
mov    $0x2,%ecx
mov    $0x2,%r8d
mov    $0x1,%r9d
call   1070 <mult@plt>
mov    0x38(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <print@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"A\0A\00"
@.str.1 = [3 x i8] c"B\0A\00"
@.str.2 = [3 x i8] c"L\0A\00"
@.str.3 = [3 x i8] c"U\0A\00"
@.str.4 = [3 x i8] c"x\0A\00"
define void @testLU() {
%1 = alloca double*
%2 = alloca double*
%3 = alloca double*
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = call i32 @zeros(i32 2, i32 2, double** %1)
%9 = load double*, double** %1
%10 = getelementptr inbounds double, double* %9, i64 0
store double 1.000000e+00, double* %10
%11 = load double*, double** %1
%12 = getelementptr inbounds double, double* %11, i64 1
store double 2.000000e+00, double* %12
%13 = load double*, double** %1
%14 = getelementptr inbounds double, double* %13, i64 2
store double 3.000000e+00, double* %14
%15 = load double*, double** %1
%16 = getelementptr inbounds double, double* %15, i64 3
store double 4.000000e+00, double* %16
%17 = call i32 @zeros(i32 2, i32 1, double** %2)
%18 = load double*, double** %2
%19 = getelementptr inbounds double, double* %18, i64 0
store double 1.000000e+00, double* %19
%20 = load double*, double** %2
%21 = getelementptr inbounds double, double* %20, i64 1
store double 2.000000e+00, double* %21
%22 = call i32 @zeros(i32 2, i32 2, double** %3)
%23 = call i32 @zeros(i32 2, i32 2, double** %4)
%24 = call i32 @zeros(i32 2, i32 1, double** %5)
%25 = call i32 @zeros(i32 2, i32 1, double** %6)
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%27 = load double*, double** %1
%28 = call i32 @print(double* %27, i32 2, i32 2)
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = load double*, double** %2
%31 = call i32 @print(double* %30, i32 2, i32 1)
%32 = load double*, double** %1
%33 = call i32 @LUDecomposition(double* %32, i32 2, double** %3, double** %4)
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%35 = load double*, double** %3
%36 = call i32 @print(double* %35, i32 2, i32 2)
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%38 = load double*, double** %4
%39 = call i32 @print(double* %38, i32 2, i32 2)
%40 = load double*, double** %3
%41 = load double*, double** %2
%42 = call i32 @BackSubstitution(double* %40, double* %41, i32 2, double** %5, i32 1)
%43 = load double*, double** %4
%44 = load double*, double** %5
%45 = call i32 @BackSubstitution(double* %43, double* %44, i32 2, double** %6, i32 0)
%46 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%47 = load double*, double** %6
%48 = call i32 @print(double* %47, i32 2, i32 1)
%49 = call i32 @zeros(i32 2, i32 1, double** %7)
%50 = load double*, double** %1
%51 = load double*, double** %6
%52 = call i32 @mult(double* %50, double* %51, i32 2, i32 2, i32 2, i32 1, double** %7)
%53 = load double*, double** %7
%54 = call i32 @print(double* %53, i32 2, i32 1)
ret void
}

LLVM IR (-O2):
@str = [2 x i8] c"A\00"
@str.5 = [2 x i8] c"B\00"
@str.6 = [2 x i8] c"L\00"
@str.7 = [2 x i8] c"U\00"
@str.8 = [2 x i8] c"x\00"
define void @testLU() {
%1 = alloca double*
%2 = alloca double*
%3 = alloca double*
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = bitcast double** %1 to i8*
%9 = call i32 @zeros(i32 2, i32 2, double** %1)
%10 = load double*, double** %1
%11 = bitcast double* %10 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 2.000000e+00>, <2 x double>* %11
%12 = getelementptr inbounds double, double* %10, i64 2
%13 = bitcast double* %12 to <2 x double>*
store <2 x double> <double 3.000000e+00, double 4.000000e+00>, <2 x double>* %13
%14 = bitcast double** %2 to i8*
%15 = call i32 @zeros(i32 2, i32 1, double** %2)
%16 = bitcast double** %2 to <2 x double>**
%17 = load <2 x double>*, <2 x double>** %16
store <2 x double> <double 1.000000e+00, double 2.000000e+00>, <2 x double>* %17
%18 = bitcast double** %3 to i8*
%19 = bitcast double** %4 to i8*
%20 = bitcast double** %5 to i8*
%21 = bitcast double** %6 to i8*
%22 = call i32 @zeros(i32 2, i32 2, double** %3)
%23 = call i32 @zeros(i32 2, i32 2, double** %4)
%24 = call i32 @zeros(i32 2, i32 1, double** %5)
%25 = call i32 @zeros(i32 2, i32 1, double** %6)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%27 = load double*, double** %1
%28 = call i32 @print(double* %27, i32 2, i32 2)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%30 = load double*, double** %2
%31 = call i32 @print(double* %30, i32 2, i32 1)
%32 = load double*, double** %1
%33 = call i32 @LUDecomposition(double* %32, i32 2, double** %3, double** %4)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0))
%35 = load double*, double** %3
%36 = call i32 @print(double* %35, i32 2, i32 2)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0))
%38 = load double*, double** %4
%39 = call i32 @print(double* %38, i32 2, i32 2)
%40 = load double*, double** %3
%41 = load double*, double** %2
%42 = call i32 @BackSubstitution(double* %40, double* %41, i32 2, double** %5, i32 1)
%43 = load double*, double** %4
%44 = load double*, double** %5
%45 = call i32 @BackSubstitution(double* %43, double* %44, i32 2, double** %6, i32 0)
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.8, i64 0, i64 0))
%47 = load double*, double** %6
%48 = call i32 @print(double* %47, i32 2, i32 1)
%49 = bitcast double** %7 to i8*
%50 = call i32 @zeros(i32 2, i32 1, double** %7)
%51 = load double*, double** %1
%52 = load double*, double** %6
%53 = call i32 @mult(double* %51, double* %52, i32 2, i32 2, i32 2, i32 1, double** %7)
%54 = load double*, double** %7
%55 = call i32 @print(double* %54, i32 2, i32 1)
ret void
}