#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__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void readData(unsigned long numdata, FILE *fp) {
  int i;
  for (i = 0; i < numdata; i++) {
    if (fgetc(fp) == EOF) {
      printf("ReadData reached end of file unexpectedly\n");
      fclose(fp);
      exit(2);
    }
  }
}


x86 assembly (clang, -O0):
<readData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11b0 <readData+0x70>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jne    119d <readData+0x5d>
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
jmp    11a2 <readData+0x62>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <readData+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readData>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1173 <readData+0x33>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e91(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%rax
je     1179 <readData+0x39>
add    $0xffffffffffffffff,%rbx
jne    1160 <readData+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@EOF = global i64 0
@.str = [43 x i8] c"ReadData reached end of file unexpectedly\0A\00"
define void @readData(i64 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32
store i64 %0, i64* %3
store i32* %1, i32** %4
store i32 0, i32* %5
br label %6
6: ; preds = %22, %2
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = load i64, i64* %3
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %25
11: ; preds = %6
%12 = load i32*, i32** %4
%13 = call i64 @fgetc(i32* %12)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
%20 = call i32 @exit(i32 2)
unreachable
21: ; preds = %11
br label %22
22: ; preds = %21
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %6
25: ; preds = %6
ret void
}

LLVM IR (-O2):
@EOF = global i64 0
@str = [42 x i8] c"ReadData reached end of file unexpectedly\00"
define void @readData(i64 %0, i32* nocapture %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %16, label %6
4: ; preds = %6
%5 = icmp eq i64 %11, %0
br i1 %5, label %16, label %6
6: ; preds = %2, %4
%7 = phi i64 [ %11, %4 ], [ 0, %2 ]
%8 = tail call i64 @fgetc(i32* %1)
%9 = load i64, i64* @EOF
%10 = icmp eq i64 %8, %9
%11 = add nuw i64 %7, 1
br i1 %10, label %12, label %4
12: ; preds = %6
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @fclose(i32* %1)
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %4, %2
ret void
}