#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 /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ printf(char *);
int 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_invalid_request() {
  printf("Test process request: invalid request\n");
  const char *FILENAME = "test_server_invalid_request";
  char *ROOT = "invalid_request";
  int root_created = 0;
  struct stat *st = {0};
  if (stat(ROOT, st) == -1) {
    mkdir(ROOT, 0700);
    root_created = 1;
  }
  write_to_file(FILENAME, "");
  FILE *f = fopen(FILENAME, "a+");
  do {
    if (!(f != NULL))
      return "Error, f == NULL";
  } while (0);
  int returncode = process_request(f, ROOT);
  fclose(f);
  remove(FILENAME);
  do {
    if (!(returncode == -1))
      return "Error, process_request should've returned -1";
  } while (0);
  write_to_file(FILENAME, "GET");
  f = fopen(FILENAME, "a+");
  do {
    if (!(f != NULL))
      return "Error, f == NULL";
  } while (0);
  returncode = process_request(f, ROOT);
  fclose(f);
  remove(FILENAME);
  do {
    if (!(returncode == -1))
      return "Error, process_request should've returned -1";
  } while (0);
  write_to_file(FILENAME, "GET /");
  f = fopen(FILENAME, "a+");
  do {
    if (!(f != NULL))
      return "Error, f == NULL";
  } while (0);
  returncode = process_request(f, ROOT);
  fclose(f);
  do {
    if (!(returncode == -1))
      return "Error, process_request should've returned -1";
  } while (0);
  if (root_created == 1)
    rmdir(ROOT);
  remove(FILENAME);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_process_request_invalid_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe61(%rip),%rdi
call   1080 <printf@plt>
lea    0xe7c(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0xffffffff,%eax
jne    11f4 <test_process_request_invalid_request+0x64>
mov    -0x18(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1090 <write_to_file@plt>
mov    -0x10(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1233 <test_process_request_invalid_request+0xa3>
lea    0xe1c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <test_process_request_invalid_request+0x21a>
jmp    1238 <test_process_request_invalid_request+0xa8>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <process_request@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <remove@plt>
cmpl   $0xffffffff,-0x34(%rbp)
je     1274 <test_process_request_invalid_request+0xe4>
lea    0xdec(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <test_process_request_invalid_request+0x21a>
jmp    1279 <test_process_request_invalid_request+0xe9>
mov    -0x10(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1090 <write_to_file@plt>
mov    -0x10(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12b8 <test_process_request_invalid_request+0x128>
lea    0xd97(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <test_process_request_invalid_request+0x21a>
jmp    12bd <test_process_request_invalid_request+0x12d>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <process_request@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <remove@plt>
cmpl   $0xffffffff,-0x34(%rbp)
je     12f9 <test_process_request_invalid_request+0x169>
lea    0xd67(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <test_process_request_invalid_request+0x21a>
jmp    12fe <test_process_request_invalid_request+0x16e>
mov    -0x10(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   1090 <write_to_file@plt>
mov    -0x10(%rbp),%rdi
lea    0xd2a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    133d <test_process_request_invalid_request+0x1ad>
lea    0xd12(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <test_process_request_invalid_request+0x21a>
jmp    1342 <test_process_request_invalid_request+0x1b2>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <process_request@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0xffffffff,-0x34(%rbp)
je     1375 <test_process_request_invalid_request+0x1e5>
lea    0xceb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13aa <test_process_request_invalid_request+0x21a>
jmp    137a <test_process_request_invalid_request+0x1ea>
cmpl   $0x1,-0x1c(%rbp)
jne    138d <test_process_request_invalid_request+0x1fd>
mov    -0x18(%rbp),%rdi
call   1070 <rmdir@plt>
mov    -0x10(%rbp),%rdi
call   1030 <remove@plt>
lea    0xc88(%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_invalid_request>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1060 <puts@plt>
lea    0xe4e(%rip),%rdi
xor    %esi,%esi
call   10b0 <stat@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    11de <test_process_request_invalid_request+0x3e>
lea    0xe38(%rip),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
lea    0xe1b(%rip),%rbx
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <write_to_file@plt>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
lea    0xe15(%rip),%r12
test   %rax,%rax
je     1246 <test_process_request_invalid_request+0xa6>
mov    %rax,%rbp
lea    0xdf3(%rip),%rsi
mov    %rax,%rdi
call   1070 <process_request@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1080 <fclose@plt>
lea    0xdce(%rip),%rdi
call   1040 <remove@plt>
lea    0xdf2(%rip),%r13
cmp    $0xffffffff,%ebx
je     1258 <test_process_request_invalid_request+0xb8>
mov    %r13,%r12
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda1(%rip),%rbx
lea    0xdf7(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <write_to_file@plt>
lea    0xda7(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1246 <test_process_request_invalid_request+0xa6>
mov    %rax,%rbp
lea    0xd80(%rip),%rsi
mov    %rax,%rdi
call   1070 <process_request@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1080 <fclose@plt>
lea    0xd5b(%rip),%rdi
call   1040 <remove@plt>
cmp    $0xffffffff,%ebx
jne    1243 <test_process_request_invalid_request+0xa3>
lea    0xd4a(%rip),%rbx
lea    0xda4(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <write_to_file@plt>
lea    0xd50(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1246 <test_process_request_invalid_request+0xa6>
mov    %rax,%r14
lea    0xd25(%rip),%rsi
mov    %rax,%rdi
call   1070 <process_request@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1080 <fclose@plt>
mov    %r13,%r12
cmp    $0xffffffff,%ebx
jne    1246 <test_process_request_invalid_request+0xa6>
cmp    $0xffffffff,%r15d
jne    1317 <test_process_request_invalid_request+0x177>
lea    0xcfa(%rip),%rdi
call   1090 <rmdir@plt>
lea    0xce2(%rip),%rdi
call   1040 <remove@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r12d,%r12d
jmp    1246 <test_process_request_invalid_request+0xa6>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [39 x i8] c"Test process request: invalid request\0A\00"
@.str.1 = [28 x i8] c"test_server_invalid_request\00"
@.str.2 = [16 x i8] c"invalid_request\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [3 x i8] c"a+\00"
@.str.5 = [17 x i8] c"Error, f == NULL\00"
@.str.6 = [45 x i8] c"Error, process_request should've returned -1\00"
@.str.7 = [4 x i8] c"GET\00"
@.str.8 = [6 x i8] c"GET /\00"
@.str.9 = [2 x i8] c"\0A\00"
define i8* @test_process_request_invalid_request() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.stat*
%6 = alloca i32*
%7 = alloca i32
%8 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8** %3
store i32 0, i32* %4
store %struct.stat* null, %struct.stat** %5
%9 = load i8*, i8** %3
%10 = load %struct.stat*, %struct.stat** %5
%11 = call i32 @stat(i8* %9, %struct.stat* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i8*, i8** %3
%15 = call i32 @mkdir(i8* %14, i32 448)
store i32 1, i32* %4
br label %16
16: ; preds = %13, %0
%17 = load i8*, i8** %2
%18 = call i32 @write_to_file(i8* %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%19 = load i8*, i8** %2
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %20, i32** %6
br label %21
21: ; preds = %16
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %25, label %24
24: ; preds = %21
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %93
25: ; preds = %21
br label %26
26: ; preds = %25
%27 = load i32*, i32** %6
%28 = load i8*, i8** %3
%29 = call i32 @process_request(i32* %27, i8* %28)
store i32 %29, i32* %7
%30 = load i32*, i32** %6
%31 = call i32 @fclose(i32* %30)
%32 = load i8*, i8** %2
%33 = call i32 @remove(i8* %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, -1
br i1 %36, label %38, label %37
37: ; preds = %34
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i8** %1
br label %93
38: ; preds = %34
br label %39
39: ; preds = %38
%40 = load i8*, i8** %2
%41 = call i32 @write_to_file(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%42 = load i8*, i8** %2
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %43, i32** %6
br label %44
44: ; preds = %39
%45 = load i32*, i32** %6
%46 = icmp ne i32* %45, null
br i1 %46, label %48, label %47
47: ; preds = %44
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %93
48: ; preds = %44
br label %49
49: ; preds = %48
%50 = load i32*, i32** %6
%51 = load i8*, i8** %3
%52 = call i32 @process_request(i32* %50, i8* %51)
store i32 %52, i32* %7
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
%55 = load i8*, i8** %2
%56 = call i32 @remove(i8* %55)
br label %57
57: ; preds = %49
%58 = load i32, i32* %7
%59 = icmp eq i32 %58, -1
br i1 %59, label %61, label %60
60: ; preds = %57
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i8** %1
br label %93
61: ; preds = %57
br label %62
62: ; preds = %61
%63 = load i8*, i8** %2
%64 = call i32 @write_to_file(i8* %63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%65 = load i8*, i8** %2
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %66, i32** %6
br label %67
67: ; preds = %62
%68 = load i32*, i32** %6
%69 = icmp ne i32* %68, null
br i1 %69, label %71, label %70
70: ; preds = %67
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %93
71: ; preds = %67
br label %72
72: ; preds = %71
%73 = load i32*, i32** %6
%74 = load i8*, i8** %3
%75 = call i32 @process_request(i32* %73, i8* %74)
store i32 %75, i32* %7
%76 = load i32*, i32** %6
%77 = call i32 @fclose(i32* %76)
br label %78
78: ; preds = %72
%79 = load i32, i32* %7
%80 = icmp eq i32 %79, -1
br i1 %80, label %82, label %81
81: ; preds = %78
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i8** %1
br label %93
82: ; preds = %78
br label %83
83: ; preds = %82
%84 = load i32, i32* %4
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i8*, i8** %3
%88 = call i32 @rmdir(i8* %87)
br label %89
89: ; preds = %86, %83
%90 = load i8*, i8** %2
%91 = call i32 @remove(i8* %90)
%92 = 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 %93
93: ; preds = %89, %81, %70, %60, %47, %37, %24
%94 = load i8*, i8** %1
ret i8* %94
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [28 x i8] c"test_server_invalid_request\00"
@.str.2 = [16 x i8] c"invalid_request\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [3 x i8] c"a+\00"
@.str.5 = [17 x i8] c"Error, f == NULL\00"
@.str.6 = [45 x i8] c"Error, process_request should've returned -1\00"
@.str.7 = [4 x i8] c"GET\00"
@.str.8 = [6 x i8] c"GET /\00"
@str = [38 x i8] c"Test process request: invalid request\00"
define i8* @test_process_request_invalid_request() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %struct.stat* null)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @mkdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 448)
br label %6
6: ; preds = %4, %0
%7 = tail call i32 @write_to_file(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %38, label %10
10: ; preds = %6
%11 = tail call i32 @process_request(i32* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @fclose(i32* %8)
%13 = tail call i32 @remove(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %11, -1
br i1 %14, label %15, label %38
15: ; preds = %10
%16 = tail call i32 @write_to_file(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %38, label %19
19: ; preds = %15
%20 = tail call i32 @process_request(i32* %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 @fclose(i32* %17)
%22 = tail call i32 @remove(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32 %20, -1
br i1 %23, label %24, label %38
24: ; preds = %19
%25 = tail call i32 @write_to_file(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%26 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %38, label %28
28: ; preds = %24
%29 = tail call i32 @process_request(i32* %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%30 = tail call i32 @fclose(i32* %26)
%31 = icmp eq i32 %29, -1
br i1 %31, label %32, label %38
32: ; preds = %28
br i1 %3, label %33, label %35
33: ; preds = %32
%34 = tail call i32 @rmdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %32
%36 = tail call i32 @remove(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%37 = tail call i32 @putchar(i32 10)
br label %38
38: ; preds = %35, %10, %15, %19, %24, %28, %6
%39 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %6 ], [ null, %35 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), %10 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %15 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), %19 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %24 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), %28 ]
ret i8* %39
}