#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 */
struct stat {
  int st_size;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int fstat(int, struct stat *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, scalar_t__);
char *load_banner(void) {
  char *buf = NULL, *p;
  struct stat st;
  int fd;
  ssize_t remaining, count;
  fd = open("/etc/issue", O_RDONLY);
  if (fd == -1)
    goto out;
  if (fstat(fd, &st) == -1)
    goto out;
  buf = malloc(st.st_size + 1);
  if (buf == NULL)
    goto out;
  remaining = st.st_size;
  p = buf;
  while (remaining > 0) {
    count = read(fd, p, remaining);
    if (count == -1) {
      close(fd);
      goto out;
    }
    p += count;
    remaining -= count;
  }
  buf[st.st_size] = '\0';
  close(fd);
  return buf;
out:
  free(buf);
  return "\n\\s \\r (\\n) (\\l)\r\n\n";
}


x86 assembly (clang, -O0):
<load_banner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x10(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1197 <load_banner+0x37>
jmp    1258 <load_banner+0xf8>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11b1 <load_banner+0x51>
jmp    1258 <load_banner+0xf8>
mov    -0x20(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d0 <load_banner+0x70>
jmp    1258 <load_banner+0xf8>
movslq -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x30(%rbp)
jle    1237 <load_banner+0xd7>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <read@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0xffffffffffffffff,-0x38(%rbp)
jne    1217 <load_banner+0xb7>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
jmp    1258 <load_banner+0xf8>
mov    -0x38(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    11e0 <load_banner+0x80>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    126c <load_banner+0x10c>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xda3(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_banner>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11eb <load_banner+0x8b>
mov    %eax,%r15d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
je     11eb <load_banner+0x8b>
movslq 0x8(%rsp),%r12
lea    0x1(%r12),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11eb <load_banner+0x8b>
mov    %rax,%r14
test   %r12d,%r12d
jle    11dc <load_banner+0x7c>
mov    %r12,%rbx
mov    %r14,%rbp
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <read@plt>
cmp    $0xffffffffffffffff,%rax
je     120d <load_banner+0xad>
add    %rax,%rbp
sub    %rax,%rbx
jg     11c0 <load_banner+0x60>
movb   $0x0,(%r14,%r12,1)
mov    %r15d,%edi
call   1040 <close@plt>
jmp    11fd <load_banner+0x9d>
xor    %r14d,%r14d
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe0e(%rip),%r14
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%edi
call   1040 <close@plt>
jmp    11ee <load_banner+0x8e>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [11 x i8] c"/etc/issue\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"\0A\\s \\r (\\n) (\\l)\0D\0A\0A\00"
define i8* @load_banner() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i8* null, i8** %2
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %0
br label %60
13: ; preds = %0
%14 = load i32, i32* %5
%15 = call i32 @fstat(i32 %14, %struct.stat* %4)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %13
br label %60
18: ; preds = %13
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %2
%23 = load i8*, i8** %2
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %18
br label %60
26: ; preds = %18
%27 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
store i64 %29, i64* %6
%30 = load i8*, i8** %2
store i8* %30, i8** %3
br label %31
31: ; preds = %44, %26
%32 = load i64, i64* %6
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %51
34: ; preds = %31
%35 = load i32, i32* %5
%36 = load i8*, i8** %3
%37 = load i64, i64* %6
%38 = call i64 @read(i32 %35, i8* %36, i64 %37)
store i64 %38, i64* %7
%39 = load i64, i64* %7
%40 = icmp eq i64 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = load i32, i32* %5
%43 = call i32 @close(i32 %42)
br label %60
44: ; preds = %34
%45 = load i64, i64* %7
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 %45
store i8* %47, i8** %3
%48 = load i64, i64* %7
%49 = load i64, i64* %6
%50 = sub nsw i64 %49, %48
store i64 %50, i64* %6
br label %31
51: ; preds = %31
%52 = load i8*, i8** %2
%53 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%54 = load i32, i32* %53
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8 0, i8* %56
%57 = load i32, i32* %5
%58 = call i32 @close(i32 %57)
%59 = load i8*, i8** %2
store i8* %59, i8** %1
br label %63
60: ; preds = %41, %25, %17, %12
%61 = load i8*, i8** %2
%62 = call i32 @free(i8* %61)
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %63
63: ; preds = %60, %51
%64 = load i8*, i8** %1
ret i8* %64
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [11 x i8] c"/etc/issue\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"\0A\\s \\r (\\n) (\\l)\0D\0A\0A\00"
define i8* @load_banner() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %32, label %6
6: ; preds = %0
%7 = call i32 @fstat(i32 %4, %struct.stat* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %32, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %32, label %15
15: ; preds = %9
%16 = sext i32 %11 to i64
%17 = icmp sgt i32 %11, 0
br i1 %17, label %18, label %29
18: ; preds = %15, %25
%19 = phi i64 [ %27, %25 ], [ %16, %15 ]
%20 = phi i8* [ %26, %25 ], [ %13, %15 ]
%21 = tail call i64 @read(i32 %4, i8* %20, i64 %19)
%22 = icmp eq i64 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @close(i32 %4)
br label %32
25: ; preds = %18
%26 = getelementptr inbounds i8, i8* %20, i64 %21
%27 = sub nsw i64 %19, %21
%28 = icmp sgt i64 %27, 0
br i1 %28, label %18, label %29
29: ; preds = %25, %15
%30 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 0, i8* %30
%31 = tail call i32 @close(i32 %4)
br label %35
32: ; preds = %9, %6, %0, %23
%33 = phi i8* [ null, %0 ], [ null, %6 ], [ null, %9 ], [ %13, %23 ]
%34 = tail call i32 @free(i8* %33)
br label %35
35: ; preds = %32, %29
%36 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %32 ], [ %13, %29 ]
ret i8* %36
}