#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*/);
char *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 *php = "/index.php";
  char *html = "/index.html";
  char *new_pathPHP = malloc(strlen(path) + strlen(php) + 2);
  char *new_pathHTML = malloc(strlen(path) + strlen(html) + 2);
  strcpy(new_pathPHP, path);
  strcat(new_pathPHP, php);
  strcpy(new_pathHTML, path);
  strcat(new_pathHTML, html);
  if (access(new_pathPHP, R_OK) != -1) {
    return new_pathPHP;
  } else if (access(new_pathHTML, R_OK) != -1) {
    return new_pathHTML;
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<indexes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     1222 <indexes+0xd2>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1252 <indexes+0x102>
mov    -0x30(%rbp),%rdi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     124a <indexes+0xfa>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1252 <indexes+0x102>
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,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
lea    0xc(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
add    $0xd,%rbx
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xe70(%rip),%rsi
mov    %r12,%rdi
call   1070 <strcat@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xe61(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    0x2e27(%rip),%rbx
mov    (%rbx),%esi
mov    %r12,%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
jne    11dc <indexes+0x8c>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1060 <access@plt>
xor    %r12d,%r12d
cmp    $0xffffffff,%eax
cmovne %r14,%r12
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
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
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 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %9, %11
%13 = add nsw i64 %12, 2
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %6
%15 = load i8*, i8** %3
%16 = call i64 @strlen(i8* %15)
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %16, %18
%20 = add nsw i64 %19, 2
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %6
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %6
%26 = load i8*, i8** %4
%27 = call i32 @strcat(i8* %25, i8* %26)
%28 = load i8*, i8** %7
%29 = load i8*, i8** %3
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = load i8*, i8** %7
%32 = load i8*, i8** %5
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = load i8*, i8** %6
%35 = load i32, i32* @R_OK
%36 = call i32 @access(i8* %34, i32 %35)
%37 = icmp ne i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %1
%39 = load i8*, i8** %6
store i8* %39, i8** %2
br label %48
40: ; preds = %1
%41 = load i8*, i8** %7
%42 = load i32, i32* @R_OK
%43 = call i32 @access(i8* %41, i32 %42)
%44 = icmp ne i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = load i8*, i8** %7
store i8* %46, i8** %2
br label %48
47: ; preds = %40
store i8* null, i8** %2
br label %48
48: ; preds = %47, %45, %38
%49 = load i8*, i8** %2
ret i8* %49
}

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
define i8* @indexes(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 12
%4 = tail call i8* @malloc(i64 %3)
%5 = add nsw i64 %2, 13
%6 = tail call i8* @malloc(i64 %5)
%7 = tail call i32 @strcpy(i8* %4, i8* %0)
%8 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @strcpy(i8* %6, i8* %0)
%10 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @R_OK
%12 = tail call i32 @access(i8* %4, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* @R_OK
%16 = tail call i32 @access(i8* %6, i32 %15)
%17 = icmp eq i32 %16, -1
%18 = select i1 %17, i8* null, i8* %6
br label %19
19: ; preds = %14, %1
%20 = phi i8* [ %4, %1 ], [ %18, %14 ]
ret i8* %20
}