#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 confere_solucao_linear(double **, double **, int);
int /*<<< orphan*/ free(double **);
int /*<<< orphan*/ imprime_matriz(double **, int, int, char *);
double **matriz_nula(int, int);
double **matriz_quadrada_nula(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ solucao_linear(double **, int, double **, double **,
                                  double **);
void imprime_teste_solucao_linear(double **A, double **B, double **X_ok,
                                  int dim) {
  bool correto;
  double **X, **P;
  X = matriz_nula(dim, 1);
  P = matriz_quadrada_nula(dim);
  printf("\n-------------------\n");
  printf("\nSolucao linear para o sistema: \n");
  imprime_matriz(A, dim, dim, "A = coeficientes das incognitas");
  imprime_matriz(B, dim, 1, "B = termos independentes");
  solucao_linear(A, dim, B, P, X);
  imprime_matriz(X, dim, 1, "X = resultado encontrado");
  imprime_matriz(X_ok, dim, 1, "X correto = resultado esperado");
  correto = confere_solucao_linear(X, X_ok, dim);
  if (correto) {
    printf("\nSistema resolvido com sucesso.\n");
  } else {
    printf("\nSistema nao passou nos testes.\n");
  }
  printf("\n-------------------\n");
  free(P);
  P = NULL;
  free(X);
  X = NULL;
}


x86 assembly (clang, -O0):
<imprime_teste_solucao_linear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1070 <matriz_nula@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <matriz_quadrada_nula@plt>
mov    %rax,-0x30(%rbp)
lea    0xe55(%rip),%rdi
call   1060 <printf@plt>
lea    0xe5f(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe6b(%rip),%rcx
call   1080 <imprime_matriz@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
lea    0xe73(%rip),%rcx
call   1080 <imprime_matriz@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1090 <solucao_linear@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
lea    0xe5c(%rip),%rcx
call   1080 <imprime_matriz@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
lea    0xe5d(%rip),%rcx
call   1080 <imprime_matriz@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <confere_solucao_linear@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1260 <imprime_teste_solucao_linear+0xf0>
lea    0xe53(%rip),%rdi
call   1060 <printf@plt>
jmp    126c <imprime_teste_solucao_linear+0xfc>
lea    0xe63(%rip),%rdi
call   1060 <printf@plt>
lea    0xd8d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imprime_teste_solucao_linear>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
mov    %ecx,%edi
mov    $0x1,%esi
call   1070 <matriz_nula@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1060 <matriz_quadrada_nula@plt>
mov    %rax,%r14
lea    0xf0c(%rip),%rdi
call   1040 <puts@plt>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
lea    0xe42(%rip),%rcx
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
call   1080 <imprime_matriz@plt>
lea    0xe4f(%rip),%rcx
mov    %r13,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1080 <imprime_matriz@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
call   1090 <solucao_linear@plt>
lea    0xe3f(%rip),%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1080 <imprime_matriz@plt>
lea    0xe42(%rip),%rcx
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1080 <imprime_matriz@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <confere_solucao_linear@plt>
test   %eax,%eax
lea    0xe5d(%rip),%rax
lea    0xe8b(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
lea    0xe66(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"\0A-------------------\0A\00"
@.str.1 = [34 x i8] c"\0ASolucao linear para o sistema: \0A\00"
@.str.2 = [32 x i8] c"A = coeficientes das incognitas\00"
@.str.3 = [25 x i8] c"B = termos independentes\00"
@.str.4 = [25 x i8] c"X = resultado encontrado\00"
@.str.5 = [31 x i8] c"X correto = resultado esperado\00"
@.str.6 = [33 x i8] c"\0ASistema resolvido com sucesso.\0A\00"
@.str.7 = [33 x i8] c"\0ASistema nao passou nos testes.\0A\00"
define void @imprime_teste_solucao_linear(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
%12 = load i32, i32* %8
%13 = call double** @matriz_nula(i32 %12, i32 1)
store double** %13, double*** %10
%14 = load i32, i32* %8
%15 = call double** @matriz_quadrada_nula(i32 %14)
store double** %15, double*** %11
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%18 = load double**, double*** %5
%19 = load i32, i32* %8
%20 = load i32, i32* %8
%21 = call i32 @imprime_matriz(double** %18, i32 %19, i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%22 = load double**, double*** %6
%23 = load i32, i32* %8
%24 = call i32 @imprime_matriz(double** %22, i32 %23, i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%25 = load double**, double*** %5
%26 = load i32, i32* %8
%27 = load double**, double*** %6
%28 = load double**, double*** %11
%29 = load double**, double*** %10
%30 = call i32 @solucao_linear(double** %25, i32 %26, double** %27, double** %28, double** %29)
%31 = load double**, double*** %10
%32 = load i32, i32* %8
%33 = call i32 @imprime_matriz(double** %31, i32 %32, i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%34 = load double**, double*** %7
%35 = load i32, i32* %8
%36 = call i32 @imprime_matriz(double** %34, i32 %35, i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%37 = load double**, double*** %10
%38 = load double**, double*** %7
%39 = load i32, i32* %8
%40 = call i32 @confere_solucao_linear(double** %37, double** %38, i32 %39)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %4
%44 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %47
45: ; preds = %4
%46 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %47
47: ; preds = %45, %43
%48 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%49 = load double**, double*** %11
%50 = call i32 @free(double** %49)
store double** null, double*** %11
%51 = load double**, double*** %10
%52 = call i32 @free(double** %51)
store double** null, double*** %10
ret void
}

LLVM IR (-O2):
@.str.2 = [32 x i8] c"A = coeficientes das incognitas\00"
@.str.3 = [25 x i8] c"B = termos independentes\00"
@.str.4 = [25 x i8] c"X = resultado encontrado\00"
@.str.5 = [31 x i8] c"X correto = resultado esperado\00"
@str.8 = [33 x i8] c"\0ASolucao linear para o sistema: \00"
@str.9 = [32 x i8] c"\0ASistema nao passou nos testes.\00"
@str.10 = [21 x i8] c"\0A-------------------\00"
@str.11 = [32 x i8] c"\0ASistema resolvido com sucesso.\00"
define void @imprime_teste_solucao_linear(double** %0, double** %1, double** %2, i32 %3) {
%5 = tail call double** @matriz_nula(i32 %3, i32 1)
%6 = tail call double** @matriz_quadrada_nula(i32 %3)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
%9 = tail call i32 @imprime_matriz(double** %0, i32 %3, i32 %3, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @imprime_matriz(double** %1, i32 %3, i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @solucao_linear(double** %0, i32 %3, double** %1, double** %6, double** %5)
%12 = tail call i32 @imprime_matriz(double** %5, i32 %3, i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 @imprime_matriz(double** %2, i32 %3, i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 @confere_solucao_linear(double** %5, double** %2, i32 %3)
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @str.9, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0)
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
%19 = tail call i32 @free(double** %6)
%20 = tail call i32 @free(double** %5)
ret void
}