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

/* Variables and functions */
int memcmp(char *, char *, size_t const);
size_t read_bin(int /*<<< orphan*/ *, char *, int);
int compare(FILE *fp0, FILE *fp1) {
  int result = 0;
  while (0 == result) {
    char b0[65536];
    char b1[65536];
    const size_t r0 = read_bin(fp0, b0, sizeof(b0));
    const size_t r1 = read_bin(fp1, b1, sizeof(b1));
    result = (int)r0 - (int)r1;
    if (0 == r0 || 0 == r1) {
      break;
    }
    if (0 == result) {
      result = memcmp(b0, b1, r0);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11e0 <compare+0xc0>
mov    -0x8(%rbp),%rdi
lea    -0x10020(%rbp),%rsi
mov    $0x10000,%edx
call   1030 <read_bin@plt>
mov    %rax,-0x20028(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20020(%rbp),%rsi
mov    $0x10000,%edx
call   1030 <read_bin@plt>
mov    %rax,-0x20030(%rbp)
mov    -0x20028(%rbp),%rax
mov    -0x20030(%rbp),%rcx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x20028(%rbp),%rax
je     11ae <compare+0x8e>
xor    %eax,%eax
cmp    -0x20030(%rbp),%rax
jne    11b3 <compare+0x93>
jmp    11e0 <compare+0xc0>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11db <compare+0xbb>
lea    -0x10020(%rbp),%rdi
lea    -0x20020(%rbp),%rsi
mov    -0x20028(%rbp),%rdx
call   1040 <memcmp@plt>
mov    %eax,-0x14(%rbp)
jmp    113a <compare+0x1a>
mov    -0x14(%rbp),%eax
add    $0x20030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20000,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
lea    0x10000(%rsp),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x10000,%edx
call   1030 <read_bin@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x10000,%edx
call   1030 <read_bin@plt>
mov    %rax,%rcx
mov    %ebx,%eax
sub    %ecx,%eax
test   %rbx,%rbx
je     119a <compare+0x7a>
test   %rcx,%rcx
je     119a <compare+0x7a>
test   %eax,%eax
jne    119a <compare+0x7a>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <memcmp@plt>
test   %eax,%eax
je     1150 <compare+0x30>
add    $0x20000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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