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

/* Variables and functions */
int fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int read_64bit_word(FILE *fh, uint64_t *ptr) {
  uint8_t buffer[8];
  uint64_t value;
  int rc;
  rc = fread(buffer, 8, 1, fh);
  if (rc != 1)
    return -1;
  value = (uint64_t)buffer[0] | ((uint64_t)buffer[1] << 8) |
          ((uint64_t)buffer[2] << 16) | ((uint64_t)buffer[3] << 24) |
          ((uint64_t)buffer[4] << 32) | ((uint64_t)buffer[5] << 40) |
          ((uint64_t)buffer[6] << 48) | ((uint64_t)buffer[7] << 56);
  if (ptr)
    *ptr = value;
  return 0;
}


x86 assembly (clang, -O0):
<read_64bit_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x1,-0x68(%rbp)
je     1150 <read_64bit_word+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <read_64bit_word+0xc1>
mov    -0x60(%rbp),%rax
mov    -0x58(%rbp),%rcx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x50(%rbp),%rcx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x48(%rbp),%rcx
shl    $0x18,%ecx
or     %ecx,%eax
mov    -0x40(%rbp),%rcx
mov    %ecx,%edx
mov    $0x20,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x38(%rbp),%rcx
mov    %ecx,%edx
mov    $0x28,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x30(%rbp),%rcx
mov    %ecx,%edx
mov    $0x30,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x28(%rbp),%rcx
mov    %ecx,%edx
mov    $0x38,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x64(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ca <read_64bit_word+0xba>
mov    -0x64(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_64bit_word>:
sub    $0x48,%rsp
mov    %rdi,%rcx
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
add    $0x48,%rsp
ret

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

LLVM IR (-O2):
define i32 @read_64bit_word(i32* nocapture %0, i32* readnone %1) {
%3 = alloca [8 x i64]
%4 = bitcast [8 x i64]* %3 to i8*
%5 = getelementptr inbounds [8 x i64], [8 x i64]* %3, i64 0, i64 0
%6 = call i32 @fread(i64* %5, i32 8, i32 1, i32* %0)
%7 = icmp ne i32 %6, 1
%8 = sext i1 %7 to i32
ret i32 %8
}