#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;

/* Variables and functions */
int read(int, scalar_t__ *, int);
int read_le64(int fd, uint64_t *out) {
  uint64_t tmp = 0;
  uint8_t byte;
  int i, err;
  for (i = 0; i < 8; i++) {
    err = read(fd, &byte, 1);
    if (err <= 0)
      return err;
    tmp |= ((uint64_t)byte << (i * 8));
  }
  *out = tmp;
  do {
  } while (0);
  return 8;
}


x86 assembly (clang, -O0):
<read_le64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    1180 <read_le64+0x70>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     1160 <read_le64+0x50>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1195 <read_le64+0x85>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112d <read_le64+0x1d>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    118e <read_le64+0x7e>
movl   $0x8,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_le64>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    11ce <read_le64+0xbe>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    11ce <read_le64+0xbe>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    11ce <read_le64+0xbe>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    11ce <read_le64+0xbe>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    11ce <read_le64+0xbe>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    11ce <read_le64+0xbe>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    11ce <read_le64+0xbe>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,%ecx
mov    $0x8,%eax
test   %ecx,%ecx
jg     11ce <read_le64+0xbe>
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @read_le64(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %6
store i32 0, i32* %8
br label %10
10: ; preds = %28, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %31
13: ; preds = %10
%14 = load i32, i32* %4
%15 = call i32 @read(i32 %14, i64* %7, i32 1)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i32, i32* %9
store i32 %19, i32* %3
br label %36
20: ; preds = %13
%21 = load i64, i64* %7
%22 = trunc i64 %21 to i32
%23 = load i32, i32* %8
%24 = mul nsw i32 %23, 8
%25 = shl i32 %22, %24
%26 = load i32, i32* %6
%27 = or i32 %26, %25
store i32 %27, i32* %6
br label %28
28: ; preds = %20
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %10
31: ; preds = %10
%32 = load i32, i32* %6
%33 = load i32*, i32** %5
store i32 %32, i32* %33
br label %34
34: ; preds = %31
br label %35
35: ; preds = %34
store i32 8, i32* %3
br label %36
36: ; preds = %35, %18
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @read_le64(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i32 @read(i32 %0, i64* %3, i32 1)
%6 = icmp slt i32 %5, 1
br i1 %6, label %28, label %7
7: ; preds = %2
%8 = call i32 @read(i32 %0, i64* %3, i32 1)
%9 = icmp slt i32 %8, 1
br i1 %9, label %28, label %10
10: ; preds = %7
%11 = call i32 @read(i32 %0, i64* %3, i32 1)
%12 = icmp slt i32 %11, 1
br i1 %12, label %28, label %13
13: ; preds = %10
%14 = call i32 @read(i32 %0, i64* %3, i32 1)
%15 = icmp slt i32 %14, 1
br i1 %15, label %28, label %16
16: ; preds = %13
%17 = call i32 @read(i32 %0, i64* %3, i32 1)
%18 = icmp slt i32 %17, 1
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = call i32 @read(i32 %0, i64* %3, i32 1)
%21 = icmp slt i32 %20, 1
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = call i32 @read(i32 %0, i64* %3, i32 1)
%24 = icmp slt i32 %23, 1
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = call i32 @read(i32 %0, i64* %3, i32 1)
%27 = icmp slt i32 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %25, %22, %19, %16, %13, %10, %7, %2
%29 = phi i32 [ %5, %2 ], [ %8, %7 ], [ %11, %10 ], [ %14, %13 ], [ %17, %16 ], [ %20, %19 ], [ %23, %22 ], [ %26, %25 ]
br label %30
30: ; preds = %25, %28
%31 = phi i32 [ %29, %28 ], [ 8, %25 ]
ret i32 %31
}