#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  FILE *fp;
  fp = fopen("worst.idx", "rb");
  int ticket, count = 0;
  while (!feof(fp)) {
    fread(&ticket, sizeof(int), 1, fp);
    if (feof(fp))
      break;
    printf("%d \n", ticket);
    count++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1193 <main+0x53>
jmp    11df <main+0x9f>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11c2 <main+0x82>
jmp    11df <main+0x9f>
mov    -0x1c(%rbp),%esi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1174 <main+0x34>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11bb <main+0x7b>
lea    0xc(%rsp),%r14
lea    0xe95(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11bb <main+0x7b>
mov    0xc(%rsp),%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
je     1180 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"worst.idx\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [5 x i8] c"%d \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
store i32 0, i32* %8
br label %10
10: ; preds = %22, %2
%11 = load i32*, i32** %6
%12 = call i64 @feof(i32* %11)
%13 = icmp ne i64 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %27
15: ; preds = %10
%16 = load i32*, i32** %6
%17 = call i32 @fread(i32* %7, i32 4, i32 1, i32* %16)
%18 = load i32*, i32** %6
%19 = call i64 @feof(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
br label %27
22: ; preds = %15
%23 = load i32, i32* %7
%24 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %10
27: ; preds = %21, %10
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"worst.idx\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [5 x i8] c"%d \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i32* %3 to i8*
%6 = tail call i64 @feof(i32* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %2, %12
%9 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %4)
%10 = tail call i64 @feof(i32* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* %3
%14 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i64 @feof(i32* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %8, label %17
17: ; preds = %12, %8, %2
ret i32 0
}