#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*/ off_t;

/* Variables and functions */
int EDOM;
int safe_pread(int, void *, size_t, int /*<<< orphan*/);
ssize_t safe_pread_exact(int fd, void *b, size_t c, off_t off) {
  int ret = safe_pread(fd, b, c, off);
  if (ret < 0)
    return ret;
  if (ret != (int)c)
    return -EDOM;
  return 0;
}


x86 assembly (clang, -O0):
<safe_pread_exact>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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 <safe_pread@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1151 <safe_pread_exact+0x41>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117a <safe_pread_exact+0x6a>
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
je     1173 <safe_pread_exact+0x63>
xor    %eax,%eax
mov    0x2e7f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    117a <safe_pread_exact+0x6a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_pread_exact>:
push   %rbx
mov    %rdx,%rbx
call   1030 <safe_pread@plt>
mov    %eax,%ecx
test   %eax,%eax
js     1132 <safe_pread_exact+0x22>
xor    %eax,%eax
cmp    %ebx,%ecx
je     1130 <safe_pread_exact+0x20>
mov    0x2ebc(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
ret
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EDOM = global i32 0
define i32 @safe_pread_exact(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 i32
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 i32 @safe_pread(i32 %11, i8* %12, i64 %13, i32 %14)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i32, i32* %10
store i32 %19, i32* %5
br label %29
20: ; preds = %4
%21 = load i32, i32* %10
%22 = load i64, i64* %8
%23 = trunc i64 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* @EDOM
%27 = sub nsw i32 0, %26
store i32 %27, i32* %5
br label %29
28: ; preds = %20
store i32 0, i32* %5
br label %29
29: ; preds = %28, %25, %18
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@EDOM = global i32 0
define i32 @safe_pread_exact(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = tail call i32 @safe_pread(i32 %0, i8* %1, i64 %2, i32 %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = trunc i64 %2 to i32
%9 = icmp eq i32 %5, %8
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* @EDOM
%12 = sub nsw i32 0, %11
br label %13
13: ; preds = %7, %4, %10
%14 = phi i32 [ %12, %10 ], [ %5, %4 ], [ 0, %7 ]
ret i32 %14
}