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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
int fcompare(const char *fn1, const char *fn2) {
  FILE *f1 = NULL;
  FILE *f2 = NULL;
  if ((f1 = fopen(fn1, "rb")) == NULL) {
    return 1;
  }
  if ((f2 = fopen(fn2, "rb")) == NULL) {
    fclose(f1);
    return 1;
  }
  fseek(f1, 0, SEEK_END);
  fseek(f2, 0, SEEK_END);
  size_t tf1 = ftell(f1);
  size_t tf2 = ftell(f2);
  fseek(f1, 0, SEEK_SET);
  fseek(f2, 0, SEEK_SET);
  if (tf1 != tf2) {
    fclose(f1);
    fclose(f2);
    return -1;
  }
  for (size_t i = 0; i < tf1; i++) {
    int cf1 = fgetc(f1);
    int cf2 = fgetc(f2);
    if (cf1 != cf2) {
      fclose(f1);
      fclose(f2);
      return -1;
    }
  }
  fclose(f1);
  fclose(f2);
  return 0;
}


x86 assembly (clang, -O0):
<fcompare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119a <fcompare+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    12ea <fcompare+0x19a>
mov    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11cd <fcompare+0x7d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ea <fcompare+0x19a>
mov    -0x20(%rbp),%rdi
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x28(%rbp),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x28(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     1263 <fcompare+0x113>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ea <fcompare+0x19a>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    12d1 <fcompare+0x181>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
je     12bb <fcompare+0x16b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ea <fcompare+0x19a>
jmp    12c0 <fcompare+0x170>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    126b <fcompare+0x11b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcompare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1229 <fcompare+0xd9>
mov    %rax,%r13
lea    0xe83(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1231 <fcompare+0xe1>
mov    %rax,%r14
mov    0x2e50(%rip),%rbx
mov    (%rbx),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    (%rbx),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %r13,%rdi
call   1050 <ftell@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1050 <ftell@plt>
mov    %rax,%r12
mov    0x2e0b(%rip),%rbx
mov    (%rbx),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    (%rbx),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    $0xffffffff,%r15d
cmp    %r12,%rbp
jne    121f <fcompare+0xcf>
test   %rbp,%rbp
je     121c <fcompare+0xcc>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    %eax,%ebx
jne    121f <fcompare+0xcf>
add    $0xffffffffffffffff,%rbp
jne    1200 <fcompare+0xb0>
xor    %r15d,%r15d
mov    %r13,%rdi
call   1030 <fclose@plt>
jmp    123a <fcompare+0xea>
mov    $0x1,%r15d
jmp    1242 <fcompare+0xf2>
mov    $0x1,%r15d
mov    %r13,%r14
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @fcompare(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store i32* null, i32** %7
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 1, i32* %3
br label %76
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
store i32 1, i32* %3
br label %76
24: ; preds = %17
%25 = load i32*, i32** %6
%26 = load i32, i32* @SEEK_END
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i32*, i32** %7
%29 = load i32, i32* @SEEK_END
%30 = call i32 @fseek(i32* %28, i32 0, i32 %29)
%31 = load i32*, i32** %6
%32 = call i64 @ftell(i32* %31)
store i64 %32, i64* %8
%33 = load i32*, i32** %7
%34 = call i64 @ftell(i32* %33)
store i64 %34, i64* %9
%35 = load i32*, i32** %6
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i32*, i32** %7
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = load i64, i64* %8
%42 = load i64, i64* %9
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %49
44: ; preds = %24
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
store i32 -1, i32* %3
br label %76
49: ; preds = %24
store i64 0, i64* %10
br label %50
50: ; preds = %68, %49
%51 = load i64, i64* %10
%52 = load i64, i64* %8
%53 = icmp ult i64 %51, %52
br i1 %53, label %54, label %71
54: ; preds = %50
%55 = load i32*, i32** %6
%56 = call i32 @fgetc(i32* %55)
store i32 %56, i32* %11
%57 = load i32*, i32** %7
%58 = call i32 @fgetc(i32* %57)
store i32 %58, i32* %12
%59 = load i32, i32* %11
%60 = load i32, i32* %12
%61 = icmp ne i32 %59, %60
br i1 %61, label %62, label %67
62: ; preds = %54
%63 = load i32*, i32** %6
%64 = call i32 @fclose(i32* %63)
%65 = load i32*, i32** %7
%66 = call i32 @fclose(i32* %65)
store i32 -1, i32* %3
br label %76
67: ; preds = %54
br label %68
68: ; preds = %67
%69 = load i64, i64* %10
%70 = add i64 %69, 1
store i64 %70, i64* %10
br label %50
71: ; preds = %50
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %71, %62, %44, %21, %16
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @fcompare(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %37, label %5
5: ; preds = %2
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %33, label %8
8: ; preds = %5
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %3, i32 0, i32 %9)
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %6, i32 0, i32 %11)
%13 = tail call i64 @ftell(i32* %3)
%14 = tail call i64 @ftell(i32* %6)
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %3, i32 0, i32 %15)
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @fseek(i32* %6, i32 0, i32 %17)
%19 = icmp eq i64 %13, %14
br i1 %19, label %20, label %30
20: ; preds = %8
%21 = icmp eq i64 %13, 0
br i1 %21, label %30, label %24
22: ; preds = %24
%23 = icmp eq i64 %29, %13
br i1 %23, label %30, label %24
24: ; preds = %20, %22
%25 = phi i64 [ %29, %22 ], [ 0, %20 ]
%26 = tail call i32 @fgetc(i32* %3)
%27 = tail call i32 @fgetc(i32* %6)
%28 = icmp eq i32 %26, %27
%29 = add nuw i64 %25, 1
br i1 %28, label %22, label %30
30: ; preds = %22, %24, %20, %8
%31 = phi i32 [ -1, %8 ], [ 0, %20 ], [ -1, %24 ], [ 0, %22 ]
%32 = tail call i32 @fclose(i32* %3)
br label %33
33: ; preds = %30, %5
%34 = phi i32* [ %3, %5 ], [ %6, %30 ]
%35 = phi i32 [ 1, %5 ], [ %31, %30 ]
%36 = tail call i32 @fclose(i32* %34)
br label %37
37: ; preds = %33, %2
%38 = phi i32 [ 1, %2 ], [ %35, %33 ]
ret i32 %38
}