#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ parse_request(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *strstr(char *, char *);
void *receive_func(void *arg) {
  int accepted_client = *(int *)arg;
  char msg[(1024 * 16)];
  while (1) {
    memset(msg, 0, (1024 * 16));
    if (recv(accepted_client, msg, (1024 * 16), 0) < 0) {
      perror("Recv error");
    }
    if (strstr(msg, "Connection: close") != NULL)
      break;
    if (msg[0] == 'G') {
      printf("Received a GET request\n");
      parse_request(msg, accepted_client);
    }
  }
  pthread_exit(NULL);
  return 0;
}


x86 assembly (clang, -O0):
<receive_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4010,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
lea    -0x4010(%rbp),%rdi
xor    %esi,%esi
mov    $0x4000,%edx
call   1050 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x4010(%rbp),%rsi
mov    $0x4000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jge    11c7 <receive_func+0x57>
lea    0xe3e(%rip),%rdi
call   1070 <perror@plt>
lea    -0x4010(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     11e9 <receive_func+0x79>
jmp    1219 <receive_func+0xa9>
movsbl -0x4010(%rbp),%eax
cmp    $0x47,%eax
jne    1214 <receive_func+0xa4>
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
lea    -0x4010(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <parse_request@plt>
jmp    1188 <receive_func+0x18>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
add    $0x4010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_func>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x4000,%rsp
mov    (%rdi),%ebp
mov    %rsp,%rbx
lea    0xe75(%rip),%r14
lea    0xe79(%rip),%r15
lea    0xe84(%rip),%r12
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4000,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     11ef <receive_func+0x7f>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
jne    11f9 <receive_func+0x89>
cmpb   $0x47,(%rsp)
jne    11a0 <receive_func+0x30>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <parse_request@plt>
jmp    11a0 <receive_func+0x30>
mov    %r14,%rdi
call   1070 <perror@plt>
jmp    11c5 <receive_func+0x55>
xor    %edi,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
add    $0x4000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Recv error\00"
@.str.1 = [18 x i8] c"Connection: close\00"
@.str.2 = [24 x i8] c"Received a GET request\0A\00"
define i8* @receive_func(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [16384 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i32*
%7 = load i32, i32* %6
store i32 %7, i32* %3
br label %8
8: ; preds = %1, %32
%9 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 16384)
%11 = load i32, i32* %3
%12 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%13 = call i64 @recv(i32 %11, i8* %12, i32 16384, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %8
%18 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%19 = call i32* @strstr(i8* %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %17
br label %33
22: ; preds = %17
%23 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 71
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%30 = load i32, i32* %3
%31 = call i32 @parse_request(i8* %29, i32 %30)
br label %32
32: ; preds = %27, %22
br label %8
33: ; preds = %21
%34 = call i32 @pthread_exit(i32* null)
ret i8* null
}

LLVM IR (-O2):
@.str = [11 x i8] c"Recv error\00"
@.str.1 = [18 x i8] c"Connection: close\00"
@str = [23 x i8] c"Received a GET request\00"
define noalias i8* @receive_func(i8* nocapture %0) {
%2 = alloca [16384 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [16384 x i8], [16384 x i8]* %2, i64 0, i64 0
br label %6
6: ; preds = %21, %1
%7 = call i32 @memset(i8* %5, i32 0, i32 16384)
%8 = call i64 @recv(i32 %4, i8* %5, i32 16384, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = call i32* @strstr(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i8, i8* %5
%17 = icmp eq i8 %16, 71
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%20 = call i32 @parse_request(i8* %5, i32 %4)
br label %21
21: ; preds = %18, %15
br label %6
22: ; preds = %12
%23 = call i32 @pthread_exit(i32* null)
ret i8* null
}