#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 atan2(double, double);
int /*<<< orphan*/ eval_cornu(double, double *, double *);
int fabs(double);
double hypot(double, double);
scalar_t__ mod_2pi(double);
double sqrt(double);
void fit_cornu_half(double th0, double th1, double *pt0, double *pt1,
                    double *pk0, double *pk1) {
  int i;
  const int max_iter = 21;
  double t0, t1, t_m;
  double tl, tr, t_est;
  double s0, c0, s1, c1;
  if (fabs(th0 + th1) < 1e-6) {
    th0 += 1e-6;
    th1 += 1e-6;
  }
  t_est = 0.29112 * (th1 + th0) / sqrt(th1 - th0);
  tl = t_est * .9;
  tr = t_est * 2;
  for (i = 0; i < max_iter; i++) {
    double dt;
    double chord_th;
    t_m = .5 * (tl + tr);
    dt = (th0 + th1) / (4 * t_m);
    t0 = t_m - dt;
    t1 = t_m + dt;
    eval_cornu(t0, &s0, &c0);
    eval_cornu(t1, &s1, &c1);
    chord_th = atan2(s1 - s0, c1 - c0);
    if (mod_2pi(chord_th - t0 * t0 - th0) < 0)
      tl = t_m;
    else
      tr = t_m;
  }
  *pt0 = t0;
  *pt1 = t1;
  if (pk0 || pk1) {
    double chordlen = hypot(s1 - s0, c1 - c0);
    if (pk0)
      *pk0 = t0 * chordlen;
    if (pk1)
      *pk1 = t1 * chordlen;
  }
}


x86 assembly (clang, -O0):
<fit_cornu_half>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
movl   $0x15,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe59(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d5 <fit_cornu_half+0x75>
movsd  0xe47(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe35(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
addsd  -0x8(%rbp),%xmm1
movsd  0xe31(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xdf2(%rip),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xdd8(%rip),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x15,-0x34(%rbp)
jge    1369 <fit_cornu_half+0x209>
movsd  -0x58(%rbp),%xmm1
addsd  -0x60(%rbp),%xmm1
movsd  0xdcb(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xda8(%rip),%xmm1
mulsd  -0x50(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
subsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0x40(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    -0x70(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   1050 <eval_cornu@plt>
movsd  -0x48(%rbp),%xmm0
lea    -0x80(%rbp),%rdi
lea    -0x88(%rbp),%rsi
call   1050 <eval_cornu@plt>
movsd  -0x80(%rbp),%xmm0
subsd  -0x70(%rbp),%xmm0
movsd  -0x88(%rbp),%xmm1
ff
subsd  -0x78(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x98(%rbp),%xmm1
ff
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x8(%rbp),%xmm0
call   1080 <mod_2pi@plt>
cmp    $0x0,%rax
jge    134c <fit_cornu_half+0x1ec>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1356 <fit_cornu_half+0x1f6>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    135b <fit_cornu_half+0x1fb>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1241 <fit_cornu_half+0xe1>
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    1399 <fit_cornu_half+0x239>
cmpq   $0x0,-0x30(%rbp)
je     1402 <fit_cornu_half+0x2a2>
movsd  -0x80(%rbp),%xmm0
subsd  -0x70(%rbp),%xmm0
movsd  -0x88(%rbp),%xmm1
ff
subsd  -0x78(%rbp),%xmm1
call   1060 <hypot@plt>
movsd  %xmm0,-0xa0(%rbp)
ff
cmpq   $0x0,-0x28(%rbp)
je     13dd <fit_cornu_half+0x27d>
movsd  -0x40(%rbp),%xmm0
mulsd  -0xa0(%rbp),%xmm0
ff
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     13fd <fit_cornu_half+0x29d>
movsd  -0x48(%rbp),%xmm0
mulsd  -0xa0(%rbp),%xmm0
ff
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1402 <fit_cornu_half+0x2a2>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fit_cornu_half>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
movsd  %xmm0,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
addsd  %xmm1,%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    11a1 <fit_cornu_half+0x41>
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
jmp    11c1 <fit_cornu_half+0x61>
movsd  0xe57(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
movapd %xmm0,%xmm3
addsd  %xmm1,%xmm3
movsd  0xe37(%rip),%xmm2
movsd  %xmm3,0x68(%rsp)
mulsd  %xmm3,%xmm2
subsd  %xmm1,%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
mov    %r14,0x60(%rsp)
mov    %r15,0x58(%rsp)
mov    %rbx,0x50(%rsp)
movsd  %xmm1,0x10(%rsp)
jb     1204 <fit_cornu_half+0xa4>
sqrtsd %xmm0,%xmm0
jmp    1215 <fit_cornu_half+0xb5>
movsd  %xmm2,0x18(%rsp)
call   1070 <sqrt@plt>
movsd  0x18(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  0xdef(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm2,%xmm2
mov    $0x15,%r14d
lea    0x48(%rsp),%rbx
lea    0x40(%rsp),%rbp
lea    0x38(%rsp),%r15
lea    0x30(%rsp),%r12
jmp    1266 <fit_cornu_half+0x106>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x28(%rsp),%xmm2
movsd  0x70(%rsp),%xmm0
add    $0xffffffff,%r14d
je     1327 <fit_cornu_half+0x1c7>
movsd  %xmm2,0x18(%rsp)
movsd  %xmm0,0x70(%rsp)
movapd %xmm0,%xmm1
addsd  %xmm2,%xmm1
mulsd  0xd96(%rip),%xmm1
movapd %xmm1,%xmm0
mulsd  0xd92(%rip),%xmm0
movsd  0x68(%rsp),%xmm2
divsd  %xmm0,%xmm2
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  %xmm1,0x28(%rsp)
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <eval_cornu@plt>
movsd  0x8(%rsp),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <eval_cornu@plt>
movsd  0x38(%rsp),%xmm0
subsd  0x48(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
subsd  0x40(%rsp),%xmm1
call   1030 <atan2@plt>
movsd  0x20(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
subsd  0x10(%rsp),%xmm0
call   1080 <mod_2pi@plt>
test   %rax,%rax
jns    1250 <fit_cornu_half+0xf0>
movsd  0x28(%rsp),%xmm0
movsd  0x18(%rsp),%xmm2
add    $0xffffffff,%r14d
jne    1266 <fit_cornu_half+0x106>
movsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x0(%r13)
mov    0x50(%rsp),%rax
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rax)
mov    0x58(%rsp),%rbx
mov    %rbx,%rax
mov    0x60(%rsp),%r13
or     %r13,%rax
je     1399 <fit_cornu_half+0x239>
movsd  0x38(%rsp),%xmm0
subsd  0x48(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
subsd  0x40(%rsp),%xmm1
call   1060 <hypot@plt>
test   %rbx,%rbx
je     1384 <fit_cornu_half+0x224>
movsd  0x20(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
test   %r13,%r13
je     1399 <fit_cornu_half+0x239>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%r13)
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fit_cornu_half(double %0, double %1, double* %2, double* %3, double* %4, double* %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca double
store double %0, double* %7
store double %1, double* %8
store double* %2, double** %9
store double* %3, double** %10
store double* %4, double** %11
store double* %5, double** %12
store i32 21, i32* %14
%28 = load double, double* %7
%29 = load double, double* %8
%30 = fadd double %28, %29
%31 = call i32 @fabs(double %30)
%32 = sitofp i32 %31 to double
%33 = fcmp olt double %32, 0x3EB0C6F7A0B5ED8D
br i1 %33, label %34, label %39
34: ; preds = %6
%35 = load double, double* %7
%36 = fadd double %35, 0x3EB0C6F7A0B5ED8D
store double %36, double* %7
%37 = load double, double* %8
%38 = fadd double %37, 0x3EB0C6F7A0B5ED8D
store double %38, double* %8
br label %39
39: ; preds = %34, %6
%40 = load double, double* %8
%41 = load double, double* %7
%42 = fadd double %40, %41
%43 = fmul double 2.911200e-01, %42
%44 = load double, double* %8
%45 = load double, double* %7
%46 = fsub double %44, %45
%47 = call double @sqrt(double %46)
%48 = fdiv double %43, %47
store double %48, double* %20
%49 = load double, double* %20
%50 = fmul double %49, 9.000000e-01
store double %50, double* %18
%51 = load double, double* %20
%52 = fmul double %51, 2.000000e+00
store double %52, double* %19
store i32 0, i32* %13
br label %53
53: ; preds = %98, %39
%54 = load i32, i32* %13
%55 = icmp slt i32 %54, 21
br i1 %55, label %56, label %101
56: ; preds = %53
%57 = load double, double* %18
%58 = load double, double* %19
%59 = fadd double %57, %58
%60 = fmul double 5.000000e-01, %59
store double %60, double* %17
%61 = load double, double* %7
%62 = load double, double* %8
%63 = fadd double %61, %62
%64 = load double, double* %17
%65 = fmul double 4.000000e+00, %64
%66 = fdiv double %63, %65
store double %66, double* %25
%67 = load double, double* %17
%68 = load double, double* %25
%69 = fsub double %67, %68
store double %69, double* %15
%70 = load double, double* %17
%71 = load double, double* %25
%72 = fadd double %70, %71
store double %72, double* %16
%73 = load double, double* %15
%74 = call i32 @eval_cornu(double %73, double* %21, double* %22)
%75 = load double, double* %16
%76 = call i32 @eval_cornu(double %75, double* %23, double* %24)
%77 = load double, double* %23
%78 = load double, double* %21
%79 = fsub double %77, %78
%80 = load double, double* %24
%81 = load double, double* %22
%82 = fsub double %80, %81
%83 = call double @atan2(double %79, double %82)
store double %83, double* %26
%84 = load double, double* %26
%85 = load double, double* %15
%86 = load double, double* %15
%87 = fneg double %85
%88 = call double @llvm.fmuladd.f64(double %87, double %86, double %84)
%89 = load double, double* %7
%90 = fsub double %88, %89
%91 = call i64 @mod_2pi(double %90)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %56
%94 = load double, double* %17
store double %94, double* %18
br label %97
95: ; preds = %56
%96 = load double, double* %17
store double %96, double* %19
br label %97
97: ; preds = %95, %93
br label %98
98: ; preds = %97
%99 = load i32, i32* %13
%100 = add nsw i32 %99, 1
store i32 %100, i32* %13
br label %53
101: ; preds = %53
%102 = load double, double* %15
%103 = load double*, double** %9
store double %102, double* %103
%104 = load double, double* %16
%105 = load double*, double** %10
store double %104, double* %105
%106 = load double*, double** %11
%107 = icmp ne double* %106, null
br i1 %107, label %111, label %108
108: ; preds = %101
%109 = load double*, double** %12
%110 = icmp ne double* %109, null
br i1 %110, label %111, label %135
111: ; preds = %108, %101
%112 = load double, double* %23
%113 = load double, double* %21
%114 = fsub double %112, %113
%115 = load double, double* %24
%116 = load double, double* %22
%117 = fsub double %115, %116
%118 = call double @hypot(double %114, double %117)
store double %118, double* %27
%119 = load double*, double** %11
%120 = icmp ne double* %119, null
br i1 %120, label %121, label %126
121: ; preds = %111
%122 = load double, double* %15
%123 = load double, double* %27
%124 = fmul double %122, %123
%125 = load double*, double** %11
store double %124, double* %125
br label %126
126: ; preds = %121, %111
%127 = load double*, double** %12
%128 = icmp ne double* %127, null
br i1 %128, label %129, label %134
129: ; preds = %126
%130 = load double, double* %16
%131 = load double, double* %27
%132 = fmul double %130, %131
%133 = load double*, double** %12
store double %132, double* %133
br label %134
134: ; preds = %129, %126
br label %135
135: ; preds = %134, %108
ret void
}

LLVM IR (-O2):
define void @fit_cornu_half(double %0, double %1, double* nocapture writeonly %2, double* nocapture writeonly %3, double* writeonly %4, double* writeonly %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = bitcast double* %7 to i8*
%12 = bitcast double* %8 to i8*
%13 = bitcast double* %9 to i8*
%14 = bitcast double* %10 to i8*
%15 = fadd double %0, %1
%16 = tail call i32 @fabs(double %15)
%17 = icmp slt i32 %16, 1
%18 = fadd double %0, 0x3EB0C6F7A0B5ED8D
%19 = fadd double %1, 0x3EB0C6F7A0B5ED8D
%20 = select i1 %17, double %19, double %1
%21 = select i1 %17, double %18, double %0
%22 = fadd double %20, %21
%23 = fmul double %22, 2.911200e-01
%24 = fsub double %20, %21
%25 = tail call double @sqrt(double %24)
%26 = fdiv double %23, %25
%27 = fmul double %26, 9.000000e-01
%28 = fmul double %26, 2.000000e+00
br label %29
29: ; preds = %6, %29
%30 = phi i32 [ 0, %6 ], [ %55, %29 ]
%31 = phi double [ %28, %6 ], [ %54, %29 ]
%32 = phi double [ %27, %6 ], [ %53, %29 ]
%33 = fadd double %32, %31
%34 = fmul double %33, 5.000000e-01
%35 = fmul double %34, 4.000000e+00
%36 = fdiv double %22, %35
%37 = fsub double %34, %36
%38 = fadd double %34, %36
%39 = call i32 @eval_cornu(double %37, double* %7, double* %8)
%40 = call i32 @eval_cornu(double %38, double* %9, double* %10)
%41 = load double, double* %9
%42 = load double, double* %7
%43 = fsub double %41, %42
%44 = load double, double* %10
%45 = load double, double* %8
%46 = fsub double %44, %45
%47 = call double @atan2(double %43, double %46)
%48 = fneg double %37
%49 = call double @llvm.fmuladd.f64(double %48, double %37, double %47)
%50 = fsub double %49, %21
%51 = call i64 @mod_2pi(double %50)
%52 = icmp slt i64 %51, 0
%53 = select i1 %52, double %34, double %32
%54 = select i1 %52, double %31, double %34
%55 = add nuw nsw i32 %30, 1
%56 = icmp eq i32 %55, 21
br i1 %56, label %57, label %29
57: ; preds = %29
store double %37, double* %2
store double %38, double* %3
%58 = icmp ne double* %4, null
%59 = icmp ne double* %5, null
%60 = or i1 %58, %59
br i1 %60, label %61, label %74
61: ; preds = %57
%62 = load double, double* %9
%63 = load double, double* %7
%64 = fsub double %62, %63
%65 = load double, double* %10
%66 = load double, double* %8
%67 = fsub double %65, %66
%68 = call double @hypot(double %64, double %67)
br i1 %58, label %69, label %71
69: ; preds = %61
%70 = fmul double %37, %68
store double %70, double* %4
br label %71
71: ; preds = %69, %61
br i1 %59, label %72, label %74
72: ; preds = %71
%73 = fmul double %38, %68
store double %73, double* %5
br label %74
74: ; preds = %71, %72, %57
ret void
}