#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 length) {
  int result = 0;
  while (0 == result) {
    char b0[4096];
    char b1[4096];
    const size_t r0 = read_bin(
        fp0, b0, ((length) < ((int)sizeof(b0)) ? (length) : ((int)sizeof(b0))));
    const size_t r1 = read_bin(
        fp1, b1, ((length) < ((int)sizeof(b1)) ? (length) : ((int)sizeof(b1))));
    result = (int)r0 - (int)r1;
    if (0 == r0 || 0 == r1) {
      break;
    }
    if (0 == result) {
      result = memcmp(b0, b1, r0);
    }
    length -= r0;
  }
  return result;
}


x86 assembly (clang, -O0):
<compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2060,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    1284 <compare+0x164>
mov    -0x8(%rbp),%rax
mov    %rax,-0x2040(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x2038(%rbp)
cmpl   $0x1000,-0x14(%rbp)
jge    117c <compare+0x5c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2044(%rbp)
jmp    118c <compare+0x6c>
mov    $0x1000,%eax
mov    %eax,-0x2044(%rbp)
jmp    118c <compare+0x6c>
mov    -0x2038(%rbp),%rsi
mov    -0x2040(%rbp),%rdi
mov    -0x2044(%rbp),%edx
call   1030 <read_bin@plt>
mov    %rax,-0x2028(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x2058(%rbp)
lea    -0x2020(%rbp),%rax
mov    %rax,-0x2050(%rbp)
cmpl   $0x1000,-0x14(%rbp)
jge    11e0 <compare+0xc0>
mov    -0x14(%rbp),%eax
mov    %eax,-0x205c(%rbp)
jmp    11f0 <compare+0xd0>
mov    $0x1000,%eax
mov    %eax,-0x205c(%rbp)
jmp    11f0 <compare+0xd0>
mov    -0x2050(%rbp),%rsi
mov    -0x2058(%rbp),%rdi
mov    -0x205c(%rbp),%edx
call   1030 <read_bin@plt>
mov    %rax,-0x2030(%rbp)
mov    -0x2028(%rbp),%rax
mov    -0x2030(%rbp),%rcx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x2028(%rbp),%rax
je     1241 <compare+0x121>
xor    %eax,%eax
cmp    -0x2030(%rbp),%rax
jne    1246 <compare+0x126>
jmp    1284 <compare+0x164>
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    126e <compare+0x14e>
lea    -0x1020(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
mov    -0x2028(%rbp),%rdx
call   1040 <memcmp@plt>
mov    %eax,-0x18(%rbp)
mov    -0x2028(%rbp),%rcx
movslq -0x14(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    113d <compare+0x1d>
mov    -0x18(%rbp),%eax
add    $0x2060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %edx,%r13d
mov    %rsi,0x8(%rsp)
mov    %rdi,(%rsp)
lea    0x1010(%rsp),%rsi
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
cmp    $0x1000,%r13d
mov    $0x1000,%r12d
cmovl  %r13d,%r12d
mov    (%rsp),%rdi
mov    %rsi,%r14
mov    %r12d,%edx
call   1030 <read_bin@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%rdi
mov    %rbx,%r15
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <read_bin@plt>
mov    %rax,%rcx
mov    %ebp,%eax
sub    %ecx,%eax
test   %rbp,%rbp
je     11b6 <compare+0x96>
test   %rcx,%rcx
je     11b6 <compare+0x96>
test   %eax,%eax
jne    11b6 <compare+0x96>
mov    %r14,%rdi
mov    %r15,%rbx
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <memcmp@plt>
mov    %r14,%rsi
sub    %ebp,%r13d
test   %eax,%eax
je     1150 <compare+0x30>
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @compare(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca [4096 x i8]
%10 = alloca i64
%11 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %12
12: ; preds = %55, %3
%13 = load i32, i32* %7
%14 = icmp eq i32 0, %13
br i1 %14, label %15, label %61
15: ; preds = %12
%16 = load i32*, i32** %4
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 4096
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32, i32* %6
br label %23
22: ; preds = %15
br label %23
23: ; preds = %22, %20
%24 = phi i32 [ %21, %20 ], [ 4096, %22 ]
%25 = call i64 @read_bin(i32* %16, i8* %17, i32 %24)
store i64 %25, i64* %10
%26 = load i32*, i32** %5
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 4096
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = load i32, i32* %6
br label %33
32: ; preds = %23
br label %33
33: ; preds = %32, %30
%34 = phi i32 [ %31, %30 ], [ 4096, %32 ]
%35 = call i64 @read_bin(i32* %26, i8* %27, i32 %34)
store i64 %35, i64* %11
%36 = load i64, i64* %10
%37 = trunc i64 %36 to i32
%38 = load i64, i64* %11
%39 = trunc i64 %38 to i32
%40 = sub nsw i32 %37, %39
store i32 %40, i32* %7
%41 = load i64, i64* %10
%42 = icmp eq i64 0, %41
br i1 %42, label %46, label %43
43: ; preds = %33
%44 = load i64, i64* %11
%45 = icmp eq i64 0, %44
br i1 %45, label %46, label %47
46: ; preds = %43, %33
br label %61
47: ; preds = %43
%48 = load i32, i32* %7
%49 = icmp eq i32 0, %48
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%53 = load i64, i64* %10
%54 = call i32 @memcmp(i8* %51, i8* %52, i64 %53)
store i32 %54, i32* %7
br label %55
55: ; preds = %50, %47
%56 = load i64, i64* %10
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = sub i64 %58, %56
%60 = trunc i64 %59 to i32
store i32 %60, i32* %6
br label %12
61: ; preds = %46, %12
%62 = load i32, i32* %7
ret i32 %62
}

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