#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*/ cross(int *, int *, int *);
int dot(int *, int *);
int /*<<< orphan*/ normalize(int *, int *);
int /*<<< orphan*/ vectorAdd(int *, int *, int *);
int /*<<< orphan*/ vectorScale(int *, int *, int *);
void orthoNormalize(int *matrix) {
  int delta[6];
  int i;
  int error = -1 / 2 * dot(&matrix[0], &matrix[3]);
  vectorScale(&matrix[3], &error, &delta[0]);
  vectorScale(&matrix[0], &error, &delta[3]);
  vectorAdd(&matrix[0], &delta[0], &matrix[0]);
  vectorAdd(&matrix[3], &delta[3], &matrix[3]);
  cross(&matrix[0], &matrix[3], &matrix[6]);
  for (i = 0; i < 3; i++) {
    normalize(&matrix[i * 3], &matrix[i * 3]);
  }
}


x86 assembly (clang, -O0):
<orthoNormalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0xc,%rsi
call   1030 <dot@plt>
imul   $0x0,%eax,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
add    $0xc,%rdi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1040 <vectorScale@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rdx
add    $0xc,%rdx
lea    -0x28(%rbp),%rsi
call   1040 <vectorScale@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1060 <vectorAdd@plt>
mov    -0x8(%rbp),%rdi
add    $0xc,%rdi
lea    -0x20(%rbp),%rsi
add    $0xc,%rsi
mov    -0x8(%rbp),%rdx
add    $0xc,%rdx
call   1060 <vectorAdd@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0xc,%rsi
mov    -0x8(%rbp),%rdx
add    $0x18,%rdx
call   1070 <cross@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    122a <orthoNormalize+0xda>
mov    -0x8(%rbp),%rdi
imul   $0x3,-0x24(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
imul   $0x3,-0x24(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <normalize@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11eb <orthoNormalize+0x9b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<orthoNormalize>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
lea    0xc(%rdi),%r14
mov    %r14,%rsi
call   1030 <dot@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <vectorScale@plt>
lea    0x1c(%rsp),%r13
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <vectorScale@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <vectorAdd@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1060 <vectorAdd@plt>
lea    0x18(%rbx),%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <cross@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1050 <normalize@plt>
mov    %r14,%rdi
mov    %r14,%rsi
call   1050 <normalize@plt>
mov    %r15,%rdi
mov    %r15,%rsi
call   1050 <normalize@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @orthoNormalize(i32* %0) {
%2 = alloca i32*
%3 = alloca [6 x i32]
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 0
%8 = load i32*, i32** %2
%9 = getelementptr inbounds i32, i32* %8, i64 3
%10 = call i32 @dot(i32* %7, i32* %9)
%11 = mul nsw i32 0, %10
store i32 %11, i32* %5
%12 = load i32*, i32** %2
%13 = getelementptr inbounds i32, i32* %12, i64 3
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%15 = call i32 @vectorScale(i32* %13, i32* %5, i32* %14)
%16 = load i32*, i32** %2
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 3
%19 = call i32 @vectorScale(i32* %17, i32* %5, i32* %18)
%20 = load i32*, i32** %2
%21 = getelementptr inbounds i32, i32* %20, i64 0
%22 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%23 = load i32*, i32** %2
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = call i32 @vectorAdd(i32* %21, i32* %22, i32* %24)
%26 = load i32*, i32** %2
%27 = getelementptr inbounds i32, i32* %26, i64 3
%28 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 3
%29 = load i32*, i32** %2
%30 = getelementptr inbounds i32, i32* %29, i64 3
%31 = call i32 @vectorAdd(i32* %27, i32* %28, i32* %30)
%32 = load i32*, i32** %2
%33 = getelementptr inbounds i32, i32* %32, i64 0
%34 = load i32*, i32** %2
%35 = getelementptr inbounds i32, i32* %34, i64 3
%36 = load i32*, i32** %2
%37 = getelementptr inbounds i32, i32* %36, i64 6
%38 = call i32 @cross(i32* %33, i32* %35, i32* %37)
store i32 0, i32* %4
br label %39
39: ; preds = %54, %1
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 3
br i1 %41, label %42, label %57
42: ; preds = %39
%43 = load i32*, i32** %2
%44 = load i32, i32* %4
%45 = mul nsw i32 %44, 3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %43, i64 %46
%48 = load i32*, i32** %2
%49 = load i32, i32* %4
%50 = mul nsw i32 %49, 3
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %48, i64 %51
%53 = call i32 @normalize(i32* %47, i32* %52)
br label %54
54: ; preds = %42
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %39
57: ; preds = %39
ret void
}

LLVM IR (-O2):
define void @orthoNormalize(i32* %0) {
%2 = alloca [6 x i32]
%3 = alloca i32
%4 = bitcast [6 x i32]* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds i32, i32* %0, i64 3
%7 = tail call i32 @dot(i32* %0, i32* %6)
store i32 0, i32* %3
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 0
%9 = call i32 @vectorScale(i32* %6, i32* %3, i32* %8)
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 3
%11 = call i32 @vectorScale(i32* %0, i32* %3, i32* %10)
%12 = call i32 @vectorAdd(i32* %0, i32* %8, i32* %0)
%13 = call i32 @vectorAdd(i32* %6, i32* %10, i32* %6)
%14 = getelementptr inbounds i32, i32* %0, i64 6
%15 = call i32 @cross(i32* %0, i32* %6, i32* %14)
%16 = call i32 @normalize(i32* %0, i32* %0)
%17 = call i32 @normalize(i32* %6, i32* %6)
%18 = call i32 @normalize(i32* %14, i32* %14)
ret void
}