#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int fread(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int ReadDouble(FILE *fptr, double *n, int swap) {
  unsigned char *cptr, tmp;
  if (sizeof(double) != 8) {
    fprintf(stderr, "ReadDouble: sizeof(double)=%ld and not 8\n",
            sizeof(double));
    exit(0);
  }
  if (fread(n, 8, 1, fptr) != 1)
    return (0);
  if (swap) {
    cptr = (unsigned char *)n;
    tmp = cptr[0];
    cptr[0] = cptr[7];
    cptr[7] = tmp;
    tmp = cptr[1];
    cptr[1] = cptr[6];
    cptr[6] = tmp;
    tmp = cptr[2];
    cptr[2] = cptr[5];
    cptr[5] = tmp;
    tmp = cptr[3];
    cptr[3] = cptr[4];
    cptr[4] = tmp;
  }
  return (1);
}


x86 assembly (clang, -O0):
<ReadDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     114f <ReadDouble+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11ee <ReadDouble+0xde>
cmpl   $0x0,-0x1c(%rbp)
je     11e7 <ReadDouble+0xd7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
mov    0x7(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
mov    0x6(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x28(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
mov    0x5(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x28(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x4(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadDouble>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%rcx
mov    %rsi,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    1166 <ReadDouble+0x56>
test   %ebp,%ebp
je     1161 <ReadDouble+0x51>
mov    (%rbx),%al
mov    0x7(%rbx),%cl
mov    %cl,(%rbx)
mov    %al,0x7(%rbx)
movzwl 0x1(%rbx),%eax
rol    $0x8,%ax
movzwl 0x5(%rbx),%ecx
rol    $0x8,%cx
mov    %cx,0x1(%rbx)
mov    %ax,0x5(%rbx)
rolw   $0x8,0x3(%rbx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
define i32 @ReadDouble(i32* %0, double* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8
store i32* %0, i32** %5
store double* %1, double** %6
store i32 %2, i32* %7
%10 = load double*, double** %6
%11 = load i32*, i32** %5
%12 = call i32 @fread(double* %10, i32 8, i32 1, i32* %11)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %66
15: ; preds = %3
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %65
18: ; preds = %15
%19 = load double*, double** %6
%20 = bitcast double* %19 to i8*
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
store i8 %23, i8* %9
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i64 7
%26 = load i8, i8* %25
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 %26, i8* %28
%29 = load i8, i8* %9
%30 = load i8*, i8** %8
%31 = getelementptr inbounds i8, i8* %30, i64 7
store i8 %29, i8* %31
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
store i8 %34, i8* %9
%35 = load i8*, i8** %8
%36 = getelementptr inbounds i8, i8* %35, i64 6
%37 = load i8, i8* %36
%38 = load i8*, i8** %8
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8 %37, i8* %39
%40 = load i8, i8* %9
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i64 6
store i8 %40, i8* %42
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i64 2
%45 = load i8, i8* %44
store i8 %45, i8* %9
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i64 5
%48 = load i8, i8* %47
%49 = load i8*, i8** %8
%50 = getelementptr inbounds i8, i8* %49, i64 2
store i8 %48, i8* %50
%51 = load i8, i8* %9
%52 = load i8*, i8** %8
%53 = getelementptr inbounds i8, i8* %52, i64 5
store i8 %51, i8* %53
%54 = load i8*, i8** %8
%55 = getelementptr inbounds i8, i8* %54, i64 3
%56 = load i8, i8* %55
store i8 %56, i8* %9
%57 = load i8*, i8** %8
%58 = getelementptr inbounds i8, i8* %57, i64 4
%59 = load i8, i8* %58
%60 = load i8*, i8** %8
%61 = getelementptr inbounds i8, i8* %60, i64 3
store i8 %59, i8* %61
%62 = load i8, i8* %9
%63 = load i8*, i8** %8
%64 = getelementptr inbounds i8, i8* %63, i64 4
store i8 %62, i8* %64
br label %65
65: ; preds = %18, %15
store i32 1, i32* %4
br label %66
66: ; preds = %65, %14
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
@stderr = global i32 0
define i32 @ReadDouble(i32* nocapture %0, double* nocapture %1, i32 %2) {
%4 = tail call i32 @fread(double* %1, i32 8, i32 1, i32* %0)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = icmp eq i32 %2, 0
br i1 %7, label %25, label %8
8: ; preds = %6
%9 = bitcast double* %1 to i8*
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %9, i64 7
%12 = load i8, i8* %11
store i8 %12, i8* %9
store i8 %10, i8* %11
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %9, i64 6
%16 = load i8, i8* %15
store i8 %16, i8* %13
store i8 %14, i8* %15
%17 = getelementptr inbounds i8, i8* %9, i64 2
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %9, i64 5
%20 = load i8, i8* %19
store i8 %20, i8* %17
store i8 %18, i8* %19
%21 = getelementptr inbounds i8, i8* %9, i64 3
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %9, i64 4
%24 = load i8, i8* %23
store i8 %24, i8* %21
store i8 %22, i8* %23
br label %25
25: ; preds = %6, %8, %3
%26 = phi i32 [ 0, %3 ], [ 1, %8 ], [ 1, %6 ]
ret i32 %26
}