#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*/ mat_cast_matrix_3d_to_3i(int **, double **);
scalar_t__ mat_get_determinant_d3(double **);
int /*<<< orphan*/ mat_inverse_matrix_d3(double **, double **,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ mat_multiply_matrix_d3(double **, double **, double **);
int /*<<< orphan*/ niggli_reduce(double *, double const);
int change_basis_tricli(int int_transform_mat[3][3], double conv_lattice[3][3],
                        double primitive_lattice[3][3], const double symprec) {
  int i, j;
  double niggli_cell[9];
  double smallest_lattice[3][3], inv_lattice[3][3], transform_mat[3][3];
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      niggli_cell[i * 3 + j] = conv_lattice[i][j];
    }
  }
  if (!niggli_reduce(niggli_cell, symprec * symprec)) {
    return 0;
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      smallest_lattice[i][j] = niggli_cell[i * 3 + j];
    }
  }
  if (mat_get_determinant_d3(smallest_lattice) < 0) {
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 3; j++) {
        smallest_lattice[i][j] = -smallest_lattice[i][j];
      }
    }
  }
  mat_inverse_matrix_d3(inv_lattice, primitive_lattice, 0);
  mat_multiply_matrix_d3(transform_mat, inv_lattice, smallest_lattice);
  mat_cast_matrix_3d_to_3i(int_transform_mat, transform_mat);
  return 1;
}


