#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 BUFSIZ;
int /*<<< orphan*/ cannot_do(int);
int /*<<< orphan*/ do_404(char *, int);
int /*<<< orphan*/ do_cat(char *, int);
int /*<<< orphan*/ do_exec(char *, int);
int /*<<< orphan*/ do_ls(char *, int);
scalar_t__ ends_in_cgi(char *);
scalar_t__ fork();
scalar_t__ is_dir(char *);
scalar_t__ not_exist(char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
extern void process_rq(char *request, int sock_fd) {
  char cmd[BUFSIZ], arg[BUFSIZ];
  strcpy(arg, "./");
  sscanf(request, "%s %s", cmd, arg + 2);
  if (fork() != 0)
    return;
  if (strcmp(cmd, "GET") != 0) {
    cannot_do(sock_fd);
  } else if (not_exist(arg)) {
    do_404(arg, sock_fd);
  } else if (is_dir(arg)) {
    do_ls(arg, sock_fd);
  } else if (ends_in_cgi(arg)) {
    do_exec(arg, sock_fd);
  } else {
    do_cat(arg, sock_fd);
  }
}


x86 assembly (clang, -O0):
<process_rq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
lea    0xde0(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rdi
add    $0x2,%rcx
lea    0xdc7(%rip),%rsi
call   10d0 <sscanf@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
cmp    $0x0,%rax
je     125e <process_rq+0x9e>
movl   $0x1,-0x2c(%rbp)
jmp    1313 <process_rq+0x153>
mov    -0x38(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
je     1285 <process_rq+0xc5>
mov    -0xc(%rbp),%edi
call   1070 <cannot_do@plt>
jmp    130c <process_rq+0x14c>
mov    -0x40(%rbp),%rdi
call   10a0 <not_exist@plt>
cmp    $0x0,%rax
je     12a9 <process_rq+0xe9>
mov    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <do_404@plt>
jmp    1307 <process_rq+0x147>
mov    -0x40(%rbp),%rdi
call   1080 <is_dir@plt>
cmp    $0x0,%rax
je     12cd <process_rq+0x10d>
mov    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   10c0 <do_ls@plt>
jmp    1302 <process_rq+0x142>
mov    -0x40(%rbp),%rdi
call   1090 <ends_in_cgi@plt>
cmp    $0x0,%rax
je     12f1 <process_rq+0x131>
mov    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <do_exec@plt>
jmp    12fd <process_rq+0x13d>
mov    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <do_cat@plt>
jmp    1302 <process_rq+0x142>
jmp    1307 <process_rq+0x147>
jmp    130c <process_rq+0x14c>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_rq>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe05(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0x2(%r15),%rcx
lea    0xdf5(%rip),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
call   10d0 <sscanf@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
jne    1296 <process_rq+0xd6>
lea    0xddd(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     1243 <process_rq+0x83>
mov    %r14d,%edi
call   1070 <cannot_do@plt>
jmp    1296 <process_rq+0xd6>
mov    %r15,%rdi
call   10a0 <not_exist@plt>
test   %rax,%rax
je     125d <process_rq+0x9d>
mov    %r15,%rdi
mov    %r14d,%esi
call   1040 <do_404@plt>
jmp    1296 <process_rq+0xd6>
mov    %r15,%rdi
call   1080 <is_dir@plt>
test   %rax,%rax
je     1277 <process_rq+0xb7>
mov    %r15,%rdi
mov    %r14d,%esi
call   10c0 <do_ls@plt>
jmp    1296 <process_rq+0xd6>
mov    %r15,%rdi
call   1090 <ends_in_cgi@plt>
mov    %r15,%rdi
mov    %r14d,%esi
test   %rax,%rax
je     1291 <process_rq+0xd1>
call   1050 <do_exec@plt>
jmp    1296 <process_rq+0xd6>
call   1060 <do_cat@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"./\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [4 x i8] c"GET\00"
define void @process_rq(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
store i64 %14, i64* %7
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %15, i64 2
%19 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %18)
%20 = call i64 (...) @fork()
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 1, i32* %8
br label %54
23: ; preds = %2
%24 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %4
%28 = call i32 @cannot_do(i32 %27)
br label %53
29: ; preds = %23
%30 = call i64 @not_exist(i8* %15)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %4
%34 = call i32 @do_404(i8* %15, i32 %33)
br label %52
35: ; preds = %29
%36 = call i64 @is_dir(i8* %15)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* %4
%40 = call i32 @do_ls(i8* %15, i32 %39)
br label %51
41: ; preds = %35
%42 = call i64 @ends_in_cgi(i8* %15)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* %4
%46 = call i32 @do_exec(i8* %15, i32 %45)
br label %50
47: ; preds = %41
%48 = load i32, i32* %4
%49 = call i32 @do_cat(i8* %15, i32 %48)
br label %50
50: ; preds = %47, %44
br label %51
51: ; preds = %50, %38
br label %52
52: ; preds = %51, %32
br label %53
53: ; preds = %52, %26
store i32 0, i32* %8
br label %54
54: ; preds = %53, %22
%55 = load i8*, i8** %5
%56 = load i32, i32* %8
switch i32 %56, label %58 [
i32 0, label %57
i32 1, label %57
]
57: ; preds = %54, %54
ret void
58: ; preds = %54
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"./\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [4 x i8] c"GET\00"
define void @process_rq(i8* nocapture %0, i32 %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8, i8* %6, i64 2
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %8)
%10 = call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %34
12: ; preds = %2
%13 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 @cannot_do(i32 %1)
br label %34
17: ; preds = %12
%18 = call i64 @not_exist(i8* %6)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @do_404(i8* %6, i32 %1)
br label %34
22: ; preds = %17
%23 = call i64 @is_dir(i8* %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 @do_ls(i8* %6, i32 %1)
br label %34
27: ; preds = %22
%28 = call i64 @ends_in_cgi(i8* %6)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @do_exec(i8* %6, i32 %1)
br label %34
32: ; preds = %27
%33 = call i32 @do_cat(i8* %6, i32 %1)
br label %34
34: ; preds = %15, %25, %32, %30, %20, %2
ret void
}