#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 */
scalar_t__ mat_get_determinant_l3(long **);
int snf3x3(long **, long **, long **);
int grg_get_snf3x3(long D_diag[3], long P[3][3], long Q[3][3], long A[3][3]) {
  int i, j, succeeded;
  long D[3][3];
  succeeded = 0;
  if (mat_get_determinant_l3(A) == 0) {
    goto err;
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      D[i][j] = A[i][j];
    }
  }
  succeeded = snf3x3(D, P, Q);
  for (i = 0; i < 3; i++) {
    D_diag[i] = D[i][i];
  }
err:
  return succeeded;
}


x86 assembly (clang, -O0):
<grg_get_snf3x3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <mat_get_determinant_l3@plt>
cmp    $0x0,%rax
jne    115a <grg_get_snf3x3+0x3a>
jmp    1226 <grg_get_snf3x3+0x106>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    11cb <grg_get_snf3x3+0xab>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    11b8 <grg_get_snf3x3+0x98>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x24(%rbp),%rcx
lea    -0x80(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1172 <grg_get_snf3x3+0x52>
jmp    11bd <grg_get_snf3x3+0x9d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <grg_get_snf3x3+0x41>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <snf3x3@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    1221 <grg_get_snf3x3+0x101>
movslq -0x24(%rbp),%rcx
lea    -0x80(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e6 <grg_get_snf3x3+0xc6>
jmp    1226 <grg_get_snf3x3+0x106>
mov    -0x2c(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grg_get_snf3x3>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rcx,%rdi
call   1030 <mat_get_determinant_l3@plt>
test   %rax,%rax
je     119b <grg_get_snf3x3+0x7b>
mov    0x40(%rbx),%rax
mov    %rax,0x40(%rsp)
movups (%rbx),%xmm0
movups 0x10(%rbx),%xmm1
movups 0x20(%rbx),%xmm2
movups 0x30(%rbx),%xmm3
movaps %xmm3,0x30(%rsp)
movaps %xmm2,0x20(%rsp)
movaps %xmm1,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <snf3x3@plt>
mov    (%rsp),%rcx
mov    %rcx,(%r12)
mov    0x20(%rsp),%rcx
mov    %rcx,0x8(%r12)
mov    0x40(%rsp),%rcx
mov    %rcx,0x10(%r12)
jmp    119d <grg_get_snf3x3+0x7d>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @grg_get_snf3x3(i64* %0, [3 x i64]* %1, [3 x i64]* %2, [3 x i64]* %3) {
%5 = alloca i64*
%6 = alloca [3 x i64]*
%7 = alloca [3 x i64]*
%8 = alloca [3 x i64]*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [3 x [3 x i64]]
store i64* %0, i64** %5
store [3 x i64]* %1, [3 x i64]** %6
store [3 x i64]* %2, [3 x i64]** %7
store [3 x i64]* %3, [3 x i64]** %8
store i32 0, i32* %11
%13 = load [3 x i64]*, [3 x i64]** %8
%14 = bitcast [3 x i64]* %13 to i64**
%15 = call i64 @mat_get_determinant_l3(i64** %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
br label %75
18: ; preds = %4
store i32 0, i32* %9
br label %19
19: ; preds = %45, %18
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %48
22: ; preds = %19
store i32 0, i32* %10
br label %23
23: ; preds = %41, %22
%24 = load i32, i32* %10
%25 = icmp slt i32 %24, 3
br i1 %25, label %26, label %44
26: ; preds = %23
%27 = load [3 x i64]*, [3 x i64]** %8
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [3 x i64], [3 x i64]* %27, i64 %29
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [3 x i64], [3 x i64]* %30, i64 0, i64 %32
%34 = load i64, i64* %33
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %12, i64 0, i64 %36
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [3 x i64], [3 x i64]* %37, i64 0, i64 %39
store i64 %34, i64* %40
br label %41
41: ; preds = %26
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %23
44: ; preds = %23
br label %45
45: ; preds = %44
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %19
48: ; preds = %19
%49 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %12, i64 0, i64 0
%50 = bitcast [3 x i64]* %49 to i64**
%51 = load [3 x i64]*, [3 x i64]** %6
%52 = bitcast [3 x i64]* %51 to i64**
%53 = load [3 x i64]*, [3 x i64]** %7
%54 = bitcast [3 x i64]* %53 to i64**
%55 = call i32 @snf3x3(i64** %50, i64** %52, i64** %54)
store i32 %55, i32* %11
store i32 0, i32* %9
br label %56
56: ; preds = %71, %48
%57 = load i32, i32* %9
%58 = icmp slt i32 %57, 3
br i1 %58, label %59, label %74
59: ; preds = %56
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %12, i64 0, i64 %61
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [3 x i64], [3 x i64]* %62, i64 0, i64 %64
%66 = load i64, i64* %65
%67 = load i64*, i64** %5
%68 = load i32, i32* %9
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i64, i64* %67, i64 %69
store i64 %66, i64* %70
br label %71
71: ; preds = %59
%72 = load i32, i32* %9
%73 = add nsw i32 %72, 1
store i32 %73, i32* %9
br label %56
74: ; preds = %56
br label %75
75: ; preds = %74, %17
%76 = load i32, i32* %11
ret i32 %76
}

LLVM IR (-O2):
define i32 @grg_get_snf3x3(i64* nocapture writeonly %0, [3 x i64]* %1, [3 x i64]* %2, [3 x i64]* %3) {
%5 = alloca [3 x [3 x i64]]
%6 = bitcast [3 x [3 x i64]]* %5 to i8*
%7 = bitcast [3 x i64]* %3 to i64**
%8 = tail call i64 @mat_get_determinant_l3(i64** %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %4
%11 = bitcast [3 x i64]* %3 to i8*
%12 = bitcast [3 x [3 x i64]]* %5 to i64**
%13 = bitcast [3 x i64]* %1 to i64**
%14 = bitcast [3 x i64]* %2 to i64**
%15 = call i32 @snf3x3(i64** %12, i64** %13, i64** %14)
%16 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %5, i64 0, i64 0, i64 0
%17 = load i64, i64* %16
store i64 %17, i64* %0
%18 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %5, i64 0, i64 1, i64 1
%19 = load i64, i64* %18
%20 = getelementptr inbounds i64, i64* %0, i64 1
store i64 %19, i64* %20
%21 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %5, i64 0, i64 2, i64 2
%22 = load i64, i64* %21
%23 = getelementptr inbounds i64, i64* %0, i64 2
store i64 %22, i64* %23
br label %24
24: ; preds = %10, %4
%25 = phi i32 [ 0, %4 ], [ %15, %10 ]
ret i32 %25
}