#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 dot(double *, double *, int);
int /*<<< orphan*/ free_matrix2(double **);
int /*<<< orphan*/ inv(double **, double **, int);
double **new_matrix2(int, int);
void solve(double *x, double **A, double *b, int n) {
  double **A_inv = new_matrix2(n, n);
  inv(A_inv, A, n);
  int i;
  for (i = 0; i < n; i++)
    x[i] = dot(A_inv[i], b, n);
  free_matrix2(A_inv);
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <new_matrix2@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <inv@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11bc <solve+0x7c>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <dot@plt>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117d <solve+0x3d>
mov    -0x28(%rbp),%rdi
call   1040 <free_matrix2@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %ecx,%edi
mov    %ecx,%esi
call   1060 <new_matrix2@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1050 <inv@plt>
test   %r13d,%r13d
jle    119e <solve+0x5e>
mov    %r13d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1030 <dot@plt>
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <solve+0x40>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free_matrix2@plt>

LLVM IR (-O0):
define void @solve(double* %0, double** %1, double* %2, i32 %3) {
%5 = alloca double*
%6 = alloca double**
%7 = alloca double*
%8 = alloca i32
%9 = alloca double**
%10 = alloca i32
store double* %0, double** %5
store double** %1, double*** %6
store double* %2, double** %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = load i32, i32* %8
%13 = call double** @new_matrix2(i32 %11, i32 %12)
store double** %13, double*** %9
%14 = load double**, double*** %9
%15 = load double**, double*** %6
%16 = load i32, i32* %8
%17 = call i32 @inv(double** %14, double** %15, i32 %16)
store i32 0, i32* %10
br label %18
18: ; preds = %35, %4
%19 = load i32, i32* %10
%20 = load i32, i32* %8
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %38
22: ; preds = %18
%23 = load double**, double*** %9
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double*, double** %23, i64 %25
%27 = load double*, double** %26
%28 = load double*, double** %7
%29 = load i32, i32* %8
%30 = call double @dot(double* %27, double* %28, i32 %29)
%31 = load double*, double** %5
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double %30, double* %34
br label %35
35: ; preds = %22
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %18
38: ; preds = %18
%39 = load double**, double*** %9
%40 = call i32 @free_matrix2(double** %39)
ret void
}

LLVM IR (-O2):
define void @solve(double* nocapture writeonly %0, double** %1, double* %2, i32 %3) {
%5 = tail call double** @new_matrix2(i32 %3, i32 %3)
%6 = tail call i32 @inv(double** %5, double** %1, i32 %3)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %18
8: ; preds = %4
%9 = zext i32 %3 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %16, %10 ]
%12 = getelementptr inbounds double*, double** %5, i64 %11
%13 = load double*, double** %12
%14 = tail call double @dot(double* %13, double* %2, i32 %3)
%15 = getelementptr inbounds double, double* %0, i64 %11
store double %14, double* %15
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %9
br i1 %17, label %18, label %10
18: ; preds = %10, %4
%19 = tail call i32 @free_matrix2(double** %5)
ret void
}