#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;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *indexes(const char *path) {
  const char *indexPhp;
  const char *indexHtml;
  if (path[0] == '/') {
    indexPhp = "index.php";
    indexHtml = "index.html";
  } else {
    indexPhp = "/index.php";
    indexHtml = "/index.html";
  }
  char *phpPath = malloc(sizeof(char) * (strlen(path) + strlen(indexPhp) + 1));
  strcpy(phpPath, path);
  strcat(phpPath, indexPhp);
  char *htmlPath =
      malloc(sizeof(char) * (strlen(path) + strlen(indexHtml) + 1));
  strcpy(htmlPath, path);
  strcat(htmlPath, indexHtml);
  if (access(phpPath, R_OK) == 0) {
    free(htmlPath);
    return phpPath;
  } else if (access(htmlPath, R_OK) == 0) {
    free(phpPath);
    return htmlPath;
  } else {
    free(htmlPath);
    free(phpPath);
    return NULL;
  }
}


x86 assembly (clang, -O0):
<indexes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1197 <indexes+0x37>
lea    0xe7e(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe7e(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11ad <indexes+0x4d>
lea    0xe62(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe62(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%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    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
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    0x2d94(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    1273 <indexes+0x113>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12bf <indexes+0x15f>
mov    -0x30(%rbp),%rdi
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    12a5 <indexes+0x145>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12bf <indexes+0x15f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indexes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
cmpb   $0x2f,(%rdi)
lea    0xe97(%rip),%rax
lea    0xe8f(%rip),%r14
cmove  %rax,%r14
lea    0xe7a(%rip),%rax
lea    0xe72(%rip),%rbx
cmove  %rax,%rbx
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    0x2ddc(%rip),%r14
mov    (%r14),%esi
mov    %r15,%rdi
call   1070 <access@plt>
test   %rax,%rax
je     1234 <indexes+0xd4>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1070 <access@plt>
test   %rax,%rax
je     1239 <indexes+0xd9>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
xor    %r15d,%r15d
jmp    123f <indexes+0xdf>
mov    %rbx,%rdi
jmp    123f <indexes+0xdf>
mov    %r15,%rdi
mov    %rbx,%r15
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"index.php\00"
@.str.1 = [11 x i8] c"index.html\00"
@.str.2 = [11 x i8] c"/index.php\00"
@.str.3 = [12 x i8] c"/index.html\00"
@R_OK = global i32 0
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
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 47
br i1 %12, label %13, label %14
13: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %15
14: ; preds = %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %5
br label %15
15: ; preds = %14, %13
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %17, %19
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = mul i64 1, %22
%24 = trunc i64 %23 to i32
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = load i8*, i8** %3
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = load i8*, i8** %6
%30 = load i8*, i8** %4
%31 = call i32 @strcat(i8* %29, i8* %30)
%32 = load i8*, i8** %3
%33 = call i32 @strlen(i8* %32)
%34 = load i8*, i8** %5
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %33, %35
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = mul i64 1, %38
%40 = trunc i64 %39 to i32
%41 = call i8* @malloc(i32 %40)
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = load i8*, i8** %3
%44 = call i32 @strcpy(i8* %42, i8* %43)
%45 = load i8*, i8** %7
%46 = load i8*, i8** %5
%47 = call i32 @strcat(i8* %45, i8* %46)
%48 = load i8*, i8** %6
%49 = load i32, i32* @R_OK
%50 = call i64 @access(i8* %48, i32 %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %15
%53 = load i8*, i8** %7
%54 = call i32 @free(i8* %53)
%55 = load i8*, i8** %6
store i8* %55, i8** %2
br label %70
56: ; preds = %15
%57 = load i8*, i8** %7
%58 = load i32, i32* @R_OK
%59 = call i64 @access(i8* %57, i32 %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %56
%62 = load i8*, i8** %6
%63 = call i32 @free(i8* %62)
%64 = load i8*, i8** %7
store i8* %64, i8** %2
br label %70
65: ; preds = %56
%66 = load i8*, i8** %7
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %6
%69 = call i32 @free(i8* %68)
store i8* null, i8** %2
br label %70
70: ; preds = %65, %61, %52
%71 = load i8*, i8** %2
ret i8* %71
}

LLVM IR (-O2):
@.str = [10 x i8] c"index.php\00"
@.str.1 = [11 x i8] c"index.html\00"
@.str.2 = [11 x i8] c"/index.php\00"
@.str.3 = [12 x i8] c"/index.html\00"
@R_OK = global i32 0
define i8* @indexes(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
%4 = select i1 %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0)
%5 = select i1 %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0)
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i32 @strlen(i8* %5)
%8 = add i32 %6, 1
%9 = add i32 %8, %7
%10 = tail call i8* @malloc(i32 %9)
%11 = tail call i32 @strcpy(i8* %10, i8* %0)
%12 = tail call i32 @strcat(i8* %10, i8* %5)
%13 = tail call i32 @strlen(i8* %0)
%14 = tail call i32 @strlen(i8* %4)
%15 = add i32 %13, 1
%16 = add i32 %15, %14
%17 = tail call i8* @malloc(i32 %16)
%18 = tail call i32 @strcpy(i8* %17, i8* %0)
%19 = tail call i32 @strcat(i8* %17, i8* %4)
%20 = load i32, i32* @R_OK
%21 = tail call i64 @access(i8* %10, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %1
%24 = load i32, i32* @R_OK
%25 = tail call i64 @access(i8* %17, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = tail call i32 @free(i8* %17)
br label %29
29: ; preds = %23, %1, %27
%30 = phi i8* [ %10, %27 ], [ %17, %1 ], [ %10, %23 ]
%31 = phi i8* [ null, %27 ], [ %10, %1 ], [ %17, %23 ]
%32 = tail call i32 @free(i8* %30)
ret i8* %31
}