#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 long long uint32_t;
typedef int /*<<< orphan*/ input;

/* Variables and functions */
#define EAGAIN 132
#define EBUSY 131
#define EDEADLK 130
#define EINTR 129
#define ETXTBSY 128
int errno;
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long long, ...);
int fread(long long *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strerror(int);
int verify_data(long long num_nums) {
  uint32_t num;
  for (num = 0; num < num_nums; ++num) {
    uint32_t input;
    while (fread(&input, sizeof(input), 1, stdin) != 1) {
      if (feof(stdin) != 0) {
        fprintf(stderr, "Ran out of input prematurely, after %d numbers.\n",
                num);
        return -1;
      }
      switch (errno) {
      case EINTR:
      case EBUSY:
      case EDEADLK:
      case EAGAIN:
      case ETXTBSY:
        break;
      default:
        fprintf(stderr, "Failed to read byte %d, err %d: %s\n", num, errno,
                strerror(errno));
        return -1;
        break;
      }
    }
    if (input != num) {
      fprintf(stderr, "Expected byte %d, read %d.\n", num, input);
      return -1;
    }
  }
  fprintf(stderr, "Read %d sequentail numbers.\n", num);
  return 0;
}


x86 assembly (clang, -O0):
<verify_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1293 <verify_data+0x153>
jmp    1167 <verify_data+0x27>
mov    0x2e7a(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1244 <verify_data+0x104>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11cb <verify_data+0x8b>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b5 <verify_data+0x175>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x4,%eax
ja     11ea <verify_data+0xaa>
jmp    11e5 <verify_data+0xa5>
jmp    123f <verify_data+0xff>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    %rax,%r8
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b5 <verify_data+0x175>
jmp    1167 <verify_data+0x27>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     127d <verify_data+0x13d>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b5 <verify_data+0x175>
jmp    1282 <verify_data+0x142>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1154 <verify_data+0x14>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
jle    11be <verify_data+0x7e>
mov    %rdi,%r15
xor    %r12d,%r12d
mov    0x2e89(%rip),%rbp
mov    %rsp,%r13
mov    0x2e67(%rip),%r14
nopl   0x0(%rax)
mov    0x0(%rbp),%ecx
mov    %r13,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11a4 <verify_data+0x64>
mov    0x0(%rbp),%edi
call   1050 <feof@plt>
test   %rax,%rax
jne    11dd <verify_data+0x9d>
mov    (%r14),%ebx
lea    -0x80(%rbx),%eax
cmp    $0x5,%eax
jb     1170 <verify_data+0x30>
jmp    11f9 <verify_data+0xb9>
mov    (%rsp),%rcx
cmp    %r12,%rcx
jne    1237 <verify_data+0xf7>
add    $0x1,%r12
cmp    %r15,%r12
jne    1170 <verify_data+0x30>
xor    %ebx,%ebx
jmp    11c1 <verify_data+0x81>
xor    %r15d,%r15d
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1226 <verify_data+0xe6>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1221 <verify_data+0xe1>
mov    0x2dd8(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe21(%rip),%rsi
mov    %ebp,%edi
mov    %r12,%rdx
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1221 <verify_data+0xe1>

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Ran out of input prematurely, after %d numbers.\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"Failed to read byte %d, err %d: %s\0A\00"
@.str.2 = [28 x i8] c"Expected byte %d, read %d.\0A\00"
@.str.3 = [29 x i8] c"Read %d sequentail numbers.\0A\00"
define i32 @verify_data(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %3
store i64 0, i64* %4
br label %6
6: ; preds = %44, %1
%7 = load i64, i64* %4
%8 = load i64, i64* %3
%9 = icmp slt i64 %7, %8
br i1 %9, label %10, label %47
10: ; preds = %6
br label %11
11: ; preds = %33, %10
%12 = load i32, i32* @stdin
%13 = call i32 @fread(i64* %5, i32 8, i32 1, i32 %12)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load i32, i32* @stdin
%17 = call i64 @feof(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i64, i64* %4
%22 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %21)
store i32 -1, i32* %2
br label %51
23: ; preds = %15
%24 = load i32, i32* @errno
switch i32 %24, label %26 [
i32 129, label %25
i32 131, label %25
i32 130, label %25
i32 132, label %25
i32 128, label %25
]
25: ; preds = %23, %23, %23, %23, %23
br label %33
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i64, i64* %4
%29 = load i32, i32* @errno
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %28, i32 %29, i8* %31)
store i32 -1, i32* %2
br label %51
33: ; preds = %25
br label %11
34: ; preds = %11
%35 = load i64, i64* %5
%36 = load i64, i64* %4
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = load i64, i64* %4
%41 = load i64, i64* %5
%42 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %40, i64 %41)
store i32 -1, i32* %2
br label %51
43: ; preds = %34
br label %44
44: ; preds = %43
%45 = load i64, i64* %4
%46 = add nsw i64 %45, 1
store i64 %46, i64* %4
br label %6
47: ; preds = %6
%48 = load i32, i32* @stderr
%49 = load i64, i64* %4
%50 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %49)
store i32 0, i32* %2
br label %51
51: ; preds = %47, %38, %26, %19
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Ran out of input prematurely, after %d numbers.\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"Failed to read byte %d, err %d: %s\0A\00"
@.str.2 = [28 x i8] c"Expected byte %d, read %d.\0A\00"
@.str.3 = [29 x i8] c"Read %d sequentail numbers.\0A\00"
define i32 @verify_data(i64 %0) {
%2 = alloca i64
%3 = icmp sgt i64 %0, 0
br i1 %3, label %4, label %36
4: ; preds = %1
%5 = bitcast i64* %2 to i8*
br label %6
6: ; preds = %4, %33
%7 = phi i64 [ 0, %4 ], [ %34, %33 ]
br label %8
8: ; preds = %19, %6
%9 = load i32, i32* @stdin
%10 = call i32 @fread(i64* %2, i32 8, i32 1, i32 %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %27, label %12
12: ; preds = %8
%13 = load i32, i32* @stdin
%14 = call i64 @feof(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %7)
br label %40
19: ; preds = %12
%20 = load i32, i32* @errno
%21 = add i32 %20, -128
%22 = icmp ult i32 %21, 5
br i1 %22, label %8, label %23
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i8* @strerror(i32 %20)
%26 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %7, i32 %20, i8* %25)
br label %40
27: ; preds = %8
%28 = load i64, i64* %2
%29 = icmp eq i64 %28, %7
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %7, i64 %28)
br label %40
33: ; preds = %27
%34 = add nuw nsw i64 %7, 1
%35 = icmp eq i64 %34, %0
br i1 %35, label %36, label %6
36: ; preds = %33, %1
%37 = phi i64 [ 0, %1 ], [ %0, %33 ]
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, i64, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %37)
br label %40
40: ; preds = %16, %23, %30, %36
%41 = phi i32 [ 0, %36 ], [ -1, %30 ], [ -1, %23 ], [ -1, %16 ]
ret i32 %41
}