#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 *);
int /*<<< orphan*/ http_404(int);
int /*<<< orphan*/ http_find_handler(int, char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int sscanf(char *, char *, char **, char **);
int strlen(char *);
void handle_incoming(int sock) {
  static char buf[2048 + 2];
  char *buf_processed = NULL;
  char *htmlversion = NULL;
  int i;
  if ((i = read(sock, buf, 2048)) <= 0)
    return;
  buf[i] = 0;
  printf("\nRequest:\n%s\n", buf);
  if (strlen(buf) > 4) {
    switch (sscanf(buf, "GET %as %as", &buf_processed, &htmlversion)) {
    case 1:
    case 2:
      http_find_handler(sock, buf_processed);
      free(buf_processed);
      if (htmlversion)
        free(htmlversion);
      break;
    default:
      http_404(sock);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<handle_incoming>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    0x2edb(%rip),%rsi
mov    $0x800,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jg     11b0 <handle_incoming+0x40>
jmp    124e <handle_incoming+0xde>
movslq -0x1c(%rbp),%rcx
lea    0x2eb5(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0xe3a(%rip),%rdi
lea    0x2ea3(%rip),%rsi
call   1060 <printf@plt>
lea    0x2e97(%rip),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jle    124e <handle_incoming+0xde>
lea    0x2e82(%rip),%rdi
lea    0xe19(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1080 <sscanf@plt>
add    $0xffffffff,%eax
sub    $0x1,%eax
ja     1241 <handle_incoming+0xd1>
jmp    1213 <handle_incoming+0xa3>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1090 <http_find_handler@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     123c <handle_incoming+0xcc>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1249 <handle_incoming+0xd9>
mov    -0x4(%rbp),%edi
call   1050 <http_404@plt>
jmp    124e <handle_incoming+0xde>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_incoming>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x2edf(%rip),%rbx
mov    %rbx,%rsi
mov    $0x800,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1217 <handle_incoming+0xa7>
mov    %eax,%eax
movb   $0x0,(%rax,%rbx,1)
lea    0xe51(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x5,%eax
jl     1217 <handle_incoming+0xa7>
lea    0x2ea5(%rip),%rdi
lea    0xe3c(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1080 <sscanf@plt>
add    $0xffffffff,%eax
cmp    $0x1,%eax
ja     1210 <handle_incoming+0xa0>
mov    0x8(%rsp),%rsi
mov    %ebp,%edi
call   1090 <http_find_handler@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1217 <handle_incoming+0xa7>
call   1030 <free@plt>
jmp    1217 <handle_incoming+0xa7>
mov    %ebp,%edi
call   1050 <http_404@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@handle_incoming.buf = internal global [2050 x i8] zeroinitializer
@.str = [14 x i8] c"\0ARequest:\0A%s\0A\00"
@.str.1 = [12 x i8] c"GET %as %as\00"
define void @handle_incoming(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
store i8* null, i8** %3
store i8* null, i8** %4
%6 = load i32, i32* %2
%7 = call i32 @read(i32 %6, i8* getelementptr inbounds ([2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 0), i32 2048)
store i32 %7, i32* %5
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
br label %35
10: ; preds = %1
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 0))
%15 = call i32 @strlen(i8* getelementptr inbounds ([2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 0))
%16 = icmp sgt i32 %15, 4
br i1 %16, label %17, label %35
17: ; preds = %10
%18 = call i32 @sscanf(i8* getelementptr inbounds ([2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %3, i8** %4)
switch i32 %18, label %31 [
i32 1, label %19
i32 2, label %19
]
19: ; preds = %17, %17
%20 = load i32, i32* %2
%21 = load i8*, i8** %3
%22 = call i32 @http_find_handler(i32 %20, i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %4
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i8*, i8** %4
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %27, %19
br label %34
31: ; preds = %17
%32 = load i32, i32* %2
%33 = call i32 @http_404(i32 %32)
br label %34
34: ; preds = %31, %30
br label %35
35: ; preds = %9, %34, %10
ret void
}

LLVM IR (-O2):
@handle_incoming.buf = internal global [2050 x i8] zeroinitializer
@.str = [14 x i8] c"\0ARequest:\0A%s\0A\00"
@.str.1 = [12 x i8] c"GET %as %as\00"
define void @handle_incoming(i32 %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = tail call i32 @read(i32 %0, i8* getelementptr inbounds ([2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 0), i32 2048)
%7 = icmp slt i32 %6, 1
br i1 %7, label %29, label %8
8: ; preds = %1
%9 = zext i32 %6 to i64
%10 = getelementptr inbounds [2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 %9
store i8 0, i8* %10
%11 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 0))
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 0))
%13 = icmp sgt i32 %12, 4
br i1 %13, label %14, label %29
14: ; preds = %8
%15 = call i32 @sscanf(i8* getelementptr inbounds ([2050 x i8], [2050 x i8]* @handle_incoming.buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %2, i8** %3)
%16 = add i32 %15, -1
%17 = icmp ult i32 %16, 2
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i8*, i8** %2
%20 = call i32 @http_find_handler(i32 %0, i8* %19)
%21 = load i8*, i8** %2
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %3
%24 = icmp eq i8* %23, null
br i1 %24, label %29, label %25
25: ; preds = %18
%26 = call i32 @free(i8* %23)
br label %29
27: ; preds = %14
%28 = call i32 @http_404(i32 %0)
br label %29
29: ; preds = %8, %18, %25, %27, %1
ret void
}