#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 angle_diff_signed(double, double);
double atan2(double, double);
int /*<<< orphan*/ error(char *);
double ellipse_normal_angle(double x, double y, double *foci) {
  double tmp1, tmp2, tmp3, theta;
  if (foci == NULL)
    error("ellipse_normal_angle: 'foci' must be non null");
  tmp1 = atan2(y - foci[1], x - foci[0]);
  tmp2 = atan2(y - foci[3], x - foci[2]);
  tmp3 = angle_diff_signed(tmp1, tmp2);
  theta = tmp1 - tmp3 / 2.0;
  while (theta <= -3.14159265358979323846)
    theta += 6.28318530718;
  while (theta > 3.14159265358979323846)
    theta -= 6.28318530718;
  return theta;
}


x86 assembly (clang, -O0):
<ellipse_normal_angle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115d <ellipse_normal_angle+0x2d>
lea    0xec8(%rip),%rdi
call   1050 <error@plt>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  -0x8(%rbp),%xmm1
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
subsd  0x18(%rax),%xmm0
movsd  -0x8(%rbp),%xmm1
mov    -0x18(%rbp),%rax
subsd  0x10(%rax),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1040 <angle_diff_signed@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xe32(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe25(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     1205 <ellipse_normal_angle+0xd5>
movsd  0xe22(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11db <ellipse_normal_angle+0xab>
jmp    120a <ellipse_normal_angle+0xda>
movsd  -0x38(%rbp),%xmm0
movsd  0xdf9(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    123c <ellipse_normal_angle+0x10c>
movsd  -0x38(%rbp),%xmm0
movsd  0xdea(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    120a <ellipse_normal_angle+0xda>
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ellipse_normal_angle>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movapd %xmm0,%xmm2
test   %rdi,%rdi
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
jne    1165 <ellipse_normal_angle+0x35>
lea    0xed4(%rip),%rdi
call   1050 <error@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
subsd  0x8(%rbx),%xmm0
subsd  (%rbx),%xmm2
movapd %xmm2,%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
subsd  0x18(%rbx),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  0x10(%rbx),%xmm1
call   1030 <atan2@plt>
movapd %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
call   1040 <angle_diff_signed@plt>
mulsd  0xe4d(%rip),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  0xe47(%rip),%xmm1
ucomisd %xmm0,%xmm1
jb     11da <ellipse_normal_angle+0xaa>
movsd  0xe41(%rip),%xmm2
nop
addsd  %xmm2,%xmm0
ucomisd %xmm0,%xmm1
jae    11d0 <ellipse_normal_angle+0xa0>
ucomisd 0xe36(%rip),%xmm0
jbe    120a <ellipse_normal_angle+0xda>
movsd  0xe34(%rip),%xmm1
movsd  0xe24(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
ja     1200 <ellipse_normal_angle+0xd0>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"ellipse_normal_angle: 'foci' must be non null\00"
define double @ellipse_normal_angle(double %0, double %1, double* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %4
store double %1, double* %5
store double* %2, double** %6
%11 = load double*, double** %6
%12 = icmp eq double* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = load double, double* %5
%17 = load double*, double** %6
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = fsub double %16, %19
%21 = load double, double* %4
%22 = load double*, double** %6
%23 = getelementptr inbounds double, double* %22, i64 0
%24 = load double, double* %23
%25 = fsub double %21, %24
%26 = call double @atan2(double %20, double %25)
store double %26, double* %7
%27 = load double, double* %5
%28 = load double*, double** %6
%29 = getelementptr inbounds double, double* %28, i64 3
%30 = load double, double* %29
%31 = fsub double %27, %30
%32 = load double, double* %4
%33 = load double*, double** %6
%34 = getelementptr inbounds double, double* %33, i64 2
%35 = load double, double* %34
%36 = fsub double %32, %35
%37 = call double @atan2(double %31, double %36)
store double %37, double* %8
%38 = load double, double* %7
%39 = load double, double* %8
%40 = call double @angle_diff_signed(double %38, double %39)
store double %40, double* %9
%41 = load double, double* %7
%42 = load double, double* %9
%43 = fdiv double %42, 2.000000e+00
%44 = fsub double %41, %43
store double %44, double* %10
br label %45
45: ; preds = %48, %15
%46 = load double, double* %10
%47 = fcmp ole double %46, 0xC00921FB54442D18
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load double, double* %10
%50 = fadd double %49, 0x401921FB54442EEA
store double %50, double* %10
br label %45
51: ; preds = %45
br label %52
52: ; preds = %55, %51
%53 = load double, double* %10
%54 = fcmp ogt double %53, 0x400921FB54442D18
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load double, double* %10
%57 = fsub double %56, 0x401921FB54442EEA
store double %57, double* %10
br label %52
58: ; preds = %52
%59 = load double, double* %10
ret double %59
}

LLVM IR (-O2):
@.str = [46 x i8] c"ellipse_normal_angle: 'foci' must be non null\00"
define double @ellipse_normal_angle(double %0, double %1, double* %2) {
%4 = icmp eq double* %2, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = getelementptr inbounds double, double* %2, i64 1
%9 = load double, double* %8
%10 = fsub double %1, %9
%11 = load double, double* %2
%12 = fsub double %0, %11
%13 = tail call double @atan2(double %10, double %12)
%14 = getelementptr inbounds double, double* %2, i64 3
%15 = load double, double* %14
%16 = fsub double %1, %15
%17 = getelementptr inbounds double, double* %2, i64 2
%18 = load double, double* %17
%19 = fsub double %0, %18
%20 = tail call double @atan2(double %16, double %19)
%21 = tail call double @angle_diff_signed(double %13, double %20)
%22 = fmul double %21, 5.000000e-01
%23 = fsub double %13, %22
%24 = fcmp ugt double %23, 0xC00921FB54442D18
br i1 %24, label %25, label %28
25: ; preds = %28, %7
%26 = phi double [ %23, %7 ], [ %30, %28 ]
%27 = fcmp ogt double %26, 0x400921FB54442D18
br i1 %27, label %32, label %36
28: ; preds = %7, %28
%29 = phi double [ %30, %28 ], [ %23, %7 ]
%30 = fadd double %29, 0x401921FB54442EEA
%31 = fcmp ugt double %30, 0xC00921FB54442D18
br i1 %31, label %25, label %28
32: ; preds = %25, %32
%33 = phi double [ %34, %32 ], [ %26, %25 ]
%34 = fadd double %33, 0xC01921FB54442EEA
%35 = fcmp ogt double %34, 0x400921FB54442D18
br i1 %35, label %32, label %36
36: ; preds = %32, %25
%37 = phi double [ %26, %25 ], [ %34, %32 ]
ret double %37
}