#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 */
char *calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ strchr(char *, char *);
char *read_file(int len, char *name) {
  if (!name || !*name)
    return NULL;
  if (strchr(name, "."))
    return NULL;
  else if (strchr(name, "/"))
    return NULL;
  FILE *fp = fopen(name, "r");
  if (!fp)
    return NULL;
  char *buf = calloc(len + 1, 1);
  fread(buf, 1, len, fp);
  fclose(fp);
  return buf;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1177 <read_file+0x27>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1184 <read_file+0x34>
movq   $0x0,-0x8(%rbp)
jmp    123d <read_file+0xed>
mov    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11ab <read_file+0x5b>
movq   $0x0,-0x8(%rbp)
jmp    123d <read_file+0xed>
mov    -0x18(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11d2 <read_file+0x82>
movq   $0x0,-0x8(%rbp)
jmp    123d <read_file+0xed>
jmp    11d7 <read_file+0x87>
mov    -0x18(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1203 <read_file+0xb3>
movq   $0x0,-0x8(%rbp)
jmp    123d <read_file+0xed>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     118d <read_file+0x3d>
mov    %rsi,%rbx
cmpb   $0x0,(%rsi)
je     118d <read_file+0x3d>
mov    %edi,%r14d
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strchr@plt>
test   %rax,%rax
jne    118d <read_file+0x3d>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strchr@plt>
test   %rax,%rax
je     1198 <read_file+0x48>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     118d <read_file+0x3d>
mov    %rax,%r15
lea    0x1(%r14),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    118f <read_file+0x3f>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [2 x i8] c"r\00"
define i8* @read_file(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10, %2
store i8* null, i8** %3
br label %43
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = call i64 @strchr(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i8* null, i8** %3
br label %43
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = call i64 @strchr(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i8* null, i8** %3
br label %43
25: ; preds = %20
br label %26
26: ; preds = %25
%27 = load i8*, i8** %5
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = icmp ne i32* %29, null
br i1 %30, label %32, label %31
31: ; preds = %26
store i8* null, i8** %3
br label %43
32: ; preds = %26
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
%35 = call i8* @calloc(i32 %34, i32 1)
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = load i32, i32* %4
%38 = load i32*, i32** %6
%39 = call i32 @fread(i8* %36, i32 1, i32 %37, i32* %38)
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = load i8*, i8** %7
store i8* %42, i8** %3
br label %43
43: ; preds = %32, %31, %24, %19, %14
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [2 x i8] c"r\00"
define noalias i8* @read_file(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %21, label %4
4: ; preds = %2
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = tail call i64 @strchr(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = tail call i64 @strchr(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = add nsw i32 %0, 1
%18 = tail call i8* @calloc(i32 %17, i32 1)
%19 = tail call i32 @fread(i8* %18, i32 1, i32 %0, i32* %14)
%20 = tail call i32 @fclose(i32* %14)
br label %21
21: ; preds = %16, %13, %10, %7, %2, %4
%22 = phi i8* [ null, %4 ], [ null, %2 ], [ null, %7 ], [ null, %10 ], [ %18, %16 ], [ null, %13 ]
ret i8* %22
}