#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, unsigned long, int, int);
int /*<<< orphan*/ gt_xfclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void gt_xfile_cmp(const char *file1, const char *file2) {
  FILE *fp1, *fp2;
  off_t offset;
  int cc1, cc2;
  fp1 = fopen(file1, "rb");
  fp2 = fopen(file2, "rb");
  for (offset = 0;; offset++) {
    cc1 = fgetc(fp1);
    cc2 = fgetc(fp2);
    if (cc1 != cc2) {
      fprintf(stderr, "files %s and %s differ in byte %lu: %d != %d\n", file1,
              file2, (unsigned long)offset, cc1, cc2);
      exit(EXIT_FAILURE);
    }
    if (cc1 == EOF) {
      break;
    }
  }
  gt_xfclose(fp1);
  gt_xfclose(fp2);
}


x86 assembly (clang, -O0):
<gt_xfile_cmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     11ed <gt_xfile_cmp+0x9d>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
lea    0xe2c(%rip),%rsi
mov    %eax,(%rsp)
call   1050 <fprintf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x2c(%rbp),%eax
mov    0x2df1(%rip),%rcx
cmp    (%rcx),%eax
jne    1204 <gt_xfile_cmp+0xb4>
jmp    121a <gt_xfile_cmp+0xca>
jmp    1209 <gt_xfile_cmp+0xb9>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1190 <gt_xfile_cmp+0x40>
mov    -0x18(%rbp),%rdi
call   1030 <gt_xfclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <gt_xfclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gt_xfile_cmp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0xe95(%rip),%rbx
mov    %rbx,%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
mov    %rbp,0x10(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <fopen@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1040 <fgetc@plt>
xor    %ebx,%ebx
cmp    %eax,%ebp
jne    11cf <gt_xfile_cmp+0x7f>
mov    0x2e40(%rip),%r14
nopl   0x0(%rax,%rax,1)
cmp    (%r14),%ebp
je     1203 <gt_xfile_cmp+0xb3>
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1040 <fgetc@plt>
cmp    %eax,%ebp
je     11b0 <gt_xfile_cmp+0x60>
mov    0x2e02(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,(%rsp)
lea    0xe21(%rip),%rsi
mov    %r15,%rdx
mov    0x10(%rsp),%rcx
mov    %rbx,%r8
mov    %ebp,%r9d
call   1050 <fprintf@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %r12,%rdi
call   1030 <gt_xfclose@plt>
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <gt_xfclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"files %s and %s differ in byte %lu: %d != %d\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
define void @gt_xfile_cmp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
store i64 0, i64* %7
br label %14
14: ; preds = %38, %2
%15 = load i32*, i32** %5
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %8
%17 = load i32*, i32** %6
%18 = call i32 @fgetc(i32* %17)
store i32 %18, i32* %9
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %14
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %3
%25 = load i8*, i8** %4
%26 = load i64, i64* %7
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %25, i64 %26, i32 %27, i32 %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %14
%33 = load i32, i32* %8
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %32
br label %41
37: ; preds = %32
br label %38
38: ; preds = %37
%39 = load i64, i64* %7
%40 = add nsw i64 %39, 1
store i64 %40, i64* %7
br label %14
41: ; preds = %36
%42 = load i32*, i32** %5
%43 = call i32 @gt_xfclose(i32* %42)
%44 = load i32*, i32** %6
%45 = call i32 @gt_xfclose(i32* %44)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [46 x i8] c"files %s and %s differ in byte %lu: %d != %d\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
define void @gt_xfile_cmp(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @fgetc(i32* %3)
%6 = tail call i32 @fgetc(i32* %4)
%7 = icmp eq i32 %5, %6
br i1 %7, label %16, label %8
8: ; preds = %21, %2
%9 = phi i64 [ 0, %2 ], [ %22, %21 ]
%10 = phi i32 [ %5, %2 ], [ %23, %21 ]
%11 = phi i32 [ %6, %2 ], [ %24, %21 ]
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i64 %9, i32 %10, i32 %11)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2, %21
%17 = phi i32 [ %23, %21 ], [ %5, %2 ]
%18 = phi i64 [ %22, %21 ], [ 0, %2 ]
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %17, %19
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = add nuw nsw i64 %18, 1
%23 = tail call i32 @fgetc(i32* %3)
%24 = tail call i32 @fgetc(i32* %4)
%25 = icmp eq i32 %23, %24
br i1 %25, label %16, label %8
26: ; preds = %16
%27 = tail call i32 @gt_xfclose(i32* %3)
%28 = tail call i32 @gt_xfclose(i32* %4)
ret void
}