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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
void handle_request(int clientfd) {
  int bytes_read;
  char message[256];
  bytes_read = read(clientfd, message, 256);
  if (bytes_read < 0) {
    perror("ERROR reading socket");
  } else if (bytes_read == 0) {
    printf("Client disconnected");
  } else {
    printf("Client says %s\n", message);
  }
}


x86 assembly (clang, -O0):
<handle_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1170 <handle_request+0x40>
lea    0xe9a(%rip),%rdi
call   1050 <perror@plt>
jmp    11a7 <handle_request+0x77>
cmpl   $0x0,-0x8(%rbp)
jne    118d <handle_request+0x5d>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a2 <handle_request+0x72>
lea    -0x110(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a7 <handle_request+0x77>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_request>:
sub    $0x108,%rsp
mov    %rsp,%rsi
mov    $0x100,%edx
call   1040 <read@plt>
test   %eax,%eax
js     1178 <handle_request+0x48>
je     1163 <handle_request+0x33>
lea    0xed8(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x108,%rsp
ret
lea    0xeab(%rip),%rdi
xor    %eax,%eax
add    $0x108,%rsp
jmp    1030 <printf@plt>
lea    0xe81(%rip),%rdi
add    $0x108,%rsp
jmp    1050 <perror@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"ERROR reading socket\00"
@.str.1 = [20 x i8] c"Client disconnected\00"
@.str.2 = [16 x i8] c"Client says %s\0A\00"
define void @handle_request(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @read(i32 %5, i8* %6, i32 256)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %21
12: ; preds = %1
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %20
17: ; preds = %12
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %15
br label %21
21: ; preds = %20, %10
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"ERROR reading socket\00"
@.str.1 = [20 x i8] c"Client disconnected\00"
@.str.2 = [16 x i8] c"Client says %s\0A\00"
define void @handle_request(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 256)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %14
8: ; preds = %1
%9 = icmp eq i32 %4, 0
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %14
14: ; preds = %10, %12, %6
ret void
}