#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int read_from_client(int filedes) {
  char buffer[512];
  int nbytes;
  nbytes = read(filedes, buffer, 512);
  if (nbytes < 0) {
    perror("read");
    exit(EXIT_FAILURE);
  } else if (nbytes == 0)
    return -1;
  else {
    fprintf(stderr, "Server: got message: `%s'\n", buffer);
    return 0;
  }
}


x86 assembly (clang, -O0):
<read_from_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1030 <read@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
jge    118f <read_from_client+0x4f>
lea    0xe84(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x214(%rbp)
jne    11a8 <read_from_client+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <read_from_client+0x8b>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    -0x210(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_client>:
sub    $0x208,%rsp
mov    %rsp,%rsi
mov    $0x200,%edx
call   1030 <read@plt>
test   %eax,%eax
js     1189 <read_from_client+0x49>
je     117c <read_from_client+0x3c>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
mov    %rsp,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x208,%rsp
ret
mov    $0xffffffff,%eax
add    $0x208,%rsp
ret
lea    0xe70(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Server: got message: `%s'\0A\00"
define i32 @read_from_client(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 512)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 -1, i32* %2
br label %23
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 0, i32* %2
br label %23
23: ; preds = %19, %18
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Server: got message: `%s'\0A\00"
define i32 @read_from_client(i32 %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 512)
%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, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = icmp eq i32 %4, 0
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %15
15: ; preds = %10, %12
%16 = phi i32 [ 0, %12 ], [ -1, %10 ]
ret i32 %16
}