#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ eliminate_by_row(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                    int, int);
int /*<<< orphan*/ get_identity_matrix(int /*<<< orphan*/ *, int);
int get_pivot_index(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ **, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ normalize_pivot_row(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ setup_host_tables();
int /*<<< orphan*/ switch_columns(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  int, int, int);
void CPU_invert_matrix(uint8_t *matrix, uint8_t *result, int size) {
  int row;
  int pivotIndex;
  uint8_t currentRow[size];
  int currentRowSize = size * sizeof(uint8_t);
  setup_host_tables();
  get_identity_matrix(result, size);
  for (row = 0; row < size; row++) {
    int index = row;
    memcpy(&currentRow, matrix + row * size, currentRowSize);
    pivotIndex = get_pivot_index(currentRow, index, size);
    if (pivotIndex != row) {
      switch_columns(matrix, result, index, pivotIndex, size);
    }
    normalize_pivot_row(matrix, result, index, size);
    eliminate_by_row(matrix, result, row, size);
  }
}


x86 assembly (clang, -O0):
<CPU_invert_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1050 <setup_host_tables@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <get_identity_matrix@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126a <CPU_invert_matrix+0xfa>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x34(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1060 <get_pivot_index@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1236 <CPU_invert_matrix+0xc6>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1090 <switch_columns@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1040 <normalize_pivot_row@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1080 <eliminate_by_row@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cf <CPU_invert_matrix+0x5f>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CPU_invert_matrix>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,-0x38(%rbp)
mov    %edx,%r14d
mov    %rsp,%rcx
lea    0xf(,%r14,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
xor    %eax,%eax
call   1050 <setup_host_tables@plt>
mov    %r15,-0x48(%rbp)
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <get_identity_matrix@plt>
mov    %rbx,%rax
mov    %rbx,-0x30(%rbp)
test   %ebx,%ebx
jle    127a <CPU_invert_matrix+0x10a>
mov    -0x30(%rbp),%rax
lea    0x0(,%rax,4),%eax
mov    %eax,-0x3c(%rbp)
lea    0x0(,%r14,4),%rax
mov    %rax,-0x58(%rbp)
xor    %r12d,%r12d
mov    -0x38(%rbp),%r15
mov    %r14,-0x50(%rbp)
mov    -0x48(%rbp),%r13
jmp    123b <CPU_invert_matrix+0xcb>
cs nopw 0x0(%rax,%rax,1)
nop
mov    -0x38(%rbp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
mov    -0x30(%rbp),%r14
mov    %r14d,%ecx
call   1040 <normalize_pivot_row@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
mov    %r14d,%ecx
call   1080 <eliminate_by_row@plt>
add    $0x1,%r12
add    -0x58(%rbp),%r15
mov    -0x50(%rbp),%r14
cmp    %r12,%r14
je     127a <CPU_invert_matrix+0x10a>
mov    -0x60(%rbp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    -0x3c(%rbp),%edx
call   1070 <memcpy@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
call   1060 <get_pivot_index@plt>
mov    %eax,%ecx
cmp    %rcx,%r12
je     1200 <CPU_invert_matrix+0x90>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %r12d,%edx
mov    %eax,%ecx
mov    -0x30(%rbp),%r8
call   1090 <switch_columns@plt>
jmp    1200 <CPU_invert_matrix+0x90>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @CPU_invert_matrix(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%13 = load i32, i32* %6
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i32, i64 %14
store i64 %14, i64* %10
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = trunc i64 %19 to i32
store i32 %20, i32* %11
%21 = call i32 (...) @setup_host_tables()
%22 = load i32*, i32** %5
%23 = load i32, i32* %6
%24 = call i32 @get_identity_matrix(i32* %22, i32 %23)
store i32 0, i32* %7
br label %25
25: ; preds = %64, %3
%26 = load i32, i32* %7
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %67
29: ; preds = %25
%30 = load i32, i32* %7
store i32 %30, i32* %12
%31 = bitcast i32* %16 to i32**
%32 = load i32*, i32** %4
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = mul nsw i32 %33, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %32, i64 %36
%38 = load i32, i32* %11
%39 = call i32 @memcpy(i32** %31, i32* %37, i32 %38)
%40 = load i32, i32* %12
%41 = load i32, i32* %6
%42 = call i32 @get_pivot_index(i32* %16, i32 %40, i32 %41)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = load i32, i32* %7
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %53
46: ; preds = %29
%47 = load i32*, i32** %4
%48 = load i32*, i32** %5
%49 = load i32, i32* %12
%50 = load i32, i32* %8
%51 = load i32, i32* %6
%52 = call i32 @switch_columns(i32* %47, i32* %48, i32 %49, i32 %50, i32 %51)
br label %53
53: ; preds = %46, %29
%54 = load i32*, i32** %4
%55 = load i32*, i32** %5
%56 = load i32, i32* %12
%57 = load i32, i32* %6
%58 = call i32 @normalize_pivot_row(i32* %54, i32* %55, i32 %56, i32 %57)
%59 = load i32*, i32** %4
%60 = load i32*, i32** %5
%61 = load i32, i32* %7
%62 = load i32, i32* %6
%63 = call i32 @eliminate_by_row(i32* %59, i32* %60, i32 %61, i32 %62)
br label %64
64: ; preds = %53
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %7
br label %25
67: ; preds = %25
%68 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
define void @CPU_invert_matrix(i32* %0, i32* %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = alloca i32, i64 %4
%6 = shl i32 %2, 2
%7 = tail call i32 (...) @setup_host_tables()
%8 = tail call i32 @get_identity_matrix(i32* %1, i32 %2)
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %29
10: ; preds = %3
%11 = bitcast i32* %5 to i32**
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %10, %24
%14 = phi i64 [ 0, %10 ], [ %27, %24 ]
%15 = mul nsw i64 %14, %12
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = call i32 @memcpy(i32** %11, i32* %16, i32 %6)
%18 = trunc i64 %14 to i32
%19 = call i32 @get_pivot_index(i32* %5, i32 %18, i32 %2)
%20 = zext i32 %19 to i64
%21 = icmp eq i64 %14, %20
br i1 %21, label %24, label %22
22: ; preds = %13
%23 = call i32 @switch_columns(i32* %0, i32* %1, i32 %18, i32 %19, i32 %2)
br label %24
24: ; preds = %22, %13
%25 = call i32 @normalize_pivot_row(i32* %0, i32* %1, i32 %18, i32 %2)
%26 = call i32 @eliminate_by_row(i32* %0, i32* %1, i32 %18, i32 %2)
%27 = add nuw nsw i64 %14, 1
%28 = icmp eq i64 %27, %4
br i1 %28, label %29, label %13
29: ; preds = %24, %3
ret void
}