#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 int ssize_t;
typedef int /*<<< orphan*/ len;

/* Variables and functions */
int /*<<< orphan*/ EIO;
int /*<<< orphan*/ ERANGE;
int /*<<< orphan*/ errno;
int read_all(int, size_t *, int, unsigned int);
ssize_t mpath_recv_reply_len(int fd, unsigned int timeout) {
  size_t len;
  ssize_t ret;
  ret = read_all(fd, &len, sizeof(len), timeout);
  if (ret < 0)
    return ret;
  if (ret != sizeof(len)) {
    errno = EIO;
    return -1;
  }
  if (len <= 0 || len >= (32 * 1024 * 1024)) {
    errno = ERANGE;
    return -1;
  }
  return len;
}


x86 assembly (clang, -O0):
<mpath_recv_reply_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%ecx
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1030 <read_all@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    114a <mpath_recv_reply_len+0x3a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <mpath_recv_reply_len+0xa4>
movslq -0x1c(%rbp),%rax
cmp    $0x8,%rax
je     1176 <mpath_recv_reply_len+0x66>
mov    0x2e79(%rip),%rax
mov    (%rax),%ecx
mov    0x2e68(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <mpath_recv_reply_len+0xa4>
cmpq   $0x0,-0x18(%rbp)
jbe    118f <mpath_recv_reply_len+0x7f>
cmpq   $0x2000000,-0x18(%rbp)
02
jb     11ad <mpath_recv_reply_len+0x9d>
mov    0x2e52(%rip),%rax
mov    (%rax),%ecx
mov    0x2e31(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <mpath_recv_reply_len+0xa4>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpath_recv_reply_len>:
push   %rax
mov    %esi,%ecx
mov    %rsp,%rsi
mov    $0x8,%edx
call   1030 <read_all@plt>
test   %eax,%eax
js     115d <mpath_recv_reply_len+0x4d>
cmp    $0x8,%eax
jne    1146 <mpath_recv_reply_len+0x36>
mov    (%rsp),%rax
lea    -0x2000000(%rax),%rcx
cmp    $0xfffffffffe000000,%rcx
ja     115d <mpath_recv_reply_len+0x4d>
mov    0x2ea4(%rip),%rax
jmp    114d <mpath_recv_reply_len+0x3d>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    0x2e7a(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret

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

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