#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 */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ errno;
scalar_t__ read(int, void *, size_t);
ssize_t fetch_nonssl_read(int sd, void *buf, size_t len) {
  ssize_t rlen;
  rlen = read(sd, buf, len);
  if (rlen < 0) {
    if (errno == EAGAIN || errno == EINTR)
      return -2;
    return -1;
  }
  return rlen;
}


x86 assembly (clang, -O0):
<fetch_nonssl_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <read@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1190 <fetch_nonssl_read+0x80>
mov    0x2e97(%rip),%rax
mov    (%rax),%rax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
je     1176 <fetch_nonssl_read+0x66>
mov    0x2e7d(%rip),%rax
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
jne    1183 <fetch_nonssl_read+0x73>
movq   $0xfffffffffffffffe,-0x8(%rbp)
ff
jmp    1198 <fetch_nonssl_read+0x88>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1198 <fetch_nonssl_read+0x88>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fetch_nonssl_read>:
push   %rax
call   1030 <read@plt>
test   %rax,%rax
js     111d <fetch_nonssl_read+0xd>
pop    %rcx
ret
mov    0x2ebc(%rip),%rax
mov    (%rax),%rax
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%rax
sete   %cl
mov    0x2e9d(%rip),%rdx
cmp    (%rdx),%rax
sete   %al
or     %cl,%al
movzbl %al,%eax
not    %rax
pop    %rcx
ret

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
define i64 @fetch_nonssl_read(i32 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i32, i32* %5
%10 = load i8*, i8** %6
%11 = load i64, i64* %7
%12 = call i64 @read(i32 %9, i8* %10, i64 %11)
store i64 %12, i64* %8
%13 = load i64, i64* %8
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %3
%16 = load i64, i64* @errno
%17 = load i64, i64* @EAGAIN
%18 = icmp eq i64 %16, %17
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19, %15
store i64 -2, i64* %4
br label %27
24: ; preds = %19
store i64 -1, i64* %4
br label %27
25: ; preds = %3
%26 = load i64, i64* %8
store i64 %26, i64* %4
br label %27
27: ; preds = %25, %24, %23
%28 = load i64, i64* %4
ret i64 %28
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
define i64 @fetch_nonssl_read(i32 %0, i8* nocapture %1, i64 %2) {
%4 = tail call i64 @read(i32 %0, i8* %1, i64 %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @EAGAIN
%9 = icmp eq i64 %7, %8
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %7, %10
%12 = select i1 %9, i1 true, i1 %11
%13 = select i1 %12, i64 -2, i64 -1
br label %14
14: ; preds = %6, %3
%15 = phi i64 [ %4, %3 ], [ %13, %6 ]
ret i64 %15
}