#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 /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int input(FILE *f, unsigned int count, unsigned int count2, unsigned int len,
          unsigned int begin, unsigned int end) {
  unsigned int i;
  unsigned int expected = begin;
  char str[100];
  char stre[20];
  for (i = 0; i < count; ++i) {
    if (fgets(str, 100, f) == NULL)
      goto exit_bad_fgets;
    sprintf(stre, "%u\n", expected);
    if (strcmp(str, stre) != 0)
      goto exit_mismatch;
    if (expected == end)
      expected = begin;
    else
      ++expected;
  }
  expected = begin;
  for (i = 0; i < count2; ++i) {
    if (fgets(str, len + 1, f) == NULL)
      goto exit_bad_fgets;
    sprintf(stre, "%u", expected);
    stre[len] = '\0';
    if (strcmp(str, stre) != 0)
      goto exit_mismatch;
    if (expected == end)
      expected = begin;
    else
      ++expected;
  }
  if (fgets(str, 100, f) != NULL)
    goto exit_bad_eof;
  return 0;
exit_bad_fgets:
  perror("error reading data");
  goto exit_fail;
exit_mismatch:
  fprintf(stderr, "failed to match with what was expected (at %uth data)", i);
  goto exit_fail;
exit_bad_eof:
  perror("error detecting eof after data were supposed to finish");
  goto exit_fail;
exit_fail:
  return -1;
}


x86 assembly (clang, -O0):
<input>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1218 <input+0xc8>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
jne    11ad <input+0x5d>
jmp    12fc <input+0x1ac>
lea    -0xb0(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe42(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11e5 <input+0x95>
jmp    130d <input+0x1bd>
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    11fc <input+0xac>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1205 <input+0xb5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120a <input+0xba>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117d <input+0x2d>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    12cc <input+0x17c>
lea    -0x90(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rdx
call   1030 <fgets@plt>
cmp    $0x0,%rax
jne    1256 <input+0x106>
jmp    12fc <input+0x1ac>
lea    -0xb0(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xd9d(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x1c(%rbp),%eax
movb   $0x0,-0xb0(%rbp,%rax,1)
lea    -0x90(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1299 <input+0x149>
jmp    130d <input+0x1bd>
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    12b0 <input+0x160>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    12b9 <input+0x169>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12be <input+0x16e>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1225 <input+0xd5>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     12f0 <input+0x1a0>
jmp    132a <input+0x1da>
movl   $0x0,-0x4(%rbp)
jmp    133d <input+0x1ed>
lea    0xd04(%rip),%rdi
call   1060 <perror@plt>
jmp    1336 <input+0x1e6>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xcfa(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1336 <input+0x1e6>
lea    0xd1f(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %r9d,0x4(%rsp)
mov    %r8d,%r13d
mov    %ecx,0x14(%rsp)
mov    %edx,(%rsp)
mov    %rdi,0x8(%rsp)
test   %esi,%esi
je     11e5 <input+0x95>
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0x40(%rsp),%r15
lea    0x20(%rsp),%r14
mov    %r13d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x64,%esi
mov    0x8(%rsp),%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     12c3 <input+0x173>
mov    %r14,%rdi
lea    0xe4b(%rip),%rsi
mov    %ebp,%edx
call   1070 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1295 <input+0x145>
cmp    0x4(%rsp),%ebp
lea    0x1(%rbp),%eax
cmove  %r13d,%eax
add    $0x1,%ebx
mov    %eax,%ebp
cmp    %ebx,%r12d
jne    1190 <input+0x40>
cmpl   $0x0,(%rsp)
je     1269 <input+0x119>
mov    0x14(%rsp),%r14d
mov    %r14d,%eax
mov    %rax,0x18(%rsp)
add    $0x1,%r14d
xor    %ebx,%ebx
lea    0x40(%rsp),%r15
lea    0x20(%rsp),%r12
mov    %r13d,%ebp
nop
mov    %r15,%rdi
mov    %r14d,%esi
mov    0x8(%rsp),%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     12c3 <input+0x173>
mov    %r12,%rdi
lea    0xdd1(%rip),%rsi
mov    %ebp,%edx
call   1070 <sprintf@plt>
mov    0x18(%rsp),%rax
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1295 <input+0x145>
cmp    0x4(%rsp),%ebp
lea    0x1(%rbp),%eax
cmove  %r13d,%eax
add    $0x1,%ebx
mov    %eax,%ebp
cmp    %ebx,(%rsp)
jne    1210 <input+0xc0>
lea    0x40(%rsp),%rdi
mov    $0x64,%esi
mov    0x8(%rsp),%rdx
call   1030 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     12b1 <input+0x161>
lea    0xdc2(%rip),%rdi
call   1060 <perror@plt>
jmp    12ac <input+0x15c>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd3d(%rip),%rdi
call   1060 <perror@plt>
jmp    12ac <input+0x15c>

LLVM IR (-O0):
@.str = [4 x i8] c"%u\0A\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [19 x i8] c"error reading data\00"
@stderr = global i32 0
@.str.3 = [54 x i8] c"failed to match with what was expected (at %uth data)\00"
@.str.4 = [55 x i8] c"error detecting eof after data were supposed to finish\00"
define i32 @input(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [100 x i8]
%17 = alloca [20 x i8]
store i32* %0, i32** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%18 = load i32, i32* %12
store i32 %18, i32* %15
store i32 0, i32* %14
br label %19
19: ; preds = %48, %6
%20 = load i32, i32* %14
%21 = load i32, i32* %9
%22 = icmp ult i32 %20, %21
br i1 %22, label %23, label %51
23: ; preds = %19
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%25 = load i32*, i32** %8
%26 = call i32* @fgets(i8* %24, i32 100, i32* %25)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %23
br label %97
29: ; preds = %23
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %17, i64 0, i64 0
%31 = load i32, i32* %15
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %17, i64 0, i64 0
%35 = call i64 @strcmp(i8* %33, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %29
br label %99
38: ; preds = %29
%39 = load i32, i32* %15
%40 = load i32, i32* %13
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = load i32, i32* %12
store i32 %43, i32* %15
br label %47
44: ; preds = %38
%45 = load i32, i32* %15
%46 = add i32 %45, 1
store i32 %46, i32* %15
br label %47
47: ; preds = %44, %42
br label %48
48: ; preds = %47
%49 = load i32, i32* %14
%50 = add i32 %49, 1
store i32 %50, i32* %14
br label %19
51: ; preds = %19
%52 = load i32, i32* %12
store i32 %52, i32* %15
store i32 0, i32* %14
br label %53
53: ; preds = %87, %51
%54 = load i32, i32* %14
%55 = load i32, i32* %10
%56 = icmp ult i32 %54, %55
br i1 %56, label %57, label %90
57: ; preds = %53
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%59 = load i32, i32* %11
%60 = add i32 %59, 1
%61 = load i32*, i32** %8
%62 = call i32* @fgets(i8* %58, i32 %60, i32* %61)
%63 = icmp eq i32* %62, null
br i1 %63, label %64, label %65
64: ; preds = %57
br label %97
65: ; preds = %57
%66 = getelementptr inbounds [20 x i8], [20 x i8]* %17, i64 0, i64 0
%67 = load i32, i32* %15
%68 = call i32 @sprintf(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %11
%70 = zext i32 %69 to i64
%71 = getelementptr inbounds [20 x i8], [20 x i8]* %17, i64 0, i64 %70
store i8 0, i8* %71
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%73 = getelementptr inbounds [20 x i8], [20 x i8]* %17, i64 0, i64 0
%74 = call i64 @strcmp(i8* %72, i8* %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %65
br label %99
77: ; preds = %65
%78 = load i32, i32* %15
%79 = load i32, i32* %13
%80 = icmp eq i32 %78, %79
br i1 %80, label %81, label %83
81: ; preds = %77
%82 = load i32, i32* %12
store i32 %82, i32* %15
br label %86
83: ; preds = %77
%84 = load i32, i32* %15
%85 = add i32 %84, 1
store i32 %85, i32* %15
br label %86
86: ; preds = %83, %81
br label %87
87: ; preds = %86
%88 = load i32, i32* %14
%89 = add i32 %88, 1
store i32 %89, i32* %14
br label %53
90: ; preds = %53
%91 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%92 = load i32*, i32** %8
%93 = call i32* @fgets(i8* %91, i32 100, i32* %92)
%94 = icmp ne i32* %93, null
br i1 %94, label %95, label %96
95: ; preds = %90
br label %103
96: ; preds = %90
store i32 0, i32* %7
br label %106
97: ; preds = %64, %28
%98 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %105
99: ; preds = %76, %37
%100 = load i32, i32* @stderr
%101 = load i32, i32* %14
%102 = call i32 @fprintf(i32 %100, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %101)
br label %105
103: ; preds = %95
%104 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
br label %105
105: ; preds = %103, %99, %97
store i32 -1, i32* %7
br label %106
106: ; preds = %105, %96
%107 = load i32, i32* %7
ret i32 %107
}

LLVM IR (-O2):
@.str = [4 x i8] c"%u\0A\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [19 x i8] c"error reading data\00"
@stderr = global i32 0
@.str.3 = [54 x i8] c"failed to match with what was expected (at %uth data)\00"
@.str.4 = [55 x i8] c"error detecting eof after data were supposed to finish\00"
define i32 @input(i32* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca [100 x i8]
%8 = alloca [20 x i8]
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%11 = icmp eq i32 %1, 0
br i1 %11, label %12, label %18
12: ; preds = %27, %6
%13 = icmp eq i32 %2, 0
br i1 %13, label %48, label %14
14: ; preds = %12
%15 = add i32 %3, 1
%16 = zext i32 %3 to i64
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 %16
br label %33
18: ; preds = %6, %27
%19 = phi i32 [ %30, %27 ], [ %4, %6 ]
%20 = phi i32 [ %31, %27 ], [ 0, %6 ]
%21 = call i32* @fgets(i8* %9, i32 100, i32* %0)
%22 = icmp eq i32* %21, null
br i1 %22, label %51, label %23
23: ; preds = %18
%24 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %19)
%25 = call i64 @strcmp(i8* %9, i8* %10)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %53
27: ; preds = %23
%28 = icmp eq i32 %19, %5
%29 = add i32 %19, 1
%30 = select i1 %28, i32 %4, i32 %29
%31 = add nuw i32 %20, 1
%32 = icmp eq i32 %31, %1
br i1 %32, label %12, label %18
33: ; preds = %14, %42
%34 = phi i32 [ %4, %14 ], [ %45, %42 ]
%35 = phi i32 [ 0, %14 ], [ %46, %42 ]
%36 = call i32* @fgets(i8* %9, i32 %15, i32* %0)
%37 = icmp eq i32* %36, null
br i1 %37, label %51, label %38
38: ; preds = %33
%39 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %34)
store i8 0, i8* %17
%40 = call i64 @strcmp(i8* %9, i8* %10)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %38
%43 = icmp eq i32 %34, %5
%44 = add i32 %34, 1
%45 = select i1 %43, i32 %4, i32 %44
%46 = add nuw i32 %35, 1
%47 = icmp eq i32 %46, %2
br i1 %47, label %48, label %33
48: ; preds = %42, %12
%49 = call i32* @fgets(i8* %9, i32 100, i32* %0)
%50 = icmp eq i32* %49, null
br i1 %50, label %59, label %57
51: ; preds = %18, %33
%52 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %59
53: ; preds = %23, %38
%54 = phi i32 [ %35, %38 ], [ %20, %23 ]
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i32 %54)
br label %59
57: ; preds = %48
%58 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %51, %53, %57, %48
%60 = phi i32 [ 0, %48 ], [ -1, %57 ], [ -1, %53 ], [ -1, %51 ]
ret i32 %60
}