#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 */
size_t fread(char *const, int, size_t const, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *const);
char *malloc(size_t const);
int memcmp(char *const, char *const, size_t const);
int compare(FILE *f0, FILE *f1) {
  int result = 0;
  const size_t tempBufferBytes = 65536;
  char *const b0 = malloc(tempBufferBytes);
  char *const b1 = malloc(tempBufferBytes);
  while (0 == result) {
    const size_t r0 = fread(b0, 1, tempBufferBytes, f0);
    const size_t r1 = fread(b1, 1, tempBufferBytes, f1);
    result = (int)r0 - (int)r1;
    if (0 == r0 || 0 == r1)
      break;
    if (0 == result)
      result = memcmp(b0, b1, r0);
  }
  free(b1);
  free(b0);
  return result;
}


x86 assembly (clang, -O0):
<compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x10000,-0x20(%rbp)
mov    $0x10000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x10000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    120a <compare+0xca>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1040 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1040 <fread@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
je     11e1 <compare+0xa1>
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
jne    11e6 <compare+0xa6>
jmp    120a <compare+0xca>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    1205 <compare+0xc5>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <memcmp@plt>
mov    %eax,-0x14(%rbp)
jmp    117b <compare+0x3b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x10000,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x10000,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
nopl   0x0(%rax,%rax,1)
mov    $0x10000,%edx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
mov    $0x10000,%edx
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %ebx,%ebp
sub    %eax,%ebp
test   %rbx,%rbx
je     11c3 <compare+0x83>
test   %rax,%rax
je     11c3 <compare+0x83>
test   %ebp,%ebp
jne    11c3 <compare+0x83>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <memcmp@plt>
test   %eax,%eax
je     1170 <compare+0x30>
mov    %eax,%ebp
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @compare(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i64 65536, i64* %6
%11 = call i8* @malloc(i64 65536)
store i8* %11, i8** %7
%12 = call i8* @malloc(i64 65536)
store i8* %12, i8** %8
br label %13
13: ; preds = %42, %2
%14 = load i32, i32* %5
%15 = icmp eq i32 0, %14
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = load i32*, i32** %3
%19 = call i64 @fread(i8* %17, i32 1, i64 65536, i32* %18)
store i64 %19, i64* %9
%20 = load i8*, i8** %8
%21 = load i32*, i32** %4
%22 = call i64 @fread(i8* %20, i32 1, i64 65536, i32* %21)
store i64 %22, i64* %10
%23 = load i64, i64* %9
%24 = trunc i64 %23 to i32
%25 = load i64, i64* %10
%26 = trunc i64 %25 to i32
%27 = sub nsw i32 %24, %26
store i32 %27, i32* %5
%28 = load i64, i64* %9
%29 = icmp eq i64 0, %28
br i1 %29, label %33, label %30
30: ; preds = %16
%31 = load i64, i64* %10
%32 = icmp eq i64 0, %31
br i1 %32, label %33, label %34
33: ; preds = %30, %16
br label %43
34: ; preds = %30
%35 = load i32, i32* %5
%36 = icmp eq i32 0, %35
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i8*, i8** %7
%39 = load i8*, i8** %8
%40 = load i64, i64* %9
%41 = call i32 @memcmp(i8* %38, i8* %39, i64 %40)
store i32 %41, i32* %5
br label %42
42: ; preds = %37, %34
br label %13
43: ; preds = %33, %13
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %7
%47 = call i32 @free(i8* %46)
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
define i32 @compare(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call dereferenceable_or_null(65536) i8* @malloc(i64 65536)
%4 = tail call dereferenceable_or_null(65536) i8* @malloc(i64 65536)
br label %5
5: ; preds = %2, %16
%6 = tail call i64 @fread(i8* %3, i32 1, i64 65536, i32* %0)
%7 = tail call i64 @fread(i8* %4, i32 1, i64 65536, i32* %1)
%8 = trunc i64 %6 to i32
%9 = trunc i64 %7 to i32
%10 = sub nsw i32 %8, %9
%11 = icmp ne i64 %6, 0
%12 = icmp ne i64 %7, 0
%13 = and i1 %11, %12
%14 = icmp eq i32 %10, 0
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %19
16: ; preds = %5
%17 = tail call i32 @memcmp(i8* %3, i8* %4, i64 %6)
%18 = icmp eq i32 %17, 0
br i1 %18, label %5, label %19
19: ; preds = %5, %16
%20 = phi i32 [ %17, %16 ], [ %10, %5 ]
%21 = tail call i32 @free(i8* %4)
%22 = tail call i32 @free(i8* %3)
ret i32 %20
}