#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, 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";
  n = read(sock, recv_buf, sizeof(recv_buf) - 1);
  if (n < 0) {
    perror("read");
    exit(EXIT_FAILURE);
  }
  printf("Received message: %s.\n", recv_buf);
  n = write(sock, response, strlen(response));
  if (n < 0) {
    perror("write");
    exit(EXIT_FAILURE);
  }
}


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    0xe68(%rip),%rax
mov    %rax,-0x118(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1070 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11da <process+0x6a>
lea    0xe4c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x110(%rbp),%rsi
lea    0xe30(%rip),%rdi
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    124b <process+0xdb>
lea    0xdf7(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process>:
push   %rbp
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,%rsi
mov    $0xff,%edx
call   1060 <read@plt>
test   %eax,%eax
js     121e <process+0xbe>
lea    0xe2b(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
lea    0xe04(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1227 <process+0xc7>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdee(%rip),%rdi
jmp    122e <process+0xce>
lea    0xe01(%rip),%rdi
call   1070 <perror@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"I got your message\00"
@.str.1 = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [23 x i8] c"Received message: %s.\0A\00"
@.str.3 = [6 x i8] c"write\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
%7 = load i32, i32* %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 255)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %2
%20 = load i8*, i8** %5
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = call i32 @write(i32 %19, i8* %20, i32 %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %16
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"I got your message\00"
@.str.1 = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [23 x i8] c"Received message: %s.\0A\00"
@.str.3 = [6 x i8] c"write\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 @read(i32 %0, i8* %3, i32 255)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%12 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @write(i32 %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
ret void
}