#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 */
float cos(float);
float sin(float);
float sqrt(float const);
void q_set(const float *dir, float angle, float *out) {
  float sinangle, length, ilength;
  length = sqrt(dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]);
  if (length != 0.0) {
    ilength = 1.0 / length;
    angle *= (3.14159265358979323846 / 180.0) / 2.0;
    sinangle = sin(angle);
    out[0] = dir[0] * ilength * sinangle;
    out[1] = dir[1] * ilength * sinangle;
    out[2] = dir[2] * ilength * sinangle;
    out[3] = cos(angle);
    return;
  }
  out[0] = out[1] = out[2] = 0.0;
  out[3] = 1.0;
}


x86 assembly (clang, -O0):
<q_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b4 <q_set+0x84>
jp     11b4 <q_set+0x84>
jmp    1269 <q_set+0x139>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe4b(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe25(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <sin@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mulss  -0x24(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mulss  -0x24(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
mulss  -0x24(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0xc(%rbp),%xmm0
call   1040 <cos@plt>
mov    -0x18(%rbp),%rax
movss  %xmm0,0xc(%rax)
jmp    129d <q_set+0x16d>
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movss  0xd68(%rip),%xmm0
movss  %xmm0,0xc(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<q_set>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
movaps %xmm0,%xmm2
mov    %rdi,%rbx
movss  (%rdi),%xmm1
movss  0x4(%rdi),%xmm0
mulss  %xmm0,%xmm0
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0x8(%rdi),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     116d <q_set+0x3d>
sqrtss %xmm0,%xmm0
jmp    117f <q_set+0x4f>
movss  %xmm2,(%rsp)
call   1050 <sqrt@plt>
xorps  %xmm1,%xmm1
movss  (%rsp),%xmm2
ucomiss %xmm1,%xmm0
jne    1186 <q_set+0x56>
jnp    11fa <q_set+0xca>
movss  0xe72(%rip),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
mulsd  0xe61(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rsp)
call   1030 <sin@plt>
movss  (%rbx),%xmm1
movss  0x4(%rsp),%xmm2
mulss  %xmm2,%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%r14)
movss  0x4(%rbx),%xmm1
mulss  %xmm2,%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x4(%r14)
mulss  0x8(%rbx),%xmm2
mulss  %xmm0,%xmm2
movss  %xmm2,0x8(%r14)
movss  (%rsp),%xmm0
call   1040 <cos@plt>
jmp    1211 <q_set+0xe1>
movl   $0x0,0x8(%r14)
movq   $0x0,(%r14)
movss  0xdef(%rip),%xmm0
movss  %xmm0,0xc(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @q_set(float* nocapture %0, float %1, float* nocapture writeonly %2) {
%4 = load float, float* %0
%5 = getelementptr inbounds float, float* %0, i64 1
%6 = load float, float* %5
%7 = fmul float %6, %6
%8 = tail call float @llvm.fmuladd.f32(float %4, float %4, float %7)
%9 = getelementptr inbounds float, float* %0, i64 2
%10 = load float, float* %9
%11 = tail call float @llvm.fmuladd.f32(float %10, float %10, float %8)
%12 = tail call float @sqrt(float %11)
%13 = fcmp une float %12, 0.000000e+00
br i1 %13, label %14, label %32
14: ; preds = %3
%15 = fdiv float 1.000000e+00, %12
%16 = fpext float %1 to double
%17 = fmul double %16, 0x3F81DF46A2529D39
%18 = fptrunc double %17 to float
%19 = tail call float @sin(float %18)
%20 = load float, float* %0
%21 = fmul float %15, %20
%22 = fmul float %19, %21
store float %22, float* %2
%23 = load float, float* %5
%24 = fmul float %15, %23
%25 = fmul float %19, %24
%26 = getelementptr inbounds float, float* %2, i64 1
store float %25, float* %26
%27 = load float, float* %9
%28 = fmul float %15, %27
%29 = fmul float %19, %28
%30 = getelementptr inbounds float, float* %2, i64 2
store float %29, float* %30
%31 = tail call float @cos(float %18)
br label %35
32: ; preds = %3
%33 = getelementptr inbounds float, float* %2, i64 2
store float 0.000000e+00, float* %33
%34 = getelementptr inbounds float, float* %2, i64 1
store float 0.000000e+00, float* %34
store float 0.000000e+00, float* %2
br label %35
35: ; preds = %32, %14
%36 = phi float [ %31, %14 ], [ 1.000000e+00, %32 ]
%37 = getelementptr inbounds float, float* %2, i64 3
store float %36, float* %37
ret void
}