#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 ceil(double);
double floor(double);
double d2d(double d) {
  if (d <= -360.0) {
    d += ceil(d / -360.0) * 360.0;
  }
  if (d >= 360.0) {
    d -= floor(d / 360.0) * 360.0;
  }
  return (d);
}


x86 assembly (clang, -O0):
<d2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xecb(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1170 <d2d+0x50>
movsd  -0x8(%rbp),%xmm0
movsd  0xeb3(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <ceil@plt>
movsd  -0x8(%rbp),%xmm1
movsd  0xea5(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe8b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ce <d2d+0xae>
movsd  -0x8(%rbp),%xmm0
movsd  0xe74(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
movsd  -0x8(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe47(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2d>:
push   %rax
movapd %xmm0,%xmm1
movsd  0xed3(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     115a <d2d+0x3a>
movapd %xmm1,%xmm0
divsd  0xec1(%rip),%xmm0
movsd  %xmm1,(%rsp)
call   1030 <ceil@plt>
movsd  (%rsp),%xmm1
mulsd  0xeb2(%rip),%xmm0
addsd  %xmm0,%xmm1
ucomisd 0xea6(%rip),%xmm1
jb     118b <d2d+0x6b>
movapd %xmm1,%xmm0
divsd  0xe98(%rip),%xmm0
movsd  %xmm1,(%rsp)
call   1040 <floor@plt>
mulsd  0xe86(%rip),%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @d2d(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = load double, double* %2
%4 = fcmp ole double %3, -3.600000e+02
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load double, double* %2
%7 = fdiv double %6, -3.600000e+02
%8 = call double @llvm.ceil.f64(double %7)
%9 = load double, double* %2
%10 = call double @llvm.fmuladd.f64(double %8, double 3.600000e+02, double %9)
store double %10, double* %2
br label %11
11: ; preds = %5, %1
%12 = load double, double* %2
%13 = fcmp oge double %12, 3.600000e+02
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load double, double* %2
%16 = fdiv double %15, 3.600000e+02
%17 = call double @llvm.floor.f64(double %16)
%18 = load double, double* %2
%19 = fneg double %17
%20 = call double @llvm.fmuladd.f64(double %19, double 3.600000e+02, double %18)
store double %20, double* %2
br label %21
21: ; preds = %14, %11
%22 = load double, double* %2
ret double %22
}

LLVM IR (-O2):
define double @d2d(double %0) {
%2 = fcmp ugt double %0, -3.600000e+02
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = fdiv double %0, -3.600000e+02
%5 = tail call double @llvm.ceil.f64(double %4)
%6 = tail call double @llvm.fmuladd.f64(double %5, double 3.600000e+02, double %0)
br label %7
7: ; preds = %3, %1
%8 = phi double [ %6, %3 ], [ %0, %1 ]
%9 = fcmp ult double %8, 3.600000e+02
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = fdiv double %8, 3.600000e+02
%12 = tail call double @llvm.floor.f64(double %11)
%13 = fneg double %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double 3.600000e+02, double %8)
br label %15
15: ; preds = %10, %7
%16 = phi double [ %14, %10 ], [ %8, %7 ]
ret double %16
}