#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 */
typedef int /*<<< orphan*/ recv_buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, ...);
size_t recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, size_t, int /*<<< orphan*/);
void *client_fun(void *arg) {
  int connfd = (int)arg;
  size_t recv_len = 0;
  char recv_buf[2048] = "";
  while ((recv_len = recv(connfd, recv_buf, sizeof(recv_buf), 0)) > 0) {
    send(connfd, recv_buf, recv_len, 0);
    printf("\e[34m%s\e[0m\n", recv_buf);
  }
  close(connfd);
  printf("\e[31mclient closed!\e[0m\n");
  return NULL;
}


x86 assembly (clang, -O0):
<client_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jbe    11d4 <client_fun+0x84>
mov    -0xc(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x820(%rbp),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1181 <client_fun+0x31>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_fun>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    $0x800,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     11e4 <client_fun+0x84>
mov    %rsp,%rbx
lea    0xe5e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jne    11b0 <client_fun+0x50>
mov    %r14d,%edi
call   1080 <close@plt>
lea    0xe1a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"\1B[34m%s\1B[0m\0A\00"
@.str.1 = [25 x i8] c"\1B[31mclient closed!\1B[0m\0A\00"
define i8* @client_fun(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca [2048 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = ptrtoint i8* %6 to i32
store i32 %7, i32* %3
store i64 0, i64* %4
%8 = bitcast [2048 x i8]* %5 to i8*
br label %9
9: ; preds = %14, %1
%10 = load i32, i32* %3
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%12 = call i64 @recv(i32 %10, i8* %11, i32 2048, i32 0)
store i64 %12, i64* %4
%13 = icmp ugt i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i32, i32* %3
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%17 = load i64, i64* %4
%18 = call i32 @send(i32 %15, i8* %16, i64 %17, i32 0)
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %9
21: ; preds = %9
%22 = load i32, i32* %3
%23 = call i32 @close(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
ret i8* null
}

LLVM IR (-O2):
@.str = [13 x i8] c"\1B[34m%s\1B[0m\0A\00"
@str = [24 x i8] c"\1B[31mclient closed!\1B[0m\00"
define noalias i8* @client_fun(i8* %0) {
%2 = alloca [2048 x i8]
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%6 = call i64 @recv(i32 %4, i8* %5, i32 2048, i32 0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %12, %8 ], [ %6, %1 ]
%10 = call i32 @send(i32 %4, i8* %5, i64 %9, i32 0)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %5)
%12 = call i64 @recv(i32 %4, i8* %5, i32 2048, i32 0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %8, %1
%15 = call i32 @close(i32 %4)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
ret i8* null
}