#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct stat {
  int dummy;
};
struct TYPE_2__ {
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int is_in_file(char const *, char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ process_request(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ remove(char const *);
int /*<<< orphan*/ rmdir(char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ write_to_file(char const *, char *);
char *test_process_request_no_dir_slash() {
  printf("Test process request: List directory\n");
  char *ROOT = "test_root_dir";
  char *SUBDIR = "test_root_dir/subdir";
  const char *FILENAME = "test_server_no_dir_slash";
  int root_created = 0;
  struct stat *st = {0};
  if (stat(ROOT, st) == -1) {
    mkdir(ROOT, 0700);
    mkdir(SUBDIR, 0700);
    root_created = 1;
  }
  write_to_file(FILENAME, "GET /subdir HTTP/1.1");
  FILE *f = fopen(FILENAME, "a+");
  do {
    if (!(f != NULL))
      return "Error, f == NULL";
  } while (0);
  process_request(f, ROOT);
  fclose(f);
  do {
    if (!(is_in_file(FILENAME, "302") == 1))
      return "Error, should've printed directory listing";
  } while (0);
  if (root_created == 1) {
    rmdir(SUBDIR);
    rmdir(ROOT);
  }
  remove(FILENAME);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_process_request_no_dir_slash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe51(%rip),%rdi
call   1080 <printf@plt>
lea    0xe6b(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe6e(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe78(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
jne    121d <test_process_request_no_dir_slash+0x7d>
mov    -0x10(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1090 <write_to_file@plt>
mov    -0x20(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    125c <test_process_request_no_dir_slash+0xbc>
lea    0xe27(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12de <test_process_request_no_dir_slash+0x13e>
jmp    1261 <test_process_request_no_dir_slash+0xc1>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <process_request@plt>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   10a0 <is_in_file@plt>
cmp    $0x1,%eax
je     12a0 <test_process_request_no_dir_slash+0x100>
lea    0xdf8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12de <test_process_request_no_dir_slash+0x13e>
jmp    12a5 <test_process_request_no_dir_slash+0x105>
cmpl   $0x1,-0x24(%rbp)
jne    12c1 <test_process_request_no_dir_slash+0x121>
mov    -0x18(%rbp),%rdi
call   1070 <rmdir@plt>
mov    -0x10(%rbp),%rdi
call   1070 <rmdir@plt>
mov    -0x20(%rbp),%rdi
call   1030 <remove@plt>
lea    0xd53(%rip),%rdi
call   1080 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_process_request_no_dir_slash>:
push   %rbp
push   %rbx
push   %rax
lea    0xeda(%rip),%rdi
call   1060 <puts@plt>
lea    0xe3a(%rip),%rdi
xor    %esi,%esi
call   10c0 <stat@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11f6 <test_process_request_no_dir_slash+0x46>
lea    0xe25(%rip),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
lea    0xe22(%rip),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
lea    0xe26(%rip),%rbx
lea    0xe38(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <write_to_file@plt>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1289 <test_process_request_no_dir_slash+0xd9>
mov    %rax,%rbx
lea    0xdd6(%rip),%rsi
mov    %rax,%rdi
call   1070 <process_request@plt>
mov    %rbx,%rdi
call   1080 <fclose@plt>
lea    0xde2(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   10b0 <is_in_file@plt>
cmp    $0x1,%eax
jne    1292 <test_process_request_no_dir_slash+0xe2>
cmp    $0xffffffff,%ebp
jne    126f <test_process_request_no_dir_slash+0xbf>
lea    0xdb0(%rip),%rdi
call   1090 <rmdir@plt>
lea    0xd96(%rip),%rdi
call   1090 <rmdir@plt>
lea    0xdad(%rip),%rdi
call   1040 <remove@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
jmp    1299 <test_process_request_no_dir_slash+0xe9>
lea    0xdc4(%rip),%rax
jmp    1299 <test_process_request_no_dir_slash+0xe9>
lea    0xdd0(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [38 x i8] c"Test process request: List directory\0A\00"
@.str.1 = [14 x i8] c"test_root_dir\00"
@.str.2 = [21 x i8] c"test_root_dir/subdir\00"
@.str.3 = [25 x i8] c"test_server_no_dir_slash\00"
@.str.4 = [21 x i8] c"GET /subdir HTTP/1.1\00"
@.str.5 = [3 x i8] c"a+\00"
@.str.6 = [17 x i8] c"Error, f == NULL\00"
@.str.7 = [4 x i8] c"302\00"
@.str.8 = [43 x i8] c"Error, should've printed directory listing\00"
@.str.9 = [2 x i8] c"\0A\00"
define i8* @test_process_request_no_dir_slash() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.stat*
%7 = alloca i32*
%8 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8** %4
store i32 0, i32* %5
store %struct.stat* null, %struct.stat** %6
%9 = load i8*, i8** %2
%10 = load %struct.stat*, %struct.stat** %6
%11 = call i32 @stat(i8* %9, %struct.stat* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %0
%14 = load i8*, i8** %2
%15 = call i32 @mkdir(i8* %14, i32 448)
%16 = load i8*, i8** %3
%17 = call i32 @mkdir(i8* %16, i32 448)
store i32 1, i32* %5
br label %18
18: ; preds = %13, %0
%19 = load i8*, i8** %4
%20 = call i32 @write_to_file(i8* %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%21 = load i8*, i8** %4
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %22, i32** %7
br label %23
23: ; preds = %18
%24 = load i32*, i32** %7
%25 = icmp ne i32* %24, null
br i1 %25, label %27, label %26
26: ; preds = %23
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8** %1
br label %52
27: ; preds = %23
br label %28
28: ; preds = %27
%29 = load i32*, i32** %7
%30 = load i8*, i8** %2
%31 = call i32 @process_request(i32* %29, i8* %30)
%32 = load i32*, i32** %7
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %28
%35 = load i8*, i8** %4
%36 = call i32 @is_in_file(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%37 = icmp eq i32 %36, 1
br i1 %37, label %39, label %38
38: ; preds = %34
store i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8** %1
br label %52
39: ; preds = %34
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i8*, i8** %3
%45 = call i32 @rmdir(i8* %44)
%46 = load i8*, i8** %2
%47 = call i32 @rmdir(i8* %46)
br label %48
48: ; preds = %43, %40
%49 = load i8*, i8** %4
%50 = call i32 @remove(i8* %49)
%51 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i8* null, i8** %1
br label %52
52: ; preds = %48, %38, %26
%53 = load i8*, i8** %1
ret i8* %53
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [14 x i8] c"test_root_dir\00"
@.str.2 = [21 x i8] c"test_root_dir/subdir\00"
@.str.3 = [25 x i8] c"test_server_no_dir_slash\00"
@.str.4 = [21 x i8] c"GET /subdir HTTP/1.1\00"
@.str.5 = [3 x i8] c"a+\00"
@.str.6 = [17 x i8] c"Error, f == NULL\00"
@.str.7 = [4 x i8] c"302\00"
@.str.8 = [43 x i8] c"Error, should've printed directory listing\00"
@str = [37 x i8] c"Test process request: List directory\00"
define i8* @test_process_request_no_dir_slash() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %struct.stat* null)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @mkdir(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 448)
%6 = tail call i32 @mkdir(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 448)
br label %7
7: ; preds = %4, %0
%8 = tail call i32 @write_to_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %23, label %11
11: ; preds = %7
%12 = tail call i32 @process_request(i32* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @fclose(i32* %9)
%14 = tail call i32 @is_in_file(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %23
16: ; preds = %11
br i1 %3, label %17, label %20
17: ; preds = %16
%18 = tail call i32 @rmdir(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @rmdir(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %16
%21 = tail call i32 @remove(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%22 = tail call i32 @putchar(i32 10)
br label %23
23: ; preds = %11, %7, %20
%24 = phi i8* [ null, %20 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), %7 ], [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), %11 ]
ret i8* %24
}