#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 */
scalar_t__ decode_block(unsigned char *, int *, unsigned char const *, int);
scalar_t__ decode_context(unsigned char *, int *, unsigned char const *, int);
scalar_t__ encode_block(unsigned char *, int *, unsigned char const *, int);
scalar_t__ encode_context(unsigned char *, int *, unsigned char const *, int);
int strlen(unsigned char const *);
scalar_t__ strncmp(unsigned char const *, unsigned char *, int);
int validate(const unsigned char *src, const unsigned char *dst) {
  int n;
  unsigned char buf[9];
  if (encode_block(buf, &n, src, strlen(src)) < 0)
    return (-1);
  if (n != strlen(dst))
    return (-1);
  if (strncmp(dst, buf, n))
    return (-1);
  if (decode_block(buf, &n, dst, strlen(dst)) < 0)
    return (-1);
  if (n != strlen(src))
    return (-1);
  if (strncmp(src, buf, n))
    return (-1);
  if (encode_context(buf, &n, src, strlen(src)) < 0)
    return (-1);
  if (n != strlen(dst))
    return (-1);
  if (strncmp(dst, buf, n))
    return (-1);
  if (decode_context(buf, &n, dst, strlen(dst)) < 0)
    return (-1);
  if (n != strlen(src))
    return (-1);
  if (strncmp(src, buf, n))
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x25(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
lea    -0x1c(%rbp),%rsi
call   1080 <encode_block@plt>
cmp    $0x0,%rax
jge    11b5 <validate+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
je     11dd <validate+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
mov    -0x18(%rbp),%rdi
lea    -0x25(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1203 <validate+0xa3>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
lea    -0x25(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
lea    -0x1c(%rbp),%rsi
call   1060 <decode_block@plt>
cmp    $0x0,%rax
jge    1245 <validate+0xe5>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
je     126d <validate+0x10d>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
mov    -0x10(%rbp),%rdi
lea    -0x25(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1293 <validate+0x133>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
lea    -0x25(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rdx
mov    %eax,%ecx
lea    -0x1c(%rbp),%rsi
call   1050 <encode_context@plt>
cmp    $0x0,%rax
jge    12d5 <validate+0x175>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
je     12fd <validate+0x19d>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
mov    -0x18(%rbp),%rdi
lea    -0x25(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1323 <validate+0x1c3>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
lea    -0x25(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    %eax,%ecx
lea    -0x1c(%rbp),%rsi
call   1070 <decode_context@plt>
cmp    $0x0,%rax
jge    1365 <validate+0x205>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
cmp    %ecx,%eax
je     1393 <validate+0x233>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
mov    -0x10(%rbp),%rdi
lea    -0x25(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     13b9 <validate+0x259>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c0 <validate+0x260>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0xf(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1080 <encode_block@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     11ba <validate+0x5a>
mov    0x8(%rsp),%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jne    11ba <validate+0x5a>
mov    0x8(%rsp),%edx
lea    0xf(%rsp),%rsi
mov    %r15,%rdi
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c8 <validate+0x68>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0xf(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %r15,%rdx
mov    %eax,%ecx
call   1060 <decode_block@plt>
test   %rax,%rax
js     11ba <validate+0x5a>
mov    0x8(%rsp),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jne    11ba <validate+0x5a>
mov    0x8(%rsp),%edx
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11ba <validate+0x5a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xf(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1050 <encode_context@plt>
test   %rax,%rax
js     11ba <validate+0x5a>
mov    0x8(%rsp),%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jne    11ba <validate+0x5a>
mov    0x8(%rsp),%edx
lea    0xf(%rsp),%rsi
mov    %r15,%rdi
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11ba <validate+0x5a>
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0xf(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %r15,%rdx
mov    %eax,%ecx
call   1070 <decode_context@plt>
test   %rax,%rax
js     11ba <validate+0x5a>
mov    0x8(%rsp),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jne    11ba <validate+0x5a>
mov    0x8(%rsp),%edx
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strncmp@plt>
neg    %rax
sbb    %r14d,%r14d
jmp    11ba <validate+0x5a>

LLVM IR (-O0):
define i32 @validate(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [9 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = call i64 @encode_block(i8* %8, i32* %6, i8* %9, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %92
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 -1, i32* %3
br label %92
21: ; preds = %15
%22 = load i8*, i8** %5
%23 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%24 = load i32, i32* %6
%25 = call i64 @strncmp(i8* %22, i8* %23, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 -1, i32* %3
br label %92
28: ; preds = %21
%29 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%30 = load i8*, i8** %5
%31 = load i8*, i8** %5
%32 = call i32 @strlen(i8* %31)
%33 = call i64 @decode_block(i8* %29, i32* %6, i8* %30, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %28
store i32 -1, i32* %3
br label %92
36: ; preds = %28
%37 = load i32, i32* %6
%38 = load i8*, i8** %4
%39 = call i32 @strlen(i8* %38)
%40 = icmp ne i32 %37, %39
br i1 %40, label %41, label %42
41: ; preds = %36
store i32 -1, i32* %3
br label %92
42: ; preds = %36
%43 = load i8*, i8** %4
%44 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%45 = load i32, i32* %6
%46 = call i64 @strncmp(i8* %43, i8* %44, i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %42
store i32 -1, i32* %3
br label %92
49: ; preds = %42
%50 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%51 = load i8*, i8** %4
%52 = load i8*, i8** %4
%53 = call i32 @strlen(i8* %52)
%54 = call i64 @encode_context(i8* %50, i32* %6, i8* %51, i32 %53)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %49
store i32 -1, i32* %3
br label %92
57: ; preds = %49
%58 = load i32, i32* %6
%59 = load i8*, i8** %5
%60 = call i32 @strlen(i8* %59)
%61 = icmp ne i32 %58, %60
br i1 %61, label %62, label %63
62: ; preds = %57
store i32 -1, i32* %3
br label %92
63: ; preds = %57
%64 = load i8*, i8** %5
%65 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%66 = load i32, i32* %6
%67 = call i64 @strncmp(i8* %64, i8* %65, i32 %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %63
store i32 -1, i32* %3
br label %92
70: ; preds = %63
%71 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%72 = load i8*, i8** %5
%73 = load i8*, i8** %5
%74 = call i32 @strlen(i8* %73)
%75 = call i64 @decode_context(i8* %71, i32* %6, i8* %72, i32 %74)
%76 = icmp slt i64 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %70
store i32 -1, i32* %3
br label %92
78: ; preds = %70
%79 = load i32, i32* %6
%80 = load i8*, i8** %4
%81 = call i32 @strlen(i8* %80)
%82 = icmp ne i32 %79, %81
br i1 %82, label %83, label %84
83: ; preds = %78
store i32 -1, i32* %3
br label %92
84: ; preds = %78
%85 = load i8*, i8** %4
%86 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%87 = load i32, i32* %6
%88 = call i64 @strncmp(i8* %85, i8* %86, i32 %87)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %84
store i32 -1, i32* %3
br label %92
91: ; preds = %84
store i32 0, i32* %3
br label %92
92: ; preds = %91, %90, %83, %77, %69, %62, %56, %48, %41, %35, %27, %20, %14
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
define i32 @validate(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [9 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @strlen(i8* %0)
%8 = call i64 @encode_block(i8* %6, i32* %3, i8* %0, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %55, label %10
10: ; preds = %2
%11 = load i32, i32* %3
%12 = call i32 @strlen(i8* %1)
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %55
14: ; preds = %10
%15 = load i32, i32* %3
%16 = call i64 @strncmp(i8* %1, i8* %6, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %55
18: ; preds = %14
%19 = call i32 @strlen(i8* %1)
%20 = call i64 @decode_block(i8* %6, i32* %3, i8* %1, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %55, label %22
22: ; preds = %18
%23 = load i32, i32* %3
%24 = call i32 @strlen(i8* %0)
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %55
26: ; preds = %22
%27 = load i32, i32* %3
%28 = call i64 @strncmp(i8* %0, i8* %6, i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %55
30: ; preds = %26
%31 = call i32 @strlen(i8* %0)
%32 = call i64 @encode_context(i8* %6, i32* %3, i8* %0, i32 %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %55, label %34
34: ; preds = %30
%35 = load i32, i32* %3
%36 = call i32 @strlen(i8* %1)
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %55
38: ; preds = %34
%39 = load i32, i32* %3
%40 = call i64 @strncmp(i8* %1, i8* %6, i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %55
42: ; preds = %38
%43 = call i32 @strlen(i8* %1)
%44 = call i64 @decode_context(i8* %6, i32* %3, i8* %1, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %55, label %46
46: ; preds = %42
%47 = load i32, i32* %3
%48 = call i32 @strlen(i8* %0)
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %55
50: ; preds = %46
%51 = load i32, i32* %3
%52 = call i64 @strncmp(i8* %0, i8* %6, i32 %51)
%53 = icmp ne i64 %52, 0
%54 = sext i1 %53 to i32
br label %55
55: ; preds = %50, %46, %42, %38, %34, %30, %26, %22, %18, %14, %10, %2
%56 = phi i32 [ -1, %2 ], [ -1, %10 ], [ -1, %14 ], [ -1, %18 ], [ -1, %22 ], [ -1, %26 ], [ -1, %30 ], [ -1, %34 ], [ -1, %38 ], [ -1, %42 ], [ -1, %46 ], [ %54, %50 ]
ret i32 %56
}