#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 sqrtf(float);
void vec2_normalize(float *dst) {
  float x = dst[0], y = dst[1];
  float len = x * x + y * y;
  if (len > 0) {
    len = 1 / sqrtf(len);
    dst[0] = dst[0] * len;
    dst[1] = dst[1] * len;
  }
}


x86 assembly (clang, -O0):
<vec2_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
mulss  -0x10(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11b2 <vec2_normalize+0xa2>
movss  -0x14(%rbp),%xmm0
call   1030 <sqrtf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mulss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mulss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec2_normalize>:
push   %rbx
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    115e <vec2_normalize+0x4e>
mov    %rdi,%rbx
call   1030 <sqrtf@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovb  %eax,%edx
xorps  %xmm0,%xmm0
cvtsi2ss %edx,%xmm0
movss  (%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
mulss  0x4(%rbx),%xmm0
movss  %xmm0,0x4(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @vec2_normalize(float* %0) {
%2 = alloca float*
%3 = alloca float
%4 = alloca float
%5 = alloca float
store float* %0, float** %2
%6 = load float*, float** %2
%7 = getelementptr inbounds float, float* %6, i64 0
%8 = load float, float* %7
store float %8, float* %3
%9 = load float*, float** %2
%10 = getelementptr inbounds float, float* %9, i64 1
%11 = load float, float* %10
store float %11, float* %4
%12 = load float, float* %3
%13 = load float, float* %3
%14 = load float, float* %4
%15 = load float, float* %4
%16 = fmul float %14, %15
%17 = call float @llvm.fmuladd.f32(float %12, float %13, float %16)
store float %17, float* %5
%18 = load float, float* %5
%19 = fcmp ogt float %18, 0.000000e+00
br i1 %19, label %20, label %39
20: ; preds = %1
%21 = load float, float* %5
%22 = call i32 @sqrtf(float %21)
%23 = sdiv i32 1, %22
%24 = sitofp i32 %23 to float
store float %24, float* %5
%25 = load float*, float** %2
%26 = getelementptr inbounds float, float* %25, i64 0
%27 = load float, float* %26
%28 = load float, float* %5
%29 = fmul float %27, %28
%30 = load float*, float** %2
%31 = getelementptr inbounds float, float* %30, i64 0
store float %29, float* %31
%32 = load float*, float** %2
%33 = getelementptr inbounds float, float* %32, i64 1
%34 = load float, float* %33
%35 = load float, float* %5
%36 = fmul float %34, %35
%37 = load float*, float** %2
%38 = getelementptr inbounds float, float* %37, i64 1
store float %36, float* %38
br label %39
39: ; preds = %20, %1
ret void
}

LLVM IR (-O2):
define void @vec2_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 = fcmp ogt float %6, 0.000000e+00
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = tail call i32 @sqrtf(float %6)
%10 = add i32 %9, 1
%11 = icmp ult i32 %10, 3
%12 = select i1 %11, i32 %9, i32 0
%13 = sitofp i32 %12 to float
%14 = load float, float* %0
%15 = fmul float %14, %13
store float %15, float* %0
%16 = load float, float* %3
%17 = fmul float %16, %13
store float %17, float* %3
br label %18
18: ; preds = %8, %1
ret void
}