#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*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
char *get_code(char *filename) {
  FILE *f;
  int len;
  int read;
  int allocated;
  char *code;
  if (strcmp(filename, "-") == 0)
    f = stdin;
  else
    f = fopen(filename, "rb");
  if (f == NULL) {
    fprintf(stderr, "Cannot open %s\n", filename);
    abort();
  }
  allocated = 1024;
  code = (char *)malloc(1024);
  len = 0;
  do {
    if (len + 1024 > allocated) {
      allocated = 2 * len + 1024;
      code = (char *)realloc(code, allocated);
    }
    read = fread(code + len, 1, 1024, f);
    len += read;
  } while (read);
  code[len] = 0;
  if (f != stdin)
    fclose(f);
  return code;
}


x86 assembly (clang, -O0):
<get_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11b9 <get_code+0x39>
mov    0x2e3b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    11cd <get_code+0x4d>
mov    -0x8(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f8 <get_code+0x78>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe19(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x400,-0x1c(%rbp)
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x400,%eax
cmp    -0x1c(%rbp),%eax
jle    1243 <get_code+0xc3>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0x400,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1214 <get_code+0x94>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    0x2d5a(%rip),%rcx
cmp    (%rcx),%rax
je     12a0 <get_code+0x120>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_code>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe6f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     123a <get_code+0xba>
lea    0xe5c(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
test   %r14,%r14
je     124d <get_code+0xcd>
mov    $0x400,%ebp
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
jmp    11ee <get_code+0x6e>
movslq %ebx,%rdi
add    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
add    %eax,%ebx
test   %eax,%eax
je     1210 <get_code+0x90>
lea    0x400(%rbx),%eax
cmp    %ebp,%eax
jle    11d0 <get_code+0x50>
lea    (%rbx,%rbx,1),%ebp
add    $0x400,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
call   1090 <realloc@plt>
mov    %rax,%r15
jmp    11d0 <get_code+0x50>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    0x2dc9(%rip),%rax
cmp    (%rax),%r14
je     122c <get_code+0xac>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da7(%rip),%rax
mov    (%rax),%r14
test   %r14,%r14
jne    11ba <get_code+0x3a>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
define i8* @get_code(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32*, i32** @stdin
store i32* %12, i32** %3
br label %16
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %3
br label %16
16: ; preds = %13, %11
%17 = load i32*, i32** %3
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %16
store i32 1024, i32* %6
%25 = call i64 @malloc(i32 1024)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %7
store i32 0, i32* %4
br label %27
27: ; preds = %50, %24
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1024
%30 = load i32, i32* %6
%31 = icmp sgt i32 %29, %30
br i1 %31, label %32, label %40
32: ; preds = %27
%33 = load i32, i32* %4
%34 = mul nsw i32 2, %33
%35 = add nsw i32 %34, 1024
store i32 %35, i32* %6
%36 = load i8*, i8** %7
%37 = load i32, i32* %6
%38 = call i64 @realloc(i8* %36, i32 %37)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %7
br label %40
40: ; preds = %32, %27
%41 = load i8*, i8** %7
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i32*, i32** %3
%46 = call i32 @fread(i8* %44, i32 1, i32 1024, i32* %45)
store i32 %46, i32* %5
%47 = load i32, i32* %5
%48 = load i32, i32* %4
%49 = add nsw i32 %48, %47
store i32 %49, i32* %4
br label %50
50: ; preds = %40
%51 = load i32, i32* %5
%52 = icmp ne i32 %51, 0
br i1 %52, label %27, label %53
53: ; preds = %50
%54 = load i8*, i8** %7
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 0, i8* %57
%58 = load i32*, i32** %3
%59 = load i32*, i32** @stdin
%60 = icmp ne i32* %58, %59
br i1 %60, label %61, label %64
61: ; preds = %53
%62 = load i32*, i32** %3
%63 = call i32 @fclose(i32* %62)
br label %64
64: ; preds = %61, %53
%65 = load i8*, i8** %7
ret i8* %65
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
define i8* @get_code(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i32*, i32** @stdin
br label %8
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = phi i32* [ %5, %4 ], [ %7, %6 ]
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %8
%16 = tail call i64 @malloc(i32 1024)
%17 = inttoptr i64 %16 to i8*
br label %18
18: ; preds = %29, %15
%19 = phi i32 [ 0, %15 ], [ %35, %29 ]
%20 = phi i32 [ 1024, %15 ], [ %30, %29 ]
%21 = phi i8* [ %17, %15 ], [ %31, %29 ]
%22 = add nsw i32 %19, 1024
%23 = icmp sgt i32 %22, %20
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = shl nsw i32 %19, 1
%26 = add nsw i32 %25, 1024
%27 = tail call i64 @realloc(i8* %21, i32 %26)
%28 = inttoptr i64 %27 to i8*
br label %29
29: ; preds = %24, %18
%30 = phi i32 [ %26, %24 ], [ %20, %18 ]
%31 = phi i8* [ %28, %24 ], [ %21, %18 ]
%32 = sext i32 %19 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
%34 = tail call i32 @fread(i8* %33, i32 1, i32 1024, i32* %9)
%35 = add nsw i32 %34, %19
%36 = icmp eq i32 %34, 0
br i1 %36, label %37, label %18
37: ; preds = %29
%38 = sext i32 %35 to i64
%39 = getelementptr inbounds i8, i8* %31, i64 %38
store i8 0, i8* %39
%40 = load i32*, i32** @stdin
%41 = icmp eq i32* %9, %40
br i1 %41, label %44, label %42
42: ; preds = %37
%43 = tail call i32 @fclose(i32* %9)
br label %44
44: ; preds = %42, %37
ret i8* %31
}