#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*/ R_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *indexes(const char *path) {
  char *php = "/index.php";
  char *html = "/index.html";
  char *new_pathPHP = malloc(sizeof(strlen(path) + strlen(php) + 1));
  char *new_pathHTML = malloc(sizeof(strlen(path) + strlen(html) + 1));
  strcpy(new_pathPHP, path);
  strcat(new_pathPHP, php);
  strcpy(new_pathHTML, path);
  strcat(new_pathHTML, html);
  if (access(new_pathPHP, R_OK) != -1) {
    printf("Found index.php\n");
    free(new_pathHTML);
    printf("Return Value: %s\n", new_pathPHP);
    return strcat(new_pathPHP, php);
  } else if (access(new_pathHTML, R_OK) != -1) {
    printf("Found index.html\n");
    free(new_pathPHP);
    printf("Return Value: %s\n", new_pathHTML);
    return strcat(new_pathHTML, html);
  } else {
    printf("Returned Null\n");
    free(new_pathPHP);
    free(new_pathHTML);
    return NULL;
  }
}


x86 assembly (clang, -O0):
<indexes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     122c <indexes+0xcc>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    %rax,-0x8(%rbp)
jmp    12ae <indexes+0x14e>
mov    -0x30(%rbp),%rdi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1286 <indexes+0x126>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
mov    %rax,-0x8(%rbp)
jmp    12ae <indexes+0x14e>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indexes>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movabs $0x702e7865646e692f,%r12
78 2e 70
mov    %r12,(%rbx,%rax,1)
movl   $0x706870,0x7(%rbx,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
movabs $0x682e7865646e692f,%r15
78 2e 68
mov    %r15,(%r14,%rax,1)
movl   $0x6c6d74,0x8(%r14,%rax,1)
mov    0x2df0(%rip),%r13
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
je     123c <indexes+0xcc>
lea    0xe40(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xdfb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r12,(%rbx,%rax,1)
movl   $0x706870,0x7(%rbx,%rax,1)
jmp    12aa <indexes+0x13a>
mov    0x0(%r13),%esi
mov    %r14,%rdi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
je     128c <indexes+0x11c>
lea    0xde3(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xdaf(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r15,(%r14,%rax,1)
movl   $0x6c6d74,0x8(%r14,%rax,1)
mov    %r14,%rbx
jmp    12aa <indexes+0x13a>
lea    0xd96(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/index.php\00"
@.str.1 = [12 x i8] c"/index.html\00"
@R_OK = global i32 0
@.str.2 = [17 x i8] c"Found index.php\0A\00"
@.str.3 = [18 x i8] c"Return Value: %s\0A\00"
@.str.4 = [18 x i8] c"Found index.html\0A\00"
@.str.5 = [15 x i8] c"Returned Null\0A\00"
define i8* @indexes(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %5
%8 = call i8* @malloc(i32 8)
store i8* %8, i8** %6
%9 = call i8* @malloc(i32 8)
store i8* %9, i8** %7
%10 = load i8*, i8** %6
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = load i8*, i8** %6
%14 = load i8*, i8** %4
%15 = call i8* @strcat(i8* %13, i8* %14)
%16 = load i8*, i8** %7
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %7
%20 = load i8*, i8** %5
%21 = call i8* @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %6
%23 = load i32, i32* @R_OK
%24 = call i32 @access(i8* %22, i32 %23)
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %35
26: ; preds = %1
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%28 = load i8*, i8** %7
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %6
%33 = load i8*, i8** %4
%34 = call i8* @strcat(i8* %32, i8* %33)
store i8* %34, i8** %2
br label %55
35: ; preds = %1
%36 = load i8*, i8** %7
%37 = load i32, i32* @R_OK
%38 = call i32 @access(i8* %36, i32 %37)
%39 = icmp ne i32 %38, -1
br i1 %39, label %40, label %49
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%42 = load i8*, i8** %6
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = load i8*, i8** %7
%47 = load i8*, i8** %5
%48 = call i8* @strcat(i8* %46, i8* %47)
store i8* %48, i8** %2
br label %55
49: ; preds = %35
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%51 = load i8*, i8** %6
%52 = call i32 @free(i8* %51)
%53 = load i8*, i8** %7
%54 = call i32 @free(i8* %53)
store i8* null, i8** %2
br label %55
55: ; preds = %49, %40, %26
%56 = load i8*, i8** %2
ret i8* %56
}

LLVM IR (-O2):
@.str = [11 x i8] c"/index.php\00"
@.str.1 = [12 x i8] c"/index.html\00"
@R_OK = global i32 0
@.str.3 = [18 x i8] c"Return Value: %s\0A\00"
@str = [14 x i8] c"Returned Null\00"
@str.6 = [17 x i8] c"Found index.html\00"
@str.7 = [16 x i8] c"Found index.php\00"
define i8* @indexes(i8* %0) {
%2 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%3 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%4 = tail call i32 @strcpy(i8* %2, i8* %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = getelementptr i8, i8* %2, i64 %5
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(11) %6, i8* align 1 dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 11, i1 false)
%7 = tail call i32 @strcpy(i8* %3, i8* %0)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%9 = getelementptr i8, i8* %3, i64 %8
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(12) %9, i8* align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 12, i1 false)
%10 = load i32, i32* @R_OK
%11 = tail call i32 @access(i8* %2, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %19, label %13
13: ; preds = %1
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%15 = tail call i32 @free(i8* %3)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%17 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%18 = getelementptr i8, i8* %2, i64 %17
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(11) %18, i8* align 1 dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 11, i1 false)
br label %33
19: ; preds = %1
%20 = load i32, i32* @R_OK
%21 = tail call i32 @access(i8* %3, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
%25 = tail call i32 @free(i8* %2)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%27 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%28 = getelementptr i8, i8* %3, i64 %27
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(12) %28, i8* align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 12, i1 false)
br label %33
29: ; preds = %19
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%31 = tail call i32 @free(i8* %2)
%32 = tail call i32 @free(i8* %3)
br label %33
33: ; preds = %29, %23, %13
%34 = phi i8* [ %2, %13 ], [ %3, %23 ], [ null, %29 ]
ret i8* %34
}