double frexp(value, eptr)
double value;
int *eptr;
{
  union {
    double v;
    struct {
      unsigned u_mant2 : 32;
      unsigned u_mant1 : 20;
      unsigned u_exp : 11;
      unsigned u_sign : 1;
    } s;
  } u;
  if (value) {
    u.v = value;
    *eptr = u.s.u_exp - 1022;
    u.s.u_exp = 1022;
    return (u.v);
  } else {
    *eptr = 0;
    return ((double)0);
  }
}


x86 assembly (clang, -O0):
<frexp>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    112a <frexp+0x2a>
jp     112a <frexp+0x2a>
jmp    117e <frexp+0x7e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shr    $0x34,%rax
and    $0x7ff,%rax
mov    %eax,%ecx
sub    $0x3fe,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movabs $0x800fffffffffffff,%rax
ff 0f 80
and    -0x20(%rbp),%rax
movabs $0x3fe0000000000000,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1190 <frexp+0x90>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<frexp>:
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1110 <frexp+0x10>
jnp    1145 <frexp+0x45>
movq   %xmm1,%rax
movabs $0x800fffffffffffff,%rcx
ff 0f 80
and    %rax,%rcx
shr    $0x34,%rax
and    $0x7ff,%eax
add    $0xfffffc02,%eax
mov    %eax,(%rdi)
movabs $0x3fe0000000000000,%rax
or     %rcx,%rax
movq   %rax,%xmm0
ret
movl   $0x0,(%rdi)
ret

LLVM IR (-O0):
%union.anon = type { double }
%struct.anon = type { i64 }
define double @frexp(double %0, i32* %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32*
%6 = alloca %union.anon
store double %0, double* %4
store i32* %1, i32** %5
%7 = load double, double* %4
%8 = fcmp une double %7, 0.000000e+00
br i1 %8, label %9, label %27
9: ; preds = %2
%10 = load double, double* %4
%11 = bitcast %union.anon* %6 to double*
store double %10, double* %11
%12 = bitcast %union.anon* %6 to %struct.anon*
%13 = bitcast %struct.anon* %12 to i64*
%14 = load i64, i64* %13
%15 = lshr i64 %14, 52
%16 = and i64 %15, 2047
%17 = trunc i64 %16 to i32
%18 = sub nsw i32 %17, 1022
%19 = load i32*, i32** %5
store i32 %18, i32* %19
%20 = bitcast %union.anon* %6 to %struct.anon*
%21 = bitcast %struct.anon* %20 to i64*
%22 = load i64, i64* %21
%23 = and i64 %22, -9218868437227405313
%24 = or i64 %23, 4602678819172646912
store i64 %24, i64* %21
%25 = bitcast %union.anon* %6 to double*
%26 = load double, double* %25
store double %26, double* %3
br label %29
27: ; preds = %2
%28 = load i32*, i32** %5
store i32 0, i32* %28
store double 0.000000e+00, double* %3
br label %29
29: ; preds = %27, %9
%30 = load double, double* %3
ret double %30
}

LLVM IR (-O2):
define double @frexp(double %0, i32* nocapture writeonly %1) {
%3 = fcmp une double %0, 0.000000e+00
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = bitcast double %0 to i64
%6 = lshr i64 %5, 52
%7 = trunc i64 %6 to i32
%8 = and i32 %7, 2047
%9 = add nsw i32 %8, -1022
store i32 %9, i32* %1
%10 = and i64 %5, -9218868437227405313
%11 = or i64 %10, 4602678819172646912
%12 = bitcast i64 %11 to double
br label %14
13: ; preds = %2
store i32 0, i32* %1
br label %14
14: ; preds = %13, %4
%15 = phi double [ %12, %4 ], [ 0.000000e+00, %13 ]
ret double %15
}