#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_bad_method() {
  printf("Test process request: Bad method\n");
  const char *FILENAME = "test_server_bad_method";
  char *ROOT = "not_important_dir";
  int root_created = 0;
  struct stat *st = {0};
  if (stat(ROOT, st) == -1) {
    mkdir(ROOT, 0700);
    root_created = 1;
  }
  write_to_file(FILENAME, "BAD_METHOD / 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, "501") == 1))
      return "Error, returned file does not contain 501 error code";
  } while (0);
  if (root_created == 1)
    rmdir(ROOT);
  remove(FILENAME);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_process_request_bad_method>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe51(%rip),%rdi
call   1080 <printf@plt>
lea    0xe67(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
jne    1204 <test_process_request_bad_method+0x64>
mov    -0x18(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1090 <write_to_file@plt>
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1243 <test_process_request_bad_method+0xa3>
lea    0xe2a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <test_process_request_bad_method+0x11c>
jmp    1248 <test_process_request_bad_method+0xa8>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <process_request@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   10a0 <is_in_file@plt>
cmp    $0x1,%eax
je     1287 <test_process_request_bad_method+0xe7>
lea    0xdfb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12bc <test_process_request_bad_method+0x11c>
jmp    128c <test_process_request_bad_method+0xec>
cmpl   $0x1,-0x1c(%rbp)
jne    129f <test_process_request_bad_method+0xff>
mov    -0x18(%rbp),%rdi
call   1070 <rmdir@plt>
mov    -0x10(%rbp),%rdi
call   1030 <remove@plt>
lea    0xd71(%rip),%rdi
call   1080 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_process_request_bad_method>:
push   %rbp
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
call   1060 <puts@plt>
lea    0xe51(%rip),%rdi
xor    %esi,%esi
call   10c0 <stat@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11e5 <test_process_request_bad_method+0x35>
lea    0xe3c(%rip),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
lea    0xe14(%rip),%rbx
lea    0xe36(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <write_to_file@plt>
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     126c <test_process_request_bad_method+0xbc>
mov    %rax,%rbx
lea    0xdfe(%rip),%rsi
mov    %rax,%rdi
call   1070 <process_request@plt>
mov    %rbx,%rdi
call   1080 <fclose@plt>
lea    0xdd0(%rip),%rdi
lea    0xe1c(%rip),%rsi
call   10b0 <is_in_file@plt>
cmp    $0x1,%eax
jne    1275 <test_process_request_bad_method+0xc5>
cmp    $0xffffffff,%ebp
jne    1252 <test_process_request_bad_method+0xa2>
lea    0xdca(%rip),%rdi
call   1090 <rmdir@plt>
lea    0xda7(%rip),%rdi
call   1040 <remove@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
jmp    127c <test_process_request_bad_method+0xcc>
lea    0xdcf(%rip),%rax
jmp    127c <test_process_request_bad_method+0xcc>
lea    0xddb(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [34 x i8] c"Test process request: Bad method\0A\00"
@.str.1 = [23 x i8] c"test_server_bad_method\00"
@.str.2 = [18 x i8] c"not_important_dir\00"
@.str.3 = [22 x i8] c"BAD_METHOD / HTTP/1.1\00"
@.str.4 = [3 x i8] c"a+\00"
@.str.5 = [17 x i8] c"Error, f == NULL\00"
@.str.6 = [4 x i8] c"501\00"
@.str.7 = [53 x i8] c"Error, returned file does not contain 501 error code\00"
@.str.8 = [2 x i8] c"\0A\00"
define i8* @test_process_request_bad_method() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.stat*
%6 = alloca i32*
%7 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8** %3
store i32 0, i32* %4
store %struct.stat* null, %struct.stat** %5
%8 = load i8*, i8** %3
%9 = load %struct.stat*, %struct.stat** %5
%10 = call i32 @stat(i8* %8, %struct.stat* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i8*, i8** %3
%14 = call i32 @mkdir(i8* %13, i32 448)
store i32 1, i32* %4
br label %15
15: ; preds = %12, %0
%16 = load i8*, i8** %2
%17 = call i32 @write_to_file(i8* %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%18 = load i8*, i8** %2
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %19, i32** %6
br label %20
20: ; preds = %15
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %20
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %47
24: ; preds = %20
br label %25
25: ; preds = %24
%26 = load i32*, i32** %6
%27 = load i8*, i8** %3
%28 = call i32 @process_request(i32* %26, i8* %27)
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %25
%32 = load i8*, i8** %2
%33 = call i32 @is_in_file(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%34 = icmp eq i32 %33, 1
br i1 %34, label %36, label %35
35: ; preds = %31
store i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i8** %1
br label %47
36: ; preds = %31
br label %37
37: ; preds = %36
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i8*, i8** %3
%42 = call i32 @rmdir(i8* %41)
br label %43
43: ; preds = %40, %37
%44 = load i8*, i8** %2
%45 = call i32 @remove(i8* %44)
%46 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i8* null, i8** %1
br label %47
47: ; preds = %43, %35, %23
%48 = load i8*, i8** %1
ret i8* %48
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.1 = [23 x i8] c"test_server_bad_method\00"
@.str.2 = [18 x i8] c"not_important_dir\00"
@.str.3 = [22 x i8] c"BAD_METHOD / HTTP/1.1\00"
@.str.4 = [3 x i8] c"a+\00"
@.str.5 = [17 x i8] c"Error, f == NULL\00"
@.str.6 = [4 x i8] c"501\00"
@.str.7 = [53 x i8] c"Error, returned file does not contain 501 error code\00"
@str = [33 x i8] c"Test process request: Bad method\00"
define i8* @test_process_request_bad_method() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @stat(i8* getelementptr inbounds ([18 x i8], [18 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 ([18 x i8], [18 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 ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 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 %21, label %10
10: ; preds = %6
%11 = tail call i32 @process_request(i32* %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @fclose(i32* %8)
%13 = tail call i32 @is_in_file(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %10
br i1 %3, label %16, label %18
16: ; preds = %15
%17 = tail call i32 @rmdir(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %15
%19 = tail call i32 @remove(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @putchar(i32 10)
br label %21
21: ; preds = %10, %6, %18
%22 = phi i8* [ null, %18 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %6 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), %10 ]
ret i8* %22
}