#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*/ free(double *);
double *mat(int, int);
int /*<<< orphan*/ matcpy(double *, double const *, int, int);
int matinv(double *, int);
int /*<<< orphan*/ matmul(char *, int, int, int, double, double *,
                          double const *, double, double *);
extern int solve(const char *tr, const double *A, const double *Y, int n, int m,
                 double *X) {
  double *B = mat(n, n);
  int info;
  matcpy(B, A, n, n);
  if (!(info = matinv(B, n)))
    matmul(tr[0] == 'N' ? "NN" : "TN", n, m, n, 1.0, B, Y, 0.0, X);
  free(B);
  return info;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <mat@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1070 <matcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <matinv@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    11ee <solve+0x9e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
lea    0xe54(%rip),%rdi
lea    0xe4a(%rip),%rax
cmp    $0x4e,%ecx
cmove  %rax,%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x28(%rbp),%rax
movsd  0xe1e(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %rax,(%rsp)
call   1060 <matmul@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r12
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %rdx,0x10(%rsp)
mov    %rsi,%r13
mov    %rdi,%r14
mov    %ecx,%edi
mov    %ecx,%esi
call   1040 <mat@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    %ebx,%ecx
call   1070 <matcpy@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1050 <matinv@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    11d6 <solve+0x86>
cmpb   $0x4e,(%r14)
lea    0xe60(%rip),%rax
lea    0xe5c(%rip),%rdi
cmove  %rax,%rdi
mov    %r12,(%rsp)
movsd  0xe41(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %ebx,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %rbp,%r8
mov    0x10(%rsp),%r9
call   1060 <matmul@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"NN\00"
@.str.1 = [3 x i8] c"TN\00"
define i32 @solve(i8* %0, double* %1, double* %2, i32 %3, i32 %4, double* %5) {
%7 = alloca i8*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32
store i8* %0, i8** %7
store double* %1, double** %8
store double* %2, double** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store double* %5, double** %12
%15 = load i32, i32* %10
%16 = load i32, i32* %10
%17 = call double* @mat(i32 %15, i32 %16)
store double* %17, double** %13
%18 = load double*, double** %13
%19 = load double*, double** %8
%20 = load i32, i32* %10
%21 = load i32, i32* %10
%22 = call i32 @matcpy(double* %18, double* %19, i32 %20, i32 %21)
%23 = load double*, double** %13
%24 = load i32, i32* %10
%25 = call i32 @matinv(double* %23, i32 %24)
store i32 %25, i32* %14
%26 = icmp ne i32 %25, 0
br i1 %26, label %42, label %27
27: ; preds = %6
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 78
%33 = zext i1 %32 to i64
%34 = select i1 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%35 = load i32, i32* %10
%36 = load i32, i32* %11
%37 = load i32, i32* %10
%38 = load double*, double** %13
%39 = load double*, double** %9
%40 = load double*, double** %12
%41 = call i32 @matmul(i8* %34, i32 %35, i32 %36, i32 %37, double 1.000000e+00, double* %38, double* %39, double 0.000000e+00, double* %40)
br label %42
42: ; preds = %27, %6
%43 = load double*, double** %13
%44 = call i32 @free(double* %43)
%45 = load i32, i32* %14
ret i32 %45
}

LLVM IR (-O2):
@.str = [3 x i8] c"NN\00"
@.str.1 = [3 x i8] c"TN\00"
define i32 @solve(i8* nocapture %0, double* %1, double* %2, i32 %3, i32 %4, double* %5) {
%7 = tail call double* @mat(i32 %3, i32 %3)
%8 = tail call i32 @matcpy(double* %7, double* %1, i32 %3, i32 %3)
%9 = tail call i32 @matinv(double* %7, i32 %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 78
%14 = select i1 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%15 = tail call i32 @matmul(i8* %14, i32 %3, i32 %4, i32 %3, double 1.000000e+00, double* %7, double* %2, double 0.000000e+00, double* %5)
br label %16
16: ; preds = %11, %6
%17 = tail call i32 @free(double* %7)
ret i32 %9
}