#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 */
scalar_t__ ceil(double);
scalar_t__ floor(double);
double modf(double value, double *intpart) {
  double decimal_part = 0.0;
  if (value >= 0) {
    decimal_part = value - (double)floor(value);
    *intpart = value - decimal_part;
  } else {
    decimal_part = -(value - (double)ceil(value));
    *intpart = value + decimal_part;
  }
  return decimal_part;
}


x86 assembly (clang, -O0):
<modf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1189 <modf+0x69>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
movsd  -0x20(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    11d9 <modf+0xb9>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modf>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
jae    1161 <modf+0x41>
call   1030 <ceil@plt>
movsd  0x8(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
movapd 0xea5(%rip),%xmm0
xorpd  %xmm1,%xmm0
jmp    1180 <modf+0x60>
call   1040 <floor@plt>
movsd  0x8(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
subsd  %xmm1,%xmm2
movsd  %xmm2,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @modf(double %0, double* %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca double
store double %0, double* %3
store double* %1, double** %4
store double 0.000000e+00, double* %5
%6 = load double, double* %3
%7 = fcmp oge double %6, 0.000000e+00
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load double, double* %3
%10 = load double, double* %3
%11 = call i64 @floor(double %10)
%12 = sitofp i64 %11 to double
%13 = fsub double %9, %12
store double %13, double* %5
%14 = load double, double* %3
%15 = load double, double* %5
%16 = fsub double %14, %15
%17 = load double*, double** %4
store double %16, double* %17
br label %29
18: ; preds = %2
%19 = load double, double* %3
%20 = load double, double* %3
%21 = call i64 @ceil(double %20)
%22 = sitofp i64 %21 to double
%23 = fsub double %19, %22
%24 = fneg double %23
store double %24, double* %5
%25 = load double, double* %3
%26 = load double, double* %5
%27 = fadd double %25, %26
%28 = load double*, double** %4
store double %27, double* %28
br label %29
29: ; preds = %18, %8
%30 = load double, double* %5
ret double %30
}

LLVM IR (-O2):
define double @modf(double %0, double* nocapture writeonly %1) {
%3 = fcmp ult double %0, 0.000000e+00
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i64 @floor(double %0)
%6 = sitofp i64 %5 to double
%7 = fsub double %0, %6
br label %13
8: ; preds = %2
%9 = tail call i64 @ceil(double %0)
%10 = sitofp i64 %9 to double
%11 = fsub double %0, %10
%12 = fneg double %11
br label %13
13: ; preds = %8, %4
%14 = phi double [ %11, %8 ], [ %7, %4 ]
%15 = phi double [ %12, %8 ], [ %7, %4 ]
%16 = fsub double %0, %14
store double %16, double* %1
ret double %15
}