#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void handle_client(int client_fd) {
  char buf[1024];
  int retn = 0;
  for (;;) {
    retn = recv(client_fd, buf, sizeof(buf) - 1, 0);
    if (retn > 0) {
      buf[retn] = '\0';
      fprintf(stdout, "recv: %s\n", buf);
    } else if (0 == retn) {
      fprintf(stdout, "client offline");
      break;
    } else {
      fprintf(stderr, "client error");
      break;
    }
  }
  close(client_fd);
}


x86 assembly (clang, -O0):
<handle_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x414(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    11a3 <handle_client+0x73>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11e9 <handle_client+0xb9>
xor    %eax,%eax
cmp    -0x414(%rbp),%eax
jne    11cd <handle_client+0x9d>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11ee <handle_client+0xbe>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11ee <handle_client+0xbe>
jmp    1148 <handle_client+0x18>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_client>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebp
mov    %rsp,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    119b <handle_client+0x6b>
mov    0x2e7f(%rip),%r15
lea    0xea0(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jg     1170 <handle_client+0x40>
test   %eax,%eax
lea    0xe66(%rip),%rax
lea    0xe6e(%rip),%rsi
cmove  %rax,%rsi
mov    0x2e2a(%rip),%rax
cmove  0x2e1a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [10 x i8] c"recv: %s\0A\00"
@.str.1 = [15 x i8] c"client offline\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"client error\00"
define void @handle_client(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %27, %1
%6 = load i32, i32* %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i32 @recv(i32 %6, i8* %7, i32 1023, i32 0)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %14
%15 = load i32, i32* @stdout
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %27
18: ; preds = %5
%19 = load i32, i32* %4
%20 = icmp eq i32 0, %19
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stdout
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %28
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %28
27: ; preds = %11
br label %5
28: ; preds = %24, %21
%29 = load i32, i32* %2
%30 = call i32 @close(i32 %29)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [10 x i8] c"recv: %s\0A\00"
@.str.1 = [15 x i8] c"client offline\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"client error\00"
define void @handle_client(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @recv(i32 %0, i8* %3, i32 1023, i32 0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1, %6
%7 = phi i32 [ %12, %6 ], [ %4, %1 ]
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %8
store i8 0, i8* %9
%10 = load i32, i32* @stdout
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %3)
%12 = call i32 @recv(i32 %0, i8* %3, i32 1023, i32 0)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %6, %1
%15 = phi i32 [ %4, %1 ], [ %12, %6 ]
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0)
%18 = load i32, i32* @stdout
%19 = load i32, i32* @stderr
%20 = select i1 %16, i32 %18, i32 %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* %17)
%22 = call i32 @close(i32 %0)
ret void
}