#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ generate(float *, int, int /*<<< orphan*/ *);
int getsize(int /*<<< orphan*/ *);
int /*<<< orphan*/ identity(float *, int, int);
int /*<<< orphan*/ lowertriag(float *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ normalize(float *, int);
int /*<<< orphan*/ print(float *, int, int);
int /*<<< orphan*/ printf(char *);
float uppertriag(float *, int);
int invert(FILE *fp) {
  int n = getsize(fp), i, j;
  float *array = (float *)malloc((2 * n * n) * sizeof(float));
  generate(array, n, fp);
  identity(array, n, n);
  float checkdet = uppertriag(array, n);
  if (checkdet == 0) {
    printf("The matrix is singular\n");
    return 1;
  }
  lowertriag(array, n);
  normalize(array, n);
  print(array, n, n);
  free(array);
  return 0;
}


x86 assembly (clang, -O0):
<invert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <getsize@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   10c0 <generate@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1090 <identity@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <uppertriag@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1232 <invert+0x92>
jp     1232 <invert+0x92>
lea    0xddf(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1269 <invert+0xc9>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <lowertriag@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <normalize@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <print@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invert>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   10b0 <getsize@plt>
mov    %eax,%ebx
mov    %eax,%edi
imul   %eax,%edi
shl    $0x3,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   10c0 <generate@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
call   1090 <identity@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <uppertriag@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11ff <invert+0x5f>
jp     11ff <invert+0x5f>
lea    0xe0d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1229 <invert+0x89>
mov    %r14,%rdi
mov    %ebx,%esi
call   1070 <lowertriag@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1080 <normalize@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
call   1050 <print@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"The matrix is singular\0A\00"
define i32 @invert(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float*
%8 = alloca float
store i32* %0, i32** %3
%9 = load i32*, i32** %3
%10 = call i32 @getsize(i32* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = mul nsw i32 2, %11
%13 = load i32, i32* %4
%14 = mul nsw i32 %12, %13
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to float*
store float* %19, float** %7
%20 = load float*, float** %7
%21 = load i32, i32* %4
%22 = load i32*, i32** %3
%23 = call i32 @generate(float* %20, i32 %21, i32* %22)
%24 = load float*, float** %7
%25 = load i32, i32* %4
%26 = load i32, i32* %4
%27 = call i32 @identity(float* %24, i32 %25, i32 %26)
%28 = load float*, float** %7
%29 = load i32, i32* %4
%30 = call float @uppertriag(float* %28, i32 %29)
store float %30, float* %8
%31 = load float, float* %8
%32 = fcmp oeq float %31, 0.000000e+00
br i1 %32, label %33, label %35
33: ; preds = %1
%34 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %48
35: ; preds = %1
%36 = load float*, float** %7
%37 = load i32, i32* %4
%38 = call i32 @lowertriag(float* %36, i32 %37)
%39 = load float*, float** %7
%40 = load i32, i32* %4
%41 = call i32 @normalize(float* %39, i32 %40)
%42 = load float*, float** %7
%43 = load i32, i32* %4
%44 = load i32, i32* %4
%45 = call i32 @print(float* %42, i32 %43, i32 %44)
%46 = load float*, float** %7
%47 = call i32 @free(float* %46)
store i32 0, i32* %2
br label %48
48: ; preds = %35, %33
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
@str = [23 x i8] c"The matrix is singular\00"
define i32 @invert(i32* %0) {
%2 = tail call i32 @getsize(i32* %0)
%3 = shl i32 %2, 3
%4 = mul i32 %3, %2
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to float*
%7 = tail call i32 @generate(float* %6, i32 %2, i32* %0)
%8 = tail call i32 @identity(float* %6, i32 %2, i32 %2)
%9 = tail call float @uppertriag(float* %6, i32 %2)
%10 = fcmp oeq float %9, 0.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %18
13: ; preds = %1
%14 = tail call i32 @lowertriag(float* %6, i32 %2)
%15 = tail call i32 @normalize(float* %6, i32 %2)
%16 = tail call i32 @print(float* %6, i32 %2, i32 %2)
%17 = tail call i32 @free(float* %6)
br label %18
18: ; preds = %13, %11
%19 = phi i32 [ 1, %11 ], [ 0, %13 ]
ret i32 %19
}