#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 EOF;
int /*<<< orphan*/ SEEK_CUR;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int wfh_readint(FILE *file1, int len) {
  int ret = 0;
  int i;
  int c;
  for (i = 0; i < len; i++) {
    c = fgetc(file1);
    if (c == EOF) {
      break;
    }
    ret = ret + (int)((c & 0x00ff) * (0x01 << (8 * i)));
  }
  fseek(file1, 0, SEEK_CUR);
  return ret;
}


x86 assembly (clang, -O0):
<wfh_readint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a1 <wfh_readint+0x81>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%eax
jne    116c <wfh_readint+0x4c>
jmp    11a1 <wfh_readint+0x81>
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%ecx
and    $0xff,%ecx
mov    %ecx,-0x1c(%rbp)
mov    -0x14(%rbp),%ecx
shl    $0x3,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    -0x1c(%rbp),%ecx
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <wfh_readint+0x1d>
mov    -0x8(%rbp),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wfh_readint>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
test   %esi,%esi
jle    1162 <wfh_readint+0x42>
mov    %esi,%ebx
xor    %ebp,%ebp
mov    0x2ea6(%rip),%r12
xor    %r15d,%r15d
nopl   (%rax)
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     1165 <wfh_readint+0x45>
movzbl %al,%eax
mov    %ebp,%ecx
shl    %cl,%eax
add    %eax,%r15d
add    $0x8,%ebp
add    $0xffffffff,%ebx
jne    1140 <wfh_readint+0x20>
jmp    1165 <wfh_readint+0x45>
xor    %r15d,%r15d
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@SEEK_CUR = global i32 0
define i32 @wfh_readint(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %28, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = load i32*, i32** %3
%14 = call i32 @fgetc(i32* %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %12
br label %31
19: ; preds = %12
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = and i32 %21, 255
%23 = load i32, i32* %6
%24 = mul nsw i32 8, %23
%25 = shl i32 1, %24
%26 = mul nsw i32 %22, %25
%27 = add nsw i32 %20, %26
store i32 %27, i32* %5
br label %28
28: ; preds = %19
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %8
31: ; preds = %18, %8
%32 = load i32*, i32** %3
%33 = load i32, i32* @SEEK_CUR
%34 = call i32 @fseek(i32* %32, i32 0, i32 %33)
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
@EOF = global i32 0
@SEEK_CUR = global i32 0
define i32 @wfh_readint(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %17
4: ; preds = %2, %10
%5 = phi i32 [ %14, %10 ], [ 0, %2 ]
%6 = phi i32 [ %15, %10 ], [ 0, %2 ]
%7 = tail call i32 @fgetc(i32* %0)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %17, label %10
10: ; preds = %4
%11 = and i32 %7, 255
%12 = shl nsw i32 %6, 3
%13 = shl i32 %11, %12
%14 = add nsw i32 %13, %5
%15 = add nuw nsw i32 %6, 1
%16 = icmp eq i32 %15, %1
br i1 %16, label %17, label %4
17: ; preds = %10, %4, %2
%18 = phi i32 [ 0, %2 ], [ %5, %4 ], [ %14, %10 ]
%19 = load i32, i32* @SEEK_CUR
%20 = tail call i32 @fseek(i32* %0, i32 0, i32 %19)
ret i32 %18
}