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


x86 assembly (clang, -O0):
<process_rq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   10e0 <fork@plt>
cmp    $0x0,%rax
je     11e8 <process_rq+0x28>
jmp    12f1 <process_rq+0x131>
lea    -0x810(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    -0x810(%rbp),%rcx
add    $0x2,%rcx
lea    0xdeb(%rip),%rsi
call   10d0 <sscanf@plt>
cmp    $0x2,%eax
je     122b <process_rq+0x6b>
jmp    12f1 <process_rq+0x131>
lea    -0x410(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
je     1255 <process_rq+0x95>
mov    -0xc(%rbp),%edi
call   1070 <cannot_do@plt>
jmp    12f1 <process_rq+0x131>
lea    -0x810(%rbp),%rdi
call   10a0 <not_exist@plt>
cmp    $0x0,%rax
je     127f <process_rq+0xbf>
lea    -0x810(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <do_404@plt>
jmp    12ec <process_rq+0x12c>
lea    -0x810(%rbp),%rdi
call   1080 <isadir@plt>
cmp    $0x0,%rax
je     12a9 <process_rq+0xe9>
lea    -0x810(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   10c0 <do_ls@plt>
jmp    12e7 <process_rq+0x127>
lea    -0x810(%rbp),%rdi
call   1090 <ends_in_cgi@plt>
cmp    $0x0,%rax
je     12d3 <process_rq+0x113>
lea    -0x810(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <do_exec@plt>
jmp    12e2 <process_rq+0x122>
lea    -0x810(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <do_cat@plt>
jmp    12e7 <process_rq+0x127>
jmp    12ec <process_rq+0x12c>
jmp    12f1 <process_rq+0x131>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_rq>:
push   %rbp
push   %rbx
sub    $0x808,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
jne    127a <process_rq+0xba>
lea    0xe1b(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0x2(%rsp),%rcx
lea    0xe0a(%rip),%rsi
lea    0x400(%rsp),%rdx
mov    %rbx,%rdi
call   10d0 <sscanf@plt>
cmp    $0x2,%eax
jne    127a <process_rq+0xba>
lea    0xdf4(%rip),%rsi
lea    0x400(%rsp),%rdi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     1230 <process_rq+0x70>
mov    %ebp,%edi
call   1070 <cannot_do@plt>
jmp    127a <process_rq+0xba>
mov    %rsp,%rdi
call   10a0 <not_exist@plt>
mov    %rsp,%rdi
test   %rax,%rax
je     1249 <process_rq+0x89>
mov    %ebp,%esi
call   1040 <do_404@plt>
jmp    127a <process_rq+0xba>
call   1080 <isadir@plt>
mov    %rsp,%rdi
test   %rax,%rax
je     125f <process_rq+0x9f>
mov    %ebp,%esi
call   10c0 <do_ls@plt>
jmp    127a <process_rq+0xba>
call   1090 <ends_in_cgi@plt>
mov    %rsp,%rdi
mov    %ebp,%esi
test   %rax,%rax
je     1275 <process_rq+0xb5>
call   1050 <do_exec@plt>
jmp    127a <process_rq+0xba>
call   1060 <do_cat@plt>
add    $0x808,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.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 [1024 x i8]
%6 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i64 (...) @fork()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
br label %58
10: ; preds = %2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %3
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %16)
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %10
br label %58
20: ; preds = %10
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %4
%26 = call i32 @cannot_do(i32 %25)
br label %58
27: ; preds = %20
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i64 @not_exist(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = load i32, i32* %4
%34 = call i32 @do_404(i8* %32, i32 %33)
br label %57
35: ; preds = %27
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%37 = call i64 @isadir(i8* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* %4
%42 = call i32 @do_ls(i8* %40, i32 %41)
br label %56
43: ; preds = %35
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%45 = call i64 @ends_in_cgi(i8* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%49 = load i32, i32* %4
%50 = call i32 @do_exec(i8* %48, i32 %49)
br label %55
51: ; preds = %43
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%53 = load i32, i32* %4
%54 = call i32 @do_cat(i8* %52, i32 %53)
br label %55
55: ; preds = %51, %47
br label %56
56: ; preds = %55, %39
br label %57
57: ; preds = %56, %31
br label %58
58: ; preds = %9, %19, %57, %24
ret void
}

LLVM IR (-O2):
@.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 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %36
9: ; preds = %2
%10 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 2
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %11)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %36
14: ; preds = %9
%15 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @cannot_do(i32 %1)
br label %36
19: ; preds = %14
%20 = call i64 @not_exist(i8* %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @do_404(i8* %6, i32 %1)
br label %36
24: ; preds = %19
%25 = call i64 @isadir(i8* %6)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i32 @do_ls(i8* %6, i32 %1)
br label %36
29: ; preds = %24
%30 = call i64 @ends_in_cgi(i8* %6)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @do_exec(i8* %6, i32 %1)
br label %36
34: ; preds = %29
%35 = call i32 @do_cat(i8* %6, i32 %1)
br label %36
36: ; preds = %17, %27, %34, %32, %22, %9, %2
ret void
}