#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*/ normalize_quat(float *);
int /*<<< orphan*/ vadd(float *, float *, float *);
int /*<<< orphan*/ vcopy(float *, float *);
int /*<<< orphan*/ vcross(float *, float *, float *);
float vdot(float *, float *);
int /*<<< orphan*/ vscale(float *, float);
void add_quats(float q1[4], float q2[4], float dest[4]) {
  static int count = 0;
  float t1[4], t2[4], t3[4];
  float tf[4];
  vcopy(q1, t1);
  vscale(t1, q2[3]);
  vcopy(q2, t2);
  vscale(t2, q1[3]);
  vcross(q2, q1, t3);
  vadd(t1, t2, tf);
  vadd(t3, tf, tf);
  tf[3] = q1[3] * q2[3] - vdot(q1, q2);
  dest[0] = tf[0];
  dest[1] = tf[1];
  dest[2] = tf[2];
  dest[3] = tf[3];
  if (++count > 97) {
    count = 0;
    normalize_quat(dest);
  }
}


x86 assembly (clang, -O0):
<add_quats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <vcopy@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
movss  0xc(%rax),%xmm0
call   1070 <vscale@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <vcopy@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
call   1070 <vscale@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1050 <vcross@plt>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1030 <vadd@plt>
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1030 <vadd@plt>
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
movss  %xmm0,-0x64(%rbp)
mov    -0x10(%rbp),%rax
movss  0xc(%rax),%xmm0
movss  %xmm0,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <vdot@plt>
movss  -0x68(%rbp),%xmm2
movaps %xmm0,%xmm1
movss  -0x64(%rbp),%xmm0
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x60(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x5c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x58(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x54(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0xc(%rax)
mov    0x2de2(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2dd9(%rip)
cmp    $0x61,%eax
jle    1297 <add_quats+0x137>
movl   $0x0,0x2dc6(%rip)
mov    -0x18(%rbp),%rdi
call   1040 <normalize_quat@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_quats>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
call   1080 <vcopy@plt>
movss  0xc(%r15),%xmm0
mov    %rbp,%rdi
call   1070 <vscale@plt>
lea    0x40(%rsp),%r13
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <vcopy@plt>
movss  0xc(%rbx),%xmm0
mov    %r13,%rdi
call   1070 <vscale@plt>
lea    0x30(%rsp),%rbp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <vcross@plt>
lea    0x10(%rsp),%r12
lea    0x20(%rsp),%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1030 <vadd@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r12,%rdx
call   1030 <vadd@plt>
movss  0xc(%rbx),%xmm0
mulss  0xc(%r15),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <vdot@plt>
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0x1c(%rsp)
movss  0x10(%rsp),%xmm0
movss  %xmm0,(%r14)
movss  0x14(%rsp),%xmm0
movss  %xmm0,0x4(%r14)
movss  0x18(%rsp),%xmm0
movss  %xmm0,0x8(%r14)
movss  %xmm1,0xc(%r14)
mov    0x2e14(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2e0b(%rip)
cmp    $0x61,%eax
jl     1260 <add_quats+0x100>
movl   $0x0,0x2dfc(%rip)
mov    %r14,%rdi
call   1040 <normalize_quat@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@add_quats.count = internal global i32 0
define void @add_quats(float* %0, float* %1, float* %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca float*
%7 = alloca [4 x float]
%8 = alloca [4 x float]
%9 = alloca [4 x float]
%10 = alloca [4 x float]
store float* %0, float** %4
store float* %1, float** %5
store float* %2, float** %6
%11 = load float*, float** %4
%12 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 0
%13 = call i32 @vcopy(float* %11, float* %12)
%14 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 0
%15 = load float*, float** %5
%16 = getelementptr inbounds float, float* %15, i64 3
%17 = load float, float* %16
%18 = call i32 @vscale(float* %14, float %17)
%19 = load float*, float** %5
%20 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 0
%21 = call i32 @vcopy(float* %19, float* %20)
%22 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 0
%23 = load float*, float** %4
%24 = getelementptr inbounds float, float* %23, i64 3
%25 = load float, float* %24
%26 = call i32 @vscale(float* %22, float %25)
%27 = load float*, float** %5
%28 = load float*, float** %4
%29 = getelementptr inbounds [4 x float], [4 x float]* %9, i64 0, i64 0
%30 = call i32 @vcross(float* %27, float* %28, float* %29)
%31 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 0
%32 = getelementptr inbounds [4 x float], [4 x float]* %8, i64 0, i64 0
%33 = getelementptr inbounds [4 x float], [4 x float]* %10, i64 0, i64 0
%34 = call i32 @vadd(float* %31, float* %32, float* %33)
%35 = getelementptr inbounds [4 x float], [4 x float]* %9, i64 0, i64 0
%36 = getelementptr inbounds [4 x float], [4 x float]* %10, i64 0, i64 0
%37 = getelementptr inbounds [4 x float], [4 x float]* %10, i64 0, i64 0
%38 = call i32 @vadd(float* %35, float* %36, float* %37)
%39 = load float*, float** %4
%40 = getelementptr inbounds float, float* %39, i64 3
%41 = load float, float* %40
%42 = load float*, float** %5
%43 = getelementptr inbounds float, float* %42, i64 3
%44 = load float, float* %43
%45 = load float*, float** %4
%46 = load float*, float** %5
%47 = call float @vdot(float* %45, float* %46)
%48 = fneg float %47
%49 = call float @llvm.fmuladd.f32(float %41, float %44, float %48)
%50 = getelementptr inbounds [4 x float], [4 x float]* %10, i64 0, i64 3
store float %49, float* %50
%51 = getelementptr inbounds [4 x float], [4 x float]* %10, i64 0, i64 0
%52 = load float, float* %51
%53 = load float*, float** %6
%54 = getelementptr inbounds float, float* %53, i64 0
store float %52, float* %54
%55 = getelementptr inbounds [4 x float], [4 x float]* %10, i64 0, i64 1
%56 = load float, float* %55
%57 = load float*, float** %6
%58 = getelementptr inbounds float, float* %57, i64 1
store float %56, float* %58
%59 = getelementptr inbounds [4 x float], [4 x float]* %10, i64 0, i64 2
%60 = load float, float* %59
%61 = load float*, float** %6
%62 = getelementptr inbounds float, float* %61, i64 2
store float %60, float* %62
%63 = getelementptr inbounds [4 x float], [4 x float]* %10, i64 0, i64 3
%64 = load float, float* %63
%65 = load float*, float** %6
%66 = getelementptr inbounds float, float* %65, i64 3
store float %64, float* %66
%67 = load i32, i32* @add_quats.count
%68 = add nsw i32 %67, 1
store i32 %68, i32* @add_quats.count
%69 = icmp sgt i32 %68, 97
br i1 %69, label %70, label %73
70: ; preds = %3
store i32 0, i32* @add_quats.count
%71 = load float*, float** %6
%72 = call i32 @normalize_quat(float* %71)
br label %73
73: ; preds = %70, %3
ret void
}

LLVM IR (-O2):
@add_quats.count = internal unnamed_addr global i32 0
define void @add_quats(float* %0, float* %1, float* %2) {
%4 = alloca [4 x float]
%5 = alloca [4 x float]
%6 = alloca [4 x float]
%7 = alloca [4 x float]
%8 = bitcast [4 x float]* %4 to i8*
%9 = bitcast [4 x float]* %5 to i8*
%10 = bitcast [4 x float]* %6 to i8*
%11 = bitcast [4 x float]* %7 to i8*
%12 = getelementptr inbounds [4 x float], [4 x float]* %4, i64 0, i64 0
%13 = call i32 @vcopy(float* %0, float* %12)
%14 = getelementptr inbounds float, float* %1, i64 3
%15 = load float, float* %14
%16 = call i32 @vscale(float* %12, float %15)
%17 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 0
%18 = call i32 @vcopy(float* %1, float* %17)
%19 = getelementptr inbounds float, float* %0, i64 3
%20 = load float, float* %19
%21 = call i32 @vscale(float* %17, float %20)
%22 = getelementptr inbounds [4 x float], [4 x float]* %6, i64 0, i64 0
%23 = call i32 @vcross(float* %1, float* %0, float* %22)
%24 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 0
%25 = call i32 @vadd(float* %12, float* %17, float* %24)
%26 = call i32 @vadd(float* %22, float* %24, float* %24)
%27 = load float, float* %19
%28 = load float, float* %14
%29 = call float @vdot(float* %0, float* %1)
%30 = fneg float %29
%31 = call float @llvm.fmuladd.f32(float %27, float %28, float %30)
%32 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 3
store float %31, float* %32
%33 = load float, float* %24
store float %33, float* %2
%34 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 1
%35 = load float, float* %34
%36 = getelementptr inbounds float, float* %2, i64 1
store float %35, float* %36
%37 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 2
%38 = load float, float* %37
%39 = getelementptr inbounds float, float* %2, i64 2
store float %38, float* %39
%40 = getelementptr inbounds float, float* %2, i64 3
store float %31, float* %40
%41 = load i32, i32* @add_quats.count
%42 = add nsw i32 %41, 1
store i32 %42, i32* @add_quats.count
%43 = icmp sgt i32 %41, 96
br i1 %43, label %44, label %46
44: ; preds = %3
store i32 0, i32* @add_quats.count
%45 = call i32 @normalize_quat(float* %2)
br label %46
46: ; preds = %44, %3
ret void
}