#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);
scalar_t__ backfacing();
int /*<<< orphan*/ max(double, double);
double sqr(float);
float sqrt(int /*<<< orphan*/);
float dielectricDielectricFresnel(float etai, float etat, float costhetai) {
  float eta_i, eta_t, costheta_i;
  if (backfacing()) {
    eta_i = etai;
    eta_t = etat;
    costheta_i = costhetai;
  } else {
    eta_i = etat;
    eta_t = etai;
    costheta_i = abs(costhetai);
  }
  float sintheta_i = sqrt(max(0.0, 1.0 - sqr(costheta_i)));
  float sintheta_t = eta_i / eta_t * sintheta_i;
  if (sintheta_t >= 1.0) {
    return 1.0;
  }
  float costheta_t = sqrt(max(0.0, 1.0 - sqr(sintheta_t)));
  float eta_t_costheta_i = eta_t * costheta_i;
  float eta_t_costheta_t = eta_t * costheta_t;
  float eta_i_costheta_i = eta_i * costheta_i;
  float eta_i_costheta_t = eta_i * costheta_t;
  float Rs = (eta_t_costheta_i - eta_i_costheta_t) /
             (eta_t_costheta_i + eta_i_costheta_t);
  float Rp = (eta_i_costheta_i - eta_t_costheta_t) /
             (eta_i_costheta_i + eta_t_costheta_t);
  return (sqr(Rs) + sqr(Rp)) / 2.0;
}


