#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 */
int EOF;
int fgetc(int /*<<< orphan*/ *);
int snapshot_read_double(FILE *f, double *d_return) {
  int i;
  int c;
  double val;
  unsigned char *byte_val = (unsigned char *)&val;
  for (i = 0; i < sizeof(double); i++) {
    c = fgetc(f);
    if (c == EOF) {
      return -1;
    }
    byte_val[i] = (unsigned char)c;
  }
  *d_return = val;
  return 0;
}


x86 assembly (clang, -O0):
<snapshot_read_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x8,%rax
jae    1185 <snapshot_read_double+0x75>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2e95(%rip),%rcx
cmp    (%rcx),%eax
jne    1167 <snapshot_read_double+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <snapshot_read_double+0x89>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112f <snapshot_read_double+0x1f>
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snapshot_read_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <fgetc@plt>
mov    0x2eb8(%rip),%r13
mov    $0xffffffff,%ebp
cmp    0x0(%r13),%eax
je     121a <snapshot_read_double+0x10a>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     121a <snapshot_read_double+0x10a>
mov    %eax,%r12d
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     121a <snapshot_read_double+0x10a>
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     121a <snapshot_read_double+0x10a>
mov    %rax,0x10(%rsp)
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     121a <snapshot_read_double+0x10a>
mov    %eax,0x8(%rsp)
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     121a <snapshot_read_double+0x10a>
mov    %eax,0x4(%rsp)
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     121a <snapshot_read_double+0x10a>
mov    %eax,(%rsp)
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    0x0(%r13),%eax
je     121a <snapshot_read_double+0x10a>
movzbl 0x8(%rsp),%ecx
shl    $0x20,%rcx
movzbl %bl,%edx
shl    $0x8,%r12d
movzwl %r12w,%esi
or     %edx,%esi
movzbl 0xc(%rsp),%edx
shl    $0x10,%edx
or     %esi,%edx
mov    0x10(%rsp),%rsi
shl    $0x18,%esi
or     %edx,%esi
or     %rcx,%rsi
movzbl 0x4(%rsp),%ecx
shl    $0x28,%rcx
or     %rsi,%rcx
movzbl (%rsp),%edx
shl    $0x30,%rdx
or     %rcx,%rdx
shl    $0x38,%rax
or     %rdx,%rax
mov    %rax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @snapshot_read_double(i32* nocapture %0, double* nocapture writeonly %1) {
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %61, label %6
6: ; preds = %2
%7 = tail call i32 @fgetc(i32* %0)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %61, label %10
10: ; preds = %6
%11 = tail call i32 @fgetc(i32* %0)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %61, label %14
14: ; preds = %10
%15 = tail call i32 @fgetc(i32* %0)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %61, label %18
18: ; preds = %14
%19 = tail call i32 @fgetc(i32* %0)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %61, label %22
22: ; preds = %18
%23 = tail call i32 @fgetc(i32* %0)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %61, label %26
26: ; preds = %22
%27 = tail call i32 @fgetc(i32* %0)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %61, label %30
30: ; preds = %26
%31 = tail call i32 @fgetc(i32* %0)
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %61, label %34
34: ; preds = %30
%35 = and i32 %19, 255
%36 = zext i32 %35 to i64
%37 = shl nuw nsw i64 %36, 32
%38 = and i32 %3, 255
%39 = shl i32 %7, 8
%40 = and i32 %39, 65280
%41 = or i32 %38, %40
%42 = shl i32 %11, 16
%43 = and i32 %42, 16711680
%44 = or i32 %41, %43
%45 = shl i32 %15, 24
%46 = or i32 %44, %45
%47 = zext i32 %46 to i64
%48 = or i64 %37, %47
%49 = and i32 %23, 255
%50 = zext i32 %49 to i64
%51 = shl nuw nsw i64 %50, 40
%52 = or i64 %48, %51
%53 = and i32 %27, 255
%54 = zext i32 %53 to i64
%55 = shl nuw nsw i64 %54, 48
%56 = zext i32 %31 to i64
%57 = shl i64 %56, 56
%58 = or i64 %52, %55
%59 = or i64 %58, %57
%60 = bitcast double* %1 to i64*
store i64 %59, i64* %60
br label %61
61: ; preds = %2, %6, %10, %14, %18, %22, %26, %30, %34
%62 = phi i32 [ 0, %34 ], [ -1, %30 ], [ -1, %26 ], [ -1, %22 ], [ -1, %18 ], [ -1, %14 ], [ -1, %10 ], [ -1, %6 ], [ -1, %2 ]
ret i32 %62
}