#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 fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
char *slurp(int /*<<< orphan*/ *);
char *pslurp(const char *path) {
  FILE *fh = fopen(path, "r");
  char *content;
  int ret;
  if (fh == NULL)
    return NULL;
  content = slurp(fh);
  ret = fclose(fh);
  if (content == NULL || ret != 0) {
    free(content);
    return NULL;
  }
  return content;
}


x86 assembly (clang, -O0):
<pslurp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1178 <pslurp+0x38>
movq   $0x0,-0x8(%rbp)
jmp    11c4 <pslurp+0x84>
mov    -0x18(%rbp),%rdi
call   1040 <slurp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a6 <pslurp+0x66>
cmpl   $0x0,-0x24(%rbp)
je     11bc <pslurp+0x7c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c4 <pslurp+0x84>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pslurp>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     117c <pslurp+0x3c>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <slurp@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %r14,%r14
je     1174 <pslurp+0x34>
test   %eax,%eax
je     117f <pslurp+0x3f>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i8* @pslurp(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %27
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = call i8* @slurp(i32* %13)
store i8* %14, i8** %5
%15 = load i32*, i32** %4
%16 = call i32 @fclose(i32* %15)
store i32 %16, i32* %6
%17 = load i8*, i8** %5
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19, %12
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
store i8* null, i8** %2
br label %27
25: ; preds = %19
%26 = load i8*, i8** %5
store i8* %26, i8** %2
br label %27
27: ; preds = %25, %22, %11
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i8* @pslurp(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i8* @slurp(i32* %2)
%6 = tail call i32 @fclose(i32* %2)
%7 = icmp eq i8* %5, null
%8 = icmp ne i32 %6, 0
%9 = or i1 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @free(i8* %5)
br label %12
12: ; preds = %4, %1, %10
%13 = phi i8* [ null, %10 ], [ null, %1 ], [ %5, %4 ]
ret i8* %13
}