#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 */
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void genindex(char *dir_name) {
  DIR *d;
  char path[99999];
  strcpy(path, dir_name);
  strcpy(&path[strlen(dir_name)], "index.html");
  FILE *fp = fopen(path, "r");
  if (fp) {
    printf("index.html exist\n");
    fclose(fp);
  } else {
    fp = fopen(path, "w");
    d = opendir(dir_name);
    if (!d) {
      fprintf(stderr, "Cannot open directory '%s': %s\n", dir_name,
              strerror(errno));
      exit(EXIT_FAILURE);
    }
    while (1) {
      struct dirent *entry;
      entry = readdir(d);
      if (!entry) {
        break;
      }
      if (strncmp(entry->d_name, "index.html\0", 11) != 0) {
        fprintf(fp, "<a href=\"%s\">%s</a><br>\n", entry->d_name,
                entry->d_name);
      }
    }
    if (closedir(d)) {
      fprintf(stderr, "Could not close '%s': %s\n", dir_name, strerror(errno));
      exit(EXIT_FAILURE);
    }
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<genindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x186e0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x186b0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
lea    -0x186b0(%rbp),%rdi
add    %rax,%rdi
lea    0xe07(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x186b0(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x186b8(%rbp)
cmpq   $0x0,-0x186b8(%rbp)
je     1243 <genindex+0x83>
lea    0xde0(%rip),%rdi
call   1080 <printf@plt>
mov    -0x186b8(%rbp),%rdi
call   1050 <fclose@plt>
jmp    13b7 <genindex+0x1f7>
lea    -0x186b0(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x186b8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12ca <genindex+0x10a>
mov    0x2d64(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x186d0(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x186c8(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x186d0(%rbp),%rdi
mov    -0x186c8(%rbp),%rdx
mov    %rax,%rcx
lea    0xd6a(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    12cf <genindex+0x10f>
mov    -0x10(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x186c0(%rbp)
cmpq   $0x0,-0x186c0(%rbp)
jne    12f2 <genindex+0x132>
jmp    1343 <genindex+0x183>
mov    -0x186c0(%rbp),%rax
mov    (%rax),%rdi
lea    0xd71(%rip),%rsi
mov    $0xb,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     133e <genindex+0x17e>
mov    -0x186b8(%rbp),%rdi
mov    -0x186c0(%rbp),%rax
mov    (%rax),%rdx
mov    -0x186c0(%rbp),%rax
mov    (%rax),%rcx
lea    0xd08(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    12cf <genindex+0x10f>
mov    -0x10(%rbp),%rdi
call   1090 <closedir@plt>
cmp    $0x0,%rax
je     13ab <genindex+0x1eb>
mov    0x2c83(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x186e0(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x186d8(%rbp)
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x186e0(%rbp),%rdi
mov    -0x186d8(%rbp),%rdx
mov    %rax,%rcx
lea    0xcc2(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c2c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x186b8(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x186e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genindex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x186a8,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1080 <strlen@plt>
lea    (%rsp,%rax,1),%rdi
lea    0xe0b(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xe0a(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1225 <genindex+0x65>
mov    %rax,%rbx
lea    0xe4a(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
jmp    12ba <genindex+0xfa>
lea    0xde1(%rip),%rsi
mov    %rsp,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <opendir@plt>
test   %rax,%rax
je     12d1 <genindex+0x111>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     12aa <genindex+0xea>
mov    %rax,%rbp
lea    0xe11(%rip),%r12
lea    0xdc6(%rip),%r13
jmp    1280 <genindex+0xc0>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12aa <genindex+0xea>
mov    0x0(%rbp),%rdi
mov    %r12,%rsi
mov    $0xb,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1270 <genindex+0xb0>
mov    0x0(%rbp),%rcx
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rcx,%rdx
call   10a0 <fprintf@plt>
jmp    1270 <genindex+0xb0>
mov    %rbx,%rdi
call   1090 <closedir@plt>
test   %rax,%rax
jne    12f2 <genindex+0x132>
mov    %r15,%rdi
call   1060 <fclose@plt>
add    $0x186a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d08(%rip),%rax
mov    (%rax),%rbx
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd1f(%rip),%rsi
jmp    1311 <genindex+0x151>
mov    0x2ce7(%rip),%rax
mov    (%rax),%rbx
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd37(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %rax,%rcx
call   10a0 <fprintf@plt>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [11 x i8] c"index.html\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"index.html exist\0A\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.4 = [32 x i8] c"Cannot open directory '%s': %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.5 = [12 x i8] c"index.html\00\00"
@.str.6 = [25 x i8] c"<a href=\22%s\22>%s</a><br>\0A\00"
@.str.7 = [26 x i8] c"Could not close '%s': %s\0A\00"
define void @genindex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [99999 x i8]
%5 = alloca i32*
%6 = alloca %struct.dirent*
store i8* %0, i8** %2
%7 = getelementptr inbounds [99999 x i8], [99999 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = load i8*, i8** %2
%11 = call i64 @strlen(i8* %10)
%12 = getelementptr inbounds [99999 x i8], [99999 x i8]* %4, i64 0, i64 %11
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [99999 x i8], [99999 x i8]* %4, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32*, i32** %5
%21 = call i32 @fclose(i32* %20)
br label %75
22: ; preds = %1
%23 = getelementptr inbounds [99999 x i8], [99999 x i8]* %4, i64 0, i64 0
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %24, i32** %5
%25 = load i8*, i8** %2
%26 = call i32* @opendir(i8* %25)
store i32* %26, i32** %3
%27 = load i32*, i32** %3
%28 = icmp ne i32* %27, null
br i1 %28, label %37, label %29
29: ; preds = %22
%30 = load i32*, i32** @stderr
%31 = load i8*, i8** %2
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %31, i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %22
br label %38
38: ; preds = %37, %59
%39 = load i32*, i32** %3
%40 = call %struct.dirent* @readdir(i32* %39)
store %struct.dirent* %40, %struct.dirent** %6
%41 = load %struct.dirent*, %struct.dirent** %6
%42 = icmp ne %struct.dirent* %41, null
br i1 %42, label %44, label %43
43: ; preds = %38
br label %60
44: ; preds = %38
%45 = load %struct.dirent*, %struct.dirent** %6
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = call i64 @strncmp(i8* %47, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 11)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %59
50: ; preds = %44
%51 = load i32*, i32** %5
%52 = load %struct.dirent*, %struct.dirent** %6
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i8*, i8** %53
%55 = load %struct.dirent*, %struct.dirent** %6
%56 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i32 0, i32 0
%57 = load i8*, i8** %56
%58 = call i32 @fprintf(i32* %51, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %54, i8* %57)
br label %59
59: ; preds = %50, %44
br label %38
60: ; preds = %43
%61 = load i32*, i32** %3
%62 = call i64 @closedir(i32* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %72
64: ; preds = %60
%65 = load i32*, i32** @stderr
%66 = load i8*, i8** %2
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 @fprintf(i32* %65, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %66, i8* %68)
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %60
%73 = load i32*, i32** %5
%74 = call i32 @fclose(i32* %73)
br label %75
75: ; preds = %72, %18
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [11 x i8] c"index.html\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.4 = [32 x i8] c"Cannot open directory '%s': %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.5 = [12 x i8] c"index.html\00\00"
@.str.6 = [25 x i8] c"<a href=\22%s\22>%s</a><br>\0A\00"
@.str.7 = [26 x i8] c"Could not close '%s': %s\0A\00"
@str = [17 x i8] c"index.html exist\00"
define void @genindex(i8* %0) {
%2 = alloca [99999 x i8]
%3 = getelementptr inbounds [99999 x i8], [99999 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
%5 = call i64 @strlen(i8* dereferenceable(1) %0)
%6 = getelementptr inbounds [99999 x i8], [99999 x i8]* %2, i64 0, i64 %5
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%12 = call i32 @fclose(i32* %8)
br label %51
13: ; preds = %1
%14 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32* @opendir(i8* %0)
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call %struct.dirent* @readdir(i32* %15)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %39, label %27
20: ; preds = %13
%21 = load i32*, i32** @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %17, %36
%28 = phi %struct.dirent* [ %37, %36 ], [ %18, %17 ]
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i64 0, i32 0
%30 = load i8*, i8** %29
%31 = call i64 @strncmp(i8* %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 11)
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %27
%34 = load i8*, i8** %29
%35 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %34, i8* %34)
br label %36
36: ; preds = %27, %33
%37 = call %struct.dirent* @readdir(i32* %15)
%38 = icmp eq %struct.dirent* %37, null
br i1 %38, label %39, label %27
39: ; preds = %36, %17
%40 = call i64 @closedir(i32* %15)
%41 = icmp eq i64 %40, 0
br i1 %41, label %49, label %42
42: ; preds = %39
%43 = load i32*, i32** @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 @fprintf(i32* %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %0, i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %39
%50 = call i32 @fclose(i32* %14)
br label %51
51: ; preds = %49, %10
ret void
}