#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 choldc(double *, int, double *);
int /*<<< orphan*/ cholsl(double *, int, double *, double *, double *);
int /*<<< orphan*/ copyarr(double *, double *, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int solvit(double *prod, double *rhs, int n, double *ans) {
  double *ttt;
  double *b;
  double *p;
  int i;
  int ret;
  if ((ttt = (double *)calloc((n * n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n * n);
  if ((p = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  if ((b = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  copyarr(prod, ttt, n * n);
  copyarr(rhs, b, n);
  ret = choldc(ttt, n, p);
  if (ret < 0)
    return -1;
  cholsl(ttt, n, p, b, ans);
  free(ttt);
  free(b);
  free(p);
  return 1;
}


x86 assembly (clang, -O0):
<solvit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
imul   -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11a9 <solvit+0x49>
mov    -0x1c(%rbp),%esi
imul   -0x1c(%rbp),%esi
lea    0xe5c(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11d3 <solvit+0x73>
mov    -0x1c(%rbp),%esi
lea    0xe32(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11fd <solvit+0x9d>
mov    -0x1c(%rbp),%esi
lea    0xe08(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
imul   -0x1c(%rbp),%edx
call   1070 <copyarr@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <copyarr@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x40(%rbp),%rdx
call   1040 <choldc@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    124a <solvit+0xea>
movl   $0xffffffff,-0x4(%rbp)
jmp    1284 <solvit+0x124>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1080 <cholsl@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solvit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%ebp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r14
mov    %edx,%ebx
imul   %edx,%ebx
mov    %ebx,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11a4 <solvit+0x44>
lea    0xe63(%rip),%rdi
mov    %ebx,%esi
call   1050 <fatalx@plt>
mov    %ebp,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11c6 <solvit+0x66>
lea    0xe41(%rip),%rdi
mov    %ebp,%esi
call   1050 <fatalx@plt>
mov    %ebp,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11e8 <solvit+0x88>
lea    0xe1f(%rip),%rdi
mov    %ebp,%esi
call   1050 <fatalx@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1070 <copyarr@plt>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1070 <copyarr@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1040 <choldc@plt>
test   %eax,%eax
js     1249 <solvit+0xe9>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r12,%rcx
mov    0x8(%rsp),%r8
call   1080 <cholsl@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    124e <solvit+0xee>
mov    $0xffffffff,%eax
add    $0x18,%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 @solvit(double* %0, double* %1, i32 %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store i32 %2, i32* %8
store double* %3, double** %9
%15 = load i32, i32* %8
%16 = load i32, i32* %8
%17 = mul nsw i32 %15, %16
%18 = call i64 @calloc(i32 %17, i32 8)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %10
%20 = icmp eq double* %19, null
br i1 %20, label %21, label %26
21: ; preds = %4
%22 = load i32, i32* %8
%23 = load i32, i32* %8
%24 = mul nsw i32 %22, %23
%25 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %21, %4
%27 = load i32, i32* %8
%28 = call i64 @calloc(i32 %27, i32 8)
%29 = inttoptr i64 %28 to double*
store double* %29, double** %12
%30 = icmp eq double* %29, null
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* %8
%33 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %26
%35 = load i32, i32* %8
%36 = call i64 @calloc(i32 %35, i32 8)
%37 = inttoptr i64 %36 to double*
store double* %37, double** %11
%38 = icmp eq double* %37, null
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i32, i32* %8
%41 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %34
%43 = load double*, double** %6
%44 = load double*, double** %10
%45 = load i32, i32* %8
%46 = load i32, i32* %8
%47 = mul nsw i32 %45, %46
%48 = call i32 @copyarr(double* %43, double* %44, i32 %47)
%49 = load double*, double** %7
%50 = load double*, double** %11
%51 = load i32, i32* %8
%52 = call i32 @copyarr(double* %49, double* %50, i32 %51)
%53 = load double*, double** %10
%54 = load i32, i32* %8
%55 = load double*, double** %12
%56 = call i32 @choldc(double* %53, i32 %54, double* %55)
store i32 %56, i32* %14
%57 = load i32, i32* %14
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %42
store i32 -1, i32* %5
br label %73
60: ; preds = %42
%61 = load double*, double** %10
%62 = load i32, i32* %8
%63 = load double*, double** %12
%64 = load double*, double** %11
%65 = load double*, double** %9
%66 = call i32 @cholsl(double* %61, i32 %62, double* %63, double* %64, double* %65)
%67 = load double*, double** %10
%68 = call i32 @free(double* %67)
%69 = load double*, double** %11
%70 = call i32 @free(double* %69)
%71 = load double*, double** %12
%72 = call i32 @free(double* %71)
store i32 1, i32* %5
br label %73
73: ; preds = %60, %59
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define i32 @solvit(double* %0, double* %1, i32 %2, double* %3) {
%5 = mul nsw i32 %2, %2
%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 %2, 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 %2)
br label %17
17: ; preds = %15, %11
%18 = tail call i64 @calloc(i32 %2, i32 8)
%19 = inttoptr i64 %18 to double*
%20 = icmp eq i64 %18, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %23
23: ; preds = %21, %17
%24 = tail call i32 @copyarr(double* %0, double* %7, i32 %5)
%25 = tail call i32 @copyarr(double* %1, double* %19, i32 %2)
%26 = tail call i32 @choldc(double* %7, i32 %2, double* %13)
%27 = icmp slt i32 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %23
%29 = tail call i32 @cholsl(double* %7, i32 %2, double* %13, double* %19, double* %3)
%30 = tail call i32 @free(double* %7)
%31 = tail call i32 @free(double* %19)
%32 = tail call i32 @free(double* %13)
br label %33
33: ; preds = %23, %28
%34 = phi i32 [ 1, %28 ], [ -1, %23 ]
ret i32 %34
}