#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 pow(int, char);
int /*<<< orphan*/ printf(char *, double);
double my_frexp(double x, int *exp) {
  char sign;
  double mantissa;
  unsigned long long int *p = (unsigned long long int *)&x;
  sign = *p >> 63;
  printf("Sign: %d\n", sign);
  if (!sign)
    *exp = (*p >> 52) - 1022;
  else
    *exp = (*p >> 52) - 3070;
  printf("Exponent: %d\n", *exp);
  mantissa = *p & 0xFFFFFFFFFFFFFL;
  mantissa = (((mantissa / pow(2, 52)) + 1) / 2);
  printf("Mantissa: %f\n\n", pow(-1, sign) * mantissa);
  return pow(-1, sign) * mantissa;
}


x86 assembly (clang, -O0):
<my_frexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
shr    $0x3f,%rax
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cvtsi2sd %eax,%xmm0
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
cmpb   $0x0,-0x11(%rbp)
jne    1183 <my_frexp+0x63>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
shr    $0x34,%rax
sub    $0x3fe,%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    119c <my_frexp+0x7c>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
shr    $0x34,%rax
sub    $0xbfe,%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cvtsi2sdl (%rax),%xmm0
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movabs $0xfffffffffffff,%rcx
and    %rcx,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x2,%edi
mov    $0x34,%esi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  0xe0d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xdf9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0xffffffff,%edi
movsbl -0x11(%rbp),%esi
call   1040 <pow@plt>
mulsd  -0x20(%rbp),%xmm0
lea    0xdfe(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
movsbl -0x11(%rbp),%esi
call   1040 <pow@plt>
mulsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_frexp>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movq   %xmm0,%rbx
mov    %rbx,%r15
shr    $0x3f,%r15
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
test   %rbx,%rbx
setns  %al
mov    %rbx,%rcx
shr    $0x34,%rcx
shl    $0xb,%eax
add    %ecx,%eax
add    $0xfffff402,%eax
mov    %eax,(%r14)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
movabs $0xfffffffffffff,%rax
and    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%edi
mov    $0x34,%esi
call   1040 <pow@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0xe49(%rip),%xmm1
mulsd  0xe49(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
mov    $0xffffffff,%edi
mov    %r15d,%esi
call   1040 <pow@plt>
mulsd  0x8(%rsp),%xmm0
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
mov    %r15d,%esi
call   1040 <pow@plt>
mulsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Sign: %d\0A\00"
@.str.1 = [14 x i8] c"Exponent: %d\0A\00"
@.str.2 = [15 x i8] c"Mantissa: %f\0A\0A\00"
define double @my_frexp(double %0, i32* %1) {
%3 = alloca double
%4 = alloca i32*
%5 = alloca i8
%6 = alloca double
%7 = alloca i64*
store double %0, double* %3
store i32* %1, i32** %4
%8 = bitcast double* %3 to i64*
store i64* %8, i64** %7
%9 = load i64*, i64** %7
%10 = load i64, i64* %9
%11 = lshr i64 %10, 63
%12 = trunc i64 %11 to i8
store i8 %12, i8* %5
%13 = load i8, i8* %5
%14 = sitofp i8 %13 to double
%15 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %14)
%16 = load i8, i8* %5
%17 = icmp ne i8 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %2
%19 = load i64*, i64** %7
%20 = load i64, i64* %19
%21 = lshr i64 %20, 52
%22 = sub i64 %21, 1022
%23 = trunc i64 %22 to i32
%24 = load i32*, i32** %4
store i32 %23, i32* %24
br label %32
25: ; preds = %2
%26 = load i64*, i64** %7
%27 = load i64, i64* %26
%28 = lshr i64 %27, 52
%29 = sub i64 %28, 3070
%30 = trunc i64 %29 to i32
%31 = load i32*, i32** %4
store i32 %30, i32* %31
br label %32
32: ; preds = %25, %18
%33 = load i32*, i32** %4
%34 = load i32, i32* %33
%35 = sitofp i32 %34 to double
%36 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %35)
%37 = load i64*, i64** %7
%38 = load i64, i64* %37
%39 = and i64 %38, 4503599627370495
%40 = uitofp i64 %39 to double
store double %40, double* %6
%41 = load double, double* %6
%42 = call double @pow(i32 2, i8 signext 52)
%43 = fdiv double %41, %42
%44 = fadd double %43, 1.000000e+00
%45 = fdiv double %44, 2.000000e+00
store double %45, double* %6
%46 = load i8, i8* %5
%47 = call double @pow(i32 -1, i8 signext %46)
%48 = load double, double* %6
%49 = fmul double %47, %48
%50 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %49)
%51 = load i8, i8* %5
%52 = call double @pow(i32 -1, i8 signext %51)
%53 = load double, double* %6
%54 = fmul double %52, %53
ret double %54
}

LLVM IR (-O2):
@.str = [10 x i8] c"Sign: %d\0A\00"
@.str.1 = [14 x i8] c"Exponent: %d\0A\00"
@.str.2 = [15 x i8] c"Mantissa: %f\0A\0A\00"
define double @my_frexp(double %0, i32* nocapture writeonly %1) {
%3 = bitcast double %0 to i64
%4 = lshr i64 %3, 63
%5 = trunc i64 %4 to i8
%6 = sitofp i8 %5 to double
%7 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %6)
%8 = icmp sgt i64 %3, -1
%9 = lshr i64 %3, 52
%10 = trunc i64 %9 to i32
%11 = select i1 %8, i32 -1022, i32 -3070
%12 = add nsw i32 %11, %10
store i32 %12, i32* %1
%13 = sitofp i32 %12 to double
%14 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %13)
%15 = and i64 %3, 4503599627370495
%16 = uitofp i64 %15 to double
%17 = tail call double @pow(i32 2, i8 signext 52)
%18 = fdiv double %16, %17
%19 = fadd double %18, 1.000000e+00
%20 = fmul double %19, 5.000000e-01
%21 = tail call double @pow(i32 -1, i8 signext %5)
%22 = fmul double %21, %20
%23 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %22)
%24 = tail call double @pow(i32 -1, i8 signext %5)
%25 = fmul double %24, %20
ret double %25
}