#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 /*<<< 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 (in == 0.0)
    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
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    118e <double64_le_write+0x3e>
jp     118e <double64_le_write+0x3e>
jmp    12f6 <double64_le_write+0x1a6>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11bf <double64_le_write+0x6f>
movsd  0xe5c(%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  0xe04(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1070 <floor@plt>
mov    %eax,%edi
call   1060 <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  0xd82(%rip),%xmm1
call   1030 <fmod@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  0xd68(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1070 <floor@plt>
mov    %eax,%edi
call   1060 <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
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117f <double64_le_write+0x2f>
jnp    121c <double64_le_write+0xcc>
ucomisd %xmm0,%xmm1
jbe    1191 <double64_le_write+0x41>
xorpd  0xe73(%rip),%xmm0
orb    $0x80,0x7(%rbx)
lea    0xc(%rsp),%rdi
call   1050 <frexp@plt>
mov    $0x3fe,%eax
add    0xc(%rsp),%eax
mov    %eax,%ecx
shr    $0x4,%ecx
and    $0x7f,%cl
or     %cl,0x7(%rbx)
shl    $0x4,%al
or     %al,0x6(%rbx)
mulsd  0xe53(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1070 <floor@plt>
mov    %eax,%edi
call   1060 <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  0xe28(%rip),%xmm1
movsd  0x10(%rsp),%xmm0
call   1030 <fmod@plt>
mulsd  0xe1d(%rip),%xmm0
call   1070 <floor@plt>
mov    %eax,%edi
call   1060 <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 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %2
br label %102
12: ; preds = %2
%13 = load double, double* %3
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load double, double* %3
%17 = fmul double %16, -1.000000e+00
store double %17, double* %3
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 7
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = or i32 %21, 128
%23 = trunc i32 %22 to i8
store i8 %23, i8* %19
br label %24
24: ; preds = %15, %12
%25 = load double, double* %3
%26 = call double @frexp(double %25, i32* %5)
store double %26, double* %3
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1022
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = ashr i32 %29, 4
%31 = and i32 %30, 127
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 7
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = or i32 %35, %31
%37 = trunc i32 %36 to i8
store i8 %37, i8* %33
%38 = load i32, i32* %5
%39 = shl i32 %38, 4
%40 = and i32 %39, 240
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i64 6
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = or i32 %44, %40
%46 = trunc i32 %45 to i8
store i8 %46, i8* %42
%47 = load double, double* %3
%48 = fmul double %47, 0x41C0000000000000
store double %48, double* %3
%49 = load double, double* %3
%50 = call i32 @floor(double %49)
%51 = call i32 @lrint(i32 %50)
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = ashr i32 %52, 24
%54 = and i32 %53, 15
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i64 6
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = or i32 %58, %54
%60 = trunc i32 %59 to i8
store i8 %60, i8* %56
%61 = load i32, i32* %6
%62 = ashr i32 %61, 16
%63 = and i32 %62, 255
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %4
%66 = getelementptr inbounds i8, i8* %65, i64 5
store i8 %64, i8* %66
%67 = load i32, i32* %6
%68 = ashr i32 %67, 8
%69 = and i32 %68, 255
%70 = trunc i32 %69 to i8
%71 = load i8*, i8** %4
%72 = getelementptr inbounds i8, i8* %71, i64 4
store i8 %70, i8* %72
%73 = load i32, i32* %6
%74 = and i32 %73, 255
%75 = trunc i32 %74 to i8
%76 = load i8*, i8** %4
%77 = getelementptr inbounds i8, i8* %76, i64 3
store i8 %75, i8* %77
%78 = load double, double* %3
%79 = call double @fmod(double %78, double 1.000000e+00)
store double %79, double* %3
%80 = load double, double* %3
%81 = fmul double %80, 0x4170000000000000
store double %81, double* %3
%82 = load double, double* %3
%83 = call i32 @floor(double %82)
%84 = call i32 @lrint(i32 %83)
store i32 %84, i32* %6
%85 = load i32, i32* %6
%86 = ashr i32 %85, 16
%87 = and i32 %86, 255
%88 = trunc i32 %87 to i8
%89 = load i8*, i8** %4
%90 = getelementptr inbounds i8, i8* %89, i64 2
store i8 %88, i8* %90
%91 = load i32, i32* %6
%92 = ashr i32 %91, 8
%93 = and i32 %92, 255
%94 = trunc i32 %93 to i8
%95 = load i8*, i8** %4
%96 = getelementptr inbounds i8, i8* %95, i64 1
store i8 %94, i8* %96
%97 = load i32, i32* %6
%98 = and i32 %97, 255
%99 = trunc i32 %98 to i8
%100 = load i8*, i8** %4
%101 = getelementptr inbounds i8, i8* %100, i64 0
store i8 %99, i8* %101
br label %102
102: ; preds = %24, %11
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 = fcmp oeq double %0, 0.000000e+00
br i1 %6, label %57, label %7
7: ; preds = %2
%8 = fcmp olt double %0, 0.000000e+00
br i1 %8, label %9, label %14
9: ; preds = %7
%10 = fneg double %0
%11 = getelementptr inbounds i8, i8* %1, i64 7
%12 = load i8, i8* %11
%13 = or i8 %12, -128
store i8 %13, i8* %11
br label %14
14: ; preds = %9, %7
%15 = phi double [ %10, %9 ], [ %0, %7 ]
%16 = call double @frexp(double %15, i32* %3)
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1022
%19 = lshr i32 %18, 4
%20 = getelementptr inbounds i8, i8* %1, i64 7
%21 = load i8, i8* %20
%22 = trunc i32 %19 to i8
%23 = and i8 %22, 127
%24 = or i8 %23, %21
store i8 %24, i8* %20
%25 = getelementptr inbounds i8, i8* %1, i64 6
%26 = load i8, i8* %25
%27 = trunc i32 %18 to i8
%28 = shl i8 %27, 4
%29 = or i8 %26, %28
store i8 %29, i8* %25
%30 = fmul double %16, 0x41C0000000000000
%31 = tail call i32 @floor(double %30)
%32 = tail call i32 @lrint(i32 %31)
%33 = lshr i32 %32, 24
%34 = load i8, i8* %25
%35 = trunc i32 %33 to i8
%36 = and i8 %35, 15
%37 = or i8 %36, %34
store i8 %37, i8* %25
%38 = lshr i32 %32, 16
%39 = trunc i32 %38 to i8
%40 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %39, i8* %40
%41 = lshr i32 %32, 8
%42 = trunc i32 %41 to i8
%43 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %42, i8* %43
%44 = trunc i32 %32 to i8
%45 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %44, i8* %45
%46 = tail call double @fmod(double %30, double 1.000000e+00)
%47 = fmul double %46, 0x4170000000000000
%48 = tail call i32 @floor(double %47)
%49 = tail call i32 @lrint(i32 %48)
%50 = lshr i32 %49, 16
%51 = trunc i32 %50 to i8
%52 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %51, i8* %52
%53 = lshr i32 %49, 8
%54 = trunc i32 %53 to i8
%55 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %54, i8* %55
%56 = trunc i32 %49 to i8
store i8 %56, i8* %1
br label %57
57: ; preds = %2, %14
ret void
}