#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*/ die(char *, char *, size_t);
int fgetc(int /*<<< orphan*/ *);
long xfread_value(FILE *fp, char *filename, size_t len) {
  long value = 0;
  size_t i;
  int c;
  for (i = 0; i < len; i++) {
    c = fgetc(fp);
    if (c < 0)
      die("File %s: error reading %d bytes\n", filename, len);
    value |= (c & 0xFF) << (8 * i);
  }
  return value;
}


x86 assembly (clang, -O0):
<xfread_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a9 <xfread_value+0x89>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    117c <xfread_value+0x5c>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe89(%rip),%rdi
call   1040 <die@plt>
mov    -0x2c(%rbp),%eax
and    $0xff,%eax
mov    -0x28(%rbp),%rcx
shl    $0x3,%rcx
shl    %cl,%eax
cltq
or     -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1144 <xfread_value+0x24>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xfread_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
xor    %ebx,%ebx
test   %rdx,%rdx
je     1189 <xfread_value+0x69>
mov    %rdx,%r14
mov    %rdi,%r12
mov    %rdx,%r15
xor    %r13d,%r13d
jmp    1166 <xfread_value+0x46>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl %bpl,%eax
mov    %ebx,%ecx
shl    %cl,%eax
cltq
or     %rax,%r13
add    $0x8,%ebx
add    $0xffffffffffffffff,%r15
je     118c <xfread_value+0x6c>
mov    %r12,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1150 <xfread_value+0x30>
lea    0xe85(%rip),%rdi
mov    (%rsp),%rsi
mov    %r14,%rdx
call   1040 <die@plt>
jmp    1150 <xfread_value+0x30>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"File %s: error reading %d bytes\0A\00"
define i64 @xfread_value(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i64 0, i64* %7
store i64 0, i64* %8
br label %10
10: ; preds = %33, %3
%11 = load i64, i64* %8
%12 = load i64, i64* %6
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = load i64, i64* %6
%22 = call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %20, i64 %21)
br label %23
23: ; preds = %19, %14
%24 = load i32, i32* %9
%25 = and i32 %24, 255
%26 = load i64, i64* %8
%27 = mul i64 8, %26
%28 = trunc i64 %27 to i32
%29 = shl i32 %25, %28
%30 = sext i32 %29 to i64
%31 = load i64, i64* %7
%32 = or i64 %31, %30
store i64 %32, i64* %7
br label %33
33: ; preds = %23
%34 = load i64, i64* %8
%35 = add i64 %34, 1
store i64 %35, i64* %8
br label %10
36: ; preds = %10
%37 = load i64, i64* %7
ret i64 %37
}

LLVM IR (-O2):
@.str = [33 x i8] c"File %s: error reading %d bytes\0A\00"
define i64 @xfread_value(i32* nocapture %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %21, label %5
5: ; preds = %3, %12
%6 = phi i64 [ %18, %12 ], [ 0, %3 ]
%7 = phi i64 [ %19, %12 ], [ 0, %3 ]
%8 = tail call i32 @fgetc(i32* %0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %1, i64 %2)
br label %12
12: ; preds = %10, %5
%13 = and i32 %8, 255
%14 = trunc i64 %7 to i32
%15 = shl i32 %14, 3
%16 = shl i32 %13, %15
%17 = sext i32 %16 to i64
%18 = or i64 %6, %17
%19 = add nuw i64 %7, 1
%20 = icmp eq i64 %19, %2
br i1 %20, label %21, label %5
21: ; preds = %12, %3
%22 = phi i64 [ 0, %3 ], [ %18, %12 ]
ret i64 %22
}