#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 */
double asin(double);
int /*<<< orphan*/ axis_to_quat(float *, float, float *);
float tb_project_to_sphere(float, float, float);
int /*<<< orphan*/ vcross(float const *, float const *, float *);
float vlength(float const *);
int /*<<< orphan*/ vset(float *, float, float, float);
int /*<<< orphan*/ vsub(float const *, float const *, float *);
int /*<<< orphan*/ vzero(float *);
void trackball(float *q, float p1x, float p1y, float p2x, float p2y) {
  float a[3];
  float phi;
  float p1[3];
  float p2[3];
  float d[3];
  float t;
  float tmp;
  float tmp___0;
  float tmp___1;
  double tmp___2;
  {
    if (p1x == p2x) {
      if (p1y == p2y) {
        vzero((float *)q);
        *(q + 3) = (float)1.0;
        return;
      }
    }
    tmp = tb_project_to_sphere((float)0.8, p1x, p1y);
    vset(p1, p1x, p1y, tmp);
    tmp___0 = tb_project_to_sphere((float)0.8, p2x, p2y);
    vset(p2, p2x, p2y, tmp___0);
    vcross((float const *)(p2), (float const *)(p1), a);
    vsub((float const *)(p1), (float const *)(p2), d);
    tmp___1 = vlength((float const *)(d));
    t = (float)((double)tmp___1 / (2.0 * 0.8));
    if ((double)t > 1.0) {
      t = (float)1.0;
    }
    if ((double)t < -1.0) {
      t = (float)(-1.0);
    }
    tmp___2 = asin((double)t);
    phi = (float)(2.0 * tmp___2);
    axis_to_quat((float *)(a), phi, q);
    return;
  }
}


