#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_copy_vector_d3(double *, double *);
int /*<<< orphan*/ mat_cross_product_d3(double *, double *, double *);
int /*<<< orphan*/ mat_norm_squared_d3(double *);
int /*<<< orphan*/ mat_transpose_matrix_d3(double **, double **);
double sqrt(int /*<<< orphan*/);
void get_orthonormal_basis(double basis[3][3], double lattice[3][3]) {
  int i, j;
  double length;
  double basis_T[3][3], lattice_T[3][3];
  mat_transpose_matrix_d3(lattice_T, lattice);
  mat_copy_vector_d3(basis_T[0], lattice_T[0]);
  mat_cross_product_d3(basis_T[2], lattice_T[0], lattice_T[1]);
  mat_cross_product_d3(basis_T[1], basis_T[2], lattice_T[0]);
  for (i = 0; i < 3; i++) {
    length = sqrt(mat_norm_squared_d3(basis_T[i]));
    for (j = 0; j < 3; j++) {
      basis_T[i][j] /= length;
    }
  }
  mat_transpose_matrix_d3(basis, basis_T);
}


x86 assembly (clang, -O0):
<get_orthonormal_basis>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <mat_transpose_matrix_d3@plt>
lea    -0x70(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1050 <mat_copy_vector_d3@plt>
lea    -0x70(%rbp),%rdi
add    $0x30,%rdi
lea    -0xc0(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
add    $0x18,%rdx
call   1030 <mat_cross_product_d3@plt>
lea    -0x70(%rbp),%rdi
add    $0x18,%rdi
lea    -0x70(%rbp),%rsi
add    $0x30,%rsi
lea    -0xc0(%rbp),%rdx
call   1030 <mat_cross_product_d3@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1247 <get_orthonormal_basis+0xf7>
movslq -0x14(%rbp),%rax
lea    -0x70(%rbp),%rdi
imul   $0x18,%rax,%rax
add    %rax,%rdi
call   1040 <mat_norm_squared_d3@plt>
mov    %eax,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    1234 <get_orthonormal_basis+0xe4>
movsd  -0x20(%rbp),%xmm1
movslq -0x14(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f6 <get_orthonormal_basis+0xa6>
jmp    1239 <get_orthonormal_basis+0xe9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c5 <get_orthonormal_basis+0x75>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1070 <mat_transpose_matrix_d3@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_orthonormal_basis>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa0,%rsp
mov    %rdi,%r14
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <mat_transpose_matrix_d3@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <mat_copy_vector_d3@plt>
lea    0x30(%rsp),%r12
lea    0x68(%rsp),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <mat_cross_product_d3@plt>
lea    0x18(%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <mat_cross_product_d3@plt>
mov    %r15,%rdi
call   1040 <mat_norm_squared_d3@plt>
mov    %eax,%edi
call   1060 <sqrt@plt>
movapd (%rsp),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movapd %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %r13,%rdi
call   1040 <mat_norm_squared_d3@plt>
mov    %eax,%edi
call   1060 <sqrt@plt>
movupd 0x18(%rsp),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movupd %xmm1,0x18(%rsp)
movsd  0x28(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x28(%rsp)
mov    %r12,%rdi
call   1040 <mat_norm_squared_d3@plt>
mov    %eax,%edi
call   1060 <sqrt@plt>
movapd 0x30(%rsp),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movapd %xmm1,0x30(%rsp)
movsd  0x40(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x40(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <mat_transpose_matrix_d3@plt>
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @get_orthonormal_basis([3 x double]* %0, [3 x double]* %1) {
%3 = alloca [3 x [3 x double]]
%4 = alloca [3 x [3 x double]]
%5 = bitcast [3 x [3 x double]]* %3 to i8*
%6 = bitcast [3 x [3 x double]]* %4 to i8*
%7 = bitcast [3 x [3 x double]]* %4 to double**
%8 = bitcast [3 x double]* %1 to double**
%9 = call i32 @mat_transpose_matrix_d3(double** %7, double** %8)
%10 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 0, i64 0
%11 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 0, i64 0
%12 = call i32 @mat_copy_vector_d3(double* %10, double* %11)
%13 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 2, i64 0
%14 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %4, i64 0, i64 1, i64 0
%15 = call i32 @mat_cross_product_d3(double* %13, double* %11, double* %14)
%16 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 1, i64 0
%17 = call i32 @mat_cross_product_d3(double* %16, double* %13, double* %11)
%18 = call i32 @mat_norm_squared_d3(double* %10)
%19 = call double @sqrt(i32 %18)
%20 = bitcast [3 x [3 x double]]* %3 to <2 x double>*
%21 = load <2 x double>, <2 x double>* %20
%22 = insertelement <2 x double> poison, double %19, i64 0
%23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
%24 = fdiv <2 x double> %21, %23
%25 = bitcast [3 x [3 x double]]* %3 to <2 x double>*
store <2 x double> %24, <2 x double>* %25
%26 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 0, i64 2
%27 = load double, double* %26
%28 = fdiv double %27, %19
store double %28, double* %26
%29 = call i32 @mat_norm_squared_d3(double* %16)
%30 = call double @sqrt(i32 %29)
%31 = bitcast double* %16 to <2 x double>*
%32 = load <2 x double>, <2 x double>* %31
%33 = insertelement <2 x double> poison, double %30, i64 0
%34 = shufflevector <2 x double> %33, <2 x double> poison, <2 x i32> zeroinitializer
%35 = fdiv <2 x double> %32, %34
%36 = bitcast double* %16 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]]* %3, i64 0, i64 1, i64 2
%38 = load double, double* %37
%39 = fdiv double %38, %30
store double %39, double* %37
%40 = call i32 @mat_norm_squared_d3(double* %13)
%41 = call double @sqrt(i32 %40)
%42 = bitcast double* %13 to <2 x double>*
%43 = load <2 x double>, <2 x double>* %42
%44 = insertelement <2 x double> poison, double %41, i64 0
%45 = shufflevector <2 x double> %44, <2 x double> poison, <2 x i32> zeroinitializer
%46 = fdiv <2 x double> %43, %45
%47 = bitcast double* %13 to <2 x double>*
store <2 x double> %46, <2 x double>* %47
%48 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %3, i64 0, i64 2, i64 2
%49 = load double, double* %48
%50 = fdiv double %49, %41
store double %50, double* %48
%51 = bitcast [3 x double]* %0 to double**
%52 = bitcast [3 x [3 x double]]* %3 to double**
%53 = call i32 @mat_transpose_matrix_d3(double** %51, double** %52)
ret void
}