#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 saturate(float);
float CalcWaterFogAlpha(const float flWaterZ, const float flEyePosZ,
                        const float flWorldPosZ, const float flProjPosZ,
                        const float flFogOORange) {
  float flDepthFromWater = flWaterZ - flWorldPosZ;
  float flDepthFromEye = flEyePosZ - flWorldPosZ;
  float f = saturate(flDepthFromWater * (1.0 / flDepthFromEye));
  return saturate(f * flProjPosZ * flFogOORange);
}


x86 assembly (clang, -O0):
<CalcWaterFogAlpha>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  %xmm4,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xe97(%rip),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <saturate@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
call   1030 <saturate@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalcWaterFogAlpha>:
push   %rax
movss  %xmm4,0x4(%rsp)
movss  %xmm3,(%rsp)
subss  %xmm2,%xmm0
subss  %xmm2,%xmm1
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
movsd  0xecc(%rip),%xmm2
divsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsd2ss %xmm2,%xmm0
call   1030 <saturate@plt>
mulss  (%rsp),%xmm0
mulss  0x4(%rsp),%xmm0
pop    %rax
jmp    1030 <saturate@plt>

LLVM IR (-O0):
define float @CalcWaterFogAlpha(float %0, float %1, float %2, float %3, float %4) {
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
store float %0, float* %6
store float %1, float* %7
store float %2, float* %8
store float %3, float* %9
store float %4, float* %10
%14 = load float, float* %6
%15 = load float, float* %8
%16 = fsub float %14, %15
store float %16, float* %11
%17 = load float, float* %7
%18 = load float, float* %8
%19 = fsub float %17, %18
store float %19, float* %12
%20 = load float, float* %11
%21 = fpext float %20 to double
%22 = load float, float* %12
%23 = fpext float %22 to double
%24 = fdiv double 1.000000e+00, %23
%25 = fmul double %21, %24
%26 = fptrunc double %25 to float
%27 = call float @saturate(float %26)
store float %27, float* %13
%28 = load float, float* %13
%29 = load float, float* %9
%30 = fmul float %28, %29
%31 = load float, float* %10
%32 = fmul float %30, %31
%33 = call float @saturate(float %32)
ret float %33
}

LLVM IR (-O2):
define float @CalcWaterFogAlpha(float %0, float %1, float %2, float %3, float %4) {
%6 = fsub float %0, %2
%7 = fsub float %1, %2
%8 = fpext float %6 to double
%9 = fpext float %7 to double
%10 = fdiv double 1.000000e+00, %9
%11 = fmul double %10, %8
%12 = fptrunc double %11 to float
%13 = tail call float @saturate(float %12)
%14 = fmul float %13, %3
%15 = fmul float %14, %4
%16 = tail call float @saturate(float %15)
ret float %16
}