#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 mat3_det(double **);
int /*<<< orphan*/ memcpy(double **, double **, int);
void mat3_solve(double x[3], double A[3][3], const double b[3]) {
  int i, j;
  double dA, dT, T[3][3];
  dA = mat3_det(A);
  for (i = 0; i < 3; i++) {
    memcpy(T, A, sizeof(double) * 9);
    for (j = 0; j < 3; j++)
      T[j][i] = b[j];
    dT = mat3_det(T);
    x[i] = dT / dA;
  }
}


x86 assembly (clang, -O0):
<mat3_solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <mat3_det@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    11df <mat3_solve+0xbf>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x48,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jge    11ac <mat3_solve+0x8c>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0x20(%rbp),%rcx
lea    -0x80(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116f <mat3_solve+0x4f>
lea    -0x80(%rbp),%rdi
call   1030 <mat3_det@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <mat3_solve+0x2c>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat3_solve>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <mat3_det@plt>
movsd  %xmm0,0x8(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x48,%edx
call   1040 <memcpy@plt>
movsd  (%rbx),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rbx),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x10(%rbx),%xmm0
movsd  %xmm0,0x40(%rsp)
mov    %r15,%rdi
call   1030 <mat3_det@plt>
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x48,%edx
call   1040 <memcpy@plt>
movsd  (%rbx),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rbx),%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  0x10(%rbx),%xmm0
movsd  %xmm0,0x48(%rsp)
mov    %r15,%rdi
call   1030 <mat3_det@plt>
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%r14)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x48,%edx
call   1040 <memcpy@plt>
movsd  (%rbx),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rbx),%xmm0
movsd  %xmm0,0x38(%rsp)
movsd  0x10(%rbx),%xmm0
movsd  %xmm0,0x50(%rsp)
mov    %r15,%rdi
call   1030 <mat3_det@plt>
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%r14)
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @mat3_solve(double* %0, [3 x double]* %1, double* %2) {
%4 = alloca double*
%5 = alloca [3 x double]*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca [3 x [3 x double]]
store double* %0, double** %4
store [3 x double]* %1, [3 x double]** %5
store double* %2, double** %6
%12 = load [3 x double]*, [3 x double]** %5
%13 = bitcast [3 x double]* %12 to double**
%14 = call double @mat3_det(double** %13)
store double %14, double* %9
store i32 0, i32* %7
br label %15
15: ; preds = %53, %3
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %56
18: ; preds = %15
%19 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%20 = bitcast [3 x double]* %19 to double**
%21 = load [3 x double]*, [3 x double]** %5
%22 = bitcast [3 x double]* %21 to double**
%23 = call i32 @memcpy(double** %20, double** %22, i32 72)
store i32 0, i32* %8
br label %24
24: ; preds = %39, %18
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %42
27: ; preds = %24
%28 = load double*, double** %6
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 %34
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [3 x double], [3 x double]* %35, i64 0, i64 %37
store double %32, double* %38
br label %39
39: ; preds = %27
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %24
42: ; preds = %24
%43 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%44 = bitcast [3 x double]* %43 to double**
%45 = call double @mat3_det(double** %44)
store double %45, double* %10
%46 = load double, double* %10
%47 = load double, double* %9
%48 = fdiv double %46, %47
%49 = load double*, double** %4
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
store double %48, double* %52
br label %53
53: ; preds = %42
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %15
56: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @mat3_solve(double* nocapture writeonly %0, [3 x double]* %1, double* nocapture %2) {
%4 = alloca [3 x [3 x double]]
%5 = bitcast [3 x [3 x double]]* %4 to i8*
%6 = bitcast [3 x double]* %1 to double**
%7 = tail call double @mat3_det(double** %6)
%8 = bitcast [3 x [3 x double]]* %4 to double**
%9 = call i32 @memcpy(double** %8, double** %6, i32 72)
%10 = load double, double* %2
%11 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 0, i64 0
store double %10, double* %11
%12 = getelementptr inbounds double, double* %2, i64 1
%13 = load double, double* %12
%14 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 1, i64 0
store double %13, double* %14
%15 = getelementptr inbounds double, double* %2, i64 2
%16 = load double, double* %15
%17 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 2, i64 0
store double %16, double* %17
%18 = call double @mat3_det(double** %8)
%19 = fdiv double %18, %7
store double %19, double* %0
%20 = call i32 @memcpy(double** %8, double** %6, i32 72)
%21 = load double, double* %2
%22 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 0, i64 1
store double %21, double* %22
%23 = load double, double* %12
%24 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 1, i64 1
store double %23, double* %24
%25 = load double, double* %15
%26 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 2, i64 1
store double %25, double* %26
%27 = call double @mat3_det(double** %8)
%28 = fdiv double %27, %7
%29 = getelementptr inbounds double, double* %0, i64 1
store double %28, double* %29
%30 = call i32 @memcpy(double** %8, double** %6, i32 72)
%31 = load double, double* %2
%32 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 0, i64 2
store double %31, double* %32
%33 = load double, double* %12
%34 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 1, i64 2
store double %33, double* %34
%35 = load double, double* %15
%36 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 2, i64 2
store double %35, double* %36
%37 = call double @mat3_det(double** %8)
%38 = fdiv double %37, %7
%39 = getelementptr inbounds double, double* %0, i64 2
store double %38, double* %39
ret void
}