double angle_diff_full(double a, double b, int sens) {
  a -= b;
  if (sens == 1 && a < 0)
    a += 6.28318530718;
  if (sens == 2)
    if (a > 0)
      a = 6.28318530718 - a;
    else
      a = -a;
  return a;
}


x86 assembly (clang, -O0):
<angle_diff_full>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    114e <angle_diff_full+0x4e>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    114e <angle_diff_full+0x4e>
movsd  0xebc(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    11a7 <angle_diff_full+0xa7>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1181 <angle_diff_full+0x81>
movsd  0xe8e(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a2 <angle_diff_full+0xa2>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a7 <angle_diff_full+0xa7>
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<angle_diff_full>:
subsd  %xmm1,%xmm0
cmp    $0x1,%edi
jne    1132 <angle_diff_full+0x32>
movsd  0xeef(%rip),%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
movapd %xmm3,%xmm0
cmp    $0x2,%edi
jne    115a <angle_diff_full+0x5a>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1152 <angle_diff_full+0x52>
movsd  0xeb7(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
ret
xorpd  0xeb6(%rip),%xmm0
ret

LLVM IR (-O0):
define double @angle_diff_full(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store double %0, double* %4
store double %1, double* %5
store i32 %2, i32* %6
%7 = load double, double* %5
%8 = load double, double* %4
%9 = fsub double %8, %7
store double %9, double* %4
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load double, double* %4
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load double, double* %4
%17 = fadd double %16, 0x401921FB54442EEA
store double %17, double* %4
br label %18
18: ; preds = %15, %12, %3
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load double, double* %4
%23 = fcmp ogt double %22, 0.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load double, double* %4
%26 = fsub double 0x401921FB54442EEA, %25
store double %26, double* %4
br label %30
27: ; preds = %21
%28 = load double, double* %4
%29 = fneg double %28
store double %29, double* %4
br label %30
30: ; preds = %27, %24
br label %31
31: ; preds = %30, %18
%32 = load double, double* %4
ret double %32
}

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