#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
void process(int sock) {
  int n;
  char recv_buf[256] = {'\0'};
  char *response = "I got your message";
  while (1) {
    bzero(recv_buf, sizeof(recv_buf));
    n = read(sock, recv_buf, sizeof(recv_buf) - 1);
    if (0 == n) {
      printf("client has been closed.\n");
      break;
    } else if (n < 0 && EINTR == errno) {
      continue;
    } else if (n < 0) {
      perror("read");
      close(sock);
      exit(-1);
    }
    printf("[TCP]received message: %s.\n", recv_buf);
    n = write(sock, response, strlen(response));
    if (n < 0) {
      perror("write");
      exit(-1);
    }
    printf("[TCP]send message: %s.\n", response);
  }
  close(sock);
}


x86 assembly (clang, -O0):
<process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0xe48(%rip),%rax
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   10a0 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1080 <read@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jne    1205 <process+0x75>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e9 <process+0x159>
cmpl   $0x0,-0x8(%rbp)
jge    122e <process+0x9e>
mov    0x2dc2(%rip),%rax
mov    (%rax),%rax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%rax
jne    122e <process+0x9e>
jmp    11bf <process+0x2f>
cmpl   $0x0,-0x8(%rbp)
jge    1256 <process+0xc6>
lea    0xded(%rip),%rdi
call   1090 <perror@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
jmp    125b <process+0xcb>
jmp    1260 <process+0xd0>
lea    -0x110(%rbp),%rsi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    -0x118(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x124(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12cf <process+0x13f>
lea    0xd8d(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x118(%rbp),%rsi
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11bf <process+0x2f>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10a0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1080 <read@plt>
test   %eax,%eax
je     12cc <process+0x13c>
mov    0x2da5(%rip),%r13
mov    %rsp,%rbx
lea    0xdd3(%rip),%r14
lea    0xdb4(%rip),%r15
lea    0xde7(%rip),%r12
jmp    1294 <process+0x104>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2d71(%rip),%rax
mov    (%rax),%rax
cmp    0x0(%r13),%rax
jne    1307 <process+0x177>
mov    %rbx,%rdi
mov    $0x100,%esi
call   10a0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1080 <read@plt>
test   %eax,%eax
je     12cc <process+0x13c>
test   %eax,%eax
js     1260 <process+0xd0>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
js     12f1 <process+0x161>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1274 <process+0xe4>
lea    0xd7f(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1070 <close@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd3c(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    0xd05(%rip),%rdi
call   1090 <perror@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"I got your message\00"
@.str.1 = [25 x i8] c"client has been closed.\0A\00"
@EINTR = global i64 0
@errno = global i64 0
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [28 x i8] c"[TCP]received message: %s.\0A\00"
@.str.4 = [6 x i8] c"write\00"
@.str.5 = [24 x i8] c"[TCP]send message: %s.\0A\00"
define void @process(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca i8*
store i32 %0, i32* %2
%6 = bitcast [256 x i8]* %4 to i8*
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %5
br label %7
7: ; preds = %1, %24, %48
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = call i32 @bzero(i8* %8, i32 256)
%10 = load i32, i32* %2
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 255)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 0, %13
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %51
17: ; preds = %7
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i64, i64* @EINTR
%22 = load i64, i64* @errno
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
br label %7
25: ; preds = %20, %17
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %2
%31 = call i32 @close(i32 %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %25
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %2
%39 = load i8*, i8** %5
%40 = load i8*, i8** %5
%41 = call i32 @strlen(i8* %40)
%42 = call i32 @write(i32 %38, i8* %39, i32 %41)
store i32 %42, i32* %3
%43 = load i32, i32* %3
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %35
%46 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %35
%49 = load i8*, i8** %5
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %49)
br label %7
51: ; preds = %15
%52 = load i32, i32* %2
%53 = call i32 @close(i32 %52)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"I got your message\00"
@EINTR = global i64 0
@errno = global i64 0
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [28 x i8] c"[TCP]received message: %s.\0A\00"
@.str.4 = [6 x i8] c"write\00"
@.str.5 = [24 x i8] c"[TCP]send message: %s.\0A\00"
@str = [24 x i8] c"client has been closed.\00"
define void @process(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @bzero(i8* %3, i32 256)
%5 = call i32 @read(i32 %0, i8* %3, i32 255)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %31, %1
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%9 = call i32 @close(i32 %0)
ret void
10: ; preds = %1, %31
%11 = phi i32 [ %33, %31 ], [ %5, %1 ]
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i64, i64* @EINTR
%15 = load i64, i64* @errno
%16 = icmp eq i64 %14, %15
br i1 %16, label %31, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @close(i32 %0)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %10
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%23 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @write(i32 %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %13
%32 = call i32 @bzero(i8* %3, i32 256)
%33 = call i32 @read(i32 %0, i8* %3, i32 255)
%34 = icmp eq i32 %33, 0
br i1 %34, label %7, label %10
}