#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*/ logger(int, char *);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int read_from_client(int filedes) {
  char buffer[512];
  int nbytes;
  nbytes = read(filedes, buffer, 512);
  if (nbytes < 0) {
    char *errmesg = "";
    sprintf(errmesg, "Read error from client(%d).", filedes);
    logger(1, errmesg);
  } else if (nbytes == 0) {
    return -1;
  }
  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    119f <read_from_client+0x6f>
lea    0xeaf(%rip),%rax
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe7c(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x220(%rbp),%rsi
mov    $0x1,%edi
call   1040 <logger@plt>
jmp    11bd <read_from_client+0x8d>
cmpl   $0x0,-0x214(%rbp)
jne    11b8 <read_from_client+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <read_from_client+0x94>
jmp    11bd <read_from_client+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_client>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x200,%edx
call   1030 <read@plt>
test   %eax,%eax
js     1156 <read_from_client+0x26>
jne    117b <read_from_client+0x4b>
mov    $0xffffffff,%eax
jmp    117d <read_from_client+0x4d>
lea    0xebe(%rip),%r14
lea    0xe9c(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1050 <sprintf@plt>
mov    $0x1,%edi
mov    %r14,%rsi
call   1040 <logger@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [28 x i8] c"Read error from client(%d).\00"
define i32 @read_from_client(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 512)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
%13 = load i8*, i8** %6
%14 = load i32, i32* %3
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %6
%17 = call i32 @logger(i32 1, i8* %16)
br label %23
18: ; preds = %1
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 -1, i32* %2
br label %24
22: ; preds = %18
br label %23
23: ; preds = %22, %12
store i32 0, i32* %2
br label %24
24: ; preds = %23, %21
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [28 x i8] c"Read error from client(%d).\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 %9
6: ; preds = %1
%7 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%8 = tail call i32 @logger(i32 1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = icmp eq i32 %4, 0
br i1 %10, label %12, label %11
11: ; preds = %9, %6
br label %12
12: ; preds = %9, %11
%13 = phi i32 [ 0, %11 ], [ -1, %9 ]
ret i32 %13
}