#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);
scalar_t__ 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 = (char *)malloc(tempBufferBytes);
  char *const b1 = (char *)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 i64 @malloc(i64 65536)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = call i64 @malloc(i64 65536)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %8
br label %15
15: ; preds = %44, %2
%16 = load i32, i32* %5
%17 = icmp eq i32 0, %16
br i1 %17, label %18, label %45
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = load i32*, i32** %3
%21 = call i64 @fread(i8* %19, i32 1, i64 65536, i32* %20)
store i64 %21, i64* %9
%22 = load i8*, i8** %8
%23 = load i32*, i32** %4
%24 = call i64 @fread(i8* %22, i32 1, i64 65536, i32* %23)
store i64 %24, i64* %10
%25 = load i64, i64* %9
%26 = trunc i64 %25 to i32
%27 = load i64, i64* %10
%28 = trunc i64 %27 to i32
%29 = sub nsw i32 %26, %28
store i32 %29, i32* %5
%30 = load i64, i64* %9
%31 = icmp eq i64 0, %30
br i1 %31, label %35, label %32
32: ; preds = %18
%33 = load i64, i64* %10
%34 = icmp eq i64 0, %33
br i1 %34, label %35, label %36
35: ; preds = %32, %18
br label %45
36: ; preds = %32
%37 = load i32, i32* %5
%38 = icmp eq i32 0, %37
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i8*, i8** %7
%41 = load i8*, i8** %8
%42 = load i64, i64* %9
%43 = call i32 @memcmp(i8* %40, i8* %41, i64 %42)
store i32 %43, i32* %5
br label %44
44: ; preds = %39, %36
br label %15
45: ; preds = %35, %15
%46 = load i8*, i8** %8
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %7
%49 = call i32 @free(i8* %48)
%50 = load i32, i32* %5
ret i32 %50
}

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