#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 fabs(float);
scalar_t__ sqrt(float);
void lib3ds_vector_normalize(float c[3]) {
  float l, m;
  l = (float)sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]);
  if (fabs(l) < (1e-5)) {
    if ((c[0] >= c[1]) && (c[0] >= c[2])) {
      c[0] = 1.0f;
      c[1] = c[2] = 0.0f;
    } else if (c[1] >= c[2]) {
      c[1] = 1.0f;
      c[0] = c[2] = 0.0f;
    } else {
      c[2] = 1.0f;
      c[0] = c[1] = 0.0f;
    }
  } else {
    m = 1.0f / l;
    c[0] *= m;
    c[1] *= m;
    c[2] *= m;
  }
}


x86 assembly (clang, -O0):
<lib3ds_vector_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%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   1040 <sqrt@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe6b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    126e <lib3ds_vector_normalize+0x14e>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomiss 0x4(%rax),%xmm0
jb     11f8 <lib3ds_vector_normalize+0xd8>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomiss 0x8(%rax),%xmm0
jb     11f8 <lib3ds_vector_normalize+0xd8>
mov    -0x8(%rbp),%rax
movss  0xe31(%rip),%xmm0
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
jmp    1269 <lib3ds_vector_normalize+0x149>
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
ucomiss 0x8(%rax),%xmm0
jb     123c <lib3ds_vector_normalize+0x11c>
mov    -0x8(%rbp),%rax
movss  0xded(%rip),%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
jmp    1264 <lib3ds_vector_normalize+0x144>
mov    -0x8(%rbp),%rax
movss  0xdc0(%rip),%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
jmp    1269 <lib3ds_vector_normalize+0x149>
jmp    12b7 <lib3ds_vector_normalize+0x197>
movss  0xd92(%rip),%xmm0
divss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,(%rax)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
movss  %xmm0,0x4(%rax)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x8(%rax),%xmm0
movss  %xmm0,0x8(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib3ds_vector_normalize>:
push   %rbx
sub    $0x10,%rsp
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
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0xc(%rsp)
call   1030 <fabs@plt>
test   %eax,%eax
jle    119a <lib3ds_vector_normalize+0x7a>
movss  0xe92(%rip),%xmm0
divss  0xc(%rsp),%xmm0
movss  (%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
movss  0x4(%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x4(%rbx)
mulss  0x8(%rbx),%xmm0
movss  %xmm0,0x8(%rbx)
jmp    11eb <lib3ds_vector_normalize+0xcb>
movss  (%rbx),%xmm2
movss  0x4(%rbx),%xmm0
ucomiss %xmm0,%xmm2
movss  0x8(%rbx),%xmm1
jb     11c2 <lib3ds_vector_normalize+0xa2>
ucomiss %xmm1,%xmm2
jb     11c2 <lib3ds_vector_normalize+0xa2>
movq   $0x3f800000,(%rbx)
movl   $0x0,0x8(%rbx)
jmp    11eb <lib3ds_vector_normalize+0xcb>
ucomiss %xmm1,%xmm0
jae    11d7 <lib3ds_vector_normalize+0xb7>
movl   $0x3f800000,0x8(%rbx)
movq   $0x0,(%rbx)
jmp    11eb <lib3ds_vector_normalize+0xcb>
movl   $0x0,0x8(%rbx)
movabs $0x3f80000000000000,%rax
mov    %rax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define void @lib3ds_vector_normalize(float* nocapture %0) {
%2 = load float, float* %0
%3 = getelementptr inbounds float, float* %0, i64 1
%4 = load float, float* %3
%5 = fmul float %4, %4
%6 = tail call float @llvm.fmuladd.f32(float %2, float %2, float %5)
%7 = getelementptr inbounds float, float* %0, i64 2
%8 = load float, float* %7
%9 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %6)
%10 = tail call i64 @sqrt(float %9)
%11 = sitofp i64 %10 to float
%12 = tail call i32 @fabs(float %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %26
14: ; preds = %1
%15 = load float, float* %0
%16 = load float, float* %3
%17 = fcmp ult float %15, %16
%18 = load float, float* %7
%19 = fcmp ult float %15, %18
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %22, label %21
21: ; preds = %14
store float 1.000000e+00, float* %0
store float 0.000000e+00, float* %7
store float 0.000000e+00, float* %3
br label %34
22: ; preds = %14
%23 = fcmp ult float %16, %18
br i1 %23, label %25, label %24
24: ; preds = %22
store float 1.000000e+00, float* %3
store float 0.000000e+00, float* %7
store float 0.000000e+00, float* %0
br label %34
25: ; preds = %22
store float 1.000000e+00, float* %7
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %0
br label %34
26: ; preds = %1
%27 = fdiv float 1.000000e+00, %11
%28 = load float, float* %0
%29 = fmul float %27, %28
store float %29, float* %0
%30 = load float, float* %3
%31 = fmul float %27, %30
store float %31, float* %3
%32 = load float, float* %7
%33 = fmul float %27, %32
store float %33, float* %7
br label %34
34: ; preds = %21, %25, %24, %26
ret void
}