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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ mpz_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strlen(char *);
int fromFiletoArray(char filepath[], mpz_t arr[]) {
  FILE *fp;
  char str[2048];
  int i = 0;
  if ((fp = fopen(filepath, "r")) == NULL) {
    printf("Failed to open %s\n", filepath);
    return -1;
  }
  while (fgets(str, 1024, fp) != NULL) {
    if (strlen(str) <= 0)
      break;
    mpz_set_str(arr[i], str, 10);
    i++;
  }
  fclose(fp);
  return i;
}


x86 assembly (clang, -O0):
<fromFiletoArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x824(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b7 <fromFiletoArray+0x57>
mov    -0x10(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <fromFiletoArray+0xdb>
jmp    11bc <fromFiletoArray+0x5c>
lea    -0x820(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1229 <fromFiletoArray+0xc9>
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jg     11f6 <fromFiletoArray+0x96>
jmp    1229 <fromFiletoArray+0xc9>
mov    -0x18(%rbp),%rax
movslq -0x824(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x820(%rbp),%rsi
mov    $0xa,%edx
call   1070 <mpz_set_str@plt>
mov    -0x824(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x824(%rbp)
jmp    11bc <fromFiletoArray+0x5c>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fromFiletoArray>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f1 <fromFiletoArray+0x91>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11e7 <fromFiletoArray+0x87>
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    11e7 <fromFiletoArray+0x87>
mov    (%r14,%rbx,4),%edi
mov    %r12,%rsi
mov    $0xa,%edx
call   1070 <mpz_set_str@plt>
add    $0x1,%rbx
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <fromFiletoArray+0x50>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    1205 <fromFiletoArray+0xa5>
lea    0xe0a(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [19 x i8] c"Failed to open %s\0A\00"
define i32 @fromFiletoArray(i8* %0, i32* nocapture %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%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 %10, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 1024, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %26, label %12
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %29
12: ; preds = %7, %16
%13 = phi i64 [ %20, %16 ], [ 0, %7 ]
%14 = call i64 @strlen(i8* %4)
%15 = icmp slt i64 %14, 1
br i1 %15, label %23, label %16
16: ; preds = %12
%17 = getelementptr inbounds i32, i32* %1, i64 %13
%18 = load i32, i32* %17
%19 = call i32 @mpz_set_str(i32 %18, i8* %4, i32 10)
%20 = add nuw i64 %13, 1
%21 = call i32* @fgets(i8* %4, i32 1024, i32* %5)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %12
23: ; preds = %12, %16
%24 = phi i64 [ %20, %16 ], [ %13, %12 ]
%25 = trunc i64 %24 to i32
br label %26
26: ; preds = %23, %7
%27 = phi i32 [ 0, %7 ], [ %25, %23 ]
%28 = call i32 @fclose(i32* %5)
br label %29
29: ; preds = %26, %10
%30 = phi i32 [ -1, %10 ], [ %27, %26 ]
ret i32 %30
}