#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 atan2(double const, double const);
void endpoint_ths(const double xs[], const double ys[], double ths[], int n) {
  ths[0] = 2 * atan2(ys[1] - ys[0], xs[1] - xs[0]) - ths[1];
  ths[n - 1] =
      2 * atan2(ys[n - 1] - ys[n - 2], xs[n - 1] - xs[n - 2]) - ths[n - 2];
}


x86 assembly (clang, -O0):
<endpoint_ths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
subsd  (%rax),%xmm1
call   1030 <atan2@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
subsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm1
call   1030 <atan2@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endpoint_ths>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
movsd  0x8(%rsi),%xmm0
subsd  (%rsi),%xmm0
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbp
movsd  0x8(%rdi),%xmm1
subsd  (%rdi),%xmm1
call   1030 <atan2@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  0x8(%r14),%xmm0
movsd  %xmm0,(%r14)
movslq %r15d,%rbx
movsd  -0x8(%r12,%rbx,8),%xmm0
subsd  -0x10(%r12,%rbx,8),%xmm0
movsd  -0x8(%rbp,%rbx,8),%xmm1
subsd  -0x10(%rbp,%rbx,8),%xmm1
call   1030 <atan2@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  -0x10(%r14,%rbx,8),%xmm0
movsd  %xmm0,-0x8(%r14,%rbx,8)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @endpoint_ths(double* %0, double* %1, double* %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
%9 = load double*, double** %6
%10 = getelementptr inbounds double, double* %9, i64 1
%11 = load double, double* %10
%12 = load double*, double** %6
%13 = getelementptr inbounds double, double* %12, i64 0
%14 = load double, double* %13
%15 = fsub double %11, %14
%16 = load double*, double** %5
%17 = getelementptr inbounds double, double* %16, i64 1
%18 = load double, double* %17
%19 = load double*, double** %5
%20 = getelementptr inbounds double, double* %19, i64 0
%21 = load double, double* %20
%22 = fsub double %18, %21
%23 = call i32 @atan2(double %15, double %22)
%24 = mul nsw i32 2, %23
%25 = sitofp i32 %24 to double
%26 = load double*, double** %7
%27 = getelementptr inbounds double, double* %26, i64 1
%28 = load double, double* %27
%29 = fsub double %25, %28
%30 = load double*, double** %7
%31 = getelementptr inbounds double, double* %30, i64 0
store double %29, double* %31
%32 = load double*, double** %6
%33 = load i32, i32* %8
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %32, i64 %35
%37 = load double, double* %36
%38 = load double*, double** %6
%39 = load i32, i32* %8
%40 = sub nsw i32 %39, 2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %38, i64 %41
%43 = load double, double* %42
%44 = fsub double %37, %43
%45 = load double*, double** %5
%46 = load i32, i32* %8
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %45, i64 %48
%50 = load double, double* %49
%51 = load double*, double** %5
%52 = load i32, i32* %8
%53 = sub nsw i32 %52, 2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %51, i64 %54
%56 = load double, double* %55
%57 = fsub double %50, %56
%58 = call i32 @atan2(double %44, double %57)
%59 = mul nsw i32 2, %58
%60 = sitofp i32 %59 to double
%61 = load double*, double** %7
%62 = load i32, i32* %8
%63 = sub nsw i32 %62, 2
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds double, double* %61, i64 %64
%66 = load double, double* %65
%67 = fsub double %60, %66
%68 = load double*, double** %7
%69 = load i32, i32* %8
%70 = sub nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %68, i64 %71
store double %67, double* %72
ret void
}

LLVM IR (-O2):
define void @endpoint_ths(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3) {
%5 = getelementptr inbounds double, double* %1, i64 1
%6 = load double, double* %5
%7 = load double, double* %1
%8 = fsub double %6, %7
%9 = getelementptr inbounds double, double* %0, i64 1
%10 = load double, double* %9
%11 = load double, double* %0
%12 = fsub double %10, %11
%13 = tail call i32 @atan2(double %8, double %12)
%14 = shl nsw i32 %13, 1
%15 = sitofp i32 %14 to double
%16 = getelementptr inbounds double, double* %2, i64 1
%17 = load double, double* %16
%18 = fsub double %15, %17
store double %18, double* %2
%19 = add nsw i32 %3, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %1, i64 %20
%22 = load double, double* %21
%23 = add nsw i32 %3, -2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %1, i64 %24
%26 = load double, double* %25
%27 = fsub double %22, %26
%28 = getelementptr inbounds double, double* %0, i64 %20
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %0, i64 %24
%31 = load double, double* %30
%32 = fsub double %29, %31
%33 = tail call i32 @atan2(double %27, double %32)
%34 = shl nsw i32 %33, 1
%35 = sitofp i32 %34 to double
%36 = getelementptr inbounds double, double* %2, i64 %24
%37 = load double, double* %36
%38 = fsub double %35, %37
%39 = getelementptr inbounds double, double* %2, i64 %20
store double %38, double* %39
ret void
}