#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 floor(double);
double limit_degrees180pm(double degrees) {
  double limited;
  degrees /= 360.0;
  limited = 360.0 * (degrees - floor(degrees));
  if (limited < -180.0)
    limited += 360.0;
  else if (limited > 180.0)
    limited -= 360.0;
  return limited;
}


x86 assembly (clang, -O0):
<limit_degrees180pm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xede(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <floor@plt>
movsd  -0x18(%rbp),%xmm1
subsd  %xmm0,%xmm1
movsd  0xeb0(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe97(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    118b <limit_degrees180pm+0x7b>
movsd  0xe8c(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11bd <limit_degrees180pm+0xad>
movsd  -0x10(%rbp),%xmm0
movsd  0xe78(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b8 <limit_degrees180pm+0xa8>
movsd  -0x10(%rbp),%xmm0
movsd  0xe59(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11bd <limit_degrees180pm+0xad>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<limit_degrees180pm>:
push   %rax
divsd  0xee7(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1030 <floor@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xecc(%rip),%xmm1
movsd  0xecc(%rip),%xmm0
ucomisd %xmm1,%xmm0
movapd %xmm1,%xmm0
jbe    1150 <limit_degrees180pm+0x40>
addsd  0xeb2(%rip),%xmm0
pop    %rax
ret
ucomisd 0xeb8(%rip),%xmm0
jbe    1162 <limit_degrees180pm+0x52>
addsd  0xeb6(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @limit_degrees180pm(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
%4 = load double, double* %2
%5 = fdiv double %4, 3.600000e+02
store double %5, double* %2
%6 = load double, double* %2
%7 = load double, double* %2
%8 = call double @llvm.floor.f64(double %7)
%9 = fsub double %6, %8
%10 = fmul double 3.600000e+02, %9
store double %10, double* %3
%11 = load double, double* %3
%12 = fcmp olt double %11, -1.800000e+02
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load double, double* %3
%15 = fadd double %14, 3.600000e+02
store double %15, double* %3
br label %23
16: ; preds = %1
%17 = load double, double* %3
%18 = fcmp ogt double %17, 1.800000e+02
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load double, double* %3
%21 = fsub double %20, 3.600000e+02
store double %21, double* %3
br label %22
22: ; preds = %19, %16
br label %23
23: ; preds = %22, %13
%24 = load double, double* %3
ret double %24
}

LLVM IR (-O2):
define double @limit_degrees180pm(double %0) {
%2 = fdiv double %0, 3.600000e+02
%3 = tail call double @llvm.floor.f64(double %2)
%4 = fsub double %2, %3
%5 = fmul double %4, 3.600000e+02
%6 = fcmp olt double %5, -1.800000e+02
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = fadd double %5, 3.600000e+02
br label %13
9: ; preds = %1
%10 = fcmp ogt double %5, 1.800000e+02
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = fadd double %5, -3.600000e+02
br label %13
13: ; preds = %9, %11, %7
%14 = phi double [ %8, %7 ], [ %12, %11 ], [ %5, %9 ]
ret double %14
}