double internal_modf(double value, double *iptr) {
  double int_part = (double)0.0;
  asm volatile("pushq %%rax\n\tsubq $8, %%rsp\n"
               "fnstcw 4(%%rsp)\n"
               "movzwl 4(%%rsp), %%eax\n"
               "orb $12, %%ah\n"
               "movw %%ax, (%%rsp)\n"
               "fldcw (%%rsp)\n"
               "frndint\n"
               "fldcw 4(%%rsp)\n"
               "addq $8, %%rsp\npopq %%rax"
               : "=t"(int_part)
               : "0"(value));
  if (iptr)
    *iptr = int_part;
  return (isinf(value) ? (double)0.0 : value - int_part);
}


x86 assembly (clang, -O0):
<internal_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
movsd  %xmm0,-0x20(%rbp)
fldl   -0x20(%rbp)
push   %rax
sub    $0x8,%rsp
fnstcw 0x4(%rsp)
movzwl 0x4(%rsp),%eax
or     $0xc,%ah
mov    %ax,(%rsp)
fldcw  (%rsp)
frndint
fldcw  0x4(%rsp)
add    $0x8,%rsp
pop    %rax
fstpl  -0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117e <internal_modf+0x6e>
movsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x8(%rbp),%xmm0
mov    $0x1,%al
call   1030 <isinf@plt>
cmp    $0x0,%eax
je     11a0 <internal_modf+0x90>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11af <internal_modf+0x9f>
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<internal_modf>:
sub    $0x28,%rsp
movsd  %xmm0,0x20(%rsp)
fldl   0x20(%rsp)
push   %rax
sub    $0x8,%rsp
fnstcw 0x4(%rsp)
movzwl 0x4(%rsp),%eax
or     $0xc,%ah
mov    %ax,(%rsp)
fldcw  (%rsp)
frndint
fldcw  0x4(%rsp)
add    $0x8,%rsp
pop    %rax
fstpl  0x18(%rsp)
movsd  0x18(%rsp),%xmm1
test   %rdi,%rdi
je     1154 <internal_modf+0x44>
movsd  %xmm1,(%rdi)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1030 <isinf@plt>
test   %eax,%eax
je     1173 <internal_modf+0x63>
xorps  %xmm0,%xmm0
add    $0x28,%rsp
ret
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @internal_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 = call double asm sideeffect "pushq %rax\0A\09subq $$8, %rsp\0Afnstcw 4(%rsp)\0Amovzwl 4(%rsp), %eax\0Aorb $$12, %ah\0Amovw %ax, (%rsp)\0Afldcw (%rsp)\0Afrndint\0Afldcw 4(%rsp)\0Aaddq $$8, %rsp\0Apopq %rax", "={st},0,~{dirflag},~{fpsr},~{flags}"(double %6)
store double %7, double* %5
%8 = load double*, double** %4
%9 = icmp ne double* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load double, double* %5
%12 = load double*, double** %4
store double %11, double* %12
br label %13
13: ; preds = %10, %2
%14 = load double, double* %3
%15 = call i32 (double, ...) bitcast (i32 (...)* @isinf to i32 (double, ...)*)(double %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %22
18: ; preds = %13
%19 = load double, double* %3
%20 = load double, double* %5
%21 = fsub double %19, %20
br label %22
22: ; preds = %18, %17
%23 = phi double [ 0.000000e+00, %17 ], [ %21, %18 ]
ret double %23
}

LLVM IR (-O2):
define double @internal_modf(double %0, double* writeonly %1) {
%3 = tail call double asm sideeffect "pushq %rax\0A\09subq $$8, %rsp\0Afnstcw 4(%rsp)\0Amovzwl 4(%rsp), %eax\0Aorb $$12, %ah\0Amovw %ax, (%rsp)\0Afldcw (%rsp)\0Afrndint\0Afldcw 4(%rsp)\0Aaddq $$8, %rsp\0Apopq %rax", "={st},0,~{dirflag},~{fpsr},~{flags}"(double %0)
%4 = icmp eq double* %1, null
br i1 %4, label %6, label %5
5: ; preds = %2
store double %3, double* %1
br label %6
6: ; preds = %5, %2
%7 = tail call i32 (double, ...) bitcast (i32 (...)* @isinf to i32 (double, ...)*)(double %0)
%8 = icmp eq i32 %7, 0
%9 = fsub double %0, %3
%10 = select i1 %8, double %9, double 0.000000e+00
ret double %10
}