#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 alloc_symm_matrix(double ***, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ free_matrix(double **, int);
double *malloc(int);
int posdef_positive_solver_fast(double **, double *, double *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ transpose_and_multiply(double **, double **, int);
int /*<<< orphan*/ transpose_and_multiply_matrix_vector(double **, double *,
                                                        int, double *);
int positive_solver(double **A, double *x, double *b, int n) {
  int status = 0;
  double **AtA = NULL;
  double *Atb = NULL;
  status = alloc_symm_matrix(&AtA, n);
  {
    if ((status) < 0) {
      {
        {
          fprintf(stderr, "Line %3d of File %s \n", 243,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                  "heads/master/OPERATORS/AX_EQUALS_B/src/positive_solver.c");
        };
        status = (status);
        goto BYE;
      }
    }
  };
  Atb = malloc(n * sizeof(double));
  {
    if (Atb == NULL) {
      fprintf(stderr, "Unable to allocate memory\n");
      {
        {
          fprintf(stderr, "Line %3d of File %s \n", 244,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                  "heads/master/OPERATORS/AX_EQUALS_B/src/positive_solver.c");
        };
        status = -1;
        goto BYE;
      };
    }
  };
  transpose_and_multiply(A, AtA, n);
  transpose_and_multiply_matrix_vector(A, b, n, Atb);
  status = posdef_positive_solver_fast(AtA, x, Atb, n);
  {
    if ((status) < 0) {
      {
        {
          fprintf(stderr, "Line %3d of File %s \n", 248,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/"
                  "heads/master/OPERATORS/AX_EQUALS_B/src/positive_solver.c");
        };
        status = (status);
        goto BYE;
      }
    }
  };
BYE:
  free_matrix(AtA, n);
  {
    if ((Atb) != NULL) {
      free((Atb));
      (Atb) = NULL;
    }
  };
  return status;
}


x86 assembly (clang, -O0):
<positive_solver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x1c(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   1060 <alloc_symm_matrix@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11f5 <positive_solver+0x75>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0xf3,%edx
lea    0xe33(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    12d1 <positive_solver+0x151>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1259 <positive_solver+0xd9>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
mov    $0xf4,%edx
lea    0xdd0(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x20(%rbp)
jmp    12d1 <positive_solver+0x151>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10a0 <transpose_and_multiply@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1070 <transpose_and_multiply_matrix_vector@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1080 <posdef_positive_solver_fast@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12cc <positive_solver+0x14c>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
mov    $0xf8,%edx
lea    0xd5c(%rip),%rcx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    12d1 <positive_solver+0x151>
jmp    12d1 <positive_solver+0x151>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <free_matrix@plt>
cmpq   $0x0,-0x30(%rbp)
je     12f9 <positive_solver+0x179>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<positive_solver>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r13
movq   $0x0,(%rsp)
mov    %rsp,%rdi
mov    %ecx,%esi
call   1060 <alloc_symm_matrix@plt>
test   %eax,%eax
js     1231 <positive_solver+0xb1>
lea    0x0(,%rbx,8),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     123a <positive_solver+0xba>
mov    %rax,%r14
mov    (%rsp),%rsi
mov    %r13,%rdi
mov    %ebx,%edx
call   10a0 <transpose_and_multiply@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %r14,%rcx
call   1070 <transpose_and_multiply_matrix_vector@plt>
mov    (%rsp),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1080 <posdef_positive_solver_fast@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    121c <positive_solver+0x9c>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
lea    0xe06(%rip),%rcx
mov    $0xf8,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rsp),%rdi
mov    %ebx,%esi
call   1040 <free_matrix@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1284 <positive_solver+0x104>
mov    %eax,%ebp
mov    $0xf3,%edx
jmp    125b <positive_solver+0xdb>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    $0xf4,%edx
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
lea    0xda4(%rip),%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rsp),%rdi
mov    %ebx,%esi
call   1040 <free_matrix@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Line %3d of File %s \0A\00"
@.str.1 = [168 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/master/OPERATORS/AX_EQUALS_B/src/positive_solver.c\00"
@.str.2 = [27 x i8] c"Unable to allocate memory\0A\00"
define i32 @positive_solver(double** %0, double* %1, double* %2, i32 %3) {
%5 = alloca double**
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double**
%11 = alloca double*
store double** %0, double*** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
store i32 0, i32* %9
store double** null, double*** %10
store double* null, double** %11
%12 = load i32, i32* %8
%13 = call i32 @alloc_symm_matrix(double*** %10, i32 %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 243, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* %9
store i32 %19, i32* %9
br label %55
20: ; preds = %4
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call double* @malloc(i32 %24)
store double* %25, double** %11
%26 = load double*, double** %11
%27 = icmp eq double* %26, null
br i1 %27, label %28, label %33
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 244, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %55
33: ; preds = %20
%34 = load double**, double*** %5
%35 = load double**, double*** %10
%36 = load i32, i32* %8
%37 = call i32 @transpose_and_multiply(double** %34, double** %35, i32 %36)
%38 = load double**, double*** %5
%39 = load double*, double** %7
%40 = load i32, i32* %8
%41 = load double*, double** %11
%42 = call i32 @transpose_and_multiply_matrix_vector(double** %38, double* %39, i32 %40, double* %41)
%43 = load double**, double*** %10
%44 = load double*, double** %6
%45 = load double*, double** %11
%46 = load i32, i32* %8
%47 = call i32 @posdef_positive_solver_fast(double** %43, double* %44, double* %45, i32 %46)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %33
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 248, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0))
%53 = load i32, i32* %9
store i32 %53, i32* %9
br label %55
54: ; preds = %33
br label %55
55: ; preds = %54, %50, %28, %16
%56 = load double**, double*** %10
%57 = load i32, i32* %8
%58 = call i32 @free_matrix(double** %56, i32 %57)
%59 = load double*, double** %11
%60 = icmp ne double* %59, null
br i1 %60, label %61, label %64
61: ; preds = %55
%62 = load double*, double** %11
%63 = call i32 @free(double* %62)
store double* null, double** %11
br label %64
64: ; preds = %61, %55
%65 = load i32, i32* %9
ret i32 %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Line %3d of File %s \0A\00"
@.str.1 = [168 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/NerdWalletOSS/Q/refs/heads/master/OPERATORS/AX_EQUALS_B/src/positive_solver.c\00"
@.str.2 = [27 x i8] c"Unable to allocate memory\0A\00"
define i32 @positive_solver(double** %0, double* %1, double* %2, i32 %3) {
%5 = alloca double**
%6 = bitcast double*** %5 to i8*
store double** null, double*** %5
%7 = call i32 @alloc_symm_matrix(double*** %5, i32 %3)
%8 = icmp slt i32 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %4
%10 = shl i32 %3, 3
%11 = call double* @malloc(i32 %10)
%12 = icmp eq double* %11, null
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %26
16: ; preds = %9
%17 = load double**, double*** %5
%18 = call i32 @transpose_and_multiply(double** %0, double** %17, i32 %3)
%19 = call i32 @transpose_and_multiply_matrix_vector(double** %0, double* %2, i32 %3, double* %11)
%20 = load double**, double*** %5
%21 = call i32 @posdef_positive_solver_fast(double** %20, double* %1, double* %11, i32 %3)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 248, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0))
br label %33
26: ; preds = %4, %13
%27 = phi i32 [ 244, %13 ], [ 243, %4 ]
%28 = phi i32 [ -1, %13 ], [ %7, %4 ]
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %27, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.1, i64 0, i64 0))
%31 = load double**, double*** %5
%32 = call i32 @free_matrix(double** %31, i32 %3)
br label %37
33: ; preds = %23, %16
%34 = load double**, double*** %5
%35 = call i32 @free_matrix(double** %34, i32 %3)
%36 = call i32 @free(double* %11)
br label %37
37: ; preds = %26, %33
%38 = phi i32 [ %28, %26 ], [ %21, %33 ]
ret i32 %38
}