#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 atoi(char *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int file2array(char *filename, int set[]) {
  FILE *fp;
  char *line = NULL;
  size_t maxlen = 8;
  int cline = 0;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    int errsv = errno;
    char error_message[32];
    sprintf(error_message, "Error opening %s", filename);
    perror(error_message);
    return errsv;
  }
  while (getline(&line, &maxlen, fp) > 0) {
    set[cline] = atoi(line);
    cline++;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<file2array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x8,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11da <file2array+0x7a>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe41(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <perror@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122e <file2array+0xce>
jmp    11df <file2array+0x7f>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0x0,%rax
jle    121e <file2array+0xbe>
mov    -0x28(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11df <file2array+0x7f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file2array>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
movq   $0x0,(%rsp)
movq   $0x8,0x8(%rsp)
lea    0xe77(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     11fa <file2array+0x9a>
mov    %rax,%r14
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1070 <getline@plt>
test   %rax,%rax
jle    11e2 <file2array+0x82>
mov    %rsp,%r15
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,(%rbx)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1070 <getline@plt>
add    $0x4,%rbx
test   %rax,%rax
jg     11c0 <file2array+0x60>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2ddf(%rip),%rax
mov    (%rax),%ebx
lea    0xdf8(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rdx
call   1080 <sprintf@plt>
mov    %r14,%rdi
call   1050 <perror@plt>
jmp    11ec <file2array+0x8c>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@.str.1 = [17 x i8] c"Error opening %s\00"
define i32 @file2array(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca [32 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* null, i8** %7
store i64 8, i64* %8
store i32 0, i32* %9
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i32, i32* @errno
store i32 %17, i32* %10
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%19 = load i8*, i8** %4
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%22 = call i32 @perror(i8* %21)
%23 = load i32, i32* %10
store i32 %23, i32* %3
br label %41
24: ; preds = %2
br label %25
25: ; preds = %29, %24
%26 = load i32*, i32** %6
%27 = call i64 @getline(i8** %7, i64* %8, i32* %26)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i8*, i8** %7
%31 = call i32 @atoi(i8* %30)
%32 = load i32*, i32** %5
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %25
38: ; preds = %25
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
store i32 0, i32* %3
br label %41
41: ; preds = %38, %16
%42 = load i32, i32* %3
ret i32 %42
}

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