#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 */
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*/ printf(char *);
int /*<<< orphan*/ process_request(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ remove(char const *);
int /*<<< orphan*/ write_to_file(char const *, char *);
char *test_process_request_not_found() {
  printf("Test process request: File not found\n");
  const char *FILENAME = "test_server_not_found";
  char *ROOT = "non_existing_root";
  write_to_file(FILENAME, "GET / 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, "404") == 1))
      return "Error, returned file does not contain 404 error code";
  } while (0);
  remove(FILENAME);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<test_process_request_not_found>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
call   1060 <printf@plt>
lea    0xe9b(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1070 <write_to_file@plt>
mov    -0x10(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d9 <test_process_request_not_found+0x69>
lea    0xe90(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123f <test_process_request_not_found+0xcf>
jmp    11de <test_process_request_not_found+0x6e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <process_request@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1080 <is_in_file@plt>
cmp    $0x1,%eax
je     121d <test_process_request_not_found+0xad>
lea    0xe61(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123f <test_process_request_not_found+0xcf>
jmp    1222 <test_process_request_not_found+0xb2>
mov    -0x10(%rbp),%rdi
call   1030 <remove@plt>
lea    0xdf2(%rip),%rdi
call   1060 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_process_request_not_found>:
push   %rbx
lea    0xefc(%rip),%rdi
call   1050 <puts@plt>
lea    0xe6c(%rip),%rbx
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <write_to_file@plt>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1203 <test_process_request_not_found+0x83>
mov    %rax,%rbx
lea    0xe55(%rip),%rsi
mov    %rax,%rdi
call   1060 <process_request@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xe28(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <is_in_file@plt>
cmp    $0x1,%eax
jne    120c <test_process_request_not_found+0x8c>
lea    0xe10(%rip),%rdi
call   1040 <remove@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe30(%rip),%rax
pop    %rbx
ret
lea    0xe3c(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Test process request: File not found\0A\00"
@.str.1 = [22 x i8] c"test_server_not_found\00"
@.str.2 = [18 x i8] c"non_existing_root\00"
@.str.3 = [15 x i8] c"GET / 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"404\00"
@.str.7 = [53 x i8] c"Error, returned file does not contain 404 error code\00"
@.str.8 = [2 x i8] c"\0A\00"
define i8* @test_process_request_not_found() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([22 x i8], [22 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
%6 = load i8*, i8** %2
%7 = call i32 @write_to_file(i8* %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %9, i32** %4
br label %10
10: ; preds = %0
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %31
14: ; preds = %10
br label %15
15: ; preds = %14
%16 = load i32*, i32** %4
%17 = load i8*, i8** %3
%18 = call i32 @process_request(i32* %16, i8* %17)
%19 = load i32*, i32** %4
%20 = call i32 @fclose(i32* %19)
br label %21
21: ; preds = %15
%22 = load i8*, i8** %2
%23 = call i32 @is_in_file(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%24 = icmp eq i32 %23, 1
br i1 %24, label %26, label %25
25: ; preds = %21
store i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i8** %1
br label %31
26: ; preds = %21
br label %27
27: ; preds = %26
%28 = load i8*, i8** %2
%29 = call i32 @remove(i8* %28)
%30 = 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 %31
31: ; preds = %27, %25, %13
%32 = load i8*, i8** %1
ret i8* %32
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"test_server_not_found\00"
@.str.2 = [18 x i8] c"non_existing_root\00"
@.str.3 = [15 x i8] c"GET / 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"404\00"
@.str.7 = [53 x i8] c"Error, returned file does not contain 404 error code\00"
@str = [37 x i8] c"Test process request: File not found\00"
define i8* @test_process_request_not_found() {
%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 @write_to_file(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = tail call i32 @process_request(i32* %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @fclose(i32* %3)
%8 = tail call i32 @is_in_file(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = tail call i32 @remove(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @putchar(i32 10)
br label %13
13: ; preds = %5, %0, %10
%14 = phi i8* [ null, %10 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), %0 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), %5 ]
ret i8* %14
}