#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 sqr(float);
float sqrt(double);
float dielectricConductorFresnel(float etai, float etat, float k,
                                 float costhetai) {
  float eta = etat / etai;
  float etak = k / etai;
  float costheta_i2 = sqr(costhetai);
  float sintheta_i2 = 1.0 - costheta_i2;
  float eta2 = sqr(eta);
  float etak2 = sqr(etak);
  float t0 = eta2 - etak2 - sintheta_i2;
  float a2b2sum = sqrt(sqr(t0) + 4.0 * eta2 * etak2);
  float t1 = a2b2sum + costheta_i2;
  float sqrt_a = sqrt(0.5 * (a2b2sum + t0));
  float t2 = 2.0 * costhetai * sqrt_a;
  float Rs = (t1 - t2) / (t1 + t2);
  float t3 = a2b2sum * costheta_i2 + sqr(sintheta_i2);
  float t4 = t2 * sintheta_i2;
  float Rp = Rs * (t3 - t4) / (t3 + t4);
  return 0.5 * (Rp + Rs);
}


x86 assembly (clang, -O0):
<dielectricConductorFresnel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
divss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
divss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <sqr@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe9e(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <sqr@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <sqr@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
subss  -0x28(%rbp),%xmm0
subss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
call   1030 <sqr@plt>
cvtss2sd %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm2
movsd  0xe38(%rip),%xmm0
mulsd  %xmm2,%xmm0
movss  -0x28(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x30(%rbp),%xmm0
addss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xde4(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdcd(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x38(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x34(%rbp),%xmm0
subss  -0x3c(%rbp),%xmm0
movss  -0x34(%rbp),%xmm1
addss  -0x3c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x50(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <sqr@plt>
movss  -0x54(%rbp),%xmm2
movaps %xmm0,%xmm1
movss  -0x50(%rbp),%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x3c(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x40(%rbp),%xmm0
movss  -0x44(%rbp),%xmm1
subss  -0x48(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  -0x44(%rbp),%xmm1
addss  -0x48(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x4c(%rbp),%xmm0
addss  -0x40(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd0b(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dielectricConductorFresnel>:
sub    $0x18,%rsp
movss  %xmm3,0xc(%rsp)
divss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
divss  %xmm0,%xmm2
movss  %xmm2,0x4(%rsp)
movaps %xmm3,%xmm0
call   1030 <sqr@plt>
movss  %xmm0,0x14(%rsp)
movss  0xead(%rip),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0x10(%rsp)
movss  (%rsp),%xmm0
call   1030 <sqr@plt>
movss  %xmm0,(%rsp)
movss  0x4(%rsp),%xmm0
call   1030 <sqr@plt>
movaps %xmm0,%xmm1
movss  %xmm0,0x8(%rsp)
movss  (%rsp),%xmm0
subss  %xmm1,%xmm0
subss  0x10(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
call   1030 <sqr@plt>
movss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xe5d(%rip),%xmm1
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
call   1040 <sqrt@plt>
movss  %xmm0,(%rsp)
movss  0x14(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mulsd  0xe19(%rip),%xmm0
call   1040 <sqrt@plt>
movss  0xc(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
addsd  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movss  %xmm2,0x4(%rsp)
movss  0x8(%rsp),%xmm1
movaps %xmm1,%xmm0
subss  %xmm2,%xmm0
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x10(%rsp),%xmm0
call   1030 <sqr@plt>
movss  (%rsp),%xmm2
mulss  0x14(%rsp),%xmm2
addss  %xmm0,%xmm2
movss  0x10(%rsp),%xmm1
mulss  0x4(%rsp),%xmm1
movaps %xmm2,%xmm0
subss  %xmm1,%xmm0
movss  0xc(%rsp),%xmm3
mulss  %xmm3,%xmm0
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
addss  %xmm3,%xmm0
mulss  0xd7f(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @dielectricConductorFresnel(float %0, float %1, float %2, float %3) {
%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
%20 = alloca float
%21 = alloca float
%22 = alloca float
%23 = alloca float
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%24 = load float, float* %6
%25 = load float, float* %5
%26 = fdiv float %24, %25
store float %26, float* %9
%27 = load float, float* %7
%28 = load float, float* %5
%29 = fdiv float %27, %28
store float %29, float* %10
%30 = load float, float* %8
%31 = call float @sqr(float %30)
store float %31, float* %11
%32 = load float, float* %11
%33 = fpext float %32 to double
%34 = fsub double 1.000000e+00, %33
%35 = fptrunc double %34 to float
store float %35, float* %12
%36 = load float, float* %9
%37 = call float @sqr(float %36)
store float %37, float* %13
%38 = load float, float* %10
%39 = call float @sqr(float %38)
store float %39, float* %14
%40 = load float, float* %13
%41 = load float, float* %14
%42 = fsub float %40, %41
%43 = load float, float* %12
%44 = fsub float %42, %43
store float %44, float* %15
%45 = load float, float* %15
%46 = call float @sqr(float %45)
%47 = fpext float %46 to double
%48 = load float, float* %13
%49 = fpext float %48 to double
%50 = fmul double 4.000000e+00, %49
%51 = load float, float* %14
%52 = fpext float %51 to double
%53 = call double @llvm.fmuladd.f64(double %50, double %52, double %47)
%54 = call float @sqrt(double %53)
store float %54, float* %16
%55 = load float, float* %16
%56 = load float, float* %11
%57 = fadd float %55, %56
store float %57, float* %17
%58 = load float, float* %16
%59 = load float, float* %15
%60 = fadd float %58, %59
%61 = fpext float %60 to double
%62 = fmul double 5.000000e-01, %61
%63 = call float @sqrt(double %62)
store float %63, float* %18
%64 = load float, float* %8
%65 = fpext float %64 to double
%66 = fmul double 2.000000e+00, %65
%67 = load float, float* %18
%68 = fpext float %67 to double
%69 = fmul double %66, %68
%70 = fptrunc double %69 to float
store float %70, float* %19
%71 = load float, float* %17
%72 = load float, float* %19
%73 = fsub float %71, %72
%74 = load float, float* %17
%75 = load float, float* %19
%76 = fadd float %74, %75
%77 = fdiv float %73, %76
store float %77, float* %20
%78 = load float, float* %16
%79 = load float, float* %11
%80 = load float, float* %12
%81 = call float @sqr(float %80)
%82 = call float @llvm.fmuladd.f32(float %78, float %79, float %81)
store float %82, float* %21
%83 = load float, float* %19
%84 = load float, float* %12
%85 = fmul float %83, %84
store float %85, float* %22
%86 = load float, float* %20
%87 = load float, float* %21
%88 = load float, float* %22
%89 = fsub float %87, %88
%90 = fmul float %86, %89
%91 = load float, float* %21
%92 = load float, float* %22
%93 = fadd float %91, %92
%94 = fdiv float %90, %93
store float %94, float* %23
%95 = load float, float* %23
%96 = load float, float* %20
%97 = fadd float %95, %96
%98 = fpext float %97 to double
%99 = fmul double 5.000000e-01, %98
%100 = fptrunc double %99 to float
ret float %100
}

LLVM IR (-O2):
define float @dielectricConductorFresnel(float %0, float %1, float %2, float %3) {
%5 = fdiv float %1, %0
%6 = fdiv float %2, %0
%7 = tail call float @sqr(float %3)
%8 = fsub float 1.000000e+00, %7
%9 = tail call float @sqr(float %5)
%10 = tail call float @sqr(float %6)
%11 = fsub float %9, %10
%12 = fsub float %11, %8
%13 = tail call float @sqr(float %12)
%14 = fpext float %13 to double
%15 = fpext float %9 to double
%16 = fmul double %15, 4.000000e+00
%17 = fpext float %10 to double
%18 = tail call double @llvm.fmuladd.f64(double %16, double %17, double %14)
%19 = tail call float @sqrt(double %18)
%20 = fadd float %7, %19
%21 = fadd float %19, %12
%22 = fpext float %21 to double
%23 = fmul double %22, 5.000000e-01
%24 = tail call float @sqrt(double %23)
%25 = fpext float %3 to double
%26 = fmul double %25, 2.000000e+00
%27 = fpext float %24 to double
%28 = fmul double %26, %27
%29 = fptrunc double %28 to float
%30 = fsub float %20, %29
%31 = fadd float %20, %29
%32 = fdiv float %30, %31
%33 = tail call float @sqr(float %8)
%34 = tail call float @llvm.fmuladd.f32(float %19, float %7, float %33)
%35 = fmul float %8, %29
%36 = fsub float %34, %35
%37 = fmul float %32, %36
%38 = fadd float %34, %35
%39 = fdiv float %37, %38
%40 = fadd float %32, %39
%41 = fmul float %40, 5.000000e-01
ret float %41
}