x86 assembly (clang, -O0):
<change_basis_tricli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jge    11d6 <change_basis_tricli+0x86>
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
jge    11c3 <change_basis_tricli+0x73>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
imul   $0x3,-0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
cltq
movsd  %xmm0,-0x80(%rbp,%rax,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1184 <change_basis_tricli+0x34>
jmp    11c8 <change_basis_tricli+0x78>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1173 <change_basis_tricli+0x23>
lea    -0x80(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1040 <niggli_reduce@plt>
cmp    $0x0,%eax
jne    11fe <change_basis_tricli+0xae>
movl   $0x0,-0x4(%rbp)
jmp    1359 <change_basis_tricli+0x209>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jge    126b <change_basis_tricli+0x11b>
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
jge    1258 <change_basis_tricli+0x108>
imul   $0x3,-0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
cltq
movsd  -0x80(%rbp,%rax,8),%xmm0
movslq -0x2c(%rbp),%rcx
lea    -0xd0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1216 <change_basis_tricli+0xc6>
jmp    125d <change_basis_tricli+0x10d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1205 <change_basis_tricli+0xb5>
lea    -0xd0(%rbp),%rdi
call   1030 <mat_get_determinant_d3@plt>
cmp    $0x0,%rax
jge    1316 <change_basis_tricli+0x1c6>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jge    1311 <change_basis_tricli+0x1c1>
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x30(%rbp)
jge    12fe <change_basis_tricli+0x1ae>
movslq -0x2c(%rbp),%rcx
lea    -0xd0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movslq -0x2c(%rbp),%rcx
lea    -0xd0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1299 <change_basis_tricli+0x149>
jmp    1303 <change_basis_tricli+0x1b3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1288 <change_basis_tricli+0x138>
jmp    1316 <change_basis_tricli+0x1c6>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <mat_inverse_matrix_d3@plt>
lea    -0x170(%rbp),%rdi
lea    -0x120(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   1070 <mat_multiply_matrix_d3@plt>
mov    -0x10(%rbp),%rdi
lea    -0x170(%rbp),%rsi
call   1060 <mat_cast_matrix_3d_to_3i@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_basis_tricli>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rdx,%r15
mov    %rdi,%r14
movupd (%rsi),%xmm1
movups 0x10(%rsi),%xmm2
movups 0x20(%rsi),%xmm3
movups 0x30(%rsi),%xmm4
movapd %xmm1,0x50(%rsp)
movaps %xmm2,0x60(%rsp)
movaps %xmm3,0x70(%rsp)
movaps %xmm4,0x80(%rsp)
mov    0x40(%rsi),%rax
mov    %rax,0x90(%rsp)
mulsd  %xmm0,%xmm0
lea    0x50(%rsp),%rdi
call   1040 <niggli_reduce@plt>
test   %eax,%eax
je     1289 <change_basis_tricli+0x139>
mov    0x90(%rsp),%rax
mov    %rax,0x40(%rsp)
movapd 0x50(%rsp),%xmm0
movapd 0x60(%rsp),%xmm1
movaps 0x70(%rsp),%xmm2
movaps 0x80(%rsp),%xmm3
movaps %xmm3,0x30(%rsp)
movaps %xmm2,0x20(%rsp)
movapd %xmm1,0x10(%rsp)
movapd %xmm0,(%rsp)
mov    %rsp,%rdi
call   1030 <mat_get_determinant_d3@plt>
test   %rax,%rax
jns    124c <change_basis_tricli+0xfc>
movapd 0xe02(%rip),%xmm0
movapd (%rsp),%xmm1
xorpd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movapd 0x10(%rsp),%xmm1
xorpd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
movapd 0x20(%rsp),%xmm1
xorpd  %xmm0,%xmm1
movapd %xmm1,0x20(%rsp)
movapd 0x30(%rsp),%xmm1
xorpd  %xmm0,%xmm1
movapd %xmm1,0x30(%rsp)
movsd  0x40(%rsp),%xmm1
xorpd  %xmm0,%xmm1
movlpd %xmm1,0x40(%rsp)
lea    0xf0(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1050 <mat_inverse_matrix_d3@plt>
lea    0xa0(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <mat_multiply_matrix_d3@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <mat_cast_matrix_3d_to_3i@plt>
mov    $0x1,%eax
jmp    128b <change_basis_tricli+0x13b>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @change_basis_tricli([3 x i32]* %0, [3 x double]* %1, [3 x double]* %2, double %3) {
%5 = alloca i32
%6 = alloca [3 x i32]*
%7 = alloca [3 x double]*
%8 = alloca [3 x double]*
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca [9 x double]
%13 = alloca [3 x [3 x double]]
%14 = alloca [3 x [3 x double]]
%15 = alloca [3 x [3 x double]]
store [3 x i32]* %0, [3 x i32]** %6
store [3 x double]* %1, [3 x double]** %7
store [3 x double]* %2, [3 x double]** %8
store double %3, double* %9
store i32 0, i32* %10
br label %16
16: ; preds = %42, %4
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %45
19: ; preds = %16
store i32 0, i32* %11
br label %20
20: ; preds = %38, %19
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %41
23: ; preds = %20
%24 = load [3 x double]*, [3 x double]** %7
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [3 x double], [3 x double]* %24, i64 %26
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [3 x double], [3 x double]* %27, i64 0, i64 %29
%31 = load double, double* %30
%32 = load i32, i32* %10
%33 = mul nsw i32 %32, 3
%34 = load i32, i32* %11
%35 = add nsw i32 %33, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [9 x double], [9 x double]* %12, i64 0, i64 %36
store double %31, double* %37
br label %38
38: ; preds = %23
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %20
41: ; preds = %20
br label %42
42: ; preds = %41
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %16
45: ; preds = %16
%46 = getelementptr inbounds [9 x double], [9 x double]* %12, i64 0, i64 0
%47 = load double, double* %9
%48 = load double, double* %9
%49 = fmul double %47, %48
%50 = call i32 @niggli_reduce(double* %46, double %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %45
store i32 0, i32* %5
br label %136
53: ; preds = %45
store i32 0, i32* %10
br label %54
54: ; preds = %79, %53
%55 = load i32, i32* %10
%56 = icmp slt i32 %55, 3
br i1 %56, label %57, label %82
57: ; preds = %54
store i32 0, i32* %11
br label %58
58: ; preds = %75, %57
%59 = load i32, i32* %11
%60 = icmp slt i32 %59, 3
br i1 %60, label %61, label %78
61: ; preds = %58
%62 = load i32, i32* %10
%63 = mul nsw i32 %62, 3
%64 = load i32, i32* %11
%65 = add nsw i32 %63, %64
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [9 x double], [9 x double]* %12, i64 0, i64 %66
%68 = load double, double* %67
%69 = load i32, i32* %10
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %13, i64 0, i64 %70
%72 = load i32, i32* %11
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [3 x double], [3 x double]* %71, i64 0, i64 %73
store double %68, double* %74
br label %75
75: ; preds = %61
%76 = load i32, i32* %11
%77 = add nsw i32 %76, 1
store i32 %77, i32* %11
br label %58
78: ; preds = %58
br label %79
79: ; preds = %78
%80 = load i32, i32* %10
%81 = add nsw i32 %80, 1
store i32 %81, i32* %10
br label %54
82: ; preds = %54
%83 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %13, i64 0, i64 0
%84 = bitcast [3 x double]* %83 to double**
%85 = call i64 @mat_get_determinant_d3(double** %84)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %118
87: ; preds = %82
store i32 0, i32* %10
br label %88
88: ; preds = %114, %87
%89 = load i32, i32* %10
%90 = icmp slt i32 %89, 3
br i1 %90, label %91, label %117
91: ; preds = %88
store i32 0, i32* %11
br label %92
92: ; preds = %110, %91
%93 = load i32, i32* %11
%94 = icmp slt i32 %93, 3
br i1 %94, label %95, label %113
95: ; preds = %92
%96 = load i32, i32* %10
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %13, i64 0, i64 %97
%99 = load i32, i32* %11
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [3 x double], [3 x double]* %98, i64 0, i64 %100
%102 = load double, double* %101
%103 = fneg double %102
%104 = load i32, i32* %10
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %13, i64 0, i64 %105
%107 = load i32, i32* %11
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [3 x double], [3 x double]* %106, i64 0, i64 %108
store double %103, double* %109
br label %110
110: ; preds = %95
%111 = load i32, i32* %11
%112 = add nsw i32 %111, 1
store i32 %112, i32* %11
br label %92
113: ; preds = %92
br label %114
114: ; preds = %113
%115 = load i32, i32* %10
%116 = add nsw i32 %115, 1
store i32 %116, i32* %10
br label %88
117: ; preds = %88
br label %118
118: ; preds = %117, %82
%119 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %14, i64 0, i64 0
%120 = bitcast [3 x double]* %119 to double**
%121 = load [3 x double]*, [3 x double]** %8
%122 = bitcast [3 x double]* %121 to double**
%123 = call i32 @mat_inverse_matrix_d3(double** %120, double** %122, i32 0)
%124 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %15, i64 0, i64 0
%125 = bitcast [3 x double]* %124 to double**
%126 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %14, i64 0, i64 0
%127 = bitcast [3 x double]* %126 to double**
%128 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %13, i64 0, i64 0
%129 = bitcast [3 x double]* %128 to double**
%130 = call i32 @mat_multiply_matrix_d3(double** %125, double** %127, double** %129)
%131 = load [3 x i32]*, [3 x i32]** %6
%132 = bitcast [3 x i32]* %131 to i32**
%133 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %15, i64 0, i64 0
%134 = bitcast [3 x double]* %133 to double**
%135 = call i32 @mat_cast_matrix_3d_to_3i(i32** %132, double** %134)
store i32 1, i32* %5
br label %136
136: ; preds = %118, %52
%137 = load i32, i32* %5
ret i32 %137
}

LLVM IR (-O2):
define i32 @change_basis_tricli([3 x i32]* %0, [3 x double]* nocapture %1, [3 x double]* %2, double %3) {
%5 = bitcast [3 x double]* %1 to i8*
%6 = alloca [9 x double]
%7 = bitcast [9 x double]* %6 to i8*
%8 = alloca [3 x [3 x double]]
%9 = bitcast [3 x [3 x double]]* %8 to i8*
%10 = alloca [3 x [3 x double]]
%11 = alloca [3 x [3 x double]]
%12 = bitcast [3 x [3 x double]]* %10 to i8*
%13 = bitcast [3 x [3 x double]]* %11 to i8*
%14 = getelementptr inbounds [9 x double], [9 x double]* %6, i64 0, i64 0
%15 = fmul double %3, %3
%16 = call i32 @niggli_reduce(double* %14, double %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %53, label %18
18: ; preds = %4
%19 = bitcast [3 x [3 x double]]* %8 to double**
%20 = call i64 @mat_get_determinant_d3(double** %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %45
22: ; preds = %18
%23 = bitcast [3 x [3 x double]]* %8 to <2 x double>*
%24 = load <2 x double>, <2 x double>* %23
%25 = fneg <2 x double> %24
%26 = bitcast [3 x [3 x double]]* %8 to <2 x double>*
store <2 x double> %25, <2 x double>* %26
%27 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %8, i64 0, i64 0, i64 2
%28 = bitcast double* %27 to <2 x double>*
%29 = load <2 x double>, <2 x double>* %28
%30 = fneg <2 x double> %29
%31 = bitcast double* %27 to <2 x double>*
store <2 x double> %30, <2 x double>* %31
%32 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %8, i64 0, i64 1, i64 1
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = fneg <2 x double> %34
%36 = bitcast double* %32 to <2 x double>*
store <2 x double> %35, <2 x double>* %36
%37 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %8, i64 0, i64 2, i64 0
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = fneg <2 x double> %39
%41 = bitcast double* %37 to <2 x double>*
store <2 x double> %40, <2 x double>* %41
%42 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %8, i64 0, i64 2, i64 2
%43 = load double, double* %42
%44 = fneg double %43
store double %44, double* %42
br label %45
45: ; preds = %22, %18
%46 = bitcast [3 x [3 x double]]* %10 to double**
%47 = bitcast [3 x double]* %2 to double**
%48 = call i32 @mat_inverse_matrix_d3(double** %46, double** %47, i32 0)
%49 = bitcast [3 x [3 x double]]* %11 to double**
%50 = call i32 @mat_multiply_matrix_d3(double** %49, double** %46, double** %19)
%51 = bitcast [3 x i32]* %0 to i32**
%52 = call i32 @mat_cast_matrix_3d_to_3i(i32** %51, double** %49)
br label %53
53: ; preds = %4, %45
%54 = phi i32 [ 1, %45 ], [ 0, %4 ]
ret i32 %54
}