#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 */
char EOF;
int /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/ *);
int getStart(int /*<<< orphan*/ *);
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
unsigned char *getHeader(FILE *myFile) {
  unsigned int size;
  size = getStart(myFile) - 1;
  unsigned char *array;
  array = malloc(size);
  if (array == NULL) {
    perror("error while allocating memory see input/initArray");
    exit(-1);
  }
  unsigned int i;
  for (i = 0; i < size; i++) {
    char temp = fgetc(myFile);
    if (temp != EOF) {
      *(array + i) = temp;
    } else {
      perror("error in input/getHeader, end of file reached");
      exit(-3);
    }
  }
  rewind(myFile);
  return array;
}


x86 assembly (clang, -O0):
<getHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getStart@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <getHeader+0x48>
lea    0xe67(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1218 <getHeader+0xb8>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
mov    0x2e16(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11ef <getHeader+0x8f>
mov    -0x1d(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1205 <getHeader+0xa5>
lea    0xe3c(%rip),%rdi
call   1070 <perror@plt>
mov    $0xfffffffd,%edi
call   1080 <exit@plt>
jmp    120a <getHeader+0xaa>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11af <getHeader+0x4f>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHeader>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1050 <getStart@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11e5 <getHeader+0x85>
mov    %rax,%r15
test   %ebp,%ebp
je     11bb <getHeader+0x5b>
mov    %ebp,%ebp
xor    %ebx,%ebx
mov    0x2e55(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%al
je     11cf <getHeader+0x6f>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <getHeader+0x40>
mov    %r14,%rdi
call   1030 <rewind@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5c(%rip),%rdi
call   1070 <perror@plt>
mov    $0xfffffffd,%edi
call   1080 <exit@plt>
lea    0xe14(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"error while allocating memory see input/initArray\00"
@EOF = global i8 0
@.str.1 = [46 x i8] c"error in input/getHeader, end of file reached\00"
define i8* @getHeader(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = call i32 @getStart(i32* %7)
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %1
store i32 0, i32* %5
br label %18
18: ; preds = %40, %17
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = load i32*, i32** %2
%24 = call signext i8 @fgetc(i32* %23)
store i8 %24, i8* %6
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
%27 = load i8, i8* @EOF
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %26, %28
br i1 %29, label %30, label %36
30: ; preds = %22
%31 = load i8, i8* %6
%32 = load i8*, i8** %4
%33 = load i32, i32* %5
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %39
36: ; preds = %22
%37 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @exit(i32 -3)
unreachable
39: ; preds = %30
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add i32 %41, 1
store i32 %42, i32* %5
br label %18
43: ; preds = %18
%44 = load i32*, i32** %2
%45 = call i32 @rewind(i32* %44)
%46 = load i8*, i8** %4
ret i8* %46
}

LLVM IR (-O2):
@.str = [50 x i8] c"error while allocating memory see input/initArray\00"
@EOF = global i8 0
@.str.1 = [46 x i8] c"error in input/getHeader, end of file reached\00"
define noalias i8* @getHeader(i32* %0) {
%2 = tail call i32 @getStart(i32* %0)
%3 = add nsw i32 %2, -1
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = icmp eq i32 %3, 0
br i1 %7, label %25, label %8
8: ; preds = %6
%9 = zext i32 %3 to i64
br label %13
10: ; preds = %1
%11 = tail call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %8, %18
%14 = phi i64 [ 0, %8 ], [ %20, %18 ]
%15 = tail call signext i8 @fgetc(i32* %0)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = getelementptr inbounds i8, i8* %4, i64 %14
store i8 %15, i8* %19
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %9
br i1 %21, label %25, label %13
22: ; preds = %13
%23 = tail call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -3)
unreachable
25: ; preds = %18, %6
%26 = tail call i32 @rewind(i32* %0)
ret i8* %4
}