#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 */

/* Variables and functions */
unsigned int array_checksum(char const *, int);
int sscanf(char const *, char *, unsigned int *);
int verify_array_checksum(const char *buf, int bsz) {
  unsigned int csc, cse;
  if (sscanf(buf + bsz - 2, "%02X", &cse) < 1) {
  }
  csc = array_checksum(buf + 1, bsz - 4);
  return (csc == cse) ? 1 : 0;
}


x86 assembly (clang, -O0):
<verify_array_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffe,%rdi
lea    0xebb(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jge    115c <verify_array_checksum+0x3c>
jmp    115c <verify_array_checksum+0x3c>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0xc(%rbp),%esi
sub    $0x4,%esi
call   1030 <array_checksum@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%esi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_array_checksum>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movslq %esi,%r14
add    %r14,%rdi
add    $0xfffffffffffffffe,%rdi
lea    0xec8(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1040 <sscanf@plt>
add    $0x1,%rbx
add    $0xfffffffc,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <array_checksum@plt>
xor    %ecx,%ecx
cmp    0x4(%rsp),%eax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define i32 @verify_array_checksum(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -2
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %6)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %2
br label %15
15: ; preds = %14, %2
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 4
%20 = call i32 @array_checksum(i8* %17, i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = icmp eq i32 %21, %22
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 1, i32 0
ret i32 %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define i32 @verify_array_checksum(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = sext i32 %1 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = getelementptr inbounds i8, i8* %6, i64 -2
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = add nsw i32 %1, -4
%11 = call i32 @array_checksum(i8* %9, i32 %10)
%12 = load i32, i32* %3
%13 = icmp eq i32 %11, %12
%14 = zext i1 %13 to i32
ret i32 %14
}