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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int process_client(int client_fd) {
  int len;
  char data[256];
  len = recv(client_fd, data, sizeof(data), 0);
  if (len == -1) {
    fprintf(stderr, "reception of TCP data failed: %m\n");
    return -1;
  } else if (len == 0) {
    printf("socket %d is closed\n", client_fd);
    return -1;
  }
  printf("Received %d bytes of data from socket %d\n", len, client_fd);
  return 0;
}


x86 assembly (clang, -O0):
<process_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1182 <process_client+0x52>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <process_client+0x99>
cmpl   $0x0,-0xc(%rbp)
jne    11a9 <process_client+0x79>
mov    -0x8(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <process_client+0x99>
jmp    11ae <process_client+0x7e>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_client>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     116f <process_client+0x3f>
cmp    $0xffffffff,%eax
jne    1186 <process_client+0x56>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    119a <process_client+0x6a>
lea    0xeac(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
jmp    119a <process_client+0x6a>
lea    0xeaa(%rip),%rdi
xor    %ebp,%ebp
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"reception of TCP data failed: %m\0A\00"
@.str.1 = [21 x i8] c"socket %d is closed\0A\00"
@.str.2 = [42 x i8] c"Received %d bytes of data from socket %d\0A\00"
define i32 @process_client(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = call i32 @recv(i32 %6, i8* %7, i32 256, i32 0)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %25
14: ; preds = %1
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %3
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %18)
store i32 -1, i32* %2
br label %25
20: ; preds = %14
br label %21
21: ; preds = %20
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %23)
store i32 0, i32* %2
br label %25
25: ; preds = %21, %17, %11
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"reception of TCP data failed: %m\0A\00"
@.str.1 = [21 x i8] c"socket %d is closed\0A\00"
@.str.2 = [42 x i8] c"Received %d bytes of data from socket %d\0A\00"
define i32 @process_client(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @recv(i32 %0, i8* %3, i32 256, i32 0)
switch i32 %4, label %10 [
i32 -1, label %5
i32 0, label %8
]
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %12
8: ; preds = %1
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %12
10: ; preds = %1
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %0)
br label %12
12: ; preds = %10, %8, %5
%13 = phi i32 [ -1, %5 ], [ -1, %8 ], [ 0, %10 ]
ret i32 %13
}