#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*/ close(int);
int handle_read(char *, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int read_reply(int fd) {
  static char buf[4096];
  int len;
  int x;
  len = read(fd, buf, 4096);
  x = handle_read(buf, len);
  if (x < 0) {
    perror("read reply");
    close(fd);
  }
  return x;
}


x86 assembly (clang, -O0):
<read_reply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0x2efb(%rip),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0x2ee4(%rip),%rdi
call   1030 <handle_read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1192 <read_reply+0x52>
lea    0xe7b(%rip),%rdi
call   1060 <perror@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_reply>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x2f04(%rip),%rbp
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <handle_read@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1172 <read_reply+0x32>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe87(%rip),%rdi
call   1060 <perror@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    1169 <read_reply+0x29>

LLVM IR (-O0):
@read_reply.buf = internal global [4096 x i8] zeroinitializer
@.str = [11 x i8] c"read reply\00"
define i32 @read_reply(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @read(i32 %5, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @read_reply.buf, i64 0, i64 0), i32 4096)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @handle_read(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @read_reply.buf, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %2
%14 = call i32 @close(i32 %13)
br label %15
15: ; preds = %11, %1
%16 = load i32, i32* %4
ret i32 %16
}

LLVM IR (-O2):
@read_reply.buf = internal global [4096 x i8] zeroinitializer
@.str = [11 x i8] c"read reply\00"
define i32 @read_reply(i32 %0) {
%2 = tail call i32 @read(i32 %0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @read_reply.buf, i64 0, i64 0), i32 4096)
%3 = tail call i32 @handle_read(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @read_reply.buf, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @close(i32 %0)
br label %8
8: ; preds = %5, %1
ret i32 %3
}