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

/* Variables and functions */
int /*<<< orphan*/ EBADF;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOSYS;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
ssize_t __libc_pread(int fd, void *buf, size_t nbytes, off_t offset) {
  if (nbytes == 0)
    return 0;
  if (fd < 0) {
    __set_errno(EBADF);
    return -1;
  }
  if (buf == NULL || offset < 0) {
    __set_errno(EINVAL);
    return -1;
  }
  __set_errno(ENOSYS);
  return -1;
}


x86 assembly (clang, -O0):
<__libc_pread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    113e <__libc_pread+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <__libc_pread+0x97>
cmpl   $0x0,-0x8(%rbp)
jge    1162 <__libc_pread+0x52>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <__libc_pread+0x97>
cmpq   $0x0,-0x10(%rbp)
je     1178 <__libc_pread+0x68>
cmpq   $0x0,-0x20(%rbp)
jge    1192 <__libc_pread+0x82>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <__libc_pread+0x97>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__libc_pread>:
test   %rdx,%rdx
je     114f <__libc_pread+0x3f>
push   %rax
mov    0x2ebb(%rip),%rdx
mov    %rdx,%rax
test   %rcx,%rcx
js     112c <__libc_pread+0x1c>
mov    0x2ebc(%rip),%rax
test   %rsi,%rsi
cmove  %rdx,%rax
test   %edi,%edi
jns    113e <__libc_pread+0x2e>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
@EBADF = global i32 0
@EINVAL = global i32 0
@ENOSYS = global i32 0
define i32 @__libc_pread(i32 %0, i8* readnone %1, i64 %2, i64 %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %17, label %6
6: ; preds = %4
%7 = icmp slt i32 %0, 0
%8 = icmp eq i8* %1, null
%9 = icmp slt i64 %3, 0
%10 = or i1 %8, %9
%11 = load i32, i32* @EBADF
%12 = load i32, i32* @EINVAL
%13 = load i32, i32* @ENOSYS
%14 = select i1 %10, i32 %12, i32 %13
%15 = select i1 %7, i32 %11, i32 %14
%16 = tail call i32 @__set_errno(i32 %15)
br label %17
17: ; preds = %6, %4
%18 = phi i32 [ 0, %4 ], [ -1, %6 ]
ret i32 %18
}