#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*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get(int, char *, char *);
char *malloc(int);
int /*<<< orphan*/ not_found(int, char *);
int /*<<< orphan*/ parse_header(char *, char **);
int /*<<< orphan*/ parse_message(char *, char **);
int /*<<< orphan*/ puts(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
void *connection_handler(void *client_sock) {
  int sock = *(int *)client_sock;
  int read_size;
  char client_message[2000];
  if ((read_size = recv(sock, client_message, 2000, 0)) > 0) {
    char http_message[20][100];
    char header[4][100];
    char *message = malloc(1024);
    parse_message(client_message, http_message);
    parse_header(http_message[0], header);
    if (strcmp(header[0], "GET") == 0) {
      get(sock, header[1], message);
    } else {
      not_found(sock, "");
    }
    free(message);
  }
  if (read_size == 0) {
    puts("client disconnected");
    fflush(stdout);
  } else if (read_size == -1) {
    puts("recv failed");
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<connection_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1150,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x7e0(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    1278 <connection_handler+0xc8>
mov    $0x400,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x1148(%rbp)
lea    -0x7e0(%rbp),%rdi
lea    -0xfb0(%rbp),%rsi
call   1060 <parse_message@plt>
lea    -0xfb0(%rbp),%rdi
lea    -0x1140(%rbp),%rsi
call   1050 <parse_header@plt>
lea    -0x1140(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    125d <connection_handler+0xad>
mov    -0xc(%rbp),%edi
lea    -0x1140(%rbp),%rsi
add    $0x64,%rsi
mov    -0x1148(%rbp),%rdx
call   10d0 <get@plt>
jmp    126c <connection_handler+0xbc>
mov    -0xc(%rbp),%edi
lea    0xd9c(%rip),%rsi
call   10a0 <not_found@plt>
mov    -0x1148(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x10(%rbp)
jne    12a1 <connection_handler+0xf1>
lea    0xd7b(%rip),%rdi
call   1070 <puts@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
jmp    12bc <connection_handler+0x10c>
cmpl   $0xffffffff,-0x10(%rbp)
jne    12b7 <connection_handler+0x107>
lea    0xd66(%rip),%rdi
call   1070 <puts@plt>
jmp    12bc <connection_handler+0x10c>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x1150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connection_handler>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1130,%rsp
mov    (%rdi),%ebx
lea    0x190(%rsp),%rsi
mov    %ebx,%edi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    124b <connection_handler+0x9b>
mov    $0x400,%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
lea    0x190(%rsp),%rdi
lea    0x960(%rsp),%r15
mov    %r15,%rsi
call   1060 <parse_message@plt>
mov    %rsp,%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <parse_header@plt>
lea    0xde9(%rip),%rsi
mov    %r12,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1234 <connection_handler+0x84>
lea    0xdd8(%rip),%rsi
mov    %ebx,%edi
call   10a0 <not_found@plt>
jmp    1243 <connection_handler+0x93>
lea    0x64(%rsp),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
call   10d0 <get@plt>
mov    %r14,%rdi
call   1030 <free@plt>
cmp    $0xffffffff,%ebp
je     1270 <connection_handler+0xc0>
test   %ebp,%ebp
jne    127c <connection_handler+0xcc>
lea    0xda9(%rip),%rdi
call   1070 <puts@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
jmp    127c <connection_handler+0xcc>
lea    0xda1(%rip),%rdi
call   1070 <puts@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x1130,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"GET\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [20 x i8] c"client disconnected\00"
@stdout = global i32 0
@.str.3 = [12 x i8] c"recv failed\00"
define i8* @connection_handler(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2000 x i8]
%6 = alloca [20 x [100 x i8]]
%7 = alloca [4 x [100 x i8]]
%8 = alloca i8*
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%14 = call i32 @recv(i32 %12, i8* %13, i32 2000, i32 0)
store i32 %14, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %43
16: ; preds = %1
%17 = call i8* @malloc(i32 1024)
store i8* %17, i8** %8
%18 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds [20 x [100 x i8]], [20 x [100 x i8]]* %6, i64 0, i64 0
%20 = bitcast [100 x i8]* %19 to i8**
%21 = call i32 @parse_message(i8* %18, i8** %20)
%22 = getelementptr inbounds [20 x [100 x i8]], [20 x [100 x i8]]* %6, i64 0, i64 0
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %22, i64 0, i64 0
%24 = getelementptr inbounds [4 x [100 x i8]], [4 x [100 x i8]]* %7, i64 0, i64 0
%25 = bitcast [100 x i8]* %24 to i8**
%26 = call i32 @parse_header(i8* %23, i8** %25)
%27 = getelementptr inbounds [4 x [100 x i8]], [4 x [100 x i8]]* %7, i64 0, i64 0
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %27, i64 0, i64 0
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %16
%32 = load i32, i32* %3
%33 = getelementptr inbounds [4 x [100 x i8]], [4 x [100 x i8]]* %7, i64 0, i64 1
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %33, i64 0, i64 0
%35 = load i8*, i8** %8
%36 = call i32 @get(i32 %32, i8* %34, i8* %35)
br label %40
37: ; preds = %16
%38 = load i32, i32* %3
%39 = call i32 @not_found(i32 %38, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %37, %31
%41 = load i8*, i8** %8
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %40, %1
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* @stdout
%49 = call i32 @fflush(i32 %48)
br label %56
50: ; preds = %43
%51 = load i32, i32* %4
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
br label %56
56: ; preds = %55, %46
%57 = load i32, i32* %3
%58 = call i32 @close(i32 %57)
ret i8* null
}

LLVM IR (-O2):
@.str = [4 x i8] c"GET\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [20 x i8] c"client disconnected\00"
@stdout = global i32 0
@.str.3 = [12 x i8] c"recv failed\00"
define noalias i8* @connection_handler(i8* nocapture %0) {
%2 = alloca [2000 x i8]
%3 = alloca [20 x [100 x i8]]
%4 = alloca [4 x [100 x i8]]
%5 = bitcast i8* %0 to i32*
%6 = load i32, i32* %5
%7 = getelementptr inbounds [2000 x i8], [2000 x i8]* %2, i64 0, i64 0
%8 = call i32 @recv(i32 %6, i8* %7, i32 2000, i32 0)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %1
%11 = getelementptr inbounds [20 x [100 x i8]], [20 x [100 x i8]]* %3, i64 0, i64 0, i64 0
%12 = getelementptr inbounds [4 x [100 x i8]], [4 x [100 x i8]]* %4, i64 0, i64 0, i64 0
%13 = call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%14 = bitcast [20 x [100 x i8]]* %3 to i8**
%15 = call i32 @parse_message(i8* %7, i8** %14)
%16 = bitcast [4 x [100 x i8]]* %4 to i8**
%17 = call i32 @parse_header(i8* %11, i8** %16)
%18 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %10
%21 = getelementptr inbounds [4 x [100 x i8]], [4 x [100 x i8]]* %4, i64 0, i64 1, i64 0
%22 = call i32 @get(i32 %6, i8* %21, i8* %13)
br label %25
23: ; preds = %10
%24 = call i32 @not_found(i32 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = call i32 @free(i8* %13)
br label %27
27: ; preds = %25, %1
switch i32 %8, label %34 [
i32 0, label %28
i32 -1, label %32
]
28: ; preds = %27
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @stdout
%31 = call i32 @fflush(i32 %30)
br label %34
32: ; preds = %27
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %27, %32, %28
%35 = call i32 @close(i32 %6)
ret i8* null
}