#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 /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fputs("Error - wrong number of argumets", stderr);
    exit(1);
  }
  char *name = argv[1];
  char *file;
  FILE *fp = fopen(name, "r");
  if (fp == NULL) {
    fputs("Can't open input file \n", stderr);
    exit(1);
  }
  fseek(fp, 0, SEEK_END);
  size_t sizeOfFile = ftell(fp), bytesRead;
  fseek(fp, 0, SEEK_SET);
  file = (char *)malloc(sizeOfFile);
  if (file == NULL) {
    fputs("Reading allocating memory\n", stderr);
    exit(1);
  }
  bytesRead = fread(file, sizeof(char), sizeOfFile, fp);
  if (bytesRead != sizeOfFile) {
    fputs("Reading error\n", stderr);
    exit(1);
  }
  fclose(fp);
  free(file);
  puts("Done ;)\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11df <main+0x3f>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0xe30(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1229 <main+0x89>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    0xe09(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d7b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1295 <main+0xf5>
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
lea    0xdb5(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     12dc <main+0x13c>
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
lea    0xd89(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xd70(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    1247 <main+0xa7>
mov    0x8(%rsi),%rdi
lea    0xe68(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1259 <main+0xb9>
mov    %rax,%rbx
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r14
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r14,%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     126b <main+0xcb>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    %r14,%rax
jne    127d <main+0xdd>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xe2b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
lea    0xda9(%rip),%rdi
jmp    128d <main+0xed>
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
lea    0xdba(%rip),%rdi
jmp    128d <main+0xed>
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
lea    0xdc0(%rip),%rdi
jmp    128d <main+0xed>
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
lea    0xdc9(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"Error - wrong number of argumets\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Can't open input file \0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [27 x i8] c"Reading allocating memory\0A\00"
@.str.4 = [15 x i8] c"Reading error\0A\00"
@.str.5 = [9 x i8] c"Done ;)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %8
%23 = load i32*, i32** %8
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %17
%30 = load i32*, i32** %8
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i32 0, i32 %31)
%33 = load i32*, i32** %8
%34 = call i64 @ftell(i32* %33)
store i64 %34, i64* %9
%35 = load i32*, i32** %8
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i64, i64* %9
%39 = call i64 @malloc(i64 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %29
%44 = load i32, i32* @stderr
%45 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %29
%48 = load i8*, i8** %7
%49 = load i64, i64* %9
%50 = load i32*, i32** %8
%51 = call i64 @fread(i8* %48, i32 1, i64 %49, i32* %50)
store i64 %51, i64* %10
%52 = load i64, i64* %10
%53 = load i64, i64* %9
%54 = icmp ne i64 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %47
%56 = load i32, i32* @stderr
%57 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %47
%60 = load i32*, i32** %8
%61 = call i32 @fclose(i32* %60)
%62 = load i8*, i8** %7
%63 = call i32 @free(i8* %62)
%64 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Error - wrong number of argumets\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Can't open input file \0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [27 x i8] c"Reading allocating memory\0A\00"
@.str.4 = [15 x i8] c"Reading error\0A\00"
@.str.5 = [9 x i8] c"Done ;)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = load i32, i32* @SEEK_END
%19 = tail call i32 @fseek(i32* %11, i32 0, i32 %18)
%20 = tail call i64 @ftell(i32* %11)
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %11, i32 0, i32 %21)
%23 = tail call i64 @malloc(i64 %20)
%24 = inttoptr i64 %23 to i8*
%25 = icmp eq i64 %23, 0
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = tail call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = tail call i64 @fread(i8* %24, i32 1, i64 %20, i32* %11)
%32 = icmp eq i64 %31, %20
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = tail call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %30
%38 = tail call i32 @fclose(i32* %11)
%39 = tail call i32 @free(i8* %24)
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}