x86 assembly (clang, -O0):
<dielectricDielectricFresnel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
mov    $0x0,%al
call   1060 <backfacing@plt>
cmp    $0x0,%rax
je     119b <dielectricDielectricFresnel+0x4b>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11be <dielectricDielectricFresnel+0x6e>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <abs@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1050 <sqr@plt>
movsd  0xe30(%rip),%xmm1
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
call   1040 <max@plt>
mov    %eax,%edi
call   1070 <sqrt@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
divss  -0x18(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdf3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1229 <dielectricDielectricFresnel+0xd9>
movss  0xdf1(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1303 <dielectricDielectricFresnel+0x1b3>
movss  -0x24(%rbp),%xmm0
call   1050 <sqr@plt>
movsd  0xdc5(%rip),%xmm1
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
call   1040 <max@plt>
mov    %eax,%edi
call   1070 <sqrt@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x2c(%rbp),%xmm0
subss  -0x38(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm1
addss  -0x38(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x34(%rbp),%xmm0
subss  -0x30(%rbp),%xmm0
movss  -0x34(%rbp),%xmm1
addss  -0x30(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1050 <sqr@plt>
movsd  %xmm0,-0x48(%rbp)
movss  -0x40(%rbp),%xmm0
call   1050 <sqr@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xd12(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dielectricDielectricFresnel>:
sub    $0x18,%rsp
movss  %xmm2,0x4(%rsp)
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0x14(%rsp)
xor    %eax,%eax
call   1060 <backfacing@plt>
test   %rax,%rax
je     1192 <dielectricDielectricFresnel+0x42>
movss  0x8(%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
movss  0x14(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
movss  0x4(%rsp),%xmm0
jmp    11a9 <dielectricDielectricFresnel+0x59>
movss  0x4(%rsp),%xmm0
call   1030 <abs@plt>
movss  0x14(%rsp),%xmm1
movss  %xmm1,0x10(%rsp)
movss  %xmm0,0x4(%rsp)
call   1050 <sqr@plt>
movsd  0xe44(%rip),%xmm1
subsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
call   1040 <max@plt>
mov    %eax,%edi
call   1070 <sqrt@plt>
movapd %xmm0,%xmm1
movss  0x8(%rsp),%xmm2
movaps %xmm2,%xmm0
divss  0x10(%rsp),%xmm0
mulss  %xmm1,%xmm0
movss  0xe21(%rip),%xmm1
ucomiss %xmm1,%xmm0
jae    1292 <dielectricDielectricFresnel+0x142>
movss  %xmm2,0x8(%rsp)
call   1050 <sqr@plt>
movsd  0xdf5(%rip),%xmm1
subsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
call   1040 <max@plt>
mov    %eax,%edi
call   1070 <sqrt@plt>
movss  0x4(%rsp),%xmm3
movaps %xmm3,%xmm1
movss  0x10(%rsp),%xmm2
mulss  %xmm2,%xmm1
mulss  %xmm0,%xmm2
movss  0x8(%rsp),%xmm4
mulss  %xmm4,%xmm3
mulss  %xmm0,%xmm4
movaps %xmm1,%xmm0
subss  %xmm4,%xmm0
addss  %xmm1,%xmm4
divss  %xmm4,%xmm0
movaps %xmm3,%xmm1
subss  %xmm2,%xmm1
addss  %xmm2,%xmm3
divss  %xmm3,%xmm1
movss  %xmm1,0x4(%rsp)
call   1050 <sqr@plt>
movsd  %xmm0,0x8(%rsp)
movss  0x4(%rsp),%xmm0
call   1050 <sqr@plt>
addsd  0x8(%rsp),%xmm0
mulsd  0xd7d(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @dielectricDielectricFresnel(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%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
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
%20 = call i64 (...) @backfacing()
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %3
%23 = load float, float* %5
store float %23, float* %8
%24 = load float, float* %6
store float %24, float* %9
%25 = load float, float* %7
store float %25, float* %10
br label %31
26: ; preds = %3
%27 = load float, float* %6
store float %27, float* %8
%28 = load float, float* %5
store float %28, float* %9
%29 = load float, float* %7
%30 = call float @abs(float %29)
store float %30, float* %10
br label %31
31: ; preds = %26, %22
%32 = load float, float* %10
%33 = call double @sqr(float %32)
%34 = fsub double 1.000000e+00, %33
%35 = call i32 @max(double 0.000000e+00, double %34)
%36 = call float @sqrt(i32 %35)
store float %36, float* %11
%37 = load float, float* %8
%38 = load float, float* %9
%39 = fdiv float %37, %38
%40 = load float, float* %11
%41 = fmul float %39, %40
store float %41, float* %12
%42 = load float, float* %12
%43 = fpext float %42 to double
%44 = fcmp oge double %43, 1.000000e+00
br i1 %44, label %45, label %46
45: ; preds = %31
store float 1.000000e+00, float* %4
br label %85
46: ; preds = %31
%47 = load float, float* %12
%48 = call double @sqr(float %47)
%49 = fsub double 1.000000e+00, %48
%50 = call i32 @max(double 0.000000e+00, double %49)
%51 = call float @sqrt(i32 %50)
store float %51, float* %13
%52 = load float, float* %9
%53 = load float, float* %10
%54 = fmul float %52, %53
store float %54, float* %14
%55 = load float, float* %9
%56 = load float, float* %13
%57 = fmul float %55, %56
store float %57, float* %15
%58 = load float, float* %8
%59 = load float, float* %10
%60 = fmul float %58, %59
store float %60, float* %16
%61 = load float, float* %8
%62 = load float, float* %13
%63 = fmul float %61, %62
store float %63, float* %17
%64 = load float, float* %14
%65 = load float, float* %17
%66 = fsub float %64, %65
%67 = load float, float* %14
%68 = load float, float* %17
%69 = fadd float %67, %68
%70 = fdiv float %66, %69
store float %70, float* %18
%71 = load float, float* %16
%72 = load float, float* %15
%73 = fsub float %71, %72
%74 = load float, float* %16
%75 = load float, float* %15
%76 = fadd float %74, %75
%77 = fdiv float %73, %76
store float %77, float* %19
%78 = load float, float* %18
%79 = call double @sqr(float %78)
%80 = load float, float* %19
%81 = call double @sqr(float %80)
%82 = fadd double %79, %81
%83 = fdiv double %82, 2.000000e+00
%84 = fptrunc double %83 to float
store float %84, float* %4
br label %85
85: ; preds = %46, %45
%86 = load float, float* %4
ret float %86
}

LLVM IR (-O2):
define float @dielectricDielectricFresnel(float %0, float %1, float %2) {
%4 = tail call i64 (...) @backfacing()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call float @abs(float %2)
br label %8
8: ; preds = %3, %6
%9 = phi float [ %7, %6 ], [ %2, %3 ]
%10 = phi float [ %0, %6 ], [ %1, %3 ]
%11 = phi float [ %1, %6 ], [ %0, %3 ]
%12 = tail call double @sqr(float %9)
%13 = fsub double 1.000000e+00, %12
%14 = tail call i32 @max(double 0.000000e+00, double %13)
%15 = tail call float @sqrt(i32 %14)
%16 = fdiv float %11, %10
%17 = fmul float %16, %15
%18 = fcmp ult float %17, 1.000000e+00
br i1 %18, label %19, label %39
19: ; preds = %8
%20 = tail call double @sqr(float %17)
%21 = fsub double 1.000000e+00, %20
%22 = tail call i32 @max(double 0.000000e+00, double %21)
%23 = tail call float @sqrt(i32 %22)
%24 = fmul float %9, %10
%25 = fmul float %10, %23
%26 = fmul float %9, %11
%27 = fmul float %11, %23
%28 = fsub float %24, %27
%29 = fadd float %24, %27
%30 = fdiv float %28, %29
%31 = fsub float %26, %25
%32 = fadd float %26, %25
%33 = fdiv float %31, %32
%34 = tail call double @sqr(float %30)
%35 = tail call double @sqr(float %33)
%36 = fadd double %34, %35
%37 = fmul double %36, 5.000000e-01
%38 = fptrunc double %37 to float
br label %39
39: ; preds = %8, %19
%40 = phi float [ %38, %19 ], [ 1.000000e+00, %8 ]
ret float %40
}