#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 */
char *como_read_file(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char *contents = como_read_file("test_como_io.c");
  if (contents == NULL) {
    printf("ERROR READING");
  }
  printf("%s", contents);
  free(contents);
  contents = como_read_file("THIS_DOES_NOT_EXIST");
  if (contents == NULL) {
    printf("success\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1050 <como_read_file@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1168 <main+0x38>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe96(%rip),%rdi
call   1050 <como_read_file@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ac <main+0x7c>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1060 <como_read_file@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1163 <main+0x23>
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe9d(%rip),%rdi
call   1060 <como_read_file@plt>
test   %rax,%rax
jne    1199 <main+0x59>
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"test_como_io.c\00"
@.str.1 = [14 x i8] c"ERROR READING\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [20 x i8] c"THIS_DOES_NOT_EXIST\00"
@.str.4 = [9 x i8] c"success\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @como_read_file(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = load i8*, i8** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %2
%12 = call i32 @free(i8* %11)
%13 = call i8* @como_read_file(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i8* %13, i8** %2
%14 = load i8*, i8** %2
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %8
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"test_como_io.c\00"
@.str.1 = [14 x i8] c"ERROR READING\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [20 x i8] c"THIS_DOES_NOT_EXIST\00"
@str = [8 x i8] c"success\00"
define i32 @main() {
%1 = tail call i8* @como_read_file(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%7 = tail call i32 @free(i8* %1)
%8 = tail call i8* @como_read_file(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %5
ret i32 0
}