#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
char *realloc(char *, int);
int /*<<< orphan*/ stderr;
char *get_src(char *path) {
  int fd;
  char *src;
  int i;
  int r;
  r = 0;
  fprintf(stderr, "Opening %s\n", path);
  if ((fd = open(path, O_RDONLY)) <= 0) {
    fprintf(stderr, "%sFailed to open %s%s\n", "\033[31m", path, "\033[0m");
    return (NULL);
  }
  if ((src = malloc(50 + 1)) == NULL) {
    fprintf(stderr, "%sFailed to get %s:Malloc failed%s\n", "\033[31m", path,
            "\033[0m");
    return (NULL);
  }
  while ((i = read(fd, &src[r], 50)) > 0) {
    r = r + i;
    if ((src = realloc(src, r + 50 + 1)) == NULL) {
      fprintf(stderr, "%sFailed to get %s:Malloc failed%s\n", "\033[31m", path,
              "\033[0m");
      return (NULL);
    }
  }
  src[r] = '\0';
  close(fd);
  return (src);
}


x86 assembly (clang, -O0):
<get_src>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jg     11e2 <get_src+0x82>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xe4c(%rip),%rsi
lea    0xe5c(%rip),%rdx
lea    0xe5b(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12d9 <get_src+0x179>
mov    $0x33,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1230 <get_src+0xd0>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xe20(%rip),%rsi
lea    0xe0e(%rip),%rdx
lea    0xe0d(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12d9 <get_src+0x179>
jmp    1235 <get_src+0xd5>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
movslq -0x28(%rbp),%rax
add    %rax,%rsi
mov    $0x32,%edx
call   1040 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    12bd <get_src+0x15d>
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
add    $0x32,%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12b8 <get_src+0x158>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xd98(%rip),%rsi
lea    0xd86(%rip),%rdx
lea    0xd85(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12d9 <get_src+0x179>
jmp    1235 <get_src+0xd5>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_src>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e63(%rip),%r12
mov    (%r12),%edi
lea    0xe80(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <open@plt>
test   %eax,%eax
jle    1202 <get_src+0xa2>
mov    %eax,%r15d
mov    $0x33,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11f5 <get_src+0x95>
mov    %rax,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movslq %ebx,%rbp
add    %r13,%rbp
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x32,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    123a <get_src+0xda>
lea    (%rax,%rbx,1),%ebp
lea    (%rax,%rbx,1),%esi
add    $0x33,%esi
mov    %r13,%rdi
call   1070 <realloc@plt>
mov    %rax,%r13
mov    %ebp,%ebx
test   %rax,%rax
jne    11c0 <get_src+0x60>
mov    (%r12),%edi
lea    0xe2e(%rip),%rsi
jmp    120d <get_src+0xad>
mov    (%r12),%edi
lea    0xdff(%rip),%rsi
lea    0xe0f(%rip),%rdx
lea    0xe0e(%rip),%r8
xor    %r13d,%r13d
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,0x0(%rbp)
mov    %r15d,%edi
call   1030 <close@plt>
jmp    1228 <get_src+0xc8>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"Opening %s\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"%sFailed to open %s%s\0A\00"
@.str.2 = [6 x i8] c"\1B[31m\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
@.str.4 = [36 x i8] c"%sFailed to get %s:Malloc failed%s\0A\00"
define i8* @get_src(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %3
%10 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %3
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %4
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %3
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %2
br label %58
19: ; preds = %1
%20 = call i8* @malloc(i32 51)
store i8* %20, i8** %5
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %3
%25 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %2
br label %58
26: ; preds = %19
br label %27
27: ; preds = %49, %26
%28 = load i32, i32* %4
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = call i32 @read(i32 %28, i8* %32, i32 50)
store i32 %33, i32* %6
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %50
35: ; preds = %27
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = add nsw i32 %36, %37
store i32 %38, i32* %7
%39 = load i8*, i8** %5
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 50
%42 = add nsw i32 %41, 1
%43 = call i8* @realloc(i8* %39, i32 %42)
store i8* %43, i8** %5
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %3
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %2
br label %58
49: ; preds = %35
br label %27
50: ; preds = %27
%51 = load i8*, i8** %5
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
%55 = load i32, i32* %4
%56 = call i32 @close(i32 %55)
%57 = load i8*, i8** %5
store i8* %57, i8** %2
br label %58
58: ; preds = %50, %45, %22, %15
%59 = load i8*, i8** %2
ret i8* %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"Opening %s\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"%sFailed to open %s%s\0A\00"
@.str.2 = [6 x i8] c"\1B[31m\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
@.str.4 = [36 x i8] c"%sFailed to get %s:Malloc failed%s\0A\00"
define i8* @get_src(i8* %0) {
%2 = load i32, i32* @stderr
%3 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %33
10: ; preds = %1
%11 = tail call dereferenceable_or_null(51) i8* @malloc(i32 51)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %33
16: ; preds = %10, %23
%17 = phi i8* [ %26, %23 ], [ %11, %10 ]
%18 = phi i32 [ %24, %23 ], [ 0, %10 ]
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = tail call i32 @read(i32 %5, i8* %20, i32 50)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %16
%24 = add nsw i32 %21, %18
%25 = add nsw i32 %24, 51
%26 = tail call i8* @realloc(i8* %17, i32 %25)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %16
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %33
31: ; preds = %16
store i8 0, i8* %20
%32 = tail call i32 @close(i32 %5)
br label %33
33: ; preds = %31, %28, %13, %7
%34 = phi i8* [ null, %7 ], [ null, %13 ], [ null, %28 ], [ %17, %31 ]
ret i8* %34
}