#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 unsigned char uint8_t;
typedef int ssize_t;

/* Variables and functions */
scalar_t__ yodel_checksum_buffer(void const *, int, unsigned char *,
                                 unsigned char *);
int yodel_length(void const *, size_t);
ssize_t yodel_validate(const void *buffer, size_t size) {
  ssize_t result = -1;
  ssize_t length = 0;
  const uint8_t *bp = (uint8_t *)0;
  uint8_t csa = 0;
  uint8_t csb = 0;
  if ((length = yodel_length(buffer, size)) <= 0) {
  } else if ((bp = (uint8_t *)yodel_checksum_buffer(
                  buffer, length, &csa, &csb)) == (unsigned char *)0) {
  } else if ((csa != bp[0]) || (csb != bp[1])) {
  } else {
    result = length;
  }
  return result;
}


x86 assembly (clang, -O0):
<yodel_validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
movb   $0x0,-0x22(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <yodel_length@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jg     116c <yodel_validate+0x4c>
jmp    11cf <yodel_validate+0xaf>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
lea    -0x21(%rbp),%rdx
lea    -0x22(%rbp),%rcx
call   1040 <yodel_checksum_buffer@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1193 <yodel_validate+0x73>
jmp    11ca <yodel_validate+0xaa>
movzbl -0x21(%rbp),%eax
mov    -0x20(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11ba <yodel_validate+0x9a>
movzbl -0x22(%rbp),%eax
mov    -0x20(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
je     11bf <yodel_validate+0x9f>
jmp    11c5 <yodel_validate+0xa5>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11ca <yodel_validate+0xaa>
jmp    11cf <yodel_validate+0xaf>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yodel_validate>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movb   $0x0,0xf(%rsp)
movb   $0x0,0xe(%rsp)
call   1030 <yodel_length@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
jle    1178 <yodel_validate+0x58>
mov    %eax,%ebp
lea    0xf(%rsp),%rdx
lea    0xe(%rsp),%rcx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <yodel_checksum_buffer@plt>
test   %rax,%rax
je     1178 <yodel_validate+0x58>
mov    0xf(%rsp),%cl
cmp    (%rax),%cl
jne    1178 <yodel_validate+0x58>
mov    0xe(%rsp),%cl
cmp    0x1(%rax),%cl
mov    $0xffffffff,%r14d
cmove  %ebp,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @yodel_validate(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 -1, i32* %5
store i32 0, i32* %6
store i8* null, i8** %7
store i8 0, i8* %8
store i8 0, i8* %9
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = call i32 @yodel_length(i8* %10, i64 %11)
store i32 %12, i32* %6
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
br label %43
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = load i32, i32* %6
%18 = call i64 @yodel_checksum_buffer(i8* %16, i32 %17, i8* %8, i8* %9)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %7
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %15
br label %42
22: ; preds = %15
%23 = load i8, i8* %8
%24 = zext i8 %23 to i32
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = icmp ne i32 %24, %28
br i1 %29, label %38, label %30
30: ; preds = %22
%31 = load i8, i8* %9
%32 = zext i8 %31 to i32
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = icmp ne i32 %32, %36
br i1 %37, label %38, label %39
38: ; preds = %30, %22
br label %41
39: ; preds = %30
%40 = load i32, i32* %6
store i32 %40, i32* %5
br label %41
41: ; preds = %39, %38
br label %42
42: ; preds = %41, %21
br label %43
43: ; preds = %42, %14
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
define i32 @yodel_validate(i8* %0, i64 %1) {
%3 = alloca i8
%4 = alloca i8
store i8 0, i8* %3
store i8 0, i8* %4
%5 = tail call i32 @yodel_length(i8* %0, i64 %1)
%6 = icmp slt i32 %5, 1
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = call i64 @yodel_checksum_buffer(i8* %0, i32 %5, i8* %3, i8* %4)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = load i8, i8* %3
%13 = load i8, i8* %9
%14 = icmp eq i8 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i8, i8* %4
%17 = getelementptr inbounds i8, i8* %9, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %16, %18
%20 = select i1 %19, i32 %5, i32 -1
br label %21
21: ; preds = %15, %7, %11, %2
%22 = phi i32 [ -1, %2 ], [ -1, %7 ], [ -1, %11 ], [ %20, %15 ]
ret i32 %22
}