#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ cat_file(char *);
int /*<<< orphan*/ fgets(char *, long, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *malloc(long);
int /*<<< orphan*/ print_dirlist(char *);
int /*<<< orphan*/ replace_special_chars(char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
scalar_t__ strlen(char *);
char *strsep(char **, char *);
long strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ write_to_file(char *, char *);
int main(int argc, char *argv[]) {
  char *len_str, *buf, *key, *val;
  struct stat statbuf;
  char *filename = NULL;
  char *writeval = NULL;
  long int len = 0, errno = 0;
  char *bufptr;
  fprintf(stdout, "Content-type: text/html\n\n");
  fprintf(stdout, "<html><head><title>Cat-a-file</title></head>");
  fprintf(stdout, "<body>");
  fprintf(stdout, "<fieldset>");
  fprintf(stdout,
          "<legend>Enter a (proc/debugfs) file to 'cat' or write</legend>");
  fprintf(stdout, "<form action=catafile?catfile method=post>");
  fprintf(stdout, " <table>");
  fprintf(stdout, "  <tr>");
  fprintf(stdout, "   <td align=right>File or directory:</td>");
  fprintf(stdout,
          "   <td align=left><input type=text name=filename size=75></td>");
  fprintf(stdout, "  </tr>");
  fprintf(stdout, "  <tr>");
  fprintf(stdout,
          "   <td align=right>Write this to file (or leave blank):</td>");
  fprintf(stdout,
          "   <td align=left><input type=text name=writeval size=75></td>");
  fprintf(stdout, "  </tr>");
  fprintf(stdout, "  <tr>");
  fprintf(stdout, " <table>");
  fprintf(stdout, " <input type=submit value='Submit'>");
  fprintf(stdout, "</fieldset>");
  fprintf(stdout, "</form>");
  len_str = getenv("CONTENT_LENGTH");
  if (len_str) {
    len = strtol(len_str, NULL, 10);
    if (errno || !len)
      goto out;
  }
  buf = malloc(len + 1);
  if (!fgets(buf, len + 1, stdin))
    goto out;
  bufptr = buf;
  val = strsep(&bufptr, "&");
  if (!val)
    goto out;
  key = strsep(&val, "=");
  if (!strcmp(key, "filename")) {
    if (!val)
      goto out;
    filename = val;
  }
  val = bufptr;
  key = strsep(&val, "=");
  if (!strcmp(key, "writeval")) {
    if (val)
      writeval = val;
  }
  replace_special_chars(filename);
  stat(filename, &statbuf);
  if (S_ISDIR(statbuf.st_mode))
    print_dirlist(filename);
  else if (writeval && strlen(writeval))
    write_to_file(filename, writeval);
  else
    cat_file(filename);
out:
  fprintf(stdout, "</body></html>\n");
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
lea    0xd5b(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c1c(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xe28(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     141b <main+0x22b>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10c0 <strtol@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1411 <main+0x221>
cmpq   $0x0,-0x50(%rbp)
jne    1416 <main+0x226>
jmp    158b <main+0x39b>
jmp    141b <main+0x22b>
mov    -0x50(%rbp),%rdi
add    $0x1,%rdi
call   10e0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x50(%rbp),%rsi
add    $0x1,%rsi
mov    0x2ba9(%rip),%rax
mov    (%rax),%edx
call   1080 <fgets@plt>
cmp    $0x0,%eax
jne    1454 <main+0x264>
jmp    158b <main+0x39b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xda1(%rip),%rsi
call   10f0 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1480 <main+0x290>
jmp    158b <main+0x39b>
lea    -0x30(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   10f0 <strsep@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd6d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    14c5 <main+0x2d5>
cmpq   $0x0,-0x30(%rbp)
jne    14bd <main+0x2cd>
jmp    158b <main+0x39b>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xd32(%rip),%rsi
call   10f0 <strsep@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd29(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    1512 <main+0x322>
cmpq   $0x0,-0x30(%rbp)
je     150d <main+0x31d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1512 <main+0x322>
mov    -0x40(%rbp),%rdi
call   10d0 <replace_special_chars@plt>
mov    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <stat@plt>
mov    -0x38(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1548 <main+0x358>
mov    -0x40(%rbp),%rdi
call   1100 <print_dirlist@plt>
jmp    1586 <main+0x396>
cmpq   $0x0,-0x48(%rbp)
je     1578 <main+0x388>
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     1578 <main+0x388>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1070 <write_to_file@plt>
jmp    1581 <main+0x391>
mov    -0x40(%rbp),%rdi
call   1110 <cat_file@plt>
jmp    1586 <main+0x396>
jmp    158b <main+0x39b>
mov    0x2a46(%rip),%rax
mov    (%rax),%edi
lea    0xc83(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    0x2de4(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe01(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe0b(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe28(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe1f(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe1a(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe49(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe64(%rip),%r14
mov    %r14,%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe5a(%rip),%r15
mov    %r15,%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe4e(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe69(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe98(%rip),%rbx
mov    %rbx,%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r15,%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe81(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xeae(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r15,%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r14,%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xeb9(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xecd(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xec9(%rip),%rsi
call   1090 <fprintf@plt>
lea    0xec5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     135a <main+0x17a>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    135c <main+0x17c>
jmp    1467 <main+0x287>
xor    %ebx,%ebx
add    $0x1,%rbx
mov    %rbx,%rdi
call   10d0 <malloc@plt>
mov    %rax,%r12
mov    0x2c76(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <fgets@plt>
test   %eax,%eax
je     1467 <main+0x287>
mov    %r12,0x18(%rsp)
lea    0xe75(%rip),%rsi
lea    0x18(%rsp),%rdi
call   10e0 <strsep@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1467 <main+0x287>
lea    0xe58(%rip),%rsi
lea    0x8(%rsp),%rdi
call   10e0 <strsep@plt>
lea    0xe49(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
je     13d4 <main+0x1f4>
xor    %r14d,%r14d
jmp    13e2 <main+0x202>
mov    0x8(%rsp),%r14
test   %r14,%r14
je     1467 <main+0x287>
mov    0x18(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0xe17(%rip),%rsi
lea    0x8(%rsp),%rdi
call   10e0 <strsep@plt>
lea    0xe11(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    1417 <main+0x237>
mov    0x8(%rsp),%r15
jmp    141a <main+0x23a>
xor    %r15d,%r15d
mov    %r14,%rdi
call   10c0 <replace_special_chars@plt>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   10a0 <stat@plt>
mov    0x10(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     1447 <main+0x267>
mov    %r14,%rdi
call   10f0 <print_dirlist@plt>
jmp    1467 <main+0x287>
test   %r15,%r15
je     145f <main+0x27f>
cmpb   $0x0,(%r15)
je     145f <main+0x27f>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <write_to_file@plt>
jmp    1467 <main+0x287>
mov    %r14,%rdi
call   1100 <cat_file@plt>
mov    0x0(%r13),%edi
lea    0xdac(%rip),%rsi
call   1090 <fprintf@plt>
mov    %r12,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stdout = global i32 0
@.str = [26 x i8] c"Content-type: text/html\0A\0A\00"
@.str.1 = [45 x i8] c"<html><head><title>Cat-a-file</title></head>\00"
@.str.2 = [7 x i8] c"<body>\00"
@.str.3 = [11 x i8] c"<fieldset>\00"
@.str.4 = [63 x i8] c"<legend>Enter a (proc/debugfs) file to 'cat' or write</legend>\00"
@.str.5 = [43 x i8] c"<form action=catafile?catfile method=post>\00"
@.str.6 = [9 x i8] c" <table>\00"
@.str.7 = [7 x i8] c" <tr>\00"
@.str.8 = [43 x i8] c" <td align=right>File or directory:</td>\00"
@.str.9 = [63 x i8] c" <td align=left><input type=text name=filename size=75></td>\00"
@.str.10 = [8 x i8] c" </tr>\00"
@.str.11 = [61 x i8] c" <td align=right>Write this to file (or leave blank):</td>\00"
@.str.12 = [63 x i8] c" <td align=left><input type=text name=writeval size=75></td>\00"
@.str.13 = [36 x i8] c" <input type=submit value='Submit'>\00"
@.str.14 = [12 x i8] c"</fieldset>\00"
@.str.15 = [8 x i8] c"</form>\00"
@.str.16 = [15 x i8] c"CONTENT_LENGTH\00"
@stdin = global i32 0
@.str.17 = [2 x i8] c"&\00"
@.str.18 = [2 x i8] c"=\00"
@.str.19 = [9 x i8] c"filename\00"
@.str.20 = [9 x i8] c"writeval\00"
@.str.21 = [16 x i8] c"</body></html>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.stat
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %11
store i8* null, i8** %12
store i64 0, i64* %13
store i64 0, i64* %14
%16 = load i32, i32* @stdout
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @stdout
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @stdout
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @stdout
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @stdout
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* @stdout
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%28 = load i32, i32* @stdout
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%30 = load i32, i32* @stdout
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%32 = load i32, i32* @stdout
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%34 = load i32, i32* @stdout
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.9, i64 0, i64 0))
%36 = load i32, i32* @stdout
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%38 = load i32, i32* @stdout
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%40 = load i32, i32* @stdout
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.11, i64 0, i64 0))
%42 = load i32, i32* @stdout
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.12, i64 0, i64 0))
%44 = load i32, i32* @stdout
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%46 = load i32, i32* @stdout
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%48 = load i32, i32* @stdout
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%50 = load i32, i32* @stdout
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.13, i64 0, i64 0))
%52 = load i32, i32* @stdout
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
%54 = load i32, i32* @stdout
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
%56 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.16, i64 0, i64 0))
store i8* %56, i8** %6
%57 = load i8*, i8** %6
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %69
59: ; preds = %2
%60 = load i8*, i8** %6
%61 = call i64 @strtol(i8* %60, i32* null, i32 10)
store i64 %61, i64* %13
%62 = load i64, i64* %14
%63 = icmp ne i64 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %59
%65 = load i64, i64* %13
%66 = icmp ne i64 %65, 0
br i1 %66, label %68, label %67
67: ; preds = %64, %59
br label %137
68: ; preds = %64
br label %69
69: ; preds = %68, %2
%70 = load i64, i64* %13
%71 = add nsw i64 %70, 1
%72 = call i8* @malloc(i64 %71)
store i8* %72, i8** %7
%73 = load i8*, i8** %7
%74 = load i64, i64* %13
%75 = add nsw i64 %74, 1
%76 = load i32, i32* @stdin
%77 = call i32 @fgets(i8* %73, i64 %75, i32 %76)
%78 = icmp ne i32 %77, 0
br i1 %78, label %80, label %79
79: ; preds = %69
br label %137
80: ; preds = %69
%81 = load i8*, i8** %7
store i8* %81, i8** %15
%82 = call i8* @strsep(i8** %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
store i8* %82, i8** %9
%83 = load i8*, i8** %9
%84 = icmp ne i8* %83, null
br i1 %84, label %86, label %85
85: ; preds = %80
br label %137
86: ; preds = %80
%87 = call i8* @strsep(i8** %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
store i8* %87, i8** %8
%88 = load i8*, i8** %8
%89 = call i32 @strcmp(i8* %88, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
%90 = icmp ne i32 %89, 0
br i1 %90, label %97, label %91
91: ; preds = %86
%92 = load i8*, i8** %9
%93 = icmp ne i8* %92, null
br i1 %93, label %95, label %94
94: ; preds = %91
br label %137
95: ; preds = %91
%96 = load i8*, i8** %9
store i8* %96, i8** %11
br label %97
97: ; preds = %95, %86
%98 = load i8*, i8** %15
store i8* %98, i8** %9
%99 = call i8* @strsep(i8** %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
store i8* %99, i8** %8
%100 = load i8*, i8** %8
%101 = call i32 @strcmp(i8* %100, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.20, i64 0, i64 0))
%102 = icmp ne i32 %101, 0
br i1 %102, label %109, label %103
103: ; preds = %97
%104 = load i8*, i8** %9
%105 = icmp ne i8* %104, null
br i1 %105, label %106, label %108
106: ; preds = %103
%107 = load i8*, i8** %9
store i8* %107, i8** %12
br label %108
108: ; preds = %106, %103
br label %109
109: ; preds = %108, %97
%110 = load i8*, i8** %11
%111 = call i32 @replace_special_chars(i8* %110)
%112 = load i8*, i8** %11
%113 = call i32 @stat(i8* %112, %struct.stat* %10)
%114 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%115 = load i32, i32* %114
%116 = call i64 @S_ISDIR(i32 %115)
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %121
118: ; preds = %109
%119 = load i8*, i8** %11
%120 = call i32 @print_dirlist(i8* %119)
br label %136
121: ; preds = %109
%122 = load i8*, i8** %12
%123 = icmp ne i8* %122, null
br i1 %123, label %124, label %132
124: ; preds = %121
%125 = load i8*, i8** %12
%126 = call i64 @strlen(i8* %125)
%127 = icmp ne i64 %126, 0
br i1 %127, label %128, label %132
128: ; preds = %124
%129 = load i8*, i8** %11
%130 = load i8*, i8** %12
%131 = call i32 @write_to_file(i8* %129, i8* %130)
br label %135
132: ; preds = %124, %121
%133 = load i8*, i8** %11
%134 = call i32 @cat_file(i8* %133)
br label %135
135: ; preds = %132, %128
br label %136
136: ; preds = %135, %118
br label %137
137: ; preds = %136, %94, %85, %79, %67
%138 = load i32, i32* @stdout
%139 = call i32 @fprintf(i32 %138, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.21, i64 0, i64 0))
%140 = load i8*, i8** %7
%141 = call i32 @free(i8* %140)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stdout = global i32 0
@.str = [26 x i8] c"Content-type: text/html\0A\0A\00"
@.str.1 = [45 x i8] c"<html><head><title>Cat-a-file</title></head>\00"
@.str.2 = [7 x i8] c"<body>\00"
@.str.3 = [11 x i8] c"<fieldset>\00"
@.str.4 = [63 x i8] c"<legend>Enter a (proc/debugfs) file to 'cat' or write</legend>\00"
@.str.5 = [43 x i8] c"<form action=catafile?catfile method=post>\00"
@.str.6 = [9 x i8] c" <table>\00"
@.str.7 = [7 x i8] c" <tr>\00"
@.str.8 = [43 x i8] c" <td align=right>File or directory:</td>\00"
@.str.9 = [63 x i8] c" <td align=left><input type=text name=filename size=75></td>\00"
@.str.10 = [8 x i8] c" </tr>\00"
@.str.11 = [61 x i8] c" <td align=right>Write this to file (or leave blank):</td>\00"
@.str.12 = [63 x i8] c" <td align=left><input type=text name=writeval size=75></td>\00"
@.str.13 = [36 x i8] c" <input type=submit value='Submit'>\00"
@.str.14 = [12 x i8] c"</fieldset>\00"
@.str.15 = [8 x i8] c"</form>\00"
@.str.16 = [15 x i8] c"CONTENT_LENGTH\00"
@stdin = global i32 0
@.str.17 = [2 x i8] c"&\00"
@.str.18 = [2 x i8] c"=\00"
@.str.19 = [9 x i8] c"filename\00"
@.str.20 = [9 x i8] c"writeval\00"
@.str.21 = [16 x i8] c"</body></html>\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i8*
%6 = bitcast i8** %3 to i8*
%7 = bitcast %struct.stat* %4 to i8*
%8 = bitcast i8** %5 to i8*
%9 = load i32, i32* @stdout
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @stdout
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @stdout
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0))
%19 = load i32, i32* @stdout
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%23 = load i32, i32* @stdout
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%25 = load i32, i32* @stdout
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.9, i64 0, i64 0))
%29 = load i32, i32* @stdout
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%31 = load i32, i32* @stdout
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%33 = load i32, i32* @stdout
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.11, i64 0, i64 0))
%35 = load i32, i32* @stdout
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.12, i64 0, i64 0))
%37 = load i32, i32* @stdout
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%39 = load i32, i32* @stdout
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%41 = load i32, i32* @stdout
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%43 = load i32, i32* @stdout
%44 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.13, i64 0, i64 0))
%45 = load i32, i32* @stdout
%46 = tail call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
%47 = load i32, i32* @stdout
%48 = tail call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
%49 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.16, i64 0, i64 0))
%50 = icmp eq i8* %49, null
br i1 %50, label %54, label %51
51: ; preds = %2
%52 = tail call i64 @strtol(i8* nocapture %49, i32* null, i32 10)
%53 = icmp eq i64 %52, 0
br i1 %53, label %98, label %54
54: ; preds = %51, %2
%55 = phi i64 [ %52, %51 ], [ 0, %2 ]
%56 = add nsw i64 %55, 1
%57 = tail call i8* @malloc(i64 %56)
%58 = load i32, i32* @stdin
%59 = tail call i32 @fgets(i8* %57, i64 %56, i32 %58)
%60 = icmp eq i32 %59, 0
br i1 %60, label %98, label %61
61: ; preds = %54
store i8* %57, i8** %5
%62 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
store i8* %62, i8** %3
%63 = icmp eq i8* %62, null
br i1 %63, label %98, label %64
64: ; preds = %61
%65 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
%66 = call i32 @strcmp(i8* dereferenceable(1) %65, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = load i8*, i8** %3
%70 = icmp eq i8* %69, null
br i1 %70, label %98, label %71
71: ; preds = %68, %64
%72 = phi i8* [ null, %64 ], [ %69, %68 ]
%73 = load i8*, i8** %5
store i8* %73, i8** %3
%74 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
%75 = call i32 @strcmp(i8* dereferenceable(1) %74, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.20, i64 0, i64 0))
%76 = icmp eq i32 %75, 0
%77 = load i8*, i8** %3
%78 = icmp ne i8* %77, null
%79 = select i1 %76, i1 %78, i1 false
%80 = select i1 %79, i8* %77, i8* null
%81 = call i32 @replace_special_chars(i8* %72)
%82 = call i32 @stat(i8* %72, %struct.stat* %4)
%83 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%84 = load i32, i32* %83
%85 = call i64 @S_ISDIR(i32 %84)
%86 = icmp eq i64 %85, 0
br i1 %86, label %89, label %87
87: ; preds = %71
%88 = call i32 @print_dirlist(i8* %72)
br label %98
89: ; preds = %71
%90 = icmp eq i8* %80, null
br i1 %90, label %96, label %91
91: ; preds = %89
%92 = load i8, i8* %80
%93 = icmp eq i8 %92, 0
br i1 %93, label %96, label %94
94: ; preds = %91
%95 = call i32 @write_to_file(i8* %72, i8* %80)
br label %98
96: ; preds = %91, %89
%97 = call i32 @cat_file(i8* %72)
br label %98
98: ; preds = %87, %96, %94, %68, %61, %54, %51
%99 = phi i8* [ %57, %87 ], [ %57, %94 ], [ %57, %96 ], [ %57, %68 ], [ %57, %61 ], [ %57, %54 ], [ undef, %51 ]
%100 = load i32, i32* @stdout
%101 = call i32 @fprintf(i32 %100, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.21, i64 0, i64 0))
%102 = call i32 @free(i8* %99)
ret i32 0
}