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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
uint8_t read_source_graph(char *name, void **out, uint32_t *buffSize,
                          FILE **file) {
  FILE *f = fopen(name, "r");
  if (f == NULL) {
    printf("[ERROR] Can't open source graph\n");
    return 1;
  }
  size_t size = 0;
  fseek(f, 0, SEEK_END);
  size = ftell(f);
  rewind(f);
  *out = malloc(size + 1);
  memset(*out, 0, size + 1);
  fread(*out, size, 1, f);
  *buffSize = size + 1;
  *file = f;
  return 0;
}


x86 assembly (clang, -O0):
<read_source_graph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11cf <read_source_graph+0x4f>
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <read_source_graph+0xe8>
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x38(%rbp),%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_source_graph>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
lea    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1212 <read_source_graph+0x92>
mov    %rax,%rbx
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %r14,(%rsp)
lea    0x1(%rbp),%r14
mov    %r14,%rdi
call   1080 <malloc@plt>
mov    %rax,(%r12)
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1060 <memset@plt>
mov    (%r12),%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r14,(%r15)
mov    (%rsp),%rax
mov    %rbx,(%rax)
jmp    1224 <read_source_graph+0xa4>
lea    0xde9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r13d
mov    %r13d,%eax
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"
@.str.1 = [33 x i8] c"[ERROR] Can't open source graph\0A\00"
@SEEK_END = global i32 0
define i32 @read_source_graph(i8* %0, i8** %1, i64* %2, i32** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i64*
%9 = alloca i32**
%10 = alloca i32*
%11 = alloca i64
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i64* %2, i64** %8
store i32** %3, i32*** %9
%12 = load i8*, i8** %6
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %10
%14 = load i32*, i32** %10
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %5
br label %45
18: ; preds = %4
store i64 0, i64* %11
%19 = load i32*, i32** %10
%20 = load i32, i32* @SEEK_END
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32*, i32** %10
%23 = call i64 @ftell(i32* %22)
store i64 %23, i64* %11
%24 = load i32*, i32** %10
%25 = call i32 @rewind(i32* %24)
%26 = load i64, i64* %11
%27 = add i64 %26, 1
%28 = call i8* @malloc(i64 %27)
%29 = load i8**, i8*** %7
store i8* %28, i8** %29
%30 = load i8**, i8*** %7
%31 = load i8*, i8** %30
%32 = load i64, i64* %11
%33 = add i64 %32, 1
%34 = call i32 @memset(i8* %31, i32 0, i64 %33)
%35 = load i8**, i8*** %7
%36 = load i8*, i8** %35
%37 = load i64, i64* %11
%38 = load i32*, i32** %10
%39 = call i32 @fread(i8* %36, i64 %37, i32 1, i32* %38)
%40 = load i64, i64* %11
%41 = add i64 %40, 1
%42 = load i64*, i64** %8
store i64 %41, i64* %42
%43 = load i32*, i32** %10
%44 = load i32**, i32*** %9
store i32* %43, i32** %44
store i32 0, i32* %5
br label %45
45: ; preds = %18, %16
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@str = [32 x i8] c"[ERROR] Can't open source graph\00"
define i32 @read_source_graph(i8* nocapture %0, i8** nocapture %1, i64* nocapture writeonly %2, i32** nocapture writeonly %3) {
%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 %7, label %9
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %19
9: ; preds = %4
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %5, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %5)
%13 = tail call i32 @rewind(i32* %5)
%14 = add i64 %12, 1
%15 = tail call i8* @malloc(i64 %14)
store i8* %15, i8** %1
%16 = tail call i32 @memset(i8* %15, i32 0, i64 %14)
%17 = load i8*, i8** %1
%18 = tail call i32 @fread(i8* %17, i64 %12, i32 1, i32* %5)
store i64 %14, i64* %2
store i32* %5, i32** %3
br label %19
19: ; preds = %9, %7
%20 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %20
}