x86 assembly (clang, -O0):
<trackball>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
movss  %xmm3,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
ucomiss -0x14(%rbp),%xmm0
jne    11ee <trackball+0x6e>
jp     11ee <trackball+0x6e>
movss  -0x10(%rbp),%xmm0
ucomiss -0x18(%rbp),%xmm0
jne    11e9 <trackball+0x69>
jp     11e9 <trackball+0x69>
mov    -0x8(%rbp),%rdi
call   10a0 <vzero@plt>
mov    -0x8(%rbp),%rax
movss  0xe45(%rip),%xmm0
movss  %xmm0,0xc(%rax)
jmp    132f <trackball+0x1af>
jmp    11ee <trackball+0x6e>
movss  -0xc(%rbp),%xmm1
movss  -0x10(%rbp),%xmm2
movss  0xe20(%rip),%xmm0
call   1030 <tb_project_to_sphere@plt>
movss  %xmm0,-0x54(%rbp)
lea    -0x34(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
movss  -0x54(%rbp),%xmm2
call   1060 <vset@plt>
movss  -0x14(%rbp),%xmm1
movss  -0x18(%rbp),%xmm2
movss  0xdec(%rip),%xmm0
call   1030 <tb_project_to_sphere@plt>
movss  %xmm0,-0x58(%rbp)
lea    -0x40(%rbp),%rdi
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
movss  -0x58(%rbp),%xmm2
call   1060 <vset@plt>
lea    -0x40(%rbp),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1090 <vcross@plt>
lea    -0x34(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1040 <vsub@plt>
lea    -0x4c(%rbp),%rdi
call   1050 <vlength@plt>
movss  %xmm0,-0x5c(%rbp)
movss  -0x5c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd71(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x50(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd4b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12cc <trackball+0x14c>
movss  0xd5d(%rip),%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x50(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd33(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12f4 <trackball+0x174>
movss  0xd39(%rip),%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x50(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1070 <asin@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  0xd09(%rip),%xmm0
mulsd  -0x68(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
lea    -0x24(%rbp),%rdi
movss  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rsi
call   1080 <axis_to_quat@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trackball>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
movaps %xmm1,%xmm4
movaps %xmm0,%xmm1
mov    %rdi,%r12
ucomiss %xmm2,%xmm0
jne    11ba <trackball+0x3a>
jp     11ba <trackball+0x3a>
ucomiss %xmm3,%xmm4
jne    11ba <trackball+0x3a>
jp     11ba <trackball+0x3a>
mov    %r12,%rdi
call   10a0 <vzero@plt>
movl   $0x3f800000,0xc(%r12)
80 3f
jmp    12a2 <trackball+0x122>
movss  0xe3e(%rip),%xmm0
movss  %xmm1,0xc(%rsp)
movss  %xmm2,(%rsp)
movaps %xmm4,%xmm2
movss  %xmm3,0x4(%rsp)
movss  %xmm4,0x8(%rsp)
call   1030 <tb_project_to_sphere@plt>
movaps %xmm0,%xmm2
lea    0x28(%rsp),%r15
mov    %r15,%rdi
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
call   1060 <vset@plt>
movss  0xdfb(%rip),%xmm0
movss  (%rsp),%xmm1
movss  0x4(%rsp),%xmm2
call   1030 <tb_project_to_sphere@plt>
movaps %xmm0,%xmm2
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
movss  (%rsp),%xmm0
movss  0x4(%rsp),%xmm1
call   1060 <vset@plt>
lea    0x34(%rsp),%r14
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1090 <vcross@plt>
lea    0x10(%rsp),%r13
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1040 <vsub@plt>
mov    %r13,%rdi
call   1050 <vlength@plt>
cvtss2sd %xmm0,%xmm0
divsd  0xda6(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  0xd8e(%rip),%xmm1
minss  %xmm0,%xmm1
movss  0xd86(%rip),%xmm0
maxss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
call   1070 <asin@plt>
addsd  %xmm0,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <axis_to_quat@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @trackball(float* %0, float %1, float %2, float %3, float %4) {
%6 = alloca float*
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca [3 x float]
%12 = alloca float
%13 = alloca [3 x float]
%14 = alloca [3 x float]
%15 = alloca [3 x float]
%16 = alloca float
%17 = alloca float
%18 = alloca float
%19 = alloca float
%20 = alloca double
store float* %0, float** %6
store float %1, float* %7
store float %2, float* %8
store float %3, float* %9
store float %4, float* %10
%21 = load float, float* %7
%22 = load float, float* %9
%23 = fcmp oeq float %21, %22
br i1 %23, label %24, label %34
24: ; preds = %5
%25 = load float, float* %8
%26 = load float, float* %10
%27 = fcmp oeq float %25, %26
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load float*, float** %6
%30 = call i32 @vzero(float* %29)
%31 = load float*, float** %6
%32 = getelementptr inbounds float, float* %31, i64 3
store float 1.000000e+00, float* %32
br label %85
33: ; preds = %24
br label %34
34: ; preds = %33, %5
%35 = load float, float* %7
%36 = load float, float* %8
%37 = call float @tb_project_to_sphere(float 0x3FE99999A0000000, float %35, float %36)
store float %37, float* %17
%38 = getelementptr inbounds [3 x float], [3 x float]* %13, i64 0, i64 0
%39 = load float, float* %7
%40 = load float, float* %8
%41 = load float, float* %17
%42 = call i32 @vset(float* %38, float %39, float %40, float %41)
%43 = load float, float* %9
%44 = load float, float* %10
%45 = call float @tb_project_to_sphere(float 0x3FE99999A0000000, float %43, float %44)
store float %45, float* %18
%46 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%47 = load float, float* %9
%48 = load float, float* %10
%49 = load float, float* %18
%50 = call i32 @vset(float* %46, float %47, float %48, float %49)
%51 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%52 = getelementptr inbounds [3 x float], [3 x float]* %13, i64 0, i64 0
%53 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%54 = call i32 @vcross(float* %51, float* %52, float* %53)
%55 = getelementptr inbounds [3 x float], [3 x float]* %13, i64 0, i64 0
%56 = getelementptr inbounds [3 x float], [3 x float]* %14, i64 0, i64 0
%57 = getelementptr inbounds [3 x float], [3 x float]* %15, i64 0, i64 0
%58 = call i32 @vsub(float* %55, float* %56, float* %57)
%59 = getelementptr inbounds [3 x float], [3 x float]* %15, i64 0, i64 0
%60 = call float @vlength(float* %59)
store float %60, float* %19
%61 = load float, float* %19
%62 = fpext float %61 to double
%63 = fdiv double %62, 1.600000e+00
%64 = fptrunc double %63 to float
store float %64, float* %16
%65 = load float, float* %16
%66 = fpext float %65 to double
%67 = fcmp ogt double %66, 1.000000e+00
br i1 %67, label %68, label %69
68: ; preds = %34
store float 1.000000e+00, float* %16
br label %69
69: ; preds = %68, %34
%70 = load float, float* %16
%71 = fpext float %70 to double
%72 = fcmp olt double %71, -1.000000e+00
br i1 %72, label %73, label %74
73: ; preds = %69
store float -1.000000e+00, float* %16
br label %74
74: ; preds = %73, %69
%75 = load float, float* %16
%76 = fpext float %75 to double
%77 = call double @asin(double %76)
store double %77, double* %20
%78 = load double, double* %20
%79 = fmul double 2.000000e+00, %78
%80 = fptrunc double %79 to float
store float %80, float* %12
%81 = getelementptr inbounds [3 x float], [3 x float]* %11, i64 0, i64 0
%82 = load float, float* %12
%83 = load float*, float** %6
%84 = call i32 @axis_to_quat(float* %81, float %82, float* %83)
br label %85
85: ; preds = %74, %28
ret void
}

LLVM IR (-O2):
define void @trackball(float* %0, float %1, float %2, float %3, float %4) {
%6 = alloca [3 x float]
%7 = alloca [3 x float]
%8 = alloca [3 x float]
%9 = alloca [3 x float]
%10 = bitcast [3 x float]* %6 to i8*
%11 = bitcast [3 x float]* %7 to i8*
%12 = bitcast [3 x float]* %8 to i8*
%13 = bitcast [3 x float]* %9 to i8*
%14 = fcmp oeq float %1, %3
%15 = fcmp oeq float %2, %4
%16 = and i1 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %5
%18 = tail call i32 @vzero(float* %0)
%19 = getelementptr inbounds float, float* %0, i64 3
store float 1.000000e+00, float* %19
br label %44
20: ; preds = %5
%21 = tail call float @tb_project_to_sphere(float 0x3FE99999A0000000, float %1, float %2)
%22 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
%23 = call i32 @vset(float* %22, float %1, float %2, float %21)
%24 = call float @tb_project_to_sphere(float 0x3FE99999A0000000, float %3, float %4)
%25 = getelementptr inbounds [3 x float], [3 x float]* %8, i64 0, i64 0
%26 = call i32 @vset(float* %25, float %3, float %4, float %24)
%27 = getelementptr inbounds [3 x float], [3 x float]* %6, i64 0, i64 0
%28 = call i32 @vcross(float* %25, float* %22, float* %27)
%29 = getelementptr inbounds [3 x float], [3 x float]* %9, i64 0, i64 0
%30 = call i32 @vsub(float* %22, float* %25, float* %29)
%31 = call float @vlength(float* %29)
%32 = fpext float %31 to double
%33 = fdiv double %32, 1.600000e+00
%34 = fptrunc double %33 to float
%35 = fcmp ogt float %34, 1.000000e+00
%36 = select i1 %35, float 1.000000e+00, float %34
%37 = fcmp olt float %36, -1.000000e+00
%38 = select i1 %37, float -1.000000e+00, float %36
%39 = fpext float %38 to double
%40 = call double @asin(double %39)
%41 = fmul double %40, 2.000000e+00
%42 = fptrunc double %41 to float
%43 = call i32 @axis_to_quat(float* %27, float %42, float* %0)
br label %44
44: ; preds = %20, %17
ret void
}