#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*/ n;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ fread(int *, int, int, int /*<<< orphan*/ *);
int fread_file(FILE *f, int *array, int len) {
  int i = 0;
  int n = 0;
  int successful_read = 0;
  int read_count = 0;
  while (i < len) {
    if (feof(f)) {
      break;
    }
    successful_read = (int)fread(&n, sizeof(n), 1, f);
    if (!successful_read) {
      break;
    }
    read_count = read_count + successful_read;
    array[i] = n;
    i = i + 1;
  }
  return read_count;
}


x86 assembly (clang, -O0):
<fread_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c1 <fread_file+0xa1>
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1173 <fread_file+0x53>
jmp    11c1 <fread_file+0xa1>
mov    -0x8(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    119c <fread_file+0x7c>
jmp    11c1 <fread_file+0xa1>
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114f <fread_file+0x2f>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
test   %edx,%edx
jle    118b <fread_file+0x6b>
mov    %rsi,%r14
mov    %rdi,%r13
mov    %edx,%r12d
xor    %ebx,%ebx
lea    0x4(%rsp),%r15
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r13,%rdi
call   1040 <feof@plt>
test   %rax,%rax
jne    118d <fread_file+0x6d>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     118d <fread_file+0x6d>
add    %eax,%ebp
mov    0x4(%rsp),%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <fread_file+0x30>
jmp    118d <fread_file+0x6d>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fread_file(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %27, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i32*, i32** %4
%17 = call i64 @feof(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %38
20: ; preds = %15
%21 = load i32*, i32** %4
%22 = call i64 @fread(i32* %8, i32 4, i32 1, i32* %21)
%23 = trunc i64 %22 to i32
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %20
br label %38
27: ; preds = %20
%28 = load i32, i32* %10
%29 = load i32, i32* %9
%30 = add nsw i32 %28, %29
store i32 %30, i32* %10
%31 = load i32, i32* %8
%32 = load i32*, i32** %5
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %11
38: ; preds = %26, %19, %11
%39 = load i32, i32* %10
ret i32 %39
}

LLVM IR (-O2):
define i32 @fread_file(i32* nocapture %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %24
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %18
%10 = phi i64 [ 0, %7 ], [ %22, %18 ]
%11 = phi i32 [ 0, %7 ], [ %19, %18 ]
%12 = tail call i64 @feof(i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = call i64 @fread(i32* %4, i32 4, i32 1, i32* %0)
%16 = trunc i64 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %14
%19 = add nsw i32 %11, %16
%20 = load i32, i32* %4
%21 = getelementptr inbounds i32, i32* %1, i64 %10
store i32 %20, i32* %21
%22 = add nuw nsw i64 %10, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %24, label %9
24: ; preds = %18, %9, %14, %3
%25 = phi i32 [ 0, %3 ], [ %11, %14 ], [ %11, %9 ], [ %19, %18 ]
ret i32 %25
}