#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__ ceilld(long double);
scalar_t__ floorld(long double);
long double modld(long double value, long double *intpart) {
  long double decimal_part = 0.0;
  if (value >= 0) {
    decimal_part = value - (long double)floorld(value);
    *intpart = value - decimal_part;
  } else {
    decimal_part = -(value - (long double)ceilld(value));
    *intpart = value + decimal_part;
  }
  return decimal_part;
}


x86 assembly (clang, -O0):
<modld>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
mov    %rdi,-0x18(%rbp)
fldz
fld    %st(0)
fstpt  -0x30(%rbp)
fldt   -0x10(%rbp)
fucomip %st(1),%st
fstp   %st(0)
jb     117f <modld+0x5f>
jmp    114b <modld+0x2b>
fldt   -0x10(%rbp)
fld    %st(0)
fstpt  -0x4c(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <floorld@plt>
fldt   -0x4c(%rbp)
mov    %rax,-0x40(%rbp)
fildll -0x40(%rbp)
fsubrp %st,%st(1)
fstpt  -0x30(%rbp)
fldt   -0x10(%rbp)
fldt   -0x30(%rbp)
fsubrp %st,%st(1)
mov    -0x18(%rbp),%rax
fstpt  (%rax)
jmp    11b0 <modld+0x90>
fldt   -0x10(%rbp)
fld    %st(0)
fstpt  -0x58(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <ceilld@plt>
fldt   -0x58(%rbp)
mov    %rax,-0x38(%rbp)
fildll -0x38(%rbp)
fsubrp %st,%st(1)
fchs
fstpt  -0x30(%rbp)
fldt   -0x10(%rbp)
fldt   -0x30(%rbp)
faddp  %st,%st(1)
mov    -0x18(%rbp),%rax
fstpt  (%rax)
fldt   -0x30(%rbp)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modld>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
fldt   0x40(%rsp)
fldz
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
fld    %st(0)
fstpt  0x14(%rsp)
jae    1159 <modld+0x39>
fstpt  (%rsp)
call   1040 <ceilld@plt>
fldt   0x14(%rsp)
mov    %rax,0x20(%rsp)
fildll 0x20(%rsp)
fsubr  %st(1),%st
fld    %st(0)
fchs
jmp    1172 <modld+0x52>
fstpt  (%rsp)
call   1030 <floorld@plt>
fldt   0x14(%rsp)
mov    %rax,0x28(%rsp)
fildll 0x28(%rsp)
fsubr  %st(1),%st
fld    %st(0)
fxch   %st(2)
fsubp  %st,%st(1)
fstpt  (%rbx)
add    $0x30,%rsp
pop    %rbx
ret

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

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