#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *parse_get_header(char *);
int /*<<< orphan*/ perror(char *);
char *read_header(int);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send_file(int, char *);
int /*<<< orphan*/ *strstr(char *, char *);
void handle_client(int fd) {
  int err = 0;
  char *html_header = read_header(fd);
  char *get_header = parse_get_header(html_header);
  if (html_header == NULL) {
    return;
  }
  if (strstr(get_header, "/../") != NULL) {
    err = send(fd, "Do not use '/../' in path.\n", 25, 0);
    if (err == -1) {
      perror("send() failed");
    }
    return;
  }
  char *file_name = get_header + 1;
  send_file(fd, file_name);
  free(html_header);
}


x86 assembly (clang, -O0):
<handle_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <read_header@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <parse_get_header@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ab <handle_client+0x3b>
jmp    121a <handle_client+0xaa>
mov    -0x18(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     11f9 <handle_client+0x89>
mov    -0x4(%rbp),%edi
lea    0xe36(%rip),%rsi
mov    $0x19,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11f4 <handle_client+0x84>
lea    0xe32(%rip),%rdi
call   1050 <perror@plt>
jmp    121a <handle_client+0xaa>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <send_file@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_client>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
call   1070 <read_header@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <parse_get_header@plt>
test   %rbx,%rbx
je     11be <handle_client+0x4e>
mov    %rax,%rbp
lea    0xe6a(%rip),%rsi
mov    %rax,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     11c3 <handle_client+0x53>
lea    0xe5b(%rip),%rsi
mov    %r14d,%edi
mov    $0x19,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     11de <handle_client+0x6e>
pop    %rbx
pop    %r14
pop    %rbp
ret
add    $0x1,%rbp
mov    %r14d,%edi
mov    %rbp,%rsi
call   1060 <send_file@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <free@plt>
lea    0xe3c(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <perror@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"/../\00"
@.str.1 = [28 x i8] c"Do not use '/../' in path.\0A\00"
@.str.2 = [14 x i8] c"send() failed\00"
define void @handle_client(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %2
store i32 0, i32* %3
%7 = load i32, i32* %2
%8 = call i8* @read_header(i32 %7)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = call i8* @parse_get_header(i8* %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
br label %34
14: ; preds = %1
%15 = load i8*, i8** %5
%16 = call i32* @strstr(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32, i32* %2
%20 = call i32 @send(i32 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 25, i32 0)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
br label %34
26: ; preds = %14
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %6
%29 = load i32, i32* %2
%30 = load i8*, i8** %6
%31 = call i32 @send_file(i32 %29, i8* %30)
%32 = load i8*, i8** %4
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %26, %25, %13
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"/../\00"
@.str.1 = [28 x i8] c"Do not use '/../' in path.\0A\00"
@.str.2 = [14 x i8] c"send() failed\00"
define void @handle_client(i32 %0) {
%2 = tail call i8* @read_header(i32 %0)
%3 = tail call i8* @parse_get_header(i8* %2)
%4 = icmp eq i8* %2, null
br i1 %4, label %17, label %5
5: ; preds = %1
%6 = tail call i32* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 25, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %17
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %3, i64 1
%15 = tail call i32 @send_file(i32 %0, i8* %14)
%16 = tail call i32 @free(i8* %2)
br label %17
17: ; preds = %8, %11, %1, %13
ret void
}