#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*/ exit(int);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char **argv) {
  char *p;
  int fd, readsz;
  ++argv;
  if (!(p = malloc(1024 * 16))) {
    printf("failed to malloc memory\n");
    exit(1);
  }
  printf("opening %s...\n", *argv);
  fd = open(*argv, 0);
  readsz = read(fd, p, 1024 * 16);
  printf("read %d bytes\nContents:\n______________________________\n%s", readsz,
         p);
  printf("\n_______________________________\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    $0x4000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a2 <main+0x52>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x4000,%edx
call   1040 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0x4000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
jne    118c <main+0x2c>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rax,%rbx
mov    0x8(%r14),%rsi
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r14),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x4000,%edx
call   1050 <read@plt>
lea    0xe4d(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"failed to malloc memory\0A\00"
@.str.1 = [15 x i8] c"opening %s...\0A\00"
@.str.2 = [58 x i8] c"read %d bytes\0AContents:\0A______________________________\0A%s\00"
@.str.3 = [34 x i8] c"\0A_______________________________\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i32 1
store i8** %10, i8*** %5
%11 = call i8* @malloc(i32 16384)
store i8* %11, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32 @open(i8* %21, i32 0)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = load i8*, i8** %6
%25 = call i32 @read(i32 %23, i8* %24, i32 16384)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = load i8*, i8** %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 %26, i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"opening %s...\0A\00"
@.str.2 = [58 x i8] c"read %d bytes\0AContents:\0A______________________________\0A%s\00"
@str = [24 x i8] c"failed to malloc memory\00"
@str.4 = [33 x i8] c"\0A_______________________________\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = tail call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %3
%13 = tail call i32 @open(i8* %12, i32 0)
%14 = tail call i32 @read(i32 %13, i8* %4, i32 16384)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 %14, i8* %4)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.4, i64 0, i64 0))
%17 = tail call i32 @exit(i32 0)
unreachable
}