#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 */
typedef int int32_t;

/* Variables and functions */
float fast_inv_sqrt(float a) {
  union fi32_u {
    float f;
    int32_t i;
  };
  union fi32_u x;
  x.f = a;
  x.i = 0x5f3759df - (x.i >> 1);
  x.f = x.f * (1.5f - x.f * x.f * 0.5f * a);
  x.f = x.f * (1.5f - x.f * x.f * 0.5f * a);
  return x.f;
}


x86 assembly (clang, -O0):
<fast_inv_sqrt>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
sar    $0x1,%ecx
mov    $0x5f3759df,%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mulss  -0x8(%rbp),%xmm1
movss  0xeca(%rip),%xmm2
mulss  %xmm2,%xmm1
movss  -0x4(%rbp),%xmm2
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm1
movss  0xea4(%rip),%xmm2
addss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mulss  -0x8(%rbp),%xmm1
movss  0xe84(%rip),%xmm2
mulss  %xmm2,%xmm1
movss  -0x4(%rbp),%xmm2
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm1
movss  0xe5e(%rip),%xmm2
addss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<fast_inv_sqrt>:
movd   %xmm0,%eax
sar    %eax
mov    $0x5f3759df,%ecx
sub    %eax,%ecx
movd   %ecx,%xmm1
movdqa %xmm1,%xmm2
mulss  %xmm1,%xmm2
movss  0xedf(%rip),%xmm3
mulss  %xmm3,%xmm2
mulss  %xmm0,%xmm2
movss  0xed3(%rip),%xmm4
addss  %xmm4,%xmm2
mulss  %xmm1,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
mulss  %xmm3,%xmm1
mulss  %xmm1,%xmm0
addss  %xmm4,%xmm0
mulss  %xmm2,%xmm0
ret

LLVM IR (-O0):
%union.fi32_u = type { float }
define float @fast_inv_sqrt(float %0) {
%2 = alloca float
%3 = alloca %union.fi32_u
store float %0, float* %2
%4 = load float, float* %2
%5 = bitcast %union.fi32_u* %3 to float*
store float %4, float* %5
%6 = bitcast %union.fi32_u* %3 to i32*
%7 = load i32, i32* %6
%8 = ashr i32 %7, 1
%9 = sub nsw i32 1597463007, %8
%10 = bitcast %union.fi32_u* %3 to i32*
store i32 %9, i32* %10
%11 = bitcast %union.fi32_u* %3 to float*
%12 = load float, float* %11
%13 = bitcast %union.fi32_u* %3 to float*
%14 = load float, float* %13
%15 = bitcast %union.fi32_u* %3 to float*
%16 = load float, float* %15
%17 = fmul float %14, %16
%18 = fmul float %17, 5.000000e-01
%19 = load float, float* %2
%20 = fneg float %18
%21 = call float @llvm.fmuladd.f32(float %20, float %19, float 1.500000e+00)
%22 = fmul float %12, %21
%23 = bitcast %union.fi32_u* %3 to float*
store float %22, float* %23
%24 = bitcast %union.fi32_u* %3 to float*
%25 = load float, float* %24
%26 = bitcast %union.fi32_u* %3 to float*
%27 = load float, float* %26
%28 = bitcast %union.fi32_u* %3 to float*
%29 = load float, float* %28
%30 = fmul float %27, %29
%31 = fmul float %30, 5.000000e-01
%32 = load float, float* %2
%33 = fneg float %31
%34 = call float @llvm.fmuladd.f32(float %33, float %32, float 1.500000e+00)
%35 = fmul float %25, %34
%36 = bitcast %union.fi32_u* %3 to float*
store float %35, float* %36
%37 = bitcast %union.fi32_u* %3 to float*
%38 = load float, float* %37
ret float %38
}

LLVM IR (-O2):
define float @fast_inv_sqrt(float %0) {
%2 = bitcast float %0 to i32
%3 = ashr i32 %2, 1
%4 = sub nsw i32 1597463007, %3
%5 = bitcast i32 %4 to float
%6 = fmul float %5, %5
%7 = fmul float %6, -5.000000e-01
%8 = tail call float @llvm.fmuladd.f32(float %7, float %0, float 1.500000e+00)
%9 = fmul float %8, %5
%10 = fmul float %9, %9
%11 = fmul float %10, -5.000000e-01
%12 = tail call float @llvm.fmuladd.f32(float %11, float %0, float 1.500000e+00)
%13 = fmul float %9, %12
ret float %13
}