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

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int lxc_read_nointr(int, void *, size_t);
scalar_t__ memcmp(void *, void const *, size_t);
int lxc_read_nointr_expect(int fd, void *buf, size_t count,
                           const void *expected_buf) {
  int ret;
  ret = lxc_read_nointr(fd, buf, count);
  if (ret <= 0)
    return ret;
  if (ret != count)
    return -1;
  if (expected_buf && memcmp(buf, expected_buf, count) != 0) {
    errno = EINVAL;
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<lxc_read_nointr_expect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <lxc_read_nointr@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     115f <lxc_read_nointr_expect+0x3f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c3 <lxc_read_nointr_expect+0xa3>
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1179 <lxc_read_nointr_expect+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <lxc_read_nointr_expect+0xa3>
cmpq   $0x0,-0x20(%rbp)
je     11bd <lxc_read_nointr_expect+0x9d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11bd <lxc_read_nointr_expect+0x9d>
mov    0x2e32(%rip),%rax
mov    (%rax),%ecx
mov    0x2e31(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <lxc_read_nointr_expect+0xa3>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lxc_read_nointr_expect>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
call   1030 <lxc_read_nointr@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1172 <lxc_read_nointr_expect+0x52>
mov    %ebx,%eax
cmp    %r14,%rax
jne    116d <lxc_read_nointr_expect+0x4d>
test   %r15,%r15
je     1172 <lxc_read_nointr_expect+0x52>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <memcmp@plt>
test   %rax,%rax
je     1172 <lxc_read_nointr_expect+0x52>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    0x2e75(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @lxc_read_nointr_expect(i32 %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
%11 = load i32, i32* %6
%12 = load i8*, i8** %7
%13 = load i64, i64* %8
%14 = call i32 @lxc_read_nointr(i32 %11, i8* %12, i64 %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %10
store i32 %18, i32* %5
br label %38
19: ; preds = %4
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = load i64, i64* %8
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -1, i32* %5
br label %38
25: ; preds = %19
%26 = load i8*, i8** %9
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i8*, i8** %7
%30 = load i8*, i8** %9
%31 = load i64, i64* %8
%32 = call i64 @memcmp(i8* %29, i8* %30, i64 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = load i32, i32* @EINVAL
store i32 %35, i32* @errno
store i32 -1, i32* %5
br label %38
36: ; preds = %28, %25
%37 = load i32, i32* %10
store i32 %37, i32* %5
br label %38
38: ; preds = %36, %34, %24, %17
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @lxc_read_nointr_expect(i32 %0, i8* %1, i64 %2, i8* %3) {
%5 = tail call i32 @lxc_read_nointr(i32 %0, i8* %1, i64 %2)
%6 = icmp slt i32 %5, 1
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = zext i32 %5 to i64
%9 = icmp eq i64 %8, %2
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = icmp eq i8* %3, null
br i1 %11, label %17, label %12
12: ; preds = %10
%13 = tail call i64 @memcmp(i8* %1, i8* %3, i64 %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = load i32, i32* @EINVAL
store i32 %16, i32* @errno
br label %17
17: ; preds = %10, %12, %7, %4, %15
%18 = phi i32 [ -1, %15 ], [ %5, %4 ], [ -1, %7 ], [ %5, %12 ], [ %5, %10 ]
ret i32 %18
}