#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 abs(float);
float sqrt(float);
float fresnelDielectricCos(float cosi, float eta) {
  float c = abs(cosi);
  float g = eta * eta - 1 + c * c;
  float result;
  if (g > 0) {
    g = sqrt(g);
    float A = (g - c) / (g + c);
    float B = (c * (g + c) - 1) / (c * (g - c) + 1);
    result = 0.5 * A * A * (1 + B * B);
  } else
    result = 1.0;
  return result;
}


x86 assembly (clang, -O0):
<fresnelDielectricCos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <abs@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
mulss  %xmm0,%xmm1
movss  0xea9(%rip),%xmm0
addss  %xmm0,%xmm1
movss  -0xc(%rbp),%xmm0
movss  -0xc(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1248 <fresnelDielectricCos+0x128>
movss  -0x10(%rbp),%xmm0
call   1040 <sqrt@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
addss  -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
addss  -0xc(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  0xe36(%rip),%xmm1
addss  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
movss  -0x10(%rbp),%xmm2
subss  -0xc(%rbp),%xmm2
mulss  %xmm2,%xmm1
movss  0xe1b(%rip),%xmm2
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe01(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x18(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movss  -0x1c(%rbp),%xmm1
movss  -0x1c(%rbp),%xmm2
mulss  %xmm2,%xmm1
movss  0xdd6(%rip),%xmm2
addss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1255 <fresnelDielectricCos+0x135>
movss  0xdb4(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fresnelDielectricCos>:
push   %rax
movss  %xmm1,0x4(%rsp)
call   1030 <abs@plt>
movaps %xmm0,%xmm3
movss  0x4(%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  0xebf(%rip),%xmm0
movaps %xmm0,%xmm1
movaps %xmm3,%xmm0
mulss  %xmm3,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    115f <fresnelDielectricCos+0x3f>
jb     1169 <fresnelDielectricCos+0x49>
sqrtss %xmm0,%xmm0
jmp    117a <fresnelDielectricCos+0x5a>
movss  0xe9d(%rip),%xmm0
pop    %rax
ret
movss  %xmm3,0x4(%rsp)
call   1040 <sqrt@plt>
movss  0x4(%rsp),%xmm3
movaps %xmm3,%xmm1
addss  %xmm0,%xmm1
subss  %xmm3,%xmm0
movaps %xmm0,%xmm2
divss  %xmm1,%xmm2
mulss  %xmm3,%xmm1
addss  0xe68(%rip),%xmm1
mulss  %xmm3,%xmm0
movss  0xe60(%rip),%xmm3
addss  %xmm3,%xmm0
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
movsd  0xe4d(%rip),%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulss  %xmm1,%xmm1
addss  %xmm3,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mulsd  %xmm2,%xmm0
cvtsd2ss %xmm0,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @fresnelDielectricCos(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
store float %0, float* %3
store float %1, float* %4
%10 = load float, float* %3
%11 = call float @abs(float %10)
store float %11, float* %5
%12 = load float, float* %4
%13 = load float, float* %4
%14 = call float @llvm.fmuladd.f32(float %12, float %13, float -1.000000e+00)
%15 = load float, float* %5
%16 = load float, float* %5
%17 = call float @llvm.fmuladd.f32(float %15, float %16, float %14)
store float %17, float* %6
%18 = load float, float* %6
%19 = fcmp ogt float %18, 0.000000e+00
br i1 %19, label %20, label %53
20: ; preds = %2
%21 = load float, float* %6
%22 = call float @sqrt(float %21)
store float %22, float* %6
%23 = load float, float* %6
%24 = load float, float* %5
%25 = fsub float %23, %24
%26 = load float, float* %6
%27 = load float, float* %5
%28 = fadd float %26, %27
%29 = fdiv float %25, %28
store float %29, float* %8
%30 = load float, float* %5
%31 = load float, float* %6
%32 = load float, float* %5
%33 = fadd float %31, %32
%34 = call float @llvm.fmuladd.f32(float %30, float %33, float -1.000000e+00)
%35 = load float, float* %5
%36 = load float, float* %6
%37 = load float, float* %5
%38 = fsub float %36, %37
%39 = call float @llvm.fmuladd.f32(float %35, float %38, float 1.000000e+00)
%40 = fdiv float %34, %39
store float %40, float* %9
%41 = load float, float* %8
%42 = fpext float %41 to double
%43 = fmul double 5.000000e-01, %42
%44 = load float, float* %8
%45 = fpext float %44 to double
%46 = fmul double %43, %45
%47 = load float, float* %9
%48 = load float, float* %9
%49 = call float @llvm.fmuladd.f32(float %47, float %48, float 1.000000e+00)
%50 = fpext float %49 to double
%51 = fmul double %46, %50
%52 = fptrunc double %51 to float
store float %52, float* %7
br label %54
53: ; preds = %2
store float 1.000000e+00, float* %7
br label %54
54: ; preds = %53, %20
%55 = load float, float* %7
ret float %55
}

LLVM IR (-O2):
define float @fresnelDielectricCos(float %0, float %1) {
%3 = tail call float @abs(float %0)
%4 = tail call float @llvm.fmuladd.f32(float %1, float %1, float -1.000000e+00)
%5 = tail call float @llvm.fmuladd.f32(float %3, float %3, float %4)
%6 = fcmp ogt float %5, 0.000000e+00
br i1 %6, label %7, label %22
7: ; preds = %2
%8 = tail call float @sqrt(float %5)
%9 = fsub float %8, %3
%10 = fadd float %3, %8
%11 = fdiv float %9, %10
%12 = tail call float @llvm.fmuladd.f32(float %3, float %10, float -1.000000e+00)
%13 = tail call float @llvm.fmuladd.f32(float %3, float %9, float 1.000000e+00)
%14 = fdiv float %12, %13
%15 = fpext float %11 to double
%16 = fmul double %15, 5.000000e-01
%17 = fmul double %16, %15
%18 = tail call float @llvm.fmuladd.f32(float %14, float %14, float 1.000000e+00)
%19 = fpext float %18 to double
%20 = fmul double %17, %19
%21 = fptrunc double %20 to float
br label %22
22: ; preds = %2, %7
%23 = phi float [ %21, %7 ], [ 1.000000e+00, %2 ]
ret float %23
}