#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 az_mod2pi(double);
double az_angle_towards(double theta, double delta, double goal) {
  const double difference = az_mod2pi(theta - goal);
  return az_mod2pi(difference < 0.0
                       ? (-difference <= delta ? goal : theta + delta)
                       : (difference <= delta ? goal : theta - delta));
}


x86 assembly (clang, -O0):
<az_angle_towards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1030 <az_mod2pi@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11a1 <az_angle_towards+0x91>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1183 <az_angle_towards+0x73>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1192 <az_angle_towards+0x82>
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11dd <az_angle_towards+0xcd>
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11c4 <az_angle_towards+0xb4>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11d3 <az_angle_towards+0xc3>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <az_mod2pi@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<az_angle_towards>:
sub    $0x38,%rsp
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
movapd %xmm2,0x20(%rsp)
subsd  %xmm2,%xmm0
call   1030 <az_mod2pi@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1153 <az_angle_towards+0x43>
xorpd  0xebf(%rip),%xmm0
movapd 0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm2
jmp    1163 <az_angle_towards+0x53>
movapd 0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm2
cmplesd %xmm1,%xmm0
movapd %xmm0,%xmm1
andnpd %xmm2,%xmm1
andpd  0x20(%rsp),%xmm0
orpd   %xmm1,%xmm0
add    $0x38,%rsp
jmp    1030 <az_mod2pi@plt>

LLVM IR (-O0):
define double @az_angle_towards(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
%8 = load double, double* %4
%9 = load double, double* %6
%10 = fsub double %8, %9
%11 = call double @az_mod2pi(double %10)
store double %11, double* %7
%12 = load double, double* %7
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %14, label %27
14: ; preds = %3
%15 = load double, double* %7
%16 = fneg double %15
%17 = load double, double* %5
%18 = fcmp ole double %16, %17
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = load double, double* %6
br label %25
21: ; preds = %14
%22 = load double, double* %4
%23 = load double, double* %5
%24 = fadd double %22, %23
br label %25
25: ; preds = %21, %19
%26 = phi double [ %20, %19 ], [ %24, %21 ]
br label %39
27: ; preds = %3
%28 = load double, double* %7
%29 = load double, double* %5
%30 = fcmp ole double %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load double, double* %6
br label %37
33: ; preds = %27
%34 = load double, double* %4
%35 = load double, double* %5
%36 = fsub double %34, %35
br label %37
37: ; preds = %33, %31
%38 = phi double [ %32, %31 ], [ %36, %33 ]
br label %39
39: ; preds = %37, %25
%40 = phi double [ %26, %25 ], [ %38, %37 ]
%41 = call double @az_mod2pi(double %40)
ret double %41
}

LLVM IR (-O2):
define double @az_angle_towards(double %0, double %1, double %2) {
%4 = fsub double %0, %2
%5 = tail call double @az_mod2pi(double %4)
%6 = fcmp olt double %5, 0.000000e+00
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = fneg double %5
%9 = fcmp ole double %8, %1
%10 = fadd double %0, %1
%11 = select i1 %9, double %2, double %10
br label %16
12: ; preds = %3
%13 = fcmp ole double %5, %1
%14 = fsub double %0, %1
%15 = select i1 %13, double %2, double %14
br label %16
16: ; preds = %12, %7
%17 = phi double [ %11, %7 ], [ %15, %12 ]
%18 = tail call double @az_mod2pi(double %17)
ret double %18
}