#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*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *indexes(const char *path) {
  char *path_index =
      (char *)malloc(strlen(path) + strlen("/index.php") + sizeof(char));
  if (path_index) {
    strcpy(path_index, path);
    strcat(path_index, "/index.php");
    if (access(path_index, F_OK) == 0) {
      return path_index;
    } else {
      free(path_index);
    }
  }
  char *path_index_html =
      (char *)malloc(strlen(path) + strlen("/index.html") + sizeof(char));
  if (path_index_html) {
    strcpy(path_index, path);
    strcat(path_index_html, "/index.html");
    if (access(path_index_html, F_OK) == 0) {
      return path_index_html;
    } else {
      free(path_index_html);
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<indexes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe80(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f8 <indexes+0x98>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    11ea <indexes+0x8a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    128c <indexes+0x12c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11f8 <indexes+0x98>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
lea    0xdff(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1284 <indexes+0x124>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    1276 <indexes+0x116>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    128c <indexes+0x12c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1284 <indexes+0x124>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indexes>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0xb(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11b6 <indexes+0x56>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <access@plt>
test   %rax,%rax
je     120e <indexes+0xae>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0xc(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     1207 <indexes+0xa7>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe2a(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1070 <access@plt>
test   %rax,%rax
je     120b <indexes+0xab>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    120e <indexes+0xae>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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