#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
unsigned int getlong(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int filecheck(FILE *file) {
  unsigned int sum = 0, chunk;
  rewind(file);
  while (1) {
    chunk = getlong(file);
    if (feof(file) || ferror(file))
      break;
    sum += chunk;
  }
  return (sum);
}


x86 assembly (clang, -O0):
<filecheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x8(%rbp),%rdi
call   1060 <getlong@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
jne    118e <filecheck+0x4e>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1193 <filecheck+0x53>
jmp    11a1 <filecheck+0x61>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    115c <filecheck+0x1c>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filecheck>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <rewind@plt>
mov    %r14,%rdi
call   1060 <getlong@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1196 <filecheck+0x56>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1196 <filecheck+0x56>
add    %ebx,%ebp
mov    %r14,%rdi
call   1060 <getlong@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <feof@plt>
test   %rax,%rax
je     1170 <filecheck+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @filecheck(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
%5 = load i32*, i32** %2
%6 = call i32 @rewind(i32* %5)
br label %7
7: ; preds = %1, %18
%8 = load i32*, i32** %2
%9 = call i32 @getlong(i32* %8)
store i32 %9, i32* %4
%10 = load i32*, i32** %2
%11 = call i64 @feof(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = load i32*, i32** %2
%15 = call i64 @ferror(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13, %7
br label %22
18: ; preds = %13
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = add i32 %20, %19
store i32 %21, i32* %3
br label %7
22: ; preds = %17
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
define i32 @filecheck(i32* %0) {
%2 = tail call i32 @rewind(i32* %0)
%3 = tail call i32 @getlong(i32* %0)
%4 = tail call i64 @feof(i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %16
6: ; preds = %10
%7 = tail call i32 @getlong(i32* %0)
%8 = tail call i64 @feof(i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %1, %6
%11 = phi i32 [ %7, %6 ], [ %3, %1 ]
%12 = phi i32 [ %15, %6 ], [ 0, %1 ]
%13 = tail call i64 @ferror(i32* %0)
%14 = icmp eq i64 %13, 0
%15 = add i32 %11, %12
br i1 %14, label %6, label %16
16: ; preds = %10, %6, %1
%17 = phi i32 [ 0, %1 ], [ %15, %6 ], [ %12, %10 ]
ret i32 %17
}