#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int *malloc(int);
int *get_key(char *path, int *key_size) {
  FILE *key_file;
  int *key;
  int size;
  char read;
  key_file = fopen(path, "r");
  if (key_file != NULL) {
    fseek(key_file, 0, SEEK_END);
    size = ftell(key_file);
    fseek(key_file, 0, SEEK_SET);
    key = malloc(sizeof(int) * size);
    while (fscanf(key_file, "%c", &read) != EOF) {
      key[*key_size] = read - '0';
      (*key_size)++;
    }
    fclose(key_file);
  } else {
    errx(-1, "It was not possible to open the key file");
  }
  return key;
}


x86 assembly (clang, -O0):
<get_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     123d <get_key+0xcd>
mov    -0x18(%rbp),%rdi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe11(%rip),%rsi
lea    -0x25(%rbp),%rdx
call   1050 <fscanf@plt>
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
je     122f <get_key+0xbf>
movsbl -0x25(%rbp),%edx
sub    $0x30,%edx
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11e6 <get_key+0x76>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    124e <get_key+0xde>
mov    $0xffffffff,%edi
lea    0xdbc(%rip),%rsi
call   1040 <errx@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xe7b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1232 <get_key+0xc2>
mov    %rax,%r14
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
shl    $0x2,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe28(%rip),%rsi
lea    0x7(%rsp),%rdx
mov    %r14,%rdi
call   1050 <fscanf@plt>
mov    0x2df2(%rip),%rbp
cmp    0x0(%rbp),%rax
je     1228 <get_key+0xb8>
lea    0xe07(%rip),%r12
lea    0x7(%rsp),%r13
movsbl 0x7(%rsp),%eax
add    $0xffffffd0,%eax
movslq (%rbx),%rcx
mov    %eax,(%r15,%rcx,4)
lea    0x1(%rcx),%eax
mov    %eax,(%rbx)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
cmp    0x0(%rbp),%rax
jne    1200 <get_key+0x90>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    1243 <get_key+0xd3>
lea    0xdcc(%rip),%rsi
mov    $0xffffffff,%edi
call   1040 <errx@plt>
mov    %r15,%rax
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"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.2 = [41 x i8] c"It was not possible to open the key file\00"
define i32* @get_key(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %3
store i32* %1, i32** %4
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %47
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = load i32, i32* @SEEK_END
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = load i32*, i32** %5
%18 = call i32 @ftell(i32* %17)
store i32 %18, i32* %7
%19 = load i32*, i32** %5
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = mul i64 4, %23
%25 = trunc i64 %24 to i32
%26 = call i32* @malloc(i32 %25)
store i32* %26, i32** %6
br label %27
27: ; preds = %32, %13
%28 = load i32*, i32** %5
%29 = call i64 @fscanf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%30 = load i64, i64* @EOF
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %44
32: ; preds = %27
%33 = load i8, i8* %8
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 48
%36 = load i32*, i32** %6
%37 = load i32*, i32** %4
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %36, i64 %39
store i32 %35, i32* %40
%41 = load i32*, i32** %4
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
store i32 %43, i32* %41
br label %27
44: ; preds = %27
%45 = load i32*, i32** %5
%46 = call i32 @fclose(i32* %45)
br label %49
47: ; preds = %2
%48 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
%50 = load i32*, i32** %6
ret i32* %50
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.2 = [41 x i8] c"It was not possible to open the key file\00"
define noalias i32* @get_key(i8* nocapture %0, i32* nocapture %1) {
%3 = alloca i8
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %30, label %6
6: ; preds = %2
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %4, i32 0, i32 %7)
%9 = tail call i32 @ftell(i32* %4)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %4, i32 0, i32 %10)
%12 = shl i32 %9, 2
%13 = tail call i32* @malloc(i32 %12)
%14 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %28, label %17
17: ; preds = %6, %17
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = add nsw i32 %19, -48
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %13, i64 %22
store i32 %20, i32* %23
%24 = add nsw i32 %21, 1
store i32 %24, i32* %1
%25 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %17
28: ; preds = %17, %6
%29 = call i32 @fclose(i32* %4)
br label %32
30: ; preds = %2
%31 = tail call i32 @errx(i32 -1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %28
%33 = phi i32* [ %13, %28 ], [ undef, %30 ]
ret i32* %33
}