#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*/ finitef(double);
double transverse_distance(double);
double comoving_distance_to_redshift(double r) {
  if (r <= 0)
    return 0;
  double z = 1;
  double dz = 0.1;
  double rt;
  while (dz > 1e-7) {
    rt = transverse_distance(z);
    dz = ((r - rt) * dz) /
         (transverse_distance(z + dz) - transverse_distance(z));
    if (!finitef(dz))
      return z;
    if (z + dz < 0)
      z /= 3.0;
    else
      z += dz;
    dz = fabs(dz);
    if (dz > 0.1)
      dz = 0.1;
  }
  return z;
}


x86 assembly (clang, -O0):
<comoving_distance_to_redshift>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1148 <comoving_distance_to_redshift+0x28>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127f <comoving_distance_to_redshift+0x15f>
movsd  0xeb8(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xea1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1275 <comoving_distance_to_redshift+0x155>
movsd  -0x18(%rbp),%xmm0
call   1030 <transverse_distance@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
call   1030 <transverse_distance@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <transverse_distance@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <finitef@plt>
cmp    $0x0,%eax
jne    11f6 <comoving_distance_to_redshift+0xd6>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127f <comoving_distance_to_redshift+0x15f>
movsd  -0x18(%rbp),%xmm1
addsd  -0x20(%rbp),%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1228 <comoving_distance_to_redshift+0x108>
movsd  -0x18(%rbp),%xmm0
movsd  0xdfe(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1237 <comoving_distance_to_redshift+0x117>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movaps 0xddd(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xda7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1270 <comoving_distance_to_redshift+0x150>
movsd  0xd95(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1162 <comoving_distance_to_redshift+0x42>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<comoving_distance_to_redshift>:
sub    $0x28,%rsp
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm1,0x20(%rsp)
ucomisd %xmm1,%xmm0
jae    1213 <comoving_distance_to_redshift+0xf3>
movsd  0xebc(%rip),%xmm1
movsd  0xebc(%rip),%xmm2
jmp    1176 <comoving_distance_to_redshift+0x56>
xchg   %ax,%ax
andpd  0xed8(%rip),%xmm3
movsd  0xea8(%rip),%xmm2
minsd  %xmm3,%xmm2
ucomisd 0xeac(%rip),%xmm2
movapd %xmm0,%xmm1
jbe    1213 <comoving_distance_to_redshift+0xf3>
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   1030 <transverse_distance@plt>
movsd  0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
addsd  (%rsp),%xmm0
call   1030 <transverse_distance@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1030 <transverse_distance@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
call   1040 <finitef@plt>
test   %eax,%eax
je     1218 <comoving_distance_to_redshift+0xf8>
movsd  (%rsp),%xmm2
movapd %xmm2,%xmm0
movapd 0x10(%rsp),%xmm3
addsd  %xmm3,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1150 <comoving_distance_to_redshift+0x30>
divsd  0xe06(%rip),%xmm2
movapd %xmm2,%xmm0
jmp    1150 <comoving_distance_to_redshift+0x30>
add    $0x28,%rsp
ret
movsd  (%rsp),%xmm0
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
define double @comoving_distance_to_redshift(double %0) {
%2 = fcmp ugt double %0, 0.000000e+00
br i1 %2, label %3, label %25
3: ; preds = %1, %16
%4 = phi double [ %23, %16 ], [ 1.000000e-01, %1 ]
%5 = phi double [ %20, %16 ], [ 1.000000e+00, %1 ]
%6 = tail call double @transverse_distance(double %5)
%7 = fsub double %0, %6
%8 = fmul double %4, %7
%9 = fadd double %5, %4
%10 = tail call double @transverse_distance(double %9)
%11 = tail call double @transverse_distance(double %5)
%12 = fsub double %10, %11
%13 = fdiv double %8, %12
%14 = tail call i32 @finitef(double %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %3
%17 = fadd double %5, %13
%18 = fcmp olt double %17, 0.000000e+00
%19 = fdiv double %5, 3.000000e+00
%20 = select i1 %18, double %19, double %17
%21 = tail call double @llvm.fabs.f64(double %13)
%22 = fcmp ogt double %21, 1.000000e-01
%23 = select i1 %22, double 1.000000e-01, double %21
%24 = fcmp ogt double %23, 0x3E7AD7F29ABCAF48
br i1 %24, label %3, label %25
25: ; preds = %3, %16, %1
%26 = phi double [ 0.000000e+00, %1 ], [ %20, %16 ], [ %5, %3 ]
ret double %26
}