#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ snapshot_write_byte(int /*<<< orphan*/ *, unsigned char);
int snapshot_write_double(FILE *f, double data) {
  unsigned char *byte_data = (unsigned char *)&data;
  int i;
  for (i = 0; i < sizeof(double); i++) {
    if (snapshot_write_byte(f, byte_data[i]) < 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<snapshot_write_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x8,%rax
jae    117c <snapshot_write_double+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
call   1030 <snapshot_write_byte@plt>
cmp    $0x0,%rax
jge    1169 <snapshot_write_double+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <snapshot_write_double+0x73>
jmp    116e <snapshot_write_double+0x5e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1130 <snapshot_write_double+0x20>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snapshot_write_double>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
movq   %xmm0,%rbx
movzbl %bl,%esi
call   1030 <snapshot_write_byte@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     11c9 <snapshot_write_double+0xb9>
movzbl %bh,%esi
mov    %r15,%rdi
call   1030 <snapshot_write_byte@plt>
test   %rax,%rax
js     11c9 <snapshot_write_double+0xb9>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%esi
mov    %r15,%rdi
call   1030 <snapshot_write_byte@plt>
test   %rax,%rax
js     11c9 <snapshot_write_double+0xb9>
mov    %ebx,%esi
shr    $0x18,%esi
mov    %r15,%rdi
call   1030 <snapshot_write_byte@plt>
test   %rax,%rax
js     11c9 <snapshot_write_double+0xb9>
mov    %rbx,%rax
shr    $0x20,%rax
movzbl %al,%esi
mov    %r15,%rdi
call   1030 <snapshot_write_byte@plt>
test   %rax,%rax
js     11c9 <snapshot_write_double+0xb9>
mov    %rbx,%rax
shr    $0x28,%rax
movzbl %al,%esi
mov    %r15,%rdi
call   1030 <snapshot_write_byte@plt>
test   %rax,%rax
js     11c9 <snapshot_write_double+0xb9>
mov    %rbx,%rax
shr    $0x30,%rax
movzbl %al,%esi
mov    %r15,%rdi
call   1030 <snapshot_write_byte@plt>
test   %rax,%rax
js     11c9 <snapshot_write_double+0xb9>
shr    $0x38,%rbx
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <snapshot_write_byte@plt>
mov    %rax,%r14
sar    $0x3f,%r14
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @snapshot_write_double(i32* %0, double %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca double
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %4
store double %1, double* %5
%8 = bitcast double* %5 to i8*
store i8* %8, i8** %6
store i32 0, i32* %7
br label %9
9: ; preds = %24, %2
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = icmp ult i64 %11, 8
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i32*, i32** %4
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @snapshot_write_byte(i32* %14, i8 zeroext %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 -1, i32* %3
br label %28
23: ; preds = %13
br label %24
24: ; preds = %23
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %9
27: ; preds = %9
store i32 0, i32* %3
br label %28
28: ; preds = %27, %22
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @snapshot_write_double(i32* %0, double %1) {
%3 = bitcast double %1 to i64
%4 = trunc i64 %3 to i8
%5 = tail call i64 @snapshot_write_byte(i32* %0, i8 zeroext %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %43, label %7
7: ; preds = %2
%8 = lshr i64 %3, 8
%9 = trunc i64 %8 to i8
%10 = tail call i64 @snapshot_write_byte(i32* %0, i8 zeroext %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %43, label %12
12: ; preds = %7
%13 = lshr i64 %3, 16
%14 = trunc i64 %13 to i8
%15 = tail call i64 @snapshot_write_byte(i32* %0, i8 zeroext %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %43, label %17
17: ; preds = %12
%18 = lshr i64 %3, 24
%19 = trunc i64 %18 to i8
%20 = tail call i64 @snapshot_write_byte(i32* %0, i8 zeroext %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %43, label %22
22: ; preds = %17
%23 = lshr i64 %3, 32
%24 = trunc i64 %23 to i8
%25 = tail call i64 @snapshot_write_byte(i32* %0, i8 zeroext %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %43, label %27
27: ; preds = %22
%28 = lshr i64 %3, 40
%29 = trunc i64 %28 to i8
%30 = tail call i64 @snapshot_write_byte(i32* %0, i8 zeroext %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %43, label %32
32: ; preds = %27
%33 = lshr i64 %3, 48
%34 = trunc i64 %33 to i8
%35 = tail call i64 @snapshot_write_byte(i32* %0, i8 zeroext %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %43, label %37
37: ; preds = %32
%38 = lshr i64 %3, 56
%39 = trunc i64 %38 to i8
%40 = tail call i64 @snapshot_write_byte(i32* %0, i8 zeroext %39)
%41 = ashr i64 %40, 63
%42 = trunc i64 %41 to i32
br label %43
43: ; preds = %37, %32, %27, %22, %17, %12, %7, %2
%44 = phi i32 [ -1, %2 ], [ -1, %7 ], [ -1, %12 ], [ -1, %17 ], [ -1, %22 ], [ -1, %27 ], [ -1, %32 ], [ %42, %37 ]
ret i32 %44
}