#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*/ SEEK_SET;
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
unsigned int getlong(int /*<<< orphan*/ *);
int getshort(int /*<<< orphan*/ *);
int filecheck(FILE *file, int off, int len) {
  unsigned int sum = 0, chunk;
  int i, len4 = len / 4;
  fseek(file, off, SEEK_SET);
  for (i = 0; i < len4; ++i) {
    chunk = getlong(file);
    if (feof(file))
      break;
    sum += chunk;
  }
  if ((len & 3) == 1)
    chunk = getc(file) << 24;
  else if ((len & 3) == 2)
    chunk = getshort(file) << 16;
  else if ((len & 3) == 3) {
    chunk = getshort(file) << 16;
    chunk |= getc(file) << 8;
  } else
    chunk = 0;
  sum += chunk;
  return (sum);
}


x86 assembly (clang, -O0):
<filecheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11da <filecheck+0x8a>
mov    -0x8(%rbp),%rdi
call   1060 <getlong@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     11c3 <filecheck+0x73>
jmp    11da <filecheck+0x8a>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1193 <filecheck+0x43>
mov    -0x10(%rbp),%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    11fd <filecheck+0xad>
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
shl    $0x18,%eax
mov    %eax,-0x18(%rbp)
jmp    1266 <filecheck+0x116>
mov    -0x10(%rbp),%eax
and    $0x3,%eax
cmp    $0x2,%eax
jne    1220 <filecheck+0xd0>
mov    -0x8(%rbp),%rdi
call   1030 <getshort@plt>
shl    $0x10,%eax
mov    %eax,-0x18(%rbp)
jmp    1261 <filecheck+0x111>
mov    -0x10(%rbp),%eax
and    $0x3,%eax
cmp    $0x3,%eax
jne    1255 <filecheck+0x105>
mov    -0x8(%rbp),%rdi
call   1030 <getshort@plt>
shl    $0x10,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
shl    $0x8,%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    125c <filecheck+0x10c>
movl   $0x0,-0x18(%rbp)
jmp    1261 <filecheck+0x111>
jmp    1266 <filecheck+0x116>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filecheck>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rdi,%r12
lea    0x3(%r15),%ebx
test   %edx,%edx
cmovns %edx,%ebx
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
xor    %r14d,%r14d
mov    $0x0,%r13d
cmp    $0x4,%r15d
jl     11af <filecheck+0x5f>
sar    $0x2,%ebx
xor    %r13d,%r13d
nopl   (%rax)
mov    %r12,%rdi
call   1060 <getlong@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1040 <feof@plt>
test   %rax,%rax
jne    11af <filecheck+0x5f>
add    %ebp,%r13d
add    $0xffffffff,%ebx
jne    1190 <filecheck+0x40>
and    $0x3,%r15d
cmp    $0x3,%r15d
je     11d6 <filecheck+0x86>
cmp    $0x2,%r15d
je     11f7 <filecheck+0xa7>
cmp    $0x1,%r15d
jne    1206 <filecheck+0xb6>
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %eax,%r14d
shl    $0x18,%r14d
jmp    1206 <filecheck+0xb6>
mov    %r12,%rdi
call   1030 <getshort@plt>
mov    %eax,%ebp
shl    $0x10,%ebp
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %eax,%r14d
shl    $0x8,%r14d
or     %ebp,%r14d
jmp    1206 <filecheck+0xb6>
mov    %r12,%rdi
call   1030 <getshort@plt>
mov    %eax,%r14d
shl    $0x10,%r14d
add    %r13d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @filecheck(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %6
%12 = sdiv i32 %11, 4
store i32 %12, i32* %10
%13 = load i32*, i32** %4
%14 = load i32, i32* %5
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %13, i32 %14, i32 %15)
store i32 0, i32* %9
br label %17
17: ; preds = %32, %3
%18 = load i32, i32* %9
%19 = load i32, i32* %10
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i32*, i32** %4
%23 = call i32 @getlong(i32* %22)
store i32 %23, i32* %8
%24 = load i32*, i32** %4
%25 = call i64 @feof(i32* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
br label %35
28: ; preds = %21
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = add i32 %30, %29
store i32 %31, i32* %7
br label %32
32: ; preds = %28
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %17
35: ; preds = %27, %17
%36 = load i32, i32* %6
%37 = and i32 %36, 3
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i32*, i32** %4
%41 = call i32 @getc(i32* %40)
%42 = shl i32 %41, 24
store i32 %42, i32* %8
br label %67
43: ; preds = %35
%44 = load i32, i32* %6
%45 = and i32 %44, 3
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load i32*, i32** %4
%49 = call i32 @getshort(i32* %48)
%50 = shl i32 %49, 16
store i32 %50, i32* %8
br label %66
51: ; preds = %43
%52 = load i32, i32* %6
%53 = and i32 %52, 3
%54 = icmp eq i32 %53, 3
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i32*, i32** %4
%57 = call i32 @getshort(i32* %56)
%58 = shl i32 %57, 16
store i32 %58, i32* %8
%59 = load i32*, i32** %4
%60 = call i32 @getc(i32* %59)
%61 = shl i32 %60, 8
%62 = load i32, i32* %8
%63 = or i32 %62, %61
store i32 %63, i32* %8
br label %65
64: ; preds = %51
store i32 0, i32* %8
br label %65
65: ; preds = %64, %55
br label %66
66: ; preds = %65, %47
br label %67
67: ; preds = %66, %39
%68 = load i32, i32* %8
%69 = load i32, i32* %7
%70 = add i32 %69, %68
store i32 %70, i32* %7
%71 = load i32, i32* %7
ret i32 %71
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @filecheck(i32* %0, i32 %1, i32 %2) {
%4 = sdiv i32 %2, 4
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i32 %1, i32 %5)
%7 = icmp sgt i32 %2, 3
br i1 %7, label %8, label %18
8: ; preds = %3, %14
%9 = phi i32 [ %15, %14 ], [ 0, %3 ]
%10 = phi i32 [ %16, %14 ], [ 0, %3 ]
%11 = tail call i32 @getlong(i32* %0)
%12 = tail call i64 @feof(i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = add i32 %11, %9
%16 = add nuw nsw i32 %10, 1
%17 = icmp eq i32 %16, %4
br i1 %17, label %18, label %8
18: ; preds = %14, %8, %3
%19 = phi i32 [ 0, %3 ], [ %9, %8 ], [ %15, %14 ]
%20 = and i32 %2, 3
switch i32 %20, label %33 [
i32 1, label %21
i32 2, label %24
i32 3, label %27
]
21: ; preds = %18
%22 = tail call i32 @getc(i32* %0)
%23 = shl i32 %22, 24
br label %33
24: ; preds = %18
%25 = tail call i32 @getshort(i32* %0)
%26 = shl i32 %25, 16
br label %33
27: ; preds = %18
%28 = tail call i32 @getshort(i32* %0)
%29 = shl i32 %28, 16
%30 = tail call i32 @getc(i32* %0)
%31 = shl i32 %30, 8
%32 = or i32 %31, %29
br label %33
33: ; preds = %18, %24, %27, %21
%34 = phi i32 [ %23, %21 ], [ %26, %24 ], [ %32, %27 ], [ 0, %18 ]
%35 = add i32 %34, %19
ret i32 %35
}