#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 exp(float);
float min(float, float);
float pow(float, int);
float saturate(float);
float CookTorrenceSpecular(float NdotL, float NdotH, float NdotV, float VdotH,
                           float roughnessSquared) {
  float geo_numerator = 2.0f * NdotH;
  float geo_denominator = VdotH;
  float geo_b = (geo_numerator * NdotV) / geo_denominator;
  float geo_c = (geo_numerator * NdotL) / geo_denominator;
  float geo = min(1.0f, min(geo_b, geo_c));
  float finalRoughness;
  {
    float roughness_a = 1.0f / (4.0f * roughnessSquared * pow(NdotH, 4));
    float roughness_b = NdotH * NdotH - 1.0f;
    float roughness_c = roughnessSquared * NdotH * NdotH;
    finalRoughness = roughness_a * exp(roughness_b / roughness_c);
  }
  float Rs_numerator = (geo * finalRoughness);
  float Rs_denominator = NdotV * NdotL;
  float Rs = Rs_numerator / Rs_denominator;
  return saturate(NdotL) * Rs;
}


x86 assembly (clang, -O0):
<CookTorrenceSpecular>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  %xmm4,-0x14(%rbp)
movss  0xea3(%rip),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
divss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0x4(%rbp),%xmm0
divss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
call   1030 <min@plt>
movaps %xmm0,%xmm1
movss  0xe45(%rip),%xmm0
call   1030 <min@plt>
movss  %xmm0,-0x28(%rbp)
movss  0xe37(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x8(%rbp),%xmm0
mov    $0x4,%edi
call   1050 <pow@plt>
movss  -0x4c(%rbp),%xmm1
mulss  %xmm0,%xmm1
movss  0xe09(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  0xde6(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x34(%rbp),%xmm0
divss  -0x38(%rbp),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movss  -0x48(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x28(%rbp),%xmm0
mulss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0xc(%rbp),%xmm0
mulss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x3c(%rbp),%xmm0
divss  -0x40(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x4(%rbp),%xmm0
call   1060 <saturate@plt>
mulss  -0x44(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CookTorrenceSpecular>:
sub    $0x28,%rsp
movss  %xmm4,0x14(%rsp)
movss  %xmm2,0x24(%rsp)
movss  %xmm1,0x10(%rsp)
movaps %xmm0,%xmm4
movss  %xmm0,0x20(%rsp)
addss  %xmm1,%xmm1
movaps %xmm1,%xmm0
mulss  %xmm2,%xmm0
divss  %xmm3,%xmm0
mulss  %xmm4,%xmm1
divss  %xmm3,%xmm1
call   1030 <min@plt>
movaps %xmm0,%xmm1
movss  0xe7a(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
call   1030 <min@plt>
movss  %xmm0,0x1c(%rsp)
movss  0xe65(%rip),%xmm0
mulss  0x14(%rsp),%xmm0
movss  %xmm0,0x18(%rsp)
movss  0x10(%rsp),%xmm0
mov    $0x4,%edi
call   1050 <pow@plt>
mulss  0x18(%rsp),%xmm0
movss  0x10(%rsp),%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
addss  0xe32(%rip),%xmm1
movss  0xc(%rsp),%xmm3
divss  %xmm0,%xmm3
movss  %xmm3,0xc(%rsp)
movss  0x14(%rsp),%xmm0
mulss  %xmm2,%xmm0
mulss  %xmm2,%xmm0
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm2
mulss  0xc(%rsp),%xmm2
mulss  0x1c(%rsp),%xmm2
movss  0x20(%rsp),%xmm0
movss  0x24(%rsp),%xmm1
mulss  %xmm0,%xmm1
divss  %xmm1,%xmm2
movss  %xmm2,0xc(%rsp)
call   1060 <saturate@plt>
mulss  0xc(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define float @CookTorrenceSpecular(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
%14 = alloca float
%15 = alloca float
%16 = alloca float
%17 = alloca float
%18 = alloca float
%19 = alloca float
%20 = alloca float
%21 = alloca float
%22 = 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
%23 = load float, float* %7
%24 = fmul float 2.000000e+00, %23
store float %24, float* %11
%25 = load float, float* %9
store float %25, float* %12
%26 = load float, float* %11
%27 = load float, float* %8
%28 = fmul float %26, %27
%29 = load float, float* %12
%30 = fdiv float %28, %29
store float %30, float* %13
%31 = load float, float* %11
%32 = load float, float* %6
%33 = fmul float %31, %32
%34 = load float, float* %12
%35 = fdiv float %33, %34
store float %35, float* %14
%36 = load float, float* %13
%37 = load float, float* %14
%38 = call float @min(float %36, float %37)
%39 = call float @min(float 1.000000e+00, float %38)
store float %39, float* %15
%40 = load float, float* %10
%41 = fmul float 4.000000e+00, %40
%42 = load float, float* %7
%43 = call float @pow(float %42, i32 4)
%44 = fmul float %41, %43
%45 = fdiv float 1.000000e+00, %44
store float %45, float* %17
%46 = load float, float* %7
%47 = load float, float* %7
%48 = call float @llvm.fmuladd.f32(float %46, float %47, float -1.000000e+00)
store float %48, float* %18
%49 = load float, float* %10
%50 = load float, float* %7
%51 = fmul float %49, %50
%52 = load float, float* %7
%53 = fmul float %51, %52
store float %53, float* %19
%54 = load float, float* %17
%55 = load float, float* %18
%56 = load float, float* %19
%57 = fdiv float %55, %56
%58 = call float @exp(float %57)
%59 = fmul float %54, %58
store float %59, float* %16
%60 = load float, float* %15
%61 = load float, float* %16
%62 = fmul float %60, %61
store float %62, float* %20
%63 = load float, float* %8
%64 = load float, float* %6
%65 = fmul float %63, %64
store float %65, float* %21
%66 = load float, float* %20
%67 = load float, float* %21
%68 = fdiv float %66, %67
store float %68, float* %22
%69 = load float, float* %6
%70 = call float @saturate(float %69)
%71 = load float, float* %22
%72 = fmul float %70, %71
ret float %72
}

LLVM IR (-O2):
define float @CookTorrenceSpecular(float %0, float %1, float %2, float %3, float %4) {
%6 = fmul float %1, 2.000000e+00
%7 = fmul float %6, %2
%8 = fdiv float %7, %3
%9 = fmul float %6, %0
%10 = fdiv float %9, %3
%11 = tail call float @min(float %8, float %10)
%12 = tail call float @min(float 1.000000e+00, float %11)
%13 = fmul float %4, 4.000000e+00
%14 = tail call float @pow(float %1, i32 4)
%15 = fmul float %13, %14
%16 = fdiv float 1.000000e+00, %15
%17 = tail call float @llvm.fmuladd.f32(float %1, float %1, float -1.000000e+00)
%18 = fmul float %1, %4
%19 = fmul float %18, %1
%20 = fdiv float %17, %19
%21 = tail call float @exp(float %20)
%22 = fmul float %21, %16
%23 = fmul float %12, %22
%24 = fmul float %0, %2
%25 = fdiv float %23, %24
%26 = tail call float @saturate(float %0)
%27 = fmul float %26, %25
ret float %27
}