#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*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
void read_data(FILE *stream) {
  int i, j;
  for (i = 0; i < 100; i++) {
    if (fscanf(stream, "%d\n", &j) != 1 || j != i) {
      if (ferror(stream))
        perror("fscanf");
      puts("Test FAILED!");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    11de <read_data+0x8e>
mov    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1196 <read_data+0x46>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11cb <read_data+0x7b>
mov    -0x8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     11b5 <read_data+0x65>
lea    0xe54(%rip),%rdi
call   1060 <perror@plt>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11d0 <read_data+0x80>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1163 <read_data+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
lea    0xe9d(%rip),%r14
lea    0x4(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    119c <read_data+0x4c>
cmp    0x4(%rsp),%ebp
jne    119c <read_data+0x4c>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1170 <read_data+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11b5 <read_data+0x65>
lea    0xe54(%rip),%rdi
call   1060 <perror@plt>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [7 x i8] c"fscanf\00"
@.str.2 = [13 x i8] c"Test FAILED!\00"
define void @read_data(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
br label %5
5: ; preds = %26, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = load i32*, i32** %2
%10 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %4)
%11 = icmp ne i32 %10, 1
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12, %8
%17 = load i32*, i32** %2
%18 = call i64 @ferror(i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %12
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %5
29: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [7 x i8] c"fscanf\00"
@.str.2 = [13 x i8] c"Test FAILED!\00"
define void @read_data(i32* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %7
4: ; preds = %7
%5 = add nuw nsw i32 %8, 1
%6 = icmp eq i32 %5, 100
br i1 %6, label %22, label %7
7: ; preds = %1, %4
%8 = phi i32 [ 0, %1 ], [ %5, %4 ]
%9 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = icmp eq i32 %9, 1
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, %8
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %4, label %14
14: ; preds = %7
%15 = call i64 @ferror(i32* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %4
ret void
}