#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*/ *open_file(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int read_affection(char *filename, int *affection) {
  FILE *infile;
  char buf[20000];
  int indicator, count;
  infile = open_file(filename, "r");
  count = 0;
  while ((fgets(buf, 20000, infile) != NULL) && buf[0] != '\0') {
    sscanf(buf, "%d", &indicator);
    affection[count] = indicator;
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<read_affection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1030 <open_file@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x4e48(%rbp)
lea    -0x4e40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x4e20,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x4e49(%rbp)
je     119e <read_affection+0x6e>
movsbl -0x4e40(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x4e49(%rbp)
mov    -0x4e49(%rbp),%al
test   $0x1,%al
jne    11b1 <read_affection+0x81>
jmp    11f3 <read_affection+0xc3>
lea    -0x4e40(%rbp),%rdi
lea    0xe43(%rip),%rsi
lea    -0x4e44(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x4e44(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x4e48(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4e48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e48(%rbp)
jmp    1161 <read_affection+0x31>
mov    -0x4e48(%rbp),%eax
add    $0x4e50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_affection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e38,%rsp
mov    %rsi,%r14
lea    0xeb5(%rip),%rsi
call   1030 <open_file@plt>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x4e20,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11c6 <read_affection+0x96>
cmpb   $0x0,0x10(%rsp)
je     11c6 <read_affection+0x96>
xor    %ebx,%ebx
lea    0xe86(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1050 <sscanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
mov    %r13,%rdi
mov    $0x4e20,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c6 <read_affection+0x96>
cmpb   $0x0,0x10(%rsp)
jne    1190 <read_affection+0x60>
mov    %ebx,%eax
add    $0x4e38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @read_affection(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [20000 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%9 = load i8*, i8** %3
%10 = call i32* @open_file(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
store i32 0, i32* %8
br label %11
11: ; preds = %23, %2
%12 = getelementptr inbounds [20000 x i8], [20000 x i8]* %6, i64 0, i64 0
%13 = load i32*, i32** %5
%14 = call i32* @fgets(i8* %12, i32 20000, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = getelementptr inbounds [20000 x i8], [20000 x i8]* %6, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br label %21
21: ; preds = %16, %11
%22 = phi i1 [ false, %11 ], [ %20, %16 ]
br i1 %22, label %23, label %33
23: ; preds = %21
%24 = getelementptr inbounds [20000 x i8], [20000 x i8]* %6, i64 0, i64 0
%25 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%26 = load i32, i32* %7
%27 = load i32*, i32** %4
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
store i32 %26, i32* %30
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %11
33: ; preds = %21
%34 = load i32, i32* %8
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @read_affection(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [20000 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [20000 x i8], [20000 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = tail call i32* @open_file(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fgets(i8* %5, i32 20000, i32* %7)
%9 = icmp ne i32* %8, null
%10 = load i8, i8* %5
%11 = icmp ne i8 %10, 0
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %13, label %26
13: ; preds = %2, %13
%14 = phi i64 [ %18, %13 ], [ 0, %2 ]
%15 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%16 = load i32, i32* %4
%17 = getelementptr inbounds i32, i32* %1, i64 %14
store i32 %16, i32* %17
%18 = add nuw i64 %14, 1
%19 = call i32* @fgets(i8* %5, i32 20000, i32* %7)
%20 = icmp ne i32* %19, null
%21 = load i8, i8* %5
%22 = icmp ne i8 %21, 0
%23 = select i1 %20, i1 %22, i1 false
br i1 %23, label %13, label %24
24: ; preds = %13
%25 = trunc i64 %18 to i32
br label %26
26: ; preds = %24, %2
%27 = phi i32 [ 0, %2 ], [ %25, %24 ]
ret i32 %27
}