#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 fabs(double);
int /*<<< orphan*/ unrefract(double, double, double, double *);
void refract(double pr, double tr, double ta, double *aa) {
  double d, t, t0, a;
  unrefract(pr, tr, ta, &t);
  d = 0.8 * (ta - t);
  t0 = t;
  a = ta;
  while (1) {
    a += d;
    unrefract(pr, tr, a, &t);
    if (fabs(ta - t) <= ((0.1 / 3600.) * 3.141592653589793 / 180.))
      break;
    d *= -(ta - t) / (t0 - t);
    t0 = t;
  }
  *aa = a;
}


x86 assembly (clang, -O0):
<refract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
lea    -0x30(%rbp),%rdi
call   1030 <unrefract@plt>
movsd  -0x18(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
movsd  0xeab(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
lea    -0x30(%rbp),%rdi
call   1030 <unrefract@plt>
movsd  -0x18(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
movaps 0xe66(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe52(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11c5 <refract+0xb5>
jmp    120d <refract+0xfd>
movsd  -0x18(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1172 <refract+0x62>
movsd  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<refract>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x30(%rsp)
movsd  %xmm0,0x28(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <unrefract@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm2
movsd  %xmm0,0x18(%rsp)
subsd  %xmm0,%xmm2
mulsd  0xea5(%rip),%xmm2
movsd  %xmm2,0x20(%rsp)
addsd  %xmm1,%xmm2
movsd  0x28(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
movsd  %xmm2,(%rsp)
mov    %rbx,%rdi
call   1030 <unrefract@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm0
movapd 0xe7a(%rip),%xmm2
andpd  %xmm0,%xmm2
movsd  0xe66(%rip),%xmm4
ucomisd %xmm2,%xmm4
jae    124a <refract+0x13a>
lea    0x8(%rsp),%rbx
movsd  (%rsp),%xmm2
movsd  0x20(%rsp),%xmm5
movsd  0x18(%rsp),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm1,0x18(%rsp)
xorpd  0xe42(%rip),%xmm0
subsd  %xmm1,%xmm4
divsd  %xmm4,%xmm0
mulsd  %xmm0,%xmm5
movsd  %xmm5,0x20(%rsp)
addsd  %xmm5,%xmm2
movsd  %xmm2,(%rsp)
movsd  0x28(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
mov    %rbx,%rdi
call   1030 <unrefract@plt>
movsd  0x20(%rsp),%xmm5
movsd  0xded(%rip),%xmm4
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm0
movapd %xmm0,%xmm2
andpd  0xdd9(%rip),%xmm2
ucomisd %xmm2,%xmm4
movsd  (%rsp),%xmm2
movsd  0x18(%rsp),%xmm4
jb     11d0 <refract+0xc0>
jmp    124f <refract+0x13f>
movsd  (%rsp),%xmm2
movsd  %xmm2,(%r14)
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @refract(double %0, double %1, double %2, double* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double* %3, double** %8
%13 = load double, double* %5
%14 = load double, double* %6
%15 = load double, double* %7
%16 = call i32 @unrefract(double %13, double %14, double %15, double* %10)
%17 = load double, double* %7
%18 = load double, double* %10
%19 = fsub double %17, %18
%20 = fmul double 8.000000e-01, %19
store double %20, double* %9
%21 = load double, double* %10
store double %21, double* %11
%22 = load double, double* %7
store double %22, double* %12
br label %23
23: ; preds = %4, %37
%24 = load double, double* %9
%25 = load double, double* %12
%26 = fadd double %25, %24
store double %26, double* %12
%27 = load double, double* %5
%28 = load double, double* %6
%29 = load double, double* %12
%30 = call i32 @unrefract(double %27, double %28, double %29, double* %10)
%31 = load double, double* %7
%32 = load double, double* %10
%33 = fsub double %31, %32
%34 = call double @llvm.fabs.f64(double %33)
%35 = fcmp ole double %34, 0x3EA044848F32D94B
br i1 %35, label %36, label %37
36: ; preds = %23
br label %49
37: ; preds = %23
%38 = load double, double* %7
%39 = load double, double* %10
%40 = fsub double %38, %39
%41 = fneg double %40
%42 = load double, double* %11
%43 = load double, double* %10
%44 = fsub double %42, %43
%45 = fdiv double %41, %44
%46 = load double, double* %9
%47 = fmul double %46, %45
store double %47, double* %9
%48 = load double, double* %10
store double %48, double* %11
br label %23
49: ; preds = %36
%50 = load double, double* %12
%51 = load double*, double** %8
store double %50, double* %51
ret void
}

LLVM IR (-O2):
define void @refract(double %0, double %1, double %2, double* nocapture writeonly %3) {
%5 = alloca double
%6 = bitcast double* %5 to i8*
%7 = call i32 @unrefract(double %0, double %1, double %2, double* %5)
%8 = load double, double* %5
%9 = fsub double %2, %8
%10 = fmul double %9, 8.000000e-01
%11 = fadd double %10, %2
%12 = call i32 @unrefract(double %0, double %1, double %11, double* %5)
%13 = load double, double* %5
%14 = fsub double %2, %13
%15 = call double @llvm.fabs.f64(double %14)
%16 = fcmp ugt double %15, 0x3EA044848F32D94B
br i1 %16, label %17, label %33
17: ; preds = %4, %17
%18 = phi double [ %30, %17 ], [ %14, %4 ]
%19 = phi double [ %29, %17 ], [ %13, %4 ]
%20 = phi double [ %27, %17 ], [ %11, %4 ]
%21 = phi double [ %19, %17 ], [ %8, %4 ]
%22 = phi double [ %26, %17 ], [ %10, %4 ]
%23 = fneg double %18
%24 = fsub double %21, %19
%25 = fdiv double %23, %24
%26 = fmul double %22, %25
%27 = fadd double %26, %20
%28 = call i32 @unrefract(double %0, double %1, double %27, double* %5)
%29 = load double, double* %5
%30 = fsub double %2, %29
%31 = call double @llvm.fabs.f64(double %30)
%32 = fcmp ugt double %31, 0x3EA044848F32D94B
br i1 %32, label %17, label %33
33: ; preds = %17, %4
%34 = phi double [ %11, %4 ], [ %27, %17 ]
store double %34, double* %3
ret void
}