#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*/ close_buffer(int /*<<< orphan*/ *);
int read_document(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ setup_buffer(int /*<<< orphan*/ *);
void process_file(FILE *f) {
  int n, document_count;
  setup_buffer(f);
  document_count = 0;
  n = read_document(f, document_count);
  document_count++;
  while (n != EOF) {
    n = read_document(f, document_count);
    document_count++;
  }
  close_buffer(f);
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <setup_buffer@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <read_document@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%eax
je     1193 <process_file+0x63>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <read_document@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1164 <process_file+0x34>
mov    -0x8(%rbp),%rdi
call   1050 <close_buffer@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <setup_buffer@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <read_document@plt>
mov    0x2e9b(%rip),%r14
cmp    (%r14),%eax
je     1172 <process_file+0x42>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <read_document@plt>
add    $0x1,%ebp
cmp    (%r14),%eax
jne    1160 <process_file+0x30>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <close_buffer@plt>

LLVM IR (-O0):
@EOF = global i32 0
define void @process_file(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 @setup_buffer(i32* %5)
store i32 0, i32* %4
%7 = load i32*, i32** %2
%8 = load i32, i32* %4
%9 = call i32 @read_document(i32* %7, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
store i32 %11, i32* %4
br label %12
12: ; preds = %16, %1
%13 = load i32, i32* %3
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i32*, i32** %2
%18 = load i32, i32* %4
%19 = call i32 @read_document(i32* %17, i32 %18)
store i32 %19, i32* %3
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %12
22: ; preds = %12
%23 = load i32*, i32** %2
%24 = call i32 @close_buffer(i32* %23)
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @process_file(i32* %0) {
%2 = tail call i32 @setup_buffer(i32* %0)
%3 = tail call i32 @read_document(i32* %0, i32 0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %12, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %9, %6 ], [ 1, %1 ]
%8 = tail call i32 @read_document(i32* %0, i32 %7)
%9 = add nuw nsw i32 %7, 1
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %8, %10
br i1 %11, label %12, label %6
12: ; preds = %6, %1
%13 = tail call i32 @close_buffer(i32* %0)
ret void
}