#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 char uint8_t;
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
typedef int /*<<< orphan*/ checksum_expected;

/* Variables and functions */
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sha256_buffer(char const *, size_t, char *);
int verify_checksum(uint8_t *buf, size_t buf_len) {
  char checksum_expected[32];
  char checksum_calc[32];
  if (buf_len <= ((size_t)(7 + 32 + 3 * sizeof(uint16_t) + sizeof(uint64_t) +
                           33 + 128 + 3 * sizeof(uint32_t) + 0))) {
    do {
      do {
      } while (0);
    } while (0);
    return (-3);
  }
  memcpy(checksum_expected, &buf[7], sizeof(checksum_expected));
  memset(&buf[7], 0, 32);
  sha256_buffer((const char *)buf, buf_len, checksum_calc);
  if (memcmp(checksum_expected, checksum_calc, 32) != 0) {
    return (-10);
  } else {
    memcpy(&buf[7], checksum_expected, sizeof(checksum_expected));
    return 0;
  }
}


x86 assembly (clang, -O0):
<verify_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0xe4,-0x18(%rbp)
ja     117e <verify_checksum+0x3e>
jmp    1163 <verify_checksum+0x23>
jmp    1168 <verify_checksum+0x28>
jmp    116d <verify_checksum+0x2d>
jmp    1172 <verify_checksum+0x32>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11fe <verify_checksum+0xbe>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x7,%rsi
mov    $0x20,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1060 <sha256_buffer@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x20,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11e1 <verify_checksum+0xa1>
movl   $0xfffffff6,-0x4(%rbp)
jmp    11fe <verify_checksum+0xbe>
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_checksum>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    $0xfffffffd,%eax
cmp    $0xe5,%rsi
jb     11c9 <verify_checksum+0x89>
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x7(%rdi),%r14
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x20,%edx
call   1050 <memcpy@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
lea    0x20(%rsp),%r13
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1060 <sha256_buffer@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x20,%edx
call   1040 <memcmp@plt>
mov    %rax,%rcx
mov    $0xfffffff6,%eax
test   %rcx,%rcx
jne    11c9 <verify_checksum+0x89>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x20,%edx
call   1050 <memcpy@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @verify_checksum(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i64, i64* %5
%9 = icmp ule i64 %8, 228
br i1 %9, label %10, label %15
10: ; preds = %2
br label %11
11: ; preds = %10
br label %12
12: ; preds = %11
br label %13
13: ; preds = %12
br label %14
14: ; preds = %13
store i32 -3, i32* %3
br label %37
15: ; preds = %2
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 7
%19 = call i32 @memcpy(i8* %16, i8* %18, i32 32)
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 7
%22 = call i32 @memset(i8* %21, i32 0, i32 32)
%23 = load i8*, i8** %4
%24 = load i64, i64* %5
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%26 = call i32 @sha256_buffer(i8* %23, i64 %24, i8* %25)
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%29 = call i64 @memcmp(i8* %27, i8* %28, i32 32)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %15
store i32 -10, i32* %3
br label %37
32: ; preds = %15
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 7
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%36 = call i32 @memcpy(i8* %34, i8* %35, i32 32)
store i32 0, i32* %3
br label %37
37: ; preds = %32, %31, %14
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @verify_checksum(i8* %0, i64 %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = icmp ult i64 %1, 229
br i1 %7, label %17, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %0, i64 7
%10 = call i32 @memcpy(i8* %5, i8* %9, i32 32)
%11 = call i32 @memset(i8* %9, i32 0, i32 32)
%12 = call i32 @sha256_buffer(i8* %0, i64 %1, i8* %6)
%13 = call i64 @memcmp(i8* %5, i8* %6, i32 32)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @memcpy(i8* %9, i8* %5, i32 32)
br label %17
17: ; preds = %8, %2, %15
%18 = phi i32 [ 0, %15 ], [ -3, %2 ], [ -10, %8 ]
ret i32 %18
}