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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int errno;
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ pread(int, unsigned char *, int, scalar_t__);
int hlp_file_bincompare(const char *file1, const char *file2) {
  int rval = 0;
  int fp1, fp2;
  off_t s1, s2, i;
  unsigned char c1 = '\0', c2 = '\0';
  fp1 = open(file1, O_RDONLY);
  if (fp1 < 0)
    return errno;
  fp2 = open(file2, O_RDONLY);
  if (fp2 < 0) {
    close(fp1);
    return errno;
  }
  s1 = lseek(fp1, 0, SEEK_END);
  s2 = lseek(fp2, 0, SEEK_END);
  lseek(fp1, 0, SEEK_SET);
  lseek(fp2, 0, SEEK_SET);
  if ((s1 < 0) || (s2 < 0))
    rval = errno;
  else {
    if (s1 == s2) {
      for (i = 0; i <= s1; i++) {
        c1 = '\0';
        c2 = '\0';
        pread(fp1, &c1, 1, i);
        pread(fp2, &c2, 1, i);
        if (c1 != c2) {
          rval = -1;
          break;
        }
      }
    } else
      rval = -1;
  }
  close(fp1);
  close(fp2);
  return rval;
}


x86 assembly (clang, -O0):
<hlp_file_bincompare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x41(%rbp)
movb   $0x0,-0x42(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    118f <hlp_file_bincompare+0x4f>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12f1 <hlp_file_bincompare+0x1b1>
mov    -0x18(%rbp),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11c7 <hlp_file_bincompare+0x87>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12f1 <hlp_file_bincompare+0x1b1>
mov    -0x20(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    -0x24(%rbp),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
cmpq   $0x0,-0x30(%rbp)
jl     1231 <hlp_file_bincompare+0xf1>
cmpq   $0x0,-0x38(%rbp)
jge    1242 <hlp_file_bincompare+0x102>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    12db <hlp_file_bincompare+0x19b>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    12cf <hlp_file_bincompare+0x18f>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x30(%rbp),%rax
jg     12ca <hlp_file_bincompare+0x18a>
movb   $0x0,-0x41(%rbp)
movb   $0x0,-0x42(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x40(%rbp),%rcx
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1060 <pread@plt>
mov    -0x24(%rbp),%edi
mov    -0x40(%rbp),%rcx
lea    -0x42(%rbp),%rsi
mov    $0x1,%edx
call   1060 <pread@plt>
movzbl -0x41(%rbp),%eax
movzbl -0x42(%rbp),%ecx
cmp    %ecx,%eax
je     12b4 <hlp_file_bincompare+0x174>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12ca <hlp_file_bincompare+0x18a>
jmp    12b9 <hlp_file_bincompare+0x179>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1258 <hlp_file_bincompare+0x118>
jmp    12d6 <hlp_file_bincompare+0x196>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12db <hlp_file_bincompare+0x19b>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hlp_file_bincompare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    0x2e8b(%rip),%r14
mov    (%r14),%esi
call   1050 <open@plt>
test   %eax,%eax
js     1241 <hlp_file_bincompare+0x101>
mov    %eax,%ebx
mov    (%r14),%esi
mov    %rbp,%rdi
call   1050 <open@plt>
test   %eax,%eax
js     123a <hlp_file_bincompare+0xfa>
mov    %eax,%r12d
mov    0x2e64(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,%r14
mov    0x0(%rbp),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,%r13
mov    0x2e1e(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
mov    0x0(%rbp),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
test   %r14,%r14
js     124d <hlp_file_bincompare+0x10d>
test   %r13,%r13
js     124d <hlp_file_bincompare+0x10d>
mov    $0xffffffff,%r15d
cmp    %r13,%r14
jne    1257 <hlp_file_bincompare+0x117>
add    $0x1,%r14
xor    %ebp,%ebp
lea    0x6(%rsp),%r13
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x7(%rsp)
movb   $0x0,0x6(%rsp)
mov    %ebx,%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1060 <pread@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1060 <pread@plt>
movzbl 0x7(%rsp),%eax
cmp    0x6(%rsp),%al
jne    1257 <hlp_file_bincompare+0x117>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11f0 <hlp_file_bincompare+0xb0>
xor    %r15d,%r15d
jmp    1257 <hlp_file_bincompare+0x117>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%r15d
jmp    1266 <hlp_file_bincompare+0x126>
mov    0x2d7c(%rip),%rax
mov    (%rax),%r15d
mov    %ebx,%edi
call   1040 <close@plt>
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @hlp_file_bincompare(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8
%13 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i8 0, i8* %12
store i8 0, i8* %13
%14 = load i8*, i8** %4
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = load i32, i32* @errno
store i32 %20, i32* %3
br label %86
21: ; preds = %2
%22 = load i8*, i8** %5
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* %7
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* @errno
store i32 %30, i32* %3
br label %86
31: ; preds = %21
%32 = load i32, i32* %7
%33 = load i32, i32* @SEEK_END
%34 = call i64 @lseek(i32 %32, i32 0, i32 %33)
store i64 %34, i64* %9
%35 = load i32, i32* %8
%36 = load i32, i32* @SEEK_END
%37 = call i64 @lseek(i32 %35, i32 0, i32 %36)
store i64 %37, i64* %10
%38 = load i32, i32* %7
%39 = load i32, i32* @SEEK_SET
%40 = call i64 @lseek(i32 %38, i32 0, i32 %39)
%41 = load i32, i32* %8
%42 = load i32, i32* @SEEK_SET
%43 = call i64 @lseek(i32 %41, i32 0, i32 %42)
%44 = load i64, i64* %9
%45 = icmp slt i64 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %31
%47 = load i64, i64* %10
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46, %31
%50 = load i32, i32* @errno
store i32 %50, i32* %6
br label %80
51: ; preds = %46
%52 = load i64, i64* %9
%53 = load i64, i64* %10
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %78
55: ; preds = %51
store i64 0, i64* %11
br label %56
56: ; preds = %74, %55
%57 = load i64, i64* %11
%58 = load i64, i64* %9
%59 = icmp sle i64 %57, %58
br i1 %59, label %60, label %77
60: ; preds = %56
store i8 0, i8* %12
store i8 0, i8* %13
%61 = load i32, i32* %7
%62 = load i64, i64* %11
%63 = call i32 @pread(i32 %61, i8* %12, i32 1, i64 %62)
%64 = load i32, i32* %8
%65 = load i64, i64* %11
%66 = call i32 @pread(i32 %64, i8* %13, i32 1, i64 %65)
%67 = load i8, i8* %12
%68 = zext i8 %67 to i32
%69 = load i8, i8* %13
%70 = zext i8 %69 to i32
%71 = icmp ne i32 %68, %70
br i1 %71, label %72, label %73
72: ; preds = %60
store i32 -1, i32* %6
br label %77
73: ; preds = %60
br label %74
74: ; preds = %73
%75 = load i64, i64* %11
%76 = add nsw i64 %75, 1
store i64 %76, i64* %11
br label %56
77: ; preds = %72, %56
br label %79
78: ; preds = %51
store i32 -1, i32* %6
br label %79
79: ; preds = %78, %77
br label %80
80: ; preds = %79, %49
%81 = load i32, i32* %7
%82 = call i32 @close(i32 %81)
%83 = load i32, i32* %8
%84 = call i32 @close(i32 %83)
%85 = load i32, i32* %6
store i32 %85, i32* %3
br label %86
86: ; preds = %80, %27, %19
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @hlp_file_bincompare(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i32, i32* @errno
br label %47
10: ; preds = %2
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %1, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 @close(i32 %6)
%16 = load i32, i32* @errno
br label %47
17: ; preds = %10
%18 = load i32, i32* @SEEK_END
%19 = tail call i64 @lseek(i32 %6, i32 0, i32 %18)
%20 = load i32, i32* @SEEK_END
%21 = tail call i64 @lseek(i32 %12, i32 0, i32 %20)
%22 = load i32, i32* @SEEK_SET
%23 = tail call i64 @lseek(i32 %6, i32 0, i32 %22)
%24 = load i32, i32* @SEEK_SET
%25 = tail call i64 @lseek(i32 %12, i32 0, i32 %24)
%26 = icmp slt i64 %19, 0
%27 = icmp slt i64 %21, 0
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %29, label %31
29: ; preds = %17
%30 = load i32, i32* @errno
br label %43
31: ; preds = %17
%32 = icmp eq i64 %19, %21
br i1 %32, label %36, label %43
33: ; preds = %36
%34 = add nuw i64 %37, 1
%35 = icmp eq i64 %37, %19
br i1 %35, label %43, label %36
36: ; preds = %31, %33
%37 = phi i64 [ %34, %33 ], [ 0, %31 ]
store i8 0, i8* %3
store i8 0, i8* %4
%38 = call i32 @pread(i32 %6, i8* %3, i32 1, i64 %37)
%39 = call i32 @pread(i32 %12, i8* %4, i32 1, i64 %37)
%40 = load i8, i8* %3
%41 = load i8, i8* %4
%42 = icmp eq i8 %40, %41
br i1 %42, label %33, label %43
43: ; preds = %33, %36, %31, %29
%44 = phi i32 [ %30, %29 ], [ -1, %31 ], [ 0, %33 ], [ -1, %36 ]
%45 = tail call i32 @close(i32 %6)
%46 = tail call i32 @close(i32 %12)
br label %47
47: ; preds = %43, %14, %8
%48 = phi i32 [ %9, %8 ], [ %16, %14 ], [ %44, %43 ]
ret i32 %48
}