#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*/ printf(char *, char *);
scalar_t__ pthread_self();
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void *connection_handler(void *socket_desc) {
  int sock = *(int *)socket_desc;
  int read_size;
  char *message, client_message[2000];
  printf("connection_handler = %p\n", (void *)pthread_self());
  message = "Greetings! I am your connection handler\n";
  write(sock, message, strlen(message));
  message = "Now type something and i shall repeat what you type \n";
  write(sock, message, strlen(message));
  recv(sock, client_message, 2000, 0);
  printf("Data received from client: %s", client_message);
  return 0;
}


x86 assembly (clang, -O0):
<connection_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %rax,%rsi
lea    0xe87(%rip),%rdi
call   1060 <printf@plt>
lea    0xe94(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x80c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x808(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x80c(%rbp),%edi
mov    -0x808(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xe81(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x7fc(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x7f8(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x7fc(%rbp),%edi
mov    -0x7f8(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x7f0(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x7f0(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connection_handler>:
push   %r14
push   %rbx
sub    $0x7d8,%rsp
mov    (%rdi),%ebx
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0xe96(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
lea    0xea0(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xeae(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xeb5(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"connection_handler = %p\0A\00"
@.str.1 = [41 x i8] c"Greetings! I am your connection handler\0A\00"
@.str.2 = [54 x i8] c"Now type something and i shall repeat what you type \0A\00"
@.str.3 = [30 x i8] c"Data received from client: %s\00"
define i8* @connection_handler(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [2000 x i8]
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
store i32 %9, i32* %3
%10 = call i64 (...) @pthread_self()
%11 = inttoptr i64 %10 to i8*
%12 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %11)
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8** %5
%13 = load i32, i32* %3
%14 = load i8*, i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @write(i32 %13, i8* %14, i32 %16)
store i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8** %5
%18 = load i32, i32* %3
%19 = load i8*, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
%23 = load i32, i32* %3
%24 = getelementptr inbounds [2000 x i8], [2000 x i8]* %6, i64 0, i64 0
%25 = call i32 @recv(i32 %23, i8* %24, i32 2000, i32 0)
%26 = getelementptr inbounds [2000 x i8], [2000 x i8]* %6, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %26)
ret i8* null
}

LLVM IR (-O2):
@.str = [25 x i8] c"connection_handler = %p\0A\00"
@.str.1 = [41 x i8] c"Greetings! I am your connection handler\0A\00"
@.str.2 = [54 x i8] c"Now type something and i shall repeat what you type \0A\00"
@.str.3 = [30 x i8] c"Data received from client: %s\00"
define noalias i8* @connection_handler(i8* nocapture %0) {
%2 = alloca [2000 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [2000 x i8], [2000 x i8]* %2, i64 0, i64 0
%6 = tail call i64 (...) @pthread_self()
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 @recv(i32 %4, i8* %5, i32 2000, i32 0)
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %5)
ret i8* null
}