#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ puts(char *);
int getNumberFromFile(char *file, int *dest, int size) {
  FILE *fp = fopen(file, "r");
  if (fp == NULL) {
    puts("Error");
    return -1;
  }
  int num = 0;
  int count = 0;
  while (fscanf(fp, "%d", &num) != EOF) {
    if (count == size) {
      fclose(fp);
      return -2;
    }
    dest[count] = num;
    count++;
  }
  fclose(fp);
  return count;
}


x86 assembly (clang, -O0):
<getNumberFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118a <getNumberFromFile+0x4a>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1208 <getNumberFromFile+0xc8>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe63(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <fscanf@plt>
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
je     11f9 <getNumberFromFile+0xb9>
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11dd <getNumberFromFile+0x9d>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1208 <getNumberFromFile+0xc8>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1198 <getNumberFromFile+0x58>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumberFromFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11cd <getNumberFromFile+0x8d>
mov    %rax,%r15
movl   $0x0,0x4(%rsp)
lea    0xe93(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0x2e61(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
je     11e5 <getNumberFromFile+0xa5>
mov    %ebp,%r13d
xor    %ebx,%ebx
lea    0xe6c(%rip),%r12
lea    0x4(%rsp),%rbp
nop
cmp    %rbx,%r13
je     11e0 <getNumberFromFile+0xa0>
mov    0x4(%rsp),%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1050 <fscanf@plt>
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%rax
jne    11a0 <getNumberFromFile+0x60>
jmp    11e5 <getNumberFromFile+0xa5>
lea    0xe2c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    11ed <getNumberFromFile+0xad>
mov    $0xfffffffe,%ebx
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x8,%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 = [6 x i8] c"Error\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
define i32 @getNumberFromFile(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %42
17: ; preds = %3
store i32 0, i32* %9
store i32 0, i32* %10
br label %18
18: ; preds = %30, %17
%19 = load i32*, i32** %8
%20 = call i64 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%21 = load i64, i64* @EOF
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %18
%24 = load i32, i32* %10
%25 = load i32, i32* %7
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32*, i32** %8
%29 = call i32 @fclose(i32* %28)
store i32 -2, i32* %4
br label %42
30: ; preds = %23
%31 = load i32, i32* %9
%32 = load i32*, i32** %6
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %18
38: ; preds = %18
%39 = load i32*, i32** %8
%40 = call i32 @fclose(i32* %39)
%41 = load i32, i32* %10
store i32 %41, i32* %4
br label %42
42: ; preds = %38, %27, %15
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"Error\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
define i32 @getNumberFromFile(i8* nocapture %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca i32
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %31
9: ; preds = %3
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
br i1 %13, label %28, label %14
14: ; preds = %9
%15 = zext i32 %2 to i64
br label %16
16: ; preds = %14, %19
%17 = phi i64 [ 0, %14 ], [ %22, %19 ]
%18 = icmp eq i64 %17, %15
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = load i32, i32* %4
%21 = getelementptr inbounds i32, i32* %1, i64 %17
store i32 %20, i32* %21
%22 = add nuw nsw i64 %17, 1
%23 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %16
26: ; preds = %19
%27 = trunc i64 %22 to i32
br label %28
28: ; preds = %16, %9, %26
%29 = phi i32 [ 0, %9 ], [ %27, %26 ], [ -2, %16 ]
%30 = call i32 @fclose(i32* %5)
br label %31
31: ; preds = %28, %7
%32 = phi i32 [ -1, %7 ], [ %29, %28 ]
ret i32 %32
}