#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 uint32_t;
typedef scalar_t__ uint16_t;

/* Variables and functions */
scalar_t__ CKSUM_FP(void const *, int);
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ checksum_simple(void const *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, scalar_t__,
                           scalar_t__);
int /*<<< orphan*/ stderr;
bool verify(const void *data, uint32_t offset, uint32_t size) {
  uint16_t csum_expected = checksum_simple(data, size);
  uint16_t csum_actual = CKSUM_FP(data, size);
  if (csum_actual != csum_expected) {
    fprintf(stderr,
            "\nInvalid checksum for offset %u size %u: "
            "actual %04x expected %04x (valid)",
            offset, size, csum_actual, csum_expected);
    if (size < 65536) {
      exit(EXIT_FAILURE);
    }
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <checksum_simple@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <CKSUM_FP@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11ca <verify+0x8a>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xe62(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0x10000,-0x18(%rbp)
jge    11be <verify+0x7e>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <verify+0x91>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %edx,%esi
call   1050 <checksum_simple@plt>
mov    %rax,%r15
mov    %rbp,%rdi
mov    %ebx,%esi
call   1030 <CKSUM_FP@plt>
mov    $0x1,%ecx
cmp    %r15,%rax
je     1197 <verify+0x57>
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%edi
lea    0xe83(%rip),%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    %rax,%r8
mov    %r15,%r9
call   1040 <fprintf@plt>
xor    %ecx,%ecx
cmp    $0xffff,%ebx
jle    11a4 <verify+0x64>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [75 x i8] c"\0AInvalid checksum for offset %u size %u: actual %04x expected %04x (valid)\00"
@EXIT_FAILURE = global i32 0
define i32 @verify(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i32, i32* %7
%12 = call i64 @checksum_simple(i8* %10, i32 %11)
store i64 %12, i64* %8
%13 = load i8*, i8** %5
%14 = load i32, i32* %7
%15 = call i64 @CKSUM_FP(i8* %13, i32 %14)
store i64 %15, i64* %9
%16 = load i64, i64* %9
%17 = load i64, i64* %8
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = load i64, i64* %9
%24 = load i64, i64* %8
%25 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22, i64 %23, i64 %24)
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 65536
br i1 %27, label %28, label %31
28: ; preds = %19
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %19
store i32 0, i32* %4
br label %33
32: ; preds = %3
store i32 1, i32* %4
br label %33
33: ; preds = %32, %31
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [75 x i8] c"\0AInvalid checksum for offset %u size %u: actual %04x expected %04x (valid)\00"
@EXIT_FAILURE = global i32 0
define i32 @verify(i8* %0, i32 %1, i32 %2) {
%4 = tail call i64 @checksum_simple(i8* %0, i32 %2)
%5 = tail call i64 @CKSUM_FP(i8* %0, i32 %2)
%6 = icmp eq i64 %5, %4
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i64 %5, i64 %4)
%10 = icmp slt i32 %2, 65536
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %3, %7
%15 = phi i32 [ 0, %7 ], [ 1, %3 ]
ret i32 %15
}