#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 atan(double);
double fabs(double);
double calculate_angle(double dx, double dy) {
  double result;
  if (fabs(dx) < 0.000001)
    result = 3.14159265358979323846 * .5;
  else
    result = fabs(atan(dy / dx));
  if (dx < 0)
    result = 3.14159265358979323846 - result;
  if (dy < 0)
    result = -result;
  if (result < 0)
    result += 2. * 3.14159265358979323846;
  return result;
}


x86 assembly (clang, -O0):
<calculate_angle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm1
movaps 0xef2(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xec6(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1156 <calculate_angle+0x46>
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1175 <calculate_angle+0x65>
movsd  -0x10(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
call   1030 <atan@plt>
movaps 0xeb4(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1195 <calculate_angle+0x85>
movsd  0xe85(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c4 <calculate_angle+0xb4>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11e4 <calculate_angle+0xd4>
movsd  0xe3e(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_angle>:
sub    $0x28,%rsp
movapd %xmm0,%xmm4
movapd 0xee0(%rip),%xmm0
andpd  %xmm4,%xmm0
movsd  0xefc(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    113c <calculate_angle+0x2c>
movsd  0xee6(%rip),%xmm0
jmp    1167 <calculate_angle+0x57>
movapd %xmm1,%xmm0
divsd  %xmm4,%xmm0
movapd %xmm1,0x10(%rsp)
movapd %xmm4,(%rsp)
call   1030 <atan@plt>
movapd (%rsp),%xmm4
movapd 0x10(%rsp),%xmm1
andpd  0xe99(%rip),%xmm0
movsd  0xec1(%rip),%xmm3
subsd  %xmm0,%xmm3
xorpd  %xmm2,%xmm2
cmpltsd %xmm2,%xmm4
andpd  %xmm4,%xmm3
andnpd %xmm0,%xmm4
orpd   %xmm3,%xmm4
movapd 0xe80(%rip),%xmm0
xorpd  %xmm4,%xmm0
cmpltsd %xmm2,%xmm1
movapd %xmm1,%xmm3
andnpd %xmm4,%xmm3
andpd  %xmm0,%xmm1
orpd   %xmm3,%xmm1
movsd  0xe87(%rip),%xmm3
addsd  %xmm1,%xmm3
movapd %xmm1,%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm3
andnpd %xmm1,%xmm0
orpd   %xmm3,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @calculate_angle(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %3
%7 = call double @llvm.fabs.f64(double %6)
%8 = fcmp olt double %7, 0x3EB0C6F7A0B5ED8D
br i1 %8, label %9, label %10
9: ; preds = %2
store double 0x3FF921FB54442D18, double* %5
br label %16
10: ; preds = %2
%11 = load double, double* %4
%12 = load double, double* %3
%13 = fdiv double %11, %12
%14 = call double @atan(double %13)
%15 = call double @llvm.fabs.f64(double %14)
store double %15, double* %5
br label %16
16: ; preds = %10, %9
%17 = load double, double* %3
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load double, double* %5
%21 = fsub double 0x400921FB54442D18, %20
store double %21, double* %5
br label %22
22: ; preds = %19, %16
%23 = load double, double* %4
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load double, double* %5
%27 = fneg double %26
store double %27, double* %5
br label %28
28: ; preds = %25, %22
%29 = load double, double* %5
%30 = fcmp olt double %29, 0.000000e+00
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load double, double* %5
%33 = fadd double %32, 0x401921FB54442D18
store double %33, double* %5
br label %34
34: ; preds = %31, %28
%35 = load double, double* %5
ret double %35
}

LLVM IR (-O2):
define double @calculate_angle(double %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %0)
%4 = fcmp olt double %3, 0x3EB0C6F7A0B5ED8D
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = fdiv double %1, %0
%7 = tail call double @atan(double %6)
%8 = tail call double @llvm.fabs.f64(double %7)
br label %9
9: ; preds = %2, %5
%10 = phi double [ %8, %5 ], [ 0x3FF921FB54442D18, %2 ]
%11 = fcmp olt double %0, 0.000000e+00
%12 = fsub double 0x400921FB54442D18, %10
%13 = select i1 %11, double %12, double %10
%14 = fcmp olt double %1, 0.000000e+00
%15 = fneg double %13
%16 = select i1 %14, double %15, double %13
%17 = fcmp olt double %16, 0.000000e+00
%18 = fadd double %16, 0x401921FB54442D18
%19 = select i1 %17, double %18, double %16
ret double %19
}