#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 */
double cos(double);
double fabs(double);
double tan(double);
double refract(double z, double refa, double refb, int flag) {
  double dz;
  double err;
  double tz0;
  double z0;
  double z0_last;
  int i;
  if (z < 0) {
    z = 0;
  } else if (z > (((87)) * ((3.14159265358979323846) / 180.0))) {
    z = (((87)) * ((3.14159265358979323846) / 180.0));
  }
  if (flag > 0) {
    z0 = z;
    for (i = 0; i < (2); i++) {
      z0_last = z0;
      tz0 = tan(z0);
      dz = tz0 * (refa + tz0 * (tz0 * refb));
      z0 -= ((z0 - z) + dz) /
            (1 + (refa + 3 * refb * tz0 * tz0) / (cos(z0) * cos(z0)));
      err = fabs(z0 - z0_last);
    }
    dz *= -1.0;
  } else {
    z0 = z;
    tz0 = tan(z0);
    dz = tz0 * (refa + tz0 * (tz0 * refb));
    z = z0 + dz;
  }
  return (dz);
}


x86 assembly (clang, -O0):
<refract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1155 <refract+0x35>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    117e <refract+0x5e>
movsd  -0x8(%rbp),%xmm0
movsd  0xe9e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1179 <refract+0x59>
movsd  0xe8c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    117e <refract+0x5e>
cmpl   $0x0,-0x1c(%rbp)
jle    12b3 <refract+0x193>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x2,-0x4c(%rbp)
jge    129c <refract+0x17c>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <tan@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm3
mulsd  -0x18(%rbp),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  0xe11(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x68(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm3,%xmm0
divsd  %xmm0,%xmm2
movsd  0xdb2(%rip),%xmm0
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movaps 0xd9b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1199 <refract+0x79>
movsd  0xd64(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1305 <refract+0x1e5>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <tan@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm3
mulsd  -0x18(%rbp),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<refract>:
sub    $0x48,%rsp
movsd  %xmm1,0x18(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     114a <refract+0x2a>
ucomisd 0xec4(%rip),%xmm0
movapd %xmm0,%xmm1
jbe    114a <refract+0x2a>
movsd  0xeb6(%rip),%xmm1
test   %edi,%edi
movsd  %xmm2,0x10(%rsp)
jle    1269 <refract+0x149>
movsd  0xea8(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x20(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1030 <tan@plt>
movapd %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm4
subsd  %xmm3,%xmm4
addsd  %xmm1,%xmm4
movsd  %xmm4,0x40(%rsp)
movsd  0x20(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,0x20(%rsp)
movapd %xmm3,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x38(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  0x38(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0xe19(%rip),%xmm1
movapd %xmm1,%xmm0
movsd  0x40(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <tan@plt>
movapd %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  0x18(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
movapd 0x20(%rsp),%xmm0
xorpd  0xdc2(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
add    $0x48,%rsp
ret
movapd %xmm1,%xmm0
call   1030 <tan@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x48,%rsp
ret

LLVM IR (-O0):
define double @refract(double %0, double %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
%15 = load double, double* %5
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %4
store double 0.000000e+00, double* %5
br label %23
18: ; preds = %4
%19 = load double, double* %5
%20 = fcmp ogt double %19, 0x3FF84B8404A84DB9
br i1 %20, label %21, label %22
21: ; preds = %18
store double 0x3FF84B8404A84DB9, double* %5
br label %22
22: ; preds = %21, %18
br label %23
23: ; preds = %22, %17
%24 = load i32, i32* %8
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %75
26: ; preds = %23
%27 = load double, double* %5
store double %27, double* %12
store i32 0, i32* %14
br label %28
28: ; preds = %69, %26
%29 = load i32, i32* %14
%30 = icmp slt i32 %29, 2
br i1 %30, label %31, label %72
31: ; preds = %28
%32 = load double, double* %12
store double %32, double* %13
%33 = load double, double* %12
%34 = call double @tan(double %33)
store double %34, double* %11
%35 = load double, double* %11
%36 = load double, double* %6
%37 = load double, double* %11
%38 = load double, double* %11
%39 = load double, double* %7
%40 = fmul double %38, %39
%41 = call double @llvm.fmuladd.f64(double %37, double %40, double %36)
%42 = fmul double %35, %41
store double %42, double* %9
%43 = load double, double* %12
%44 = load double, double* %5
%45 = fsub double %43, %44
%46 = load double, double* %9
%47 = fadd double %45, %46
%48 = load double, double* %6
%49 = load double, double* %7
%50 = fmul double 3.000000e+00, %49
%51 = load double, double* %11
%52 = fmul double %50, %51
%53 = load double, double* %11
%54 = call double @llvm.fmuladd.f64(double %52, double %53, double %48)
%55 = load double, double* %12
%56 = call double @cos(double %55)
%57 = load double, double* %12
%58 = call double @cos(double %57)
%59 = fmul double %56, %58
%60 = fdiv double %54, %59
%61 = fadd double 1.000000e+00, %60
%62 = fdiv double %47, %61
%63 = load double, double* %12
%64 = fsub double %63, %62
store double %64, double* %12
%65 = load double, double* %12
%66 = load double, double* %13
%67 = fsub double %65, %66
%68 = call double @llvm.fabs.f64(double %67)
store double %68, double* %10
br label %69
69: ; preds = %31
%70 = load i32, i32* %14
%71 = add nsw i32 %70, 1
store i32 %71, i32* %14
br label %28
72: ; preds = %28
%73 = load double, double* %9
%74 = fmul double %73, -1.000000e+00
store double %74, double* %9
br label %90
75: ; preds = %23
%76 = load double, double* %5
store double %76, double* %12
%77 = load double, double* %12
%78 = call double @tan(double %77)
store double %78, double* %11
%79 = load double, double* %11
%80 = load double, double* %6
%81 = load double, double* %11
%82 = load double, double* %11
%83 = load double, double* %7
%84 = fmul double %82, %83
%85 = call double @llvm.fmuladd.f64(double %81, double %84, double %80)
%86 = fmul double %79, %85
store double %86, double* %9
%87 = load double, double* %12
%88 = load double, double* %9
%89 = fadd double %87, %88
store double %89, double* %5
br label %90
90: ; preds = %75, %72
%91 = load double, double* %9
ret double %91
}

LLVM IR (-O2):
define double @refract(double %0, double %1, double %2, i32 %3) {
%5 = fcmp olt double %0, 0.000000e+00
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = fcmp ogt double %0, 0x3FF84B8404A84DB9
br i1 %7, label %8, label %9
8: ; preds = %6
br label %9
9: ; preds = %4, %6, %8
%10 = phi double [ 0x3FF84B8404A84DB9, %8 ], [ %0, %6 ], [ 0.000000e+00, %4 ]
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %36
12: ; preds = %9
%13 = fmul double %2, 3.000000e+00
%14 = tail call double @tan(double %10)
%15 = fmul double %14, %2
%16 = tail call double @llvm.fmuladd.f64(double %14, double %15, double %1)
%17 = fmul double %14, %16
%18 = fsub double %10, %10
%19 = fadd double %18, %17
%20 = fmul double %13, %14
%21 = tail call double @llvm.fmuladd.f64(double %20, double %14, double %1)
%22 = tail call double @cos(double %10)
%23 = tail call double @cos(double %10)
%24 = fmul double %22, %23
%25 = fdiv double %21, %24
%26 = fadd double %25, 1.000000e+00
%27 = fdiv double %19, %26
%28 = fsub double %10, %27
%29 = tail call double @tan(double %28)
%30 = fmul double %29, %2
%31 = tail call double @llvm.fmuladd.f64(double %29, double %30, double %1)
%32 = tail call double @cos(double %28)
%33 = tail call double @cos(double %28)
%34 = fneg double %29
%35 = fmul double %31, %34
br label %41
36: ; preds = %9
%37 = tail call double @tan(double %10)
%38 = fmul double %37, %2
%39 = tail call double @llvm.fmuladd.f64(double %37, double %38, double %1)
%40 = fmul double %37, %39
br label %41
41: ; preds = %12, %36
%42 = phi double [ %40, %36 ], [ %35, %12 ]
ret double %42
}