#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 */
scalar_t__ is_a_cgi_file(char *);
scalar_t__ is_a_dir(char *);
scalar_t__ not_exist(char *);
int /*<<< orphan*/ resp_cannot_do(int);
int /*<<< orphan*/ resp_do_404(char *, int);
int /*<<< orphan*/ resp_do_cat(char *, int);
int /*<<< orphan*/ resp_do_exec(char *, int);
int /*<<< orphan*/ resp_do_ls(char *, int);
int sscanf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int process_request(char *rq, int fd) {
  char cmd[1024];
  char arg[1024];
  strcpy(arg, "./");
  if (sscanf(rq, "%s %s", cmd, arg + 2) != 2) {
    return 1;
  }
  if (strcmp(cmd, "GET") != 0) {
    resp_cannot_do(fd);
  } else if (not_exist(arg)) {
    resp_do_404(arg, fd);
  } else if (is_a_dir(arg)) {
    resp_do_ls(arg, fd);
  } else if (is_a_cgi_file(arg)) {
    resp_do_exec(arg, fd);
  } else {
    resp_do_cat(arg, fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<process_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x820(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    -0x820(%rbp),%rcx
add    $0x2,%rcx
lea    0xe11(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x2,%eax
je     120c <process_request+0x5c>
movl   $0x1,-0x4(%rbp)
jmp    12d9 <process_request+0x129>
lea    -0x420(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1236 <process_request+0x86>
mov    -0x14(%rbp),%edi
call   1070 <resp_cannot_do@plt>
jmp    12d2 <process_request+0x122>
lea    -0x820(%rbp),%rdi
call   1050 <not_exist@plt>
cmp    $0x0,%rax
je     1260 <process_request+0xb0>
lea    -0x820(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <resp_do_404@plt>
jmp    12cd <process_request+0x11d>
lea    -0x820(%rbp),%rdi
call   10d0 <is_a_dir@plt>
cmp    $0x0,%rax
je     128a <process_request+0xda>
lea    -0x820(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10b0 <resp_do_ls@plt>
jmp    12c8 <process_request+0x118>
lea    -0x820(%rbp),%rdi
call   10a0 <is_a_cgi_file@plt>
cmp    $0x0,%rax
je     12b4 <process_request+0x104>
lea    -0x820(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <resp_do_exec@plt>
jmp    12c3 <process_request+0x113>
lea    -0x820(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10c0 <resp_do_cat@plt>
jmp    12c8 <process_request+0x118>
jmp    12cd <process_request+0x11d>
jmp    12d2 <process_request+0x122>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_request>:
push   %rbp
push   %rbx
sub    $0x808,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe3b(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0x2(%rsp),%rcx
lea    0xe2a(%rip),%rsi
lea    0x400(%rsp),%rdx
mov    %rbx,%rdi
call   1080 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x2,%ecx
jne    1263 <process_request+0xb3>
lea    0xe0d(%rip),%rsi
lea    0x400(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1217 <process_request+0x67>
mov    %ebp,%edi
call   1070 <resp_cannot_do@plt>
jmp    1261 <process_request+0xb1>
mov    %rsp,%rdi
call   1050 <not_exist@plt>
mov    %rsp,%rdi
test   %rax,%rax
je     1230 <process_request+0x80>
mov    %ebp,%esi
call   1090 <resp_do_404@plt>
jmp    1261 <process_request+0xb1>
call   10d0 <is_a_dir@plt>
mov    %rsp,%rdi
test   %rax,%rax
je     1246 <process_request+0x96>
mov    %ebp,%esi
call   10b0 <resp_do_ls@plt>
jmp    1261 <process_request+0xb1>
call   10a0 <is_a_cgi_file@plt>
mov    %rsp,%rdi
mov    %ebp,%esi
test   %rax,%rax
je     125c <process_request+0xac>
call   1040 <resp_do_exec@plt>
jmp    1261 <process_request+0xb1>
call   10c0 <resp_do_cat@plt>
xor    %eax,%eax
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 i32 @process_request(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %4
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds i8, i8* %12, i64 2
%14 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %13)
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 1, i32* %3
br label %56
17: ; preds = %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %5
%23 = call i32 @resp_cannot_do(i32 %22)
br label %55
24: ; preds = %17
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = call i64 @not_exist(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* %5
%31 = call i32 @resp_do_404(i8* %29, i32 %30)
br label %54
32: ; preds = %24
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = call i64 @is_a_dir(i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = load i32, i32* %5
%39 = call i32 @resp_do_ls(i8* %37, i32 %38)
br label %53
40: ; preds = %32
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = call i64 @is_a_cgi_file(i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%46 = load i32, i32* %5
%47 = call i32 @resp_do_exec(i8* %45, i32 %46)
br label %52
48: ; preds = %40
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%50 = load i32, i32* %5
%51 = call i32 @resp_do_cat(i8* %49, i32 %50)
br label %52
52: ; preds = %48, %44
br label %53
53: ; preds = %52, %36
br label %54
54: ; preds = %53, %28
br label %55
55: ; preds = %54, %21
store i32 0, i32* %3
br label %56
56: ; preds = %55, %16
%57 = load i32, i32* %3
ret i32 %57
}

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 i32 @process_request(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 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, 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 = icmp eq i32 %9, 2
br i1 %10, label %11, label %33
11: ; preds = %2
%12 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @resp_cannot_do(i32 %1)
br label %33
16: ; preds = %11
%17 = call i64 @not_exist(i8* %6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32 @resp_do_404(i8* %6, i32 %1)
br label %33
21: ; preds = %16
%22 = call i64 @is_a_dir(i8* %6)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @resp_do_ls(i8* %6, i32 %1)
br label %33
26: ; preds = %21
%27 = call i64 @is_a_cgi_file(i8* %6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 @resp_do_exec(i8* %6, i32 %1)
br label %33
31: ; preds = %26
%32 = call i32 @resp_do_cat(i8* %6, i32 %1)
br label %33
33: ; preds = %14, %24, %31, %29, %19, %2
%34 = phi i32 [ 1, %2 ], [ 0, %19 ], [ 0, %29 ], [ 0, %31 ], [ 0, %24 ], [ 0, %14 ]
ret i32 %34
}