#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 sqrt(float);
float *qunit(float *a, float *aunit) {
  float norm = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]);
  if (!norm)
    aunit[0] = aunit[1] = aunit[2] = aunit[3] = 0;
  else {
    aunit[0] = a[0] / norm;
    aunit[1] = a[1] / norm;
    aunit[2] = a[2] / norm;
    aunit[3] = a[3] / norm;
  }
  return (aunit);
}


x86 assembly (clang, -O0):
<qunit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrt@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11d3 <qunit+0xc3>
jp     11d3 <qunit+0xc3>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
jmp    122d <qunit+0x11d>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0xc(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qunit>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
movss  0x8(%rdi),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0xc(%rdi),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1157 <qunit+0x47>
sqrtss %xmm0,%xmm0
jmp    115f <qunit+0x4f>
call   1030 <sqrt@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1166 <qunit+0x56>
jnp    119c <qunit+0x8c>
movss  (%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,(%r14)
movss  0x4(%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x4(%r14)
movss  0x8(%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x8(%r14)
movss  0xc(%rbx),%xmm1
divss  %xmm0,%xmm1
jmp    11ae <qunit+0x9e>
movl   $0x0,0x8(%r14)
movq   $0x0,(%r14)
xorps  %xmm1,%xmm1
movss  %xmm1,0xc(%r14)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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