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

/* Variables and functions */
int fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int fread_le64(uint64_t *buf, FILE *fd) {
  size_t count;
  uint8_t tmp[8];
  unsigned int i;
  if (fread(tmp, sizeof(tmp), 1, fd) != 1)
    return -1;
  *buf = 0;
  for (i = 0; i < (sizeof(tmp) / sizeof((tmp)[0])); i++)
    *buf |= (uint64_t)(tmp[i]) << (i * 8);
  return 0;
}


x86 assembly (clang, -O0):
<fread_le64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x40,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     114c <fread_le64+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <fread_le64+0x89>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    $0x8,%rax
jae    1192 <fread_le64+0x82>
mov    -0x64(%rbp),%eax
mov    -0x60(%rbp,%rax,8),%rax
mov    -0x64(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    115d <fread_le64+0x4d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_le64>:
sub    $0x48,%rsp
mov    %rsi,%rcx
mov    %rsp,%rdi
mov    $0x40,%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 @fread_le64(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca [8 x i64]
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = getelementptr inbounds [8 x i64], [8 x i64]* %7, i64 0, i64 0
%10 = load i32*, i32** %5
%11 = call i32 @fread(i64* %9, i32 64, i32 1, i32* %10)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %36
14: ; preds = %2
%15 = load i32*, i32** %4
store i32 0, i32* %15
store i32 0, i32* %8
br label %16
16: ; preds = %32, %14
%17 = load i32, i32* %8
%18 = zext i32 %17 to i64
%19 = icmp ult i64 %18, 8
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = load i32, i32* %8
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [8 x i64], [8 x i64]* %7, i64 0, i64 %22
%24 = load i64, i64* %23
%25 = trunc i64 %24 to i32
%26 = load i32, i32* %8
%27 = mul i32 %26, 8
%28 = shl i32 %25, %27
%29 = load i32*, i32** %4
%30 = load i32, i32* %29
%31 = or i32 %30, %28
store i32 %31, i32* %29
br label %32
32: ; preds = %20
%33 = load i32, i32* %8
%34 = add i32 %33, 1
store i32 %34, i32* %8
br label %16
35: ; preds = %16
store i32 0, i32* %3
br label %36
36: ; preds = %35, %13
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @fread_le64(i32* nocapture %0, i32* nocapture %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 64, i32 1, i32* %1)
%7 = icmp ne i32 %6, 1
%8 = sext i1 %7 to i32
ret i32 %8
}