#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 */
struct test_case {
  int dummy;
};
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ PROT_READ;
scalar_t__ memcmp(void *, void *, scalar_t__);
int open_rd(char const *);
int /*<<< orphan*/ t_fail(struct test_case *, char *, char const *,
                          char const *);
int /*<<< orphan*/ xclose(int);
scalar_t__ xfstat_size(int);
void *xmmap(int /*<<< orphan*/, scalar_t__, int /*<<< orphan*/,
            int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ xmunmap(void *, scalar_t__);
int t_compare(struct test_case *tc, const char *exp, const char *act) {
  int exp_fd;
  int act_fd;
  off_t size;
  void *exp_ptr;
  void *act_ptr;
  int ret = 1;
  exp_fd = open_rd(exp);
  act_fd = open_rd(act);
  size = xfstat_size(exp_fd);
  if (xfstat_size(act_fd) != size) {
    t_fail(tc, "files differ in size; expected: %s, actual: %s", exp, act);
    ret = 1;
  } else {
    exp_ptr = xmmap(0, size, PROT_READ, MAP_SHARED, exp_fd, 0);
    act_ptr = xmmap(0, size, PROT_READ, MAP_SHARED, act_fd, 0);
    if (memcmp(exp_ptr, act_ptr, size) != 0) {
      t_fail(tc, "files differ; expected: %s, actual: %s", exp, act);
      ret = 1;
    } else {
      ret = 0;
    }
    xmunmap(exp_ptr, size);
    xmunmap(act_ptr, size);
  }
  xclose(exp_fd);
  xclose(act_fd);
}


x86 assembly (clang, -O0):
<t_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <open_rd@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <open_rd@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <xfstat_size@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
call   1070 <xfstat_size@plt>
cmp    -0x30(%rbp),%rax
je     11e5 <t_compare+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe2c(%rip),%rsi
call   1090 <t_fail@plt>
movl   $0x1,-0x44(%rbp)
jmp    1297 <t_compare+0x127>
mov    -0x30(%rbp),%rsi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    0x2def(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1080 <xmmap@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    0x2dc6(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1080 <xmmap@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1276 <t_compare+0x106>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdca(%rip),%rsi
call   1090 <t_fail@plt>
movl   $0x1,-0x44(%rbp)
jmp    127d <t_compare+0x10d>
movl   $0x0,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <xmunmap@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <xmunmap@plt>
mov    -0x24(%rbp),%edi
call   1030 <xclose@plt>
mov    -0x28(%rbp),%edi
call   1030 <xclose@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t_compare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <open_rd@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
call   1040 <open_rd@plt>
mov    %eax,%r14d
mov    %r13d,%edi
call   1070 <xfstat_size@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1070 <xfstat_size@plt>
cmp    %rbx,%rax
jne    124e <t_compare+0xde>
mov    %rbp,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    0x2e15(%rip),%r12
mov    (%r12),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1080 <xmmap@plt>
mov    %rax,%rbp
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
mov    (%r12),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1080 <xmmap@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1050 <memcmp@plt>
test   %rax,%rax
je     1236 <t_compare+0xc6>
lea    0xe0b(%rip),%rsi
mov    0x10(%rsp),%rdi
mov    %r15,%rdx
mov    0x8(%rsp),%rcx
call   1090 <t_fail@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <xmunmap@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <xmunmap@plt>
jmp    1263 <t_compare+0xf3>
lea    0xdab(%rip),%rsi
mov    %r12,%rdi
mov    %r15,%rdx
mov    %rbp,%rcx
call   1090 <t_fail@plt>
mov    %r13d,%edi
call   1030 <xclose@plt>
mov    %r14d,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <xclose@plt>

LLVM IR (-O0):
%struct.test_case = type { i32 }
@.str = [47 x i8] c"files differ in size; expected: %s, actual: %s\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.1 = [39 x i8] c"files differ; expected: %s, actual: %s\00"
define i32 @t_compare(%struct.test_case* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.test_case*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store %struct.test_case* %0, %struct.test_case** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 1, i32* %13
%14 = load i8*, i8** %6
%15 = call i32 @open_rd(i8* %14)
store i32 %15, i32* %8
%16 = load i8*, i8** %7
%17 = call i32 @open_rd(i8* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %8
%19 = call i64 @xfstat_size(i32 %18)
store i64 %19, i64* %10
%20 = load i32, i32* %9
%21 = call i64 @xfstat_size(i32 %20)
%22 = load i64, i64* %10
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %3
%25 = load %struct.test_case*, %struct.test_case** %5
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = call i32 @t_fail(%struct.test_case* %25, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %27)
store i32 1, i32* %13
br label %58
29: ; preds = %3
%30 = load i64, i64* %10
%31 = load i32, i32* @PROT_READ
%32 = load i32, i32* @MAP_SHARED
%33 = load i32, i32* %8
%34 = call i8* @xmmap(i32 0, i64 %30, i32 %31, i32 %32, i32 %33, i32 0)
store i8* %34, i8** %11
%35 = load i64, i64* %10
%36 = load i32, i32* @PROT_READ
%37 = load i32, i32* @MAP_SHARED
%38 = load i32, i32* %9
%39 = call i8* @xmmap(i32 0, i64 %35, i32 %36, i32 %37, i32 %38, i32 0)
store i8* %39, i8** %12
%40 = load i8*, i8** %11
%41 = load i8*, i8** %12
%42 = load i64, i64* %10
%43 = call i64 @memcmp(i8* %40, i8* %41, i64 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %29
%46 = load %struct.test_case*, %struct.test_case** %5
%47 = load i8*, i8** %6
%48 = load i8*, i8** %7
%49 = call i32 @t_fail(%struct.test_case* %46, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %47, i8* %48)
store i32 1, i32* %13
br label %51
50: ; preds = %29
store i32 0, i32* %13
br label %51
51: ; preds = %50, %45
%52 = load i8*, i8** %11
%53 = load i64, i64* %10
%54 = call i32 @xmunmap(i8* %52, i64 %53)
%55 = load i8*, i8** %12
%56 = load i64, i64* %10
%57 = call i32 @xmunmap(i8* %55, i64 %56)
br label %58
58: ; preds = %51, %24
%59 = load i32, i32* %8
%60 = call i32 @xclose(i32 %59)
%61 = load i32, i32* %9
%62 = call i32 @xclose(i32 %61)
%63 = load i32, i32* %4
ret i32 %63
}

LLVM IR (-O2):
%struct.test_case = type { i32 }
@.str = [47 x i8] c"files differ in size; expected: %s, actual: %s\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.1 = [39 x i8] c"files differ; expected: %s, actual: %s\00"
define i32 @t_compare(%struct.test_case* %0, i8* %1, i8* %2) {
%4 = tail call i32 @open_rd(i8* %1)
%5 = tail call i32 @open_rd(i8* %2)
%6 = tail call i64 @xfstat_size(i32 %4)
%7 = tail call i64 @xfstat_size(i32 %5)
%8 = icmp eq i64 %7, %6
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @t_fail(%struct.test_case* %0, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
br label %25
11: ; preds = %3
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @MAP_SHARED
%14 = tail call i8* @xmmap(i32 0, i64 %6, i32 %12, i32 %13, i32 %4, i32 0)
%15 = load i32, i32* @PROT_READ
%16 = load i32, i32* @MAP_SHARED
%17 = tail call i8* @xmmap(i32 0, i64 %6, i32 %15, i32 %16, i32 %5, i32 0)
%18 = tail call i64 @memcmp(i8* %14, i8* %17, i64 %6)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %11
%21 = tail call i32 @t_fail(%struct.test_case* %0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
br label %22
22: ; preds = %11, %20
%23 = tail call i32 @xmunmap(i8* %14, i64 %6)
%24 = tail call i32 @xmunmap(i8* %17, i64 %6)
br label %25
25: ; preds = %22, %9
%26 = tail call i32 @xclose(i32 %4)
%27 = tail call i32 @xclose(i32 %5)
ret i32 undef
}