#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ copyarr(double *, double *, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int linsolvx(int, double *, double *, double *);
int linsolv(int n, double *pfMatr, double *pfVect, double *sol) {
  int ret;
  double *a, *rhs;
  if ((a = (double *)calloc((n * n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n * n);
  if ((rhs = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  copyarr(pfMatr, a, n * n);
  copyarr(pfVect, rhs, n);
  ret = linsolvx(n, a, rhs, sol);
  free(a);
  free(rhs);
  return ret;
}


x86 assembly (clang, -O0):
<linsolv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
imul   -0x4(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1199 <linsolv+0x49>
mov    -0x4(%rbp),%esi
imul   -0x4(%rbp),%esi
lea    0xe6c(%rip),%rdi
call   1040 <fatalx@plt>
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11c3 <linsolv+0x73>
mov    -0x4(%rbp),%esi
lea    0xe42(%rip),%rdi
call   1040 <fatalx@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x4(%rbp),%edx
imul   -0x4(%rbp),%edx
call   1060 <copyarr@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1060 <copyarr@plt>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1070 <linsolvx@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linsolv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %rdx,%r15
mov    %rsi,%r13
mov    %edi,%ebx
mov    %edi,%ebp
imul   %edi,%ebp
mov    %ebp,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    118e <linsolv+0x3e>
lea    0xe79(%rip),%rdi
mov    %ebp,%esi
call   1040 <fatalx@plt>
mov    %ebx,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11b0 <linsolv+0x60>
lea    0xe57(%rip),%rdi
mov    %ebx,%esi
call   1040 <fatalx@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1060 <copyarr@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <copyarr@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r14,%rdx
mov    (%rsp),%rcx
call   1070 <linsolvx@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define i32 @linsolv(i32 %0, double* %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%12 = load i32, i32* %5
%13 = load i32, i32* %5
%14 = mul nsw i32 %12, %13
%15 = call i64 @calloc(i32 %14, i32 8)
%16 = inttoptr i64 %15 to double*
store double* %16, double** %10
%17 = icmp eq double* %16, null
br i1 %17, label %18, label %23
18: ; preds = %4
%19 = load i32, i32* %5
%20 = load i32, i32* %5
%21 = mul nsw i32 %19, %20
%22 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %18, %4
%24 = load i32, i32* %5
%25 = call i64 @calloc(i32 %24, i32 8)
%26 = inttoptr i64 %25 to double*
store double* %26, double** %11
%27 = icmp eq double* %26, null
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32, i32* %5
%30 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28, %23
%32 = load double*, double** %6
%33 = load double*, double** %10
%34 = load i32, i32* %5
%35 = load i32, i32* %5
%36 = mul nsw i32 %34, %35
%37 = call i32 @copyarr(double* %32, double* %33, i32 %36)
%38 = load double*, double** %7
%39 = load double*, double** %11
%40 = load i32, i32* %5
%41 = call i32 @copyarr(double* %38, double* %39, i32 %40)
%42 = load i32, i32* %5
%43 = load double*, double** %10
%44 = load double*, double** %11
%45 = load double*, double** %8
%46 = call i32 @linsolvx(i32 %42, double* %43, double* %44, double* %45)
store i32 %46, i32* %9
%47 = load double*, double** %10
%48 = call i32 @free(double* %47)
%49 = load double*, double** %11
%50 = call i32 @free(double* %49)
%51 = load i32, i32* %9
ret i32 %51
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define i32 @linsolv(i32 %0, double* %1, double* %2, double* %3) {
%5 = mul nsw i32 %0, %0
%6 = tail call i64 @calloc(i32 %5, i32 8)
%7 = inttoptr i64 %6 to double*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %11
11: ; preds = %9, %4
%12 = tail call i64 @calloc(i32 %0, i32 8)
%13 = inttoptr i64 %12 to double*
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %17
17: ; preds = %15, %11
%18 = tail call i32 @copyarr(double* %1, double* %7, i32 %5)
%19 = tail call i32 @copyarr(double* %2, double* %13, i32 %0)
%20 = tail call i32 @linsolvx(i32 %0, double* %7, double* %13, double* %3)
%21 = tail call i32 @free(double* %7)
%22 = tail call i32 @free(double* %13)
ret i32 %20
}