#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 */
int M_PI;
double atan2(double, double);
int fabs(double);
double hypot(double, double);
int /*<<< orphan*/ isnan(double);
int sqrt(double);
double arc_math(double X, double Y, double oldX, double oldY, double *R,
                double *I, double *J, double *K, bool invert) {
  if (!isnan(*R)) {
    double d = hypot(oldX - X, oldY - Y);
    *I = (X - oldX) / 2 +
         (invert ? -1 : 1) * sqrt(*R * *R - d * d / 4) * (Y - oldY) / d;
    *J = (Y - oldY) / 2 +
         (invert ? 1 : -1) * sqrt(*R * *R - d * d / 4) * (X - oldX) / d;
    *K = 0;
  } else
    *R = hypot(*I, *J);
  double start = atan2(oldY - *J, oldX - *I);
  double end = atan2(Y - *J, X - *I);
  if ((start >= end && invert) || (end > start && !invert))
    return fabs(start - end) * *R;
  else
    return (2 * M_PI - fabs(start - end)) * *R;
}


x86 assembly (clang, -O0):
<arc_math>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %rdi,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rcx,-0x48(%rbp)
mov    %r8d,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
call   1060 <isnan@plt>
cmp    $0x0,%eax
jne    1323 <arc_math+0x1d3>
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
call   1050 <hypot@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xe3f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x4c(%rbp),%edx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
movsd  0xdf3(%rip),%xmm3
divsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  -0x88(%rbp),%xmm0
ff
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  -0x18(%rbp),%xmm2
subsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm1
divsd  -0x58(%rbp),%xmm1
addsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  0xd8e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x4c(%rbp),%edx
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
movsd  0xd45(%rip),%xmm3
divsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  -0x78(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  -0x10(%rbp),%xmm2
subsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
divsd  -0x58(%rbp),%xmm1
addsd  %xmm1,%xmm0
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x48(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    1340 <arc_math+0x1f0>
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm1
call   1050 <hypot@plt>
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x40(%rbp),%rax
subsd  (%rax),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x38(%rbp),%rax
subsd  (%rax),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x40(%rbp),%rax
subsd  (%rax),%xmm0
movsd  -0x10(%rbp),%xmm1
mov    -0x38(%rbp),%rax
subsd  (%rax),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
ucomisd -0x68(%rbp),%xmm0
jb     13a2 <arc_math+0x252>
cmpl   $0x0,-0x4c(%rbp)
jne    13bc <arc_math+0x26c>
movsd  -0x68(%rbp),%xmm0
ucomisd -0x60(%rbp),%xmm0
jbe    13e1 <arc_math+0x291>
cmpl   $0x0,-0x4c(%rbp)
jne    13e1 <arc_math+0x291>
movsd  -0x60(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
mov    -0x30(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    141d <arc_math+0x2cd>
mov    0x2c00(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
mov    %eax,-0x8c(%rbp)
movsd  -0x60(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,%ecx
mov    -0x8c(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
mov    -0x30(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arc_math>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %r8d,%r14d
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r15
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x18(%rsp)
movsd  (%rdi),%xmm0
call   1060 <isnan@plt>
test   %eax,%eax
je     11a8 <arc_math+0x58>
movsd  0x0(%rbp),%xmm0
movsd  (%rbx),%xmm1
call   1050 <hypot@plt>
movsd  %xmm0,(%r15)
jmp    129a <arc_math+0x14a>
movsd  0x10(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  0x20(%rsp),%xmm1
call   1050 <hypot@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,0x28(%rsp)
movsd  0x18(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x48(%rsp)
mulsd  0xe17(%rip),%xmm0
movsd  %xmm0,0x40(%rsp)
movsd  (%r15),%xmm0
mulsd  %xmm1,%xmm1
mulsd  0xe08(%rip),%xmm1
movsd  %xmm1,0x38(%rsp)
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
mov    %eax,%ecx
neg    %ecx
test   %r14d,%r14d
cmove  %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x20(%rsp),%xmm1
subsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x30(%rsp)
mulsd  %xmm1,%xmm0
divsd  0x28(%rsp),%xmm0
addsd  0x40(%rsp),%xmm0
movsd  %xmm0,0x0(%rbp)
movsd  (%r15),%xmm0
mulsd  %xmm0,%xmm0
addsd  0x38(%rsp),%xmm0
call   1070 <sqrt@plt>
mov    %eax,%ecx
neg    %ecx
test   %r14d,%r14d
cmovne %eax,%ecx
movsd  0x30(%rsp),%xmm1
mulsd  0xd89(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0x48(%rsp),%xmm0
divsd  0x28(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
movq   $0x0,(%r12)
movsd  0x8(%rsp),%xmm0
subsd  (%rbx),%xmm0
movsd  0x10(%rsp),%xmm1
subsd  0x0(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
subsd  (%rbx),%xmm0
movsd  0x18(%rsp),%xmm1
subsd  0x0(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
setae  %dl
test   %r14d,%r14d
setne  %al
and    %al,%dl
ucomisd %xmm1,%xmm0
setbe  %cl
cmp    $0x1,%dl
je     1315 <arc_math+0x1c5>
or     %cl,%al
je     1315 <arc_math+0x1c5>
mov    0x2ce8(%rip),%rax
mov    (%rax),%ebx
add    %ebx,%ebx
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <fabs@plt>
sub    %eax,%ebx
jmp    1324 <arc_math+0x1d4>
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1040 <fabs@plt>
mov    %eax,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  (%r15),%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@M_PI = global i32 0
define double @arc_math(double %0, double %1, double %2, double %3, double* nocapture %4, double* nocapture %5, double* nocapture %6, double* nocapture writeonly %7, i32 %8) {
%10 = load double, double* %4
%11 = tail call i32 @isnan(double %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %42
13: ; preds = %9
%14 = fsub double %2, %0
%15 = fsub double %3, %1
%16 = tail call double @hypot(double %14, double %15)
%17 = fsub double %0, %2
%18 = fmul double %17, 5.000000e-01
%19 = icmp eq i32 %8, 0
%20 = load double, double* %4
%21 = fmul double %16, %16
%22 = fmul double %21, -2.500000e-01
%23 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %22)
%24 = tail call i32 @sqrt(double %23)
%25 = sub nsw i32 0, %24
%26 = select i1 %19, i32 %24, i32 %25
%27 = sitofp i32 %26 to double
%28 = fsub double %1, %3
%29 = fmul double %28, %27
%30 = fdiv double %29, %16
%31 = fadd double %18, %30
store double %31, double* %5
%32 = fmul double %28, 5.000000e-01
%33 = load double, double* %4
%34 = tail call double @llvm.fmuladd.f64(double %33, double %33, double %22)
%35 = tail call i32 @sqrt(double %34)
%36 = sub nsw i32 0, %35
%37 = select i1 %19, i32 %36, i32 %35
%38 = sitofp i32 %37 to double
%39 = fmul double %17, %38
%40 = fdiv double %39, %16
%41 = fadd double %32, %40
store double %41, double* %6
store double 0.000000e+00, double* %7
br label %46
42: ; preds = %9
%43 = load double, double* %5
%44 = load double, double* %6
%45 = tail call double @hypot(double %43, double %44)
store double %45, double* %4
br label %46
46: ; preds = %42, %13
%47 = load double, double* %6
%48 = fsub double %3, %47
%49 = load double, double* %5
%50 = fsub double %2, %49
%51 = tail call double @atan2(double %48, double %50)
%52 = load double, double* %6
%53 = fsub double %1, %52
%54 = load double, double* %5
%55 = fsub double %0, %54
%56 = tail call double @atan2(double %53, double %55)
%57 = fcmp oge double %51, %56
%58 = icmp ne i32 %8, 0
%59 = and i1 %58, %57
%60 = xor i1 %59, true
%61 = fcmp ule double %56, %51
%62 = or i1 %58, %61
%63 = select i1 %60, i1 %62, i1 false
br i1 %63, label %67, label %64
64: ; preds = %46
%65 = fsub double %51, %56
%66 = tail call i32 @fabs(double %65)
br label %73
67: ; preds = %46
%68 = load i32, i32* @M_PI
%69 = shl nsw i32 %68, 1
%70 = fsub double %51, %56
%71 = tail call i32 @fabs(double %70)
%72 = sub nsw i32 %69, %71
br label %73
73: ; preds = %67, %64
%74 = phi i32 [ %72, %67 ], [ %66, %64 ]
%75 = sitofp i32 %74 to double
%76 = load double, double* %4
%77 = fmul double %76, %75
ret double %77
}