#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 */
int /*<<< orphan*/ CleanForBase32(char *, char const *, int);
int ConvertFromBase32(char *, char *, int);
unsigned short CreateCheck(unsigned char *, int, unsigned short);
scalar_t__ strlen(char *);
int VerifyClientCheck(const char *key, unsigned short cskey) {
  char cleankey[(((16 + 8 + 2) * 8 + 4) / 5) + 1] = "";
  unsigned char keyandcheck[16 + 8 + 2] = "";
  int keybytes = 0;
  int extradatalen = 0;
  unsigned short correctcheck = 0;
  if (!CleanForBase32(cleankey, key, (((16 + 8 + 2) * 8 + 4) / 5) + 1))
    return 0;
  keybytes =
      ConvertFromBase32((char *)keyandcheck, cleankey, (int)strlen(cleankey));
  if (keybytes <= 0)
    return 0;
  extradatalen = keybytes - 8 - 2;
  correctcheck = CreateCheck(keyandcheck, 8 + extradatalen, cskey);
  return (correctcheck == *(unsigned short *)(keyandcheck + extradatalen + 8))
             ? 1
             : 0;
}


x86 assembly (clang, -O0):
<VerifyClientCheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x2b,%edx
call   1040 <memset@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x1a,%edx
call   1040 <memset@plt>
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
movw   $0x0,-0x6a(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2b,%edx
call   1060 <CleanForBase32@plt>
cmp    $0x0,%eax
jne    11c1 <VerifyClientCheck+0x71>
movl   $0x0,-0x4(%rbp)
jmp    1241 <VerifyClientCheck+0xf1>
lea    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1050 <ConvertFromBase32@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jg     1202 <VerifyClientCheck+0xb2>
movl   $0x0,-0x4(%rbp)
jmp    1241 <VerifyClientCheck+0xf1>
mov    -0x64(%rbp),%eax
sub    $0x8,%eax
sub    $0x2,%eax
mov    %eax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%esi
add    $0x8,%esi
movzwl -0x12(%rbp),%edx
call   1070 <CreateCheck@plt>
mov    %ax,-0x6a(%rbp)
movzwl -0x6a(%rbp),%edx
movslq -0x68(%rbp),%rax
movzwl -0x58(%rbp,%rax,1),%esi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VerifyClientCheck>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %esi,%r14d
mov    %rdi,%rsi
xorps  %xmm0,%xmm0
movups %xmm0,0x1b(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movups %xmm0,0x3a(%rsp)
movaps %xmm0,0x30(%rsp)
mov    %rsp,%rdi
mov    $0x2b,%edx
call   1050 <CleanForBase32@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11bf <VerifyClientCheck+0x7f>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x30(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <ConvertFromBase32@plt>
test   %eax,%eax
jle    11bf <VerifyClientCheck+0x7f>
movslq %eax,%rbx
add    $0xfffffffe,%eax
movzwl %r14w,%edx
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <CreateCheck@plt>
xor    %ebp,%ebp
cmp    -0x2(%rbx,%r15,1),%ax
sete   %bpl
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @VerifyClientCheck(i8* %0, i16 zeroext %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i16
%6 = alloca [43 x i8]
%7 = alloca [26 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i16
store i8* %0, i8** %4
store i16 %1, i16* %5
%11 = bitcast [43 x i8]* %6 to i8*
%12 = bitcast [26 x i8]* %7 to i8*
store i32 0, i32* %8
store i32 0, i32* %9
store i16 0, i16* %10
%13 = getelementptr inbounds [43 x i8], [43 x i8]* %6, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = call i32 @CleanForBase32(i8* %13, i8* %14, i32 43)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %2
store i32 0, i32* %3
br label %50
18: ; preds = %2
%19 = getelementptr inbounds [26 x i8], [26 x i8]* %7, i64 0, i64 0
%20 = getelementptr inbounds [43 x i8], [43 x i8]* %6, i64 0, i64 0
%21 = getelementptr inbounds [43 x i8], [43 x i8]* %6, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = trunc i64 %22 to i32
%24 = call i32 @ConvertFromBase32(i8* %19, i8* %20, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %18
store i32 0, i32* %3
br label %50
28: ; preds = %18
%29 = load i32, i32* %8
%30 = sub nsw i32 %29, 8
%31 = sub nsw i32 %30, 2
store i32 %31, i32* %9
%32 = getelementptr inbounds [26 x i8], [26 x i8]* %7, i64 0, i64 0
%33 = load i32, i32* %9
%34 = add nsw i32 8, %33
%35 = load i16, i16* %5
%36 = call zeroext i16 @CreateCheck(i8* %32, i32 %34, i16 zeroext %35)
store i16 %36, i16* %10
%37 = load i16, i16* %10
%38 = zext i16 %37 to i32
%39 = getelementptr inbounds [26 x i8], [26 x i8]* %7, i64 0, i64 0
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = getelementptr inbounds i8, i8* %42, i64 8
%44 = bitcast i8* %43 to i16*
%45 = load i16, i16* %44
%46 = zext i16 %45 to i32
%47 = icmp eq i32 %38, %46
%48 = zext i1 %47 to i64
%49 = select i1 %47, i32 1, i32 0
store i32 %49, i32* %3
br label %50
50: ; preds = %28, %27, %17
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
define i32 @VerifyClientCheck(i8* %0, i16 zeroext %1) {
%3 = alloca [43 x i8]
%4 = alloca [26 x i8]
%5 = getelementptr inbounds [43 x i8], [43 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [26 x i8], [26 x i8]* %4, i64 0, i64 0
%7 = call i32 @CleanForBase32(i8* %5, i8* %0, i32 43)
%8 = icmp eq i32 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %2
%10 = call i64 @strlen(i8* %5)
%11 = trunc i64 %10 to i32
%12 = call i32 @ConvertFromBase32(i8* %6, i8* %5, i32 %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %25, label %14
14: ; preds = %9
%15 = add nsw i32 %12, -10
%16 = add nsw i32 %12, -2
%17 = call zeroext i16 @CreateCheck(i8* %6, i32 %16, i16 zeroext %1)
%18 = sext i32 %15 to i64
%19 = getelementptr inbounds [26 x i8], [26 x i8]* %4, i64 0, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 8
%21 = bitcast i8* %20 to i16*
%22 = load i16, i16* %21
%23 = icmp eq i16 %17, %22
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %9, %2, %14
%26 = phi i32 [ %24, %14 ], [ 0, %2 ], [ 0, %9 ]
ret i32 %26
}