#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(int *);
int gauss_make_triangular(double *, int *, int);
int /*<<< orphan*/ gauss_solve_triangular(double *, int *, double *, int);
int *malloc(int);
int gauss_solve(double *A, double *b, int n) {
  int *p = malloc(n * sizeof(*p));
  int err_code = 1;
  if ((err_code = gauss_make_triangular(A, p, n)))
    gauss_solve_triangular(A, p, b, n);
  free(p);
  return err_code;
}


x86 assembly (clang, -O0):
<gauss_solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <gauss_make_triangular@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     119d <gauss_solve+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1060 <gauss_solve_triangular@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauss_solve>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x0(,%r15,4),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1040 <gauss_make_triangular@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1186 <gauss_solve+0x46>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1060 <gauss_solve_triangular@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gauss_solve(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i32* @malloc(i32 %12)
store i32* %13, i32** %7
store i32 1, i32* %8
%14 = load double*, double** %4
%15 = load i32*, i32** %7
%16 = load i32, i32* %6
%17 = call i32 @gauss_make_triangular(double* %14, i32* %15, i32 %16)
store i32 %17, i32* %8
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %3
%20 = load double*, double** %4
%21 = load i32*, i32** %7
%22 = load double*, double** %5
%23 = load i32, i32* %6
%24 = call i32 @gauss_solve_triangular(double* %20, i32* %21, double* %22, i32 %23)
br label %25
25: ; preds = %19, %3
%26 = load i32*, i32** %7
%27 = call i32 @free(i32* %26)
%28 = load i32, i32* %8
ret i32 %28
}

LLVM IR (-O2):
define i32 @gauss_solve(double* %0, double* %1, i32 %2) {
%4 = shl i32 %2, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = tail call i32 @gauss_make_triangular(double* %0, i32* %5, i32 %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @gauss_solve_triangular(double* %0, i32* %5, double* %1, i32 %2)
br label %10
10: ; preds = %8, %3
%11 = tail call i32 @free(i32* %5)
ret i32 %6
}