#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*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ memcmp(char *, char *, unsigned long);
unsigned long read(int, char *, unsigned long);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void read_and_compare(int fd, char *read_buf, char *mmap_buf,
                      unsigned long len) {
  if (read(fd, read_buf, len) != len) {
    fprintf(stderr, "read problem:  %s\n", strerror(errno));
    exit(1);
  }
  if (memcmp(read_buf, mmap_buf, len) != 0) {
    fprintf(stderr, "buffer miscompare\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<read_and_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <read@plt>
cmp    -0x20(%rbp),%rax
je     11b9 <read_and_compare+0x69>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11f5 <read_and_compare+0xa5>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_and_compare>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rcx,%rdx
call   1030 <read@plt>
cmp    %rbx,%rax
jne    1184 <read_and_compare+0x34>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    11b8 <read_and_compare+0x68>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e55(%rip),%rax
mov    (%rax),%ebx
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe5e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"read problem: %s\0A\00"
@errno = global i32 0
@.str.1 = [19 x i8] c"buffer miscompare\0A\00"
define void @read_and_compare(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%9 = load i32, i32* %5
%10 = load i8*, i8** %6
%11 = load i64, i64* %8
%12 = call i64 @read(i32 %9, i8* %10, i64 %11)
%13 = load i64, i64* %8
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %4
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = load i64, i64* %8
%25 = call i64 @memcmp(i8* %22, i8* %23, i64 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"read problem: %s\0A\00"
@errno = global i32 0
@.str.1 = [19 x i8] c"buffer miscompare\0A\00"
define void @read_and_compare(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i64 @read(i32 %0, i8* %1, i64 %3)
%6 = icmp eq i64 %5, %3
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = tail call i64 @memcmp(i8* %1, i8* %2, i64 %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %13
ret void
}