#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EIO;
int /*<<< orphan*/ errno;
scalar_t__ read_all(int, char *, size_t, unsigned int);
int mpath_recv_reply_data(int fd, char *reply, size_t len,
                          unsigned int timeout) {
  ssize_t ret;
  ret = read_all(fd, reply, len, timeout);
  if (ret < 0)
    return ret;
  if ((size_t)ret != len) {
    errno = EIO;
    return -1;
  }
  reply[len - 1] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<mpath_recv_reply_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <read_all@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1154 <mpath_recv_reply_data+0x44>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1197 <mpath_recv_reply_data+0x87>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1180 <mpath_recv_reply_data+0x70>
mov    0x2e77(%rip),%rax
mov    (%rax),%ecx
mov    0x2e66(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <mpath_recv_reply_data+0x87>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpath_recv_reply_data>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
call   1030 <read_all@plt>
test   %rax,%rax
js     114a <mpath_recv_reply_data+0x3a>
cmp    %rbx,%rax
jne    1133 <mpath_recv_reply_data+0x23>
movb   $0x0,-0x1(%rbx,%r14,1)
xor    %eax,%eax
jmp    114a <mpath_recv_reply_data+0x3a>
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    0x2e95(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EIO = global i32 0
@errno = global i32 0
define i32 @mpath_recv_reply_data(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
%11 = load i32, i32* %6
%12 = load i8*, i8** %7
%13 = load i64, i64* %8
%14 = load i32, i32* %9
%15 = call i64 @read_all(i32 %11, i8* %12, i64 %13, i32 %14)
store i64 %15, i64* %10
%16 = load i64, i64* %10
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i64, i64* %10
%20 = trunc i64 %19 to i32
store i32 %20, i32* %5
br label %32
21: ; preds = %4
%22 = load i64, i64* %10
%23 = load i64, i64* %8
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* @EIO
store i32 %26, i32* @errno
store i32 -1, i32* %5
br label %32
27: ; preds = %21
%28 = load i8*, i8** %7
%29 = load i64, i64* %8
%30 = sub i64 %29, 1
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
store i32 0, i32* %5
br label %32
32: ; preds = %27, %25, %18
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@EIO = global i32 0
@errno = global i32 0
define i32 @mpath_recv_reply_data(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = tail call i64 @read_all(i32 %0, i8* %1, i64 %2, i32 %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = trunc i64 %5 to i32
br label %16
9: ; preds = %4
%10 = icmp eq i64 %5, %2
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = load i32, i32* @EIO
store i32 %12, i32* @errno
br label %16
13: ; preds = %9
%14 = add i64 %2, -1
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %13, %11, %7
%17 = phi i32 [ %8, %7 ], [ -1, %11 ], [ 0, %13 ]
ret i32 %17
}