#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);
double fit_arc(double, double);
void local_ths(const double xs[], const double ys[], double ths[], int n,
               int closed) {
  int i;
  for (i = 1 - closed; i < n - 1 + closed; i++) {
    int im1 = (i + n - 1) % n;
    double x0 = xs[im1];
    double y0 = ys[im1];
    double x1 = xs[i];
    double y1 = ys[i];
    int ip1 = (i + 1) % n;
    double x2 = xs[ip1];
    double y2 = ys[ip1];
    double dx = x2 - x0;
    double dy = y2 - y0;
    double ir2 = dx * dx + dy * dy;
    double x = ((x1 - x0) * dx + (y1 - y0) * dy) / ir2;
    double y = ((y1 - y0) * dx - (x1 - x0) * dy) / ir2;
    if (dx == 0.0 && dy == 0.0)
      ths[i] = 0.0;
    else
      ths[i] = fit_arc(x, y) + atan2(dy, dx);
  }
}


x86 assembly (clang, -O0):
<local_ths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    $0x1,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
add    -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    133c <local_ths+0x21c>
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x1c(%rbp)
mov    %edx,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x1c(%rbp)
mov    %edx,-0x4c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
movsd  -0x70(%rbp),%xmm1
mulsd  -0x70(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
mulsd  -0x70(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
mulsd  -0x70(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12e4 <local_ths+0x1c4>
jp     12e4 <local_ths+0x1c4>
movsd  -0x70(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12e4 <local_ths+0x1c4>
jp     12e4 <local_ths+0x1c4>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1329 <local_ths+0x209>
movsd  -0x80(%rbp),%xmm0
movsd  -0x88(%rbp),%xmm1
ff
call   1040 <fit_arc@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x70(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
call   1030 <atan2@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    132e <local_ths+0x20e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1149 <local_ths+0x29>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_ths>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%r15d
mov    $0x1,%eax
sub    %r8d,%eax
lea    (%r15,%r8,1),%ebp
add    $0xffffffff,%ebp
cmp    %ebp,%eax
jge    12a2 <local_ths+0x182>
mov    %rdi,%rbx
cltq
lea    (%rdx,%rax,8),%r12
lea    (%rdi,%rax,8),%rbp
lea    (%rsi,%rax,8),%r14
mov    %r15d,%r9d
sub    %r8d,%r9d
lea    (%r15,%r8,2),%r10d
add    $0xfffffffe,%r10d
mov    $0x2,%r11d
sub    %r8d,%r11d
xor    %r13d,%r13d
xorpd  %xmm5,%xmm5
mov    %r12,0x18(%rsp)
mov    %rbp,0x10(%rsp)
mov    %r14,0x8(%rsp)
mov    %rsi,(%rsp)
jmp    123e <local_ths+0x11e>
nop
movapd %xmm7,%xmm1
mulsd  %xmm7,%xmm1
movapd %xmm6,%xmm5
mulsd  %xmm6,%xmm5
addsd  %xmm1,%xmm5
subsd  %xmm4,%xmm0
subsd  %xmm3,%xmm2
movapd %xmm7,%xmm3
mulsd  %xmm0,%xmm3
movapd %xmm2,%xmm1
mulsd  %xmm6,%xmm1
subsd  %xmm3,%xmm1
divsd  %xmm5,%xmm1
mulsd  %xmm7,%xmm2
mulsd  %xmm6,%xmm0
addsd  %xmm2,%xmm0
divsd  %xmm5,%xmm0
mov    %r9,%r12
mov    %r10,%rbp
mov    %r11,%r14
movsd  %xmm6,0x28(%rsp)
movsd  %xmm7,0x20(%rsp)
call   1040 <fit_arc@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
call   1030 <atan2@plt>
xorpd  %xmm5,%xmm5
mov    %r14,%r11
mov    %rbp,%r10
mov    %r12,%r9
mov    (%rsp),%rsi
mov    0x8(%rsp),%r14
mov    0x10(%rsp),%rbp
mov    0x18(%rsp),%r12
movapd %xmm0,%xmm1
addsd  0x30(%rsp),%xmm1
movsd  %xmm1,(%r12,%r13,8)
add    $0x1,%r13
cmp    %r13d,%r10d
je     12a2 <local_ths+0x182>
lea    (%r9,%r13,1),%eax
cltd
idiv   %r15d
movslq %edx,%rax
movsd  (%rbx,%rax,8),%xmm4
movsd  (%rsi,%rax,8),%xmm3
movsd  0x0(%rbp,%r13,8),%xmm0
movsd  (%r14,%r13,8),%xmm2
lea    (%r11,%r13,1),%eax
cltd
idiv   %r15d
movslq %edx,%rax
movsd  (%rbx,%rax,8),%xmm6
movsd  (%rsi,%rax,8),%xmm7
subsd  %xmm4,%xmm6
subsd  %xmm3,%xmm7
ucomisd %xmm5,%xmm6
jne    1190 <local_ths+0x70>
jp     1190 <local_ths+0x70>
ucomisd %xmm5,%xmm7
xorpd  %xmm1,%xmm1
jne    1190 <local_ths+0x70>
jnp    122f <local_ths+0x10f>
jmp    1190 <local_ths+0x70>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @local_ths(double* nocapture %0, double* nocapture %1, double* nocapture writeonly %2, i32 %3, i32 %4) {
%6 = sub i32 1, %4
%7 = add i32 %3, -1
%8 = add i32 %7, %4
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %58
10: ; preds = %5
%11 = sext i32 %6 to i64
br label %12
12: ; preds = %10, %54
%13 = phi i64 [ %11, %10 ], [ %26, %54 ]
%14 = trunc i64 %13 to i32
%15 = add i32 %7, %14
%16 = srem i32 %15, %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %1, i64 %17
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %0, i64 %13
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %1, i64 %13
%25 = load double, double* %24
%26 = add nsw i64 %13, 1
%27 = trunc i64 %26 to i32
%28 = srem i32 %27, %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %0, i64 %29
%31 = load double, double* %30
%32 = getelementptr inbounds double, double* %1, i64 %29
%33 = load double, double* %32
%34 = fsub double %31, %19
%35 = fsub double %33, %21
%36 = fmul double %35, %35
%37 = tail call double @llvm.fmuladd.f64(double %34, double %34, double %36)
%38 = fsub double %23, %19
%39 = fsub double %25, %21
%40 = fcmp oeq double %34, 0.000000e+00
%41 = fcmp oeq double %35, 0.000000e+00
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %54, label %43
43: ; preds = %12
%44 = fneg double %38
%45 = fmul double %35, %44
%46 = tail call double @llvm.fmuladd.f64(double %39, double %34, double %45)
%47 = fdiv double %46, %37
%48 = fmul double %39, %35
%49 = tail call double @llvm.fmuladd.f64(double %38, double %34, double %48)
%50 = fdiv double %49, %37
%51 = tail call double @fit_arc(double %50, double %47)
%52 = tail call double @atan2(double %35, double %34)
%53 = fadd double %51, %52
br label %54
54: ; preds = %12, %43
%55 = phi double [ %53, %43 ], [ 0.000000e+00, %12 ]
%56 = getelementptr inbounds double, double* %2, i64 %13
store double %55, double* %56
%57 = icmp eq i32 %8, %27
br i1 %57, label %58, label %12
58: ; preds = %54, %5
ret void
}