#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 */
int fabs(double);
int /*<<< orphan*/ floor(double);
double fmod(double, double);
double frexp(double, int *);
int lrint(int /*<<< orphan*/);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void double64_le_write(double in, unsigned char *out) {
  int exponent, mantissa;
  memset(out, 0, sizeof(double));
  if (fabs(in) < 1e-30)
    return;
  if (in < 0.0) {
    in *= -1.0;
    out[7] |= 0x80;
  };
  in = frexp(in, &exponent);
  exponent += 1022;
  out[7] |= (exponent >> 4) & 0x7F;
  out[6] |= (exponent << 4) & 0xF0;
  in *= 0x20000000;
  mantissa = lrint(floor(in));
  out[6] |= (mantissa >> 24) & 0xF;
  out[5] = (mantissa >> 16) & 0xFF;
  out[4] = (mantissa >> 8) & 0xFF;
  out[3] = mantissa & 0xFF;
  in = fmod(in, 1.0);
  in *= 0x1000000;
  mantissa = lrint(floor(in));
  out[2] = (mantissa >> 16) & 0xFF;
  out[1] = (mantissa >> 8) & 0xFF;
  out[0] = mantissa & 0xFF;
  return;
}


x86 assembly (clang, -O0):
<double64_le_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movsd  -0x8(%rbp),%xmm0
call   1060 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe69(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a6 <double64_le_write+0x46>
jmp    130e <double64_le_write+0x1ae>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11d7 <double64_le_write+0x77>
movsd  0xe4c(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x7(%rax),%ecx
or     $0x80,%ecx
mov    %cl,0x7(%rax)
movsd  -0x8(%rbp),%xmm0
lea    -0x14(%rbp),%rdi
call   1050 <frexp@plt>
movsd  %xmm0,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x3fe,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
sar    $0x4,%edx
and    $0x7f,%edx
mov    -0x10(%rbp),%rax
movzbl 0x7(%rax),%ecx
or     %edx,%ecx
mov    %cl,0x7(%rax)
mov    -0x14(%rbp),%edx
shl    $0x4,%edx
and    $0xf0,%edx
mov    -0x10(%rbp),%rax
movzbl 0x6(%rax),%ecx
or     %edx,%ecx
mov    %cl,0x6(%rax)
movsd  0xdf4(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1080 <floor@plt>
mov    %eax,%edi
call   1070 <lrint@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
sar    $0x18,%edx
and    $0xf,%edx
mov    -0x10(%rbp),%rax
movzbl 0x6(%rax),%ecx
or     %edx,%ecx
mov    %cl,0x6(%rax)
mov    -0x18(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
movsd  -0x8(%rbp),%xmm0
movsd  0xd72(%rip),%xmm1
call   1030 <fmod@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  0xd58(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1080 <floor@plt>
mov    %eax,%edi
call   1070 <lrint@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<double64_le_write>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movaps %xmm0,0x10(%rsp)
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movapd 0x10(%rsp),%xmm0
call   1060 <fabs@plt>
test   %eax,%eax
jle    123b <double64_le_write+0xdb>
xorpd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm1
ucomisd %xmm1,%xmm0
movapd %xmm1,%xmm0
jbe    11ac <double64_le_write+0x4c>
xorpd  0xe58(%rip),%xmm0
orb    $0x80,0x7(%rbx)
lea    0xc(%rsp),%rdi
call   1050 <frexp@plt>
mov    $0x3fe,%eax
add    0xc(%rsp),%eax
mov    %eax,0xc(%rsp)
mov    %eax,%ecx
shr    $0x4,%ecx
and    $0x7f,%cl
or     %cl,0x7(%rbx)
shl    $0x4,%al
or     %al,0x6(%rbx)
mulsd  0xe34(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1080 <floor@plt>
mov    %eax,%edi
call   1070 <lrint@plt>
mov    %eax,%ecx
shr    $0x18,%ecx
and    $0xf,%cl
or     %cl,0x6(%rbx)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x5(%rbx)
mov    %ah,0x4(%rbx)
mov    %al,0x3(%rbx)
movsd  0xe09(%rip),%xmm1
movsd  0x10(%rsp),%xmm0
call   1030 <fmod@plt>
mulsd  0xdfe(%rip),%xmm0
call   1080 <floor@plt>
mov    %eax,%edi
call   1070 <lrint@plt>
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x2(%rbx)
mov    %ah,0x1(%rbx)
mov    %al,(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @double64_le_write(double %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store double %0, double* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @memset(i8* %7, i32 0, i32 8)
%9 = load double, double* %3
%10 = call i32 @fabs(double %9)
%11 = sitofp i32 %10 to double
%12 = fcmp olt double %11, 1.000000e-30
br i1 %12, label %13, label %14
13: ; preds = %2
br label %104
14: ; preds = %2
%15 = load double, double* %3
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load double, double* %3
%19 = fmul double %18, -1.000000e+00
store double %19, double* %3
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 7
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = or i32 %23, 128
%25 = trunc i32 %24 to i8
store i8 %25, i8* %21
br label %26
26: ; preds = %17, %14
%27 = load double, double* %3
%28 = call double @frexp(double %27, i32* %5)
store double %28, double* %3
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1022
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = ashr i32 %31, 4
%33 = and i32 %32, 127
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 7
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = or i32 %37, %33
%39 = trunc i32 %38 to i8
store i8 %39, i8* %35
%40 = load i32, i32* %5
%41 = shl i32 %40, 4
%42 = and i32 %41, 240
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i64 6
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = or i32 %46, %42
%48 = trunc i32 %47 to i8
store i8 %48, i8* %44
%49 = load double, double* %3
%50 = fmul double %49, 0x41C0000000000000
store double %50, double* %3
%51 = load double, double* %3
%52 = call i32 @floor(double %51)
%53 = call i32 @lrint(i32 %52)
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = ashr i32 %54, 24
%56 = and i32 %55, 15
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 6
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = or i32 %60, %56
%62 = trunc i32 %61 to i8
store i8 %62, i8* %58
%63 = load i32, i32* %6
%64 = ashr i32 %63, 16
%65 = and i32 %64, 255
%66 = trunc i32 %65 to i8
%67 = load i8*, i8** %4
%68 = getelementptr inbounds i8, i8* %67, i64 5
store i8 %66, i8* %68
%69 = load i32, i32* %6
%70 = ashr i32 %69, 8
%71 = and i32 %70, 255
%72 = trunc i32 %71 to i8
%73 = load i8*, i8** %4
%74 = getelementptr inbounds i8, i8* %73, i64 4
store i8 %72, i8* %74
%75 = load i32, i32* %6
%76 = and i32 %75, 255
%77 = trunc i32 %76 to i8
%78 = load i8*, i8** %4
%79 = getelementptr inbounds i8, i8* %78, i64 3
store i8 %77, i8* %79
%80 = load double, double* %3
%81 = call double @fmod(double %80, double 1.000000e+00)
store double %81, double* %3
%82 = load double, double* %3
%83 = fmul double %82, 0x4170000000000000
store double %83, double* %3
%84 = load double, double* %3
%85 = call i32 @floor(double %84)
%86 = call i32 @lrint(i32 %85)
store i32 %86, i32* %6
%87 = load i32, i32* %6
%88 = ashr i32 %87, 16
%89 = and i32 %88, 255
%90 = trunc i32 %89 to i8
%91 = load i8*, i8** %4
%92 = getelementptr inbounds i8, i8* %91, i64 2
store i8 %90, i8* %92
%93 = load i32, i32* %6
%94 = ashr i32 %93, 8
%95 = and i32 %94, 255
%96 = trunc i32 %95 to i8
%97 = load i8*, i8** %4
%98 = getelementptr inbounds i8, i8* %97, i64 1
store i8 %96, i8* %98
%99 = load i32, i32* %6
%100 = and i32 %99, 255
%101 = trunc i32 %100 to i8
%102 = load i8*, i8** %4
%103 = getelementptr inbounds i8, i8* %102, i64 0
store i8 %101, i8* %103
br label %104
104: ; preds = %26, %13
ret void
}

LLVM IR (-O2):
define void @double64_le_write(double %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @memset(i8* %1, i32 0, i32 8)
%6 = tail call i32 @fabs(double %0)
%7 = icmp slt i32 %6, 1
br i1 %7, label %58, label %8
8: ; preds = %2
%9 = fcmp olt double %0, 0.000000e+00
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = fneg double %0
%12 = getelementptr inbounds i8, i8* %1, i64 7
%13 = load i8, i8* %12
%14 = or i8 %13, -128
store i8 %14, i8* %12
br label %15
15: ; preds = %10, %8
%16 = phi double [ %11, %10 ], [ %0, %8 ]
%17 = call double @frexp(double %16, i32* %3)
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1022
store i32 %19, i32* %3
%20 = lshr i32 %19, 4
%21 = getelementptr inbounds i8, i8* %1, i64 7
%22 = load i8, i8* %21
%23 = trunc i32 %20 to i8
%24 = and i8 %23, 127
%25 = or i8 %24, %22
store i8 %25, i8* %21
%26 = getelementptr inbounds i8, i8* %1, i64 6
%27 = load i8, i8* %26
%28 = trunc i32 %19 to i8
%29 = shl i8 %28, 4
%30 = or i8 %27, %29
store i8 %30, i8* %26
%31 = fmul double %17, 0x41C0000000000000
%32 = tail call i32 @floor(double %31)
%33 = tail call i32 @lrint(i32 %32)
%34 = lshr i32 %33, 24
%35 = load i8, i8* %26
%36 = trunc i32 %34 to i8
%37 = and i8 %36, 15
%38 = or i8 %37, %35
store i8 %38, i8* %26
%39 = lshr i32 %33, 16
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %40, i8* %41
%42 = lshr i32 %33, 8
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %43, i8* %44
%45 = trunc i32 %33 to i8
%46 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %45, i8* %46
%47 = tail call double @fmod(double %31, double 1.000000e+00)
%48 = fmul double %47, 0x4170000000000000
%49 = tail call i32 @floor(double %48)
%50 = tail call i32 @lrint(i32 %49)
%51 = lshr i32 %50, 16
%52 = trunc i32 %51 to i8
%53 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %52, i8* %53
%54 = lshr i32 %50, 8
%55 = trunc i32 %54 to i8
%56 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %55, i8* %56
%57 = trunc i32 %50 to i8
store i8 %57, i8* %1
br label %58
58: ; preds = %2, %15
ret void
}