fdcompare(fd1, fd2) {
  int n1, n2, resp;
  register int i;
  register char *c1, *c2;
  char b1[512], b2[512];
  resp = 1;
  while ((n1 = read(fd1, b1, 512)) >= 0 && (n2 = read(fd2, b2, 512)) >= 0 &&
         n1 == n2) {
    c1 = b1;
    c2 = b2;
    for (i = n1 < 512 ? n1 : 512; i--;)
      if (*c1++ != *c2++) {
        resp = 0;
        goto leave;
      }
    if (n1 < 512)
      goto leave;
  }
  resp = 0;
leave:
  lseek(fd1, 0l, 0);
  lseek(fd2, 0l, 0);
  return (resp);
}


x86 assembly (clang, -O0):
<fdcompare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x200,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x431(%rbp)
jl     119f <fdcompare+0x7f>
mov    -0x8(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x200,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x431(%rbp)
jl     119f <fdcompare+0x7f>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
sete   %al
mov    %al,-0x431(%rbp)
mov    -0x431(%rbp),%al
test   $0x1,%al
jne    11b2 <fdcompare+0x92>
jmp    1264 <fdcompare+0x144>
lea    -0x230(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x200,-0xc(%rbp)
jge    11e3 <fdcompare+0xc3>
mov    -0xc(%rbp),%eax
mov    %eax,-0x438(%rbp)
jmp    11f3 <fdcompare+0xd3>
mov    $0x200,%eax
mov    %eax,-0x438(%rbp)
jmp    11f3 <fdcompare+0xd3>
mov    -0x438(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     124d <fdcompare+0x12d>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1248 <fdcompare+0x128>
movl   $0x0,-0x14(%rbp)
jmp    126b <fdcompare+0x14b>
jmp    11fc <fdcompare+0xdc>
cmpl   $0x200,-0xc(%rbp)
jge    125f <fdcompare+0x13f>
jmp    126b <fdcompare+0x14b>
jmp    1138 <fdcompare+0x18>
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
mov    $0x0,%al
call   1030 <lseek@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
mov    $0x0,%al
call   1030 <lseek@plt>
mov    -0x14(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdcompare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %esi,%r13d
mov    %edi,%ebp
lea    0x200(%rsp),%r15
mov    %rsp,%r12
xor    %r14d,%r14d
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x200,%edx
xor    %eax,%eax
call   1040 <read@plt>
test   %eax,%eax
js     11c3 <fdcompare+0xa3>
mov    %eax,%ebx
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x200,%edx
xor    %eax,%eax
call   1040 <read@plt>
test   %eax,%eax
js     11c0 <fdcompare+0xa0>
cmp    %eax,%ebx
jne    11c0 <fdcompare+0xa0>
cmp    $0x200,%ebx
mov    $0x200,%eax
cmovb  %ebx,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %ecx,%eax
je     11b0 <fdcompare+0x90>
movzbl 0x200(%rsp,%rcx,1),%edx
lea    0x1(%rcx),%rsi
cmp    (%rsp,%rcx,1),%dl
mov    %rsi,%rcx
je     1190 <fdcompare+0x70>
jmp    11c0 <fdcompare+0xa0>
nopw   0x0(%rax,%rax,1)
cmp    $0x1ff,%ebx
ja     1144 <fdcompare+0x24>
mov    $0x1,%r14d
jmp    11c3 <fdcompare+0xa3>
xor    %r14d,%r14d
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <lseek@plt>
mov    %r13d,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <lseek@plt>
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @fdcompare(i32 %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
br label %7
7: ; preds = %30, %2
%8 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* %5, i32 512)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %31
10: ; preds = %7
%11 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %1, i8* %6, i32 512)
%12 = icmp sgt i32 %11, -1
%13 = icmp eq i32 %8, %11
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %31
15: ; preds = %10
%16 = icmp ult i32 %8, 512
%17 = select i1 %16, i32 %8, i32 512
br label %18
18: ; preds = %15, %23
%19 = phi i32 [ %24, %23 ], [ %17, %15 ]
%20 = phi i8* [ %25, %23 ], [ %5, %15 ]
%21 = phi i8* [ %27, %23 ], [ %6, %15 ]
%22 = icmp eq i32 %19, 0
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = add nsw i32 %19, -1
%25 = getelementptr inbounds i8, i8* %20, i64 1
%26 = load i8, i8* %20
%27 = getelementptr inbounds i8, i8* %21, i64 1
%28 = load i8, i8* %21
%29 = icmp eq i8 %26, %28
br i1 %29, label %18, label %31
30: ; preds = %18
br i1 %16, label %31, label %7
31: ; preds = %10, %7, %30, %23
%32 = phi i32 [ 0, %23 ], [ 0, %10 ], [ 0, %7 ], [ 1, %30 ]
%33 = call i32 (i32, i64, i32, ...) bitcast (i32 (...)* @lseek to i32 (i32, i64, i32, ...)*)(i32 %0, i64 0, i32 0)
%34 = call i32 (i32, i64, i32, ...) bitcast (i32 (...)* @lseek to i32 (i32, i64, i32, ...)*)(i32 %1, i64 0, i32 0)
ret i32 %32
}