#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 floor(double);
double frexp(double, int *);
double ldexp(double, int);
void _af_convert_to_ieee_extended(double num, unsigned char *bytes) {
  int sign;
  int expon;
  double fMant, fsMant;
  unsigned long hiMant, loMant;
  if (num < 0) {
    sign = 0x8000;
    num *= -1;
  } else {
    sign = 0;
  }
  if (num == 0) {
    expon = 0;
    hiMant = 0;
    loMant = 0;
  } else {
    fMant = frexp(num, &expon);
    if ((expon > 16384) || !(fMant < 1)) {
      expon = sign | 0x7FFF;
      hiMant = 0;
      loMant = 0;
    } else {
      expon += 16382;
      if (expon < 0) {
        fMant = ldexp(fMant, expon);
        expon = 0;
      }
      expon |= sign;
      fMant = ldexp(fMant, 32);
      fsMant = floor(fMant);
      hiMant =
          ((unsigned long)(((long)(fsMant - 2147483648.0)) + 2147483647L) + 1);
      fMant = ldexp(fMant - fsMant, 32);
      fsMant = floor(fMant);
      loMant =
          ((unsigned long)(((long)(fsMant - 2147483648.0)) + 2147483647L) + 1);
    }
  }
  bytes[0] = expon >> 8;
  bytes[1] = expon;
  bytes[2] = hiMant >> 24;
  bytes[3] = hiMant >> 16;
  bytes[4] = hiMant >> 8;
  bytes[5] = hiMant;
  bytes[6] = loMant >> 24;
  bytes[7] = loMant >> 16;
  bytes[8] = loMant >> 8;
  bytes[9] = loMant;
}


x86 assembly (clang, -O0):
<_af_convert_to_ieee_extended>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    116d <_af_convert_to_ieee_extended+0x3d>
movl   $0x8000,-0x14(%rbp)
movsd  0xea2(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1174 <_af_convert_to_ieee_extended+0x44>
movl   $0x0,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a8 <_af_convert_to_ieee_extended+0x78>
jp     11a8 <_af_convert_to_ieee_extended+0x78>
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
jmp    12ca <_af_convert_to_ieee_extended+0x19a>
movsd  -0x8(%rbp),%xmm0
lea    -0x18(%rbp),%rdi
call   1040 <frexp@plt>
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x4000,-0x18(%rbp)
jg     11db <_af_convert_to_ieee_extended+0xab>
movsd  0xe38(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
ja     11fb <_af_convert_to_ieee_extended+0xcb>
mov    -0x14(%rbp),%eax
or     $0x7fff,%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
jmp    12c5 <_af_convert_to_ieee_extended+0x195>
mov    -0x18(%rbp),%eax
add    $0x3ffe,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1229 <_af_convert_to_ieee_extended+0xf9>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x20,%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xdae(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
add    $0x7fffffff,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
mov    $0x20,%edi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xd62(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
add    $0x7fffffff,%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12ca <_af_convert_to_ieee_extended+0x19a>
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x30(%rbp),%rax
shr    $0x18,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x30(%rbp),%rax
shr    $0x10,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x30(%rbp),%rax
shr    $0x8,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x30(%rbp),%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x38(%rbp),%rax
shr    $0x18,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x38(%rbp),%rax
shr    $0x10,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x38(%rbp),%rax
shr    $0x8,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x38(%rbp),%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x9(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_af_convert_to_ieee_extended>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbp
xorpd  %xmm1,%xmm1
xor    %ebx,%ebx
ucomisd %xmm0,%xmm1
seta   %al
jbe    1152 <_af_convert_to_ieee_extended+0x22>
xorpd  0xeae(%rip),%xmm0
ucomisd %xmm1,%xmm0
jne    1161 <_af_convert_to_ieee_extended+0x31>
jp     1161 <_af_convert_to_ieee_extended+0x31>
xor    %ecx,%ecx
jmp    120d <_af_convert_to_ieee_extended+0xdd>
mov    %al,%bl
shl    $0xf,%ebx
lea    0x4(%rsp),%rdi
call   1040 <frexp@plt>
mov    0x4(%rsp),%eax
cmp    $0x4000,%eax
jg     1204 <_af_convert_to_ieee_extended+0xd4>
movsd  0xe89(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1204 <_af_convert_to_ieee_extended+0xd4>
lea    0x3ffe(%rax),%edi
cmp    $0xffffc001,%eax
jg     11a1 <_af_convert_to_ieee_extended+0x71>
call   1030 <ldexp@plt>
xor    %edi,%edi
or     %edi,%ebx
mov    $0x20,%edi
mov    %rbx,%r14
call   1030 <ldexp@plt>
movsd  %xmm0,0x8(%rsp)
call   1050 <floor@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
addsd  0xe4b(%rip),%xmm0
cvttsd2si %xmm0,%rbx
sub    $0xffffffff80000000,%rbx
movapd %xmm1,%xmm0
mov    $0x20,%edi
call   1030 <ldexp@plt>
call   1050 <floor@plt>
mov    %r14,%rcx
addsd  0xe21(%rip),%xmm0
cvttsd2si %xmm0,%rax
sub    $0xffffffff80000000,%rax
jmp    1211 <_af_convert_to_ieee_extended+0xe1>
mov    %rbx,%rcx
or     $0x7fff,%ecx
xor    %ebx,%ebx
xor    %eax,%eax
mov    %ch,0x0(%rbp)
mov    %cl,0x1(%rbp)
mov    %rbx,%rcx
shr    $0x18,%rcx
mov    %cl,0x2(%rbp)
mov    %rbx,%rcx
shr    $0x10,%rcx
mov    %cl,0x3(%rbp)
mov    %bh,0x4(%rbp)
mov    %bl,0x5(%rbp)
mov    %rax,%rcx
shr    $0x18,%rcx
mov    %cl,0x6(%rbp)
mov    %rax,%rcx
shr    $0x10,%rcx
mov    %cl,0x7(%rbp)
mov    %ah,0x8(%rbp)
mov    %al,0x9(%rbp)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @_af_convert_to_ieee_extended(double %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i64
%10 = alloca i64
store double %0, double* %3
store i8* %1, i8** %4
%11 = load double, double* %3
%12 = fcmp olt double %11, 0.000000e+00
br i1 %12, label %13, label %16
13: ; preds = %2
store i32 32768, i32* %5
%14 = load double, double* %3
%15 = fmul double %14, -1.000000e+00
store double %15, double* %3
br label %17
16: ; preds = %2
store i32 0, i32* %5
br label %17
17: ; preds = %16, %13
%18 = load double, double* %3
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %6
store i64 0, i64* %9
store i64 0, i64* %10
br label %66
21: ; preds = %17
%22 = load double, double* %3
%23 = call double @frexp(double %22, i32* %6)
store double %23, double* %7
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 16384
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load double, double* %7
%28 = fcmp olt double %27, 1.000000e+00
br i1 %28, label %32, label %29
29: ; preds = %26, %21
%30 = load i32, i32* %5
%31 = or i32 %30, 32767
store i32 %31, i32* %6
store i64 0, i64* %9
store i64 0, i64* %10
br label %65
32: ; preds = %26
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 16382
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load double, double* %7
%39 = load i32, i32* %6
%40 = call double @ldexp(double %38, i32 %39)
store double %40, double* %7
store i32 0, i32* %6
br label %41
41: ; preds = %37, %32
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = or i32 %43, %42
store i32 %44, i32* %6
%45 = load double, double* %7
%46 = call double @ldexp(double %45, i32 32)
store double %46, double* %7
%47 = load double, double* %7
%48 = call double @llvm.floor.f64(double %47)
store double %48, double* %8
%49 = load double, double* %8
%50 = fsub double %49, 0x41E0000000000000
%51 = fptosi double %50 to i64
%52 = add nsw i64 %51, 2147483647
%53 = add i64 %52, 1
store i64 %53, i64* %9
%54 = load double, double* %7
%55 = load double, double* %8
%56 = fsub double %54, %55
%57 = call double @ldexp(double %56, i32 32)
store double %57, double* %7
%58 = load double, double* %7
%59 = call double @llvm.floor.f64(double %58)
store double %59, double* %8
%60 = load double, double* %8
%61 = fsub double %60, 0x41E0000000000000
%62 = fptosi double %61 to i64
%63 = add nsw i64 %62, 2147483647
%64 = add i64 %63, 1
store i64 %64, i64* %10
br label %65
65: ; preds = %41, %29
br label %66
66: ; preds = %65, %20
%67 = load i32, i32* %6
%68 = ashr i32 %67, 8
%69 = trunc i32 %68 to i8
%70 = load i8*, i8** %4
%71 = getelementptr inbounds i8, i8* %70, i64 0
store i8 %69, i8* %71
%72 = load i32, i32* %6
%73 = trunc i32 %72 to i8
%74 = load i8*, i8** %4
%75 = getelementptr inbounds i8, i8* %74, i64 1
store i8 %73, i8* %75
%76 = load i64, i64* %9
%77 = lshr i64 %76, 24
%78 = trunc i64 %77 to i8
%79 = load i8*, i8** %4
%80 = getelementptr inbounds i8, i8* %79, i64 2
store i8 %78, i8* %80
%81 = load i64, i64* %9
%82 = lshr i64 %81, 16
%83 = trunc i64 %82 to i8
%84 = load i8*, i8** %4
%85 = getelementptr inbounds i8, i8* %84, i64 3
store i8 %83, i8* %85
%86 = load i64, i64* %9
%87 = lshr i64 %86, 8
%88 = trunc i64 %87 to i8
%89 = load i8*, i8** %4
%90 = getelementptr inbounds i8, i8* %89, i64 4
store i8 %88, i8* %90
%91 = load i64, i64* %9
%92 = trunc i64 %91 to i8
%93 = load i8*, i8** %4
%94 = getelementptr inbounds i8, i8* %93, i64 5
store i8 %92, i8* %94
%95 = load i64, i64* %10
%96 = lshr i64 %95, 24
%97 = trunc i64 %96 to i8
%98 = load i8*, i8** %4
%99 = getelementptr inbounds i8, i8* %98, i64 6
store i8 %97, i8* %99
%100 = load i64, i64* %10
%101 = lshr i64 %100, 16
%102 = trunc i64 %101 to i8
%103 = load i8*, i8** %4
%104 = getelementptr inbounds i8, i8* %103, i64 7
store i8 %102, i8* %104
%105 = load i64, i64* %10
%106 = lshr i64 %105, 8
%107 = trunc i64 %106 to i8
%108 = load i8*, i8** %4
%109 = getelementptr inbounds i8, i8* %108, i64 8
store i8 %107, i8* %109
%110 = load i64, i64* %10
%111 = trunc i64 %110 to i8
%112 = load i8*, i8** %4
%113 = getelementptr inbounds i8, i8* %112, i64 9
store i8 %111, i8* %113
ret void
}

LLVM IR (-O2):
define void @_af_convert_to_ieee_extended(double %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = fcmp olt double %0, 0.000000e+00
%6 = fneg double %0
%7 = select i1 %5, i32 32768, i32 0
%8 = select i1 %5, double %6, double %0
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %38, label %10
10: ; preds = %2
%11 = call double @frexp(double %8, i32* %3)
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 16385
%14 = fcmp olt double %11, 1.000000e+00
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = or i32 %7, 32767
br label %38
18: ; preds = %10
%19 = add nsw i32 %12, 16382
%20 = icmp slt i32 %12, -16382
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call double @ldexp(double %11, i32 %19)
br label %23
23: ; preds = %21, %18
%24 = phi i32 [ 0, %21 ], [ %19, %18 ]
%25 = phi double [ %22, %21 ], [ %11, %18 ]
%26 = or i32 %24, %7
%27 = tail call double @ldexp(double %25, i32 32)
%28 = tail call double @llvm.floor.f64(double %27)
%29 = fadd double %28, 0xC1E0000000000000
%30 = fptosi double %29 to i64
%31 = add i64 %30, 2147483648
%32 = fsub double %27, %28
%33 = tail call double @ldexp(double %32, i32 32)
%34 = tail call double @llvm.floor.f64(double %33)
%35 = fadd double %34, 0xC1E0000000000000
%36 = fptosi double %35 to i64
%37 = add i64 %36, 2147483648
br label %38
38: ; preds = %2, %16, %23
%39 = phi i32 [ %26, %23 ], [ %17, %16 ], [ 0, %2 ]
%40 = phi i64 [ %31, %23 ], [ 0, %16 ], [ 0, %2 ]
%41 = phi i64 [ %37, %23 ], [ 0, %16 ], [ 0, %2 ]
%42 = lshr i32 %39, 8
%43 = trunc i32 %42 to i8
store i8 %43, i8* %1
%44 = trunc i32 %39 to i8
%45 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %44, i8* %45
%46 = lshr i64 %40, 24
%47 = trunc i64 %46 to i8
%48 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %47, i8* %48
%49 = lshr i64 %40, 16
%50 = trunc i64 %49 to i8
%51 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %50, i8* %51
%52 = lshr i64 %40, 8
%53 = trunc i64 %52 to i8
%54 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %53, i8* %54
%55 = trunc i64 %40 to i8
%56 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %55, i8* %56
%57 = lshr i64 %41, 24
%58 = trunc i64 %57 to i8
%59 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %58, i8* %59
%60 = lshr i64 %41, 16
%61 = trunc i64 %60 to i8
%62 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %61, i8* %62
%63 = lshr i64 %41, 8
%64 = trunc i64 %63 to i8
%65 = getelementptr inbounds i8, i8* %1, i64 8
store i8 %64, i8* %65
%66 = trunc i64 %41 to i8
%67 = getelementptr inbounds i8, i8* %1, i64 9
store i8 %66, i8* %67
ret void
}