#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 */
struct files_t {
  int dummy;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ memcmp(void const *, int *, int);
int /*<<< orphan*/ read_db_block(int *, int /*<<< orphan*/ const,
                                 struct files_t const *const);
int compare_blocks(const void *blk1, const off_t offset,
                   const struct files_t *const restrict files) {
  int blk2[4096 / sizeof(int)];
  const int *const check1 = (const int *)blk1;
  const int *const check2 = blk2;
  ;
  if (offset < 0)
    return -1;
  read_db_block(blk2, offset, files);
  if (*check1 != *check2)
    return -1;
  if (!memcmp(blk1, blk2, 4096))
    return 0;
  return -1;
}


x86 assembly (clang, -O0):
<compare_blocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1028(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1165 <compare_blocks+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <compare_blocks+0xad>
lea    -0x1020(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <read_db_block@plt>
mov    -0x1028(%rbp),%rax
mov    (%rax),%eax
mov    -0x1030(%rbp),%rcx
cmp    (%rcx),%eax
je     119c <compare_blocks+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <compare_blocks+0xad>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    11c6 <compare_blocks+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    11cd <compare_blocks+0xad>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_blocks>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    $0xffffffff,%ebx
test   %esi,%esi
js     115a <compare_blocks+0x3a>
mov    %rdi,%r14
mov    %rsp,%rdi
call   1040 <read_db_block@plt>
mov    (%r14),%eax
cmp    (%rsp),%eax
jne    115a <compare_blocks+0x3a>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x1000,%edx
call   1030 <memcmp@plt>
neg    %eax
sbb    %ebx,%ebx
mov    %ebx,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.files_t = type { i32 }
define i32 @compare_blocks(i8* %0, i32 %1, %struct.files_t* noalias %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.files_t*
%8 = alloca [1024 x i32]
%9 = alloca i32*
%10 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store %struct.files_t* %2, %struct.files_t** %7
%11 = load i8*, i8** %5
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %9
%13 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
store i32* %13, i32** %10
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %35
17: ; preds = %3
%18 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
%19 = load i32, i32* %6
%20 = load %struct.files_t*, %struct.files_t** %7
%21 = call i32 @read_db_block(i32* %18, i32 %19, %struct.files_t* %20)
%22 = load i32*, i32** %9
%23 = load i32, i32* %22
%24 = load i32*, i32** %10
%25 = load i32, i32* %24
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %28
27: ; preds = %17
store i32 -1, i32* %4
br label %35
28: ; preds = %17
%29 = load i8*, i8** %5
%30 = getelementptr inbounds [1024 x i32], [1024 x i32]* %8, i64 0, i64 0
%31 = call i32 @memcmp(i8* %29, i32* %30, i32 4096)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %28
store i32 0, i32* %4
br label %35
34: ; preds = %28
store i32 -1, i32* %4
br label %35
35: ; preds = %34, %33, %27, %16
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
%struct.files_t = type { i32 }
define i32 @compare_blocks(i8* %0, i32 %1, %struct.files_t* noalias %2) {
%4 = alloca [1024 x i32]
%5 = bitcast [1024 x i32]* %4 to i8*
%6 = getelementptr inbounds [1024 x i32], [1024 x i32]* %4, i64 0, i64 0
%7 = icmp slt i32 %1, 0
br i1 %7, label %18, label %8
8: ; preds = %3
%9 = bitcast i8* %0 to i32*
%10 = call i32 @read_db_block(i32* %6, i32 %1, %struct.files_t* %2)
%11 = load i32, i32* %9
%12 = load i32, i32* %6
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = call i32 @memcmp(i8* %0, i32* %6, i32 4096)
%16 = icmp ne i32 %15, 0
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %14, %8, %3
%19 = phi i32 [ -1, %3 ], [ -1, %8 ], [ %17, %14 ]
ret i32 %19
}