#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int main() {
  FILE *in = fopen("task.in", "r");
  FILE *out = fopen("task.out", "w");
  int array[100];
  int len;
  for (len = 0; len < 100 && fscanf(in, "%d", &array[len]) == 1; len++)
    ;
  fprintf(out, "%d\n", len);
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1b4(%rbp)
xor    %eax,%eax
cmpl   $0x64,-0x1b4(%rbp)
mov    %al,-0x1b5(%rbp)
jge    11d0 <main+0x90>
mov    -0x10(%rbp),%rdi
movslq -0x1b4(%rbp),%rax
lea    -0x1b0(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe56(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
sete   %al
mov    %al,-0x1b5(%rbp)
mov    -0x1b5(%rbp),%al
test   $0x1,%al
jne    11e3 <main+0xa3>
jmp    11fc <main+0xbc>
jmp    11e8 <main+0xa8>
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    118a <main+0x4a>
mov    -0x18(%rbp),%rdi
mov    -0x1b4(%rbp),%edx
lea    0xe0b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x190,%rsp
lea    0xea9(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
lea    0xe9d(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rbx
xor    %r12d,%r12d
lea    0xe8c(%rip),%r13
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11b7 <main+0x77>
add    $0x1,%r12
add    $0x4,%rbx
cmp    $0x64,%r12
jne    1190 <main+0x50>
mov    $0x64,%r12d
lea    0xe5a(%rip),%rsi
mov    %r14,%rdi
mov    %r12d,%edx
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"task.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"task.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [100 x i32]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %3
store i32 0, i32* %5
br label %8
8: ; preds = %21, %0
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 100
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32*, i32** %2
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %14
%16 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %15)
%17 = icmp eq i32 %16, 1
br label %18
18: ; preds = %11, %8
%19 = phi i1 [ false, %8 ], [ %17, %11 ]
br i1 %19, label %20, label %24
20: ; preds = %18
br label %21
21: ; preds = %20
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %8
24: ; preds = %18
%25 = load i32*, i32** %3
%26 = load i32, i32* %5
%27 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"task.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"task.out\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%4 = bitcast [100 x i32]* %1 to i8*
br label %5
5: ; preds = %0, %10
%6 = phi i64 [ 0, %0 ], [ %11, %10 ]
%7 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %6
%8 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %7)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = add nuw nsw i64 %6, 1
%12 = icmp eq i64 %11, 100
br i1 %12, label %15, label %5
13: ; preds = %5
%14 = trunc i64 %6 to i32
br label %15
15: ; preds = %10, %13
%16 = phi i32 [ %14, %13 ], [ 100, %10 ]
%17 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = call i32 @fclose(i32* %2)
%19 = call i32 @fclose(i32* %3)
ret i32 0
}