#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 SHA_DIGEST_LENGTH;
size_t base32_decode(char *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ normalize_key(char *);
char *sha(char *, int);
char *strdup(char const *);
int /*<<< orphan*/ strlen(char *);
int get_licenseinfo(const char *license, unsigned int *_serial,
                    unsigned short int *_users) {
  size_t len;
  char *buf;
  int i;
  int j;
  char *s;
  char hash[SHA_DIGEST_LENGTH], *h;
  char data[32];
  unsigned short int *users;
  unsigned int *serial;
  int check_indexes[] = {
      2, 4, 6, 8, 10, 12, 11, 15, 17, -1,
  };
  s = strdup(license);
  normalize_key(s);
  len = base32_decode(s, &buf, strlen(s));
  j = 0;
  hash[11] = buf[0];
  for (i = 1; j < 6; i++) {
    data[j++] = buf[i++];
    hash[i] = buf[i];
  }
  hash[15] = buf[i++];
  hash[17] = buf[i++];
  data[6] = '\xa1';
  h = sha(data, 4 + 2 + 1);
  for (i = 0; check_indexes[i] != -1; i++) {
    int idx = check_indexes[i];
    if ((hash[idx] & 0xff) != (h[idx] & 0xff)) {
      free(h);
      free(s);
      return 0;
    }
  }
  serial = (unsigned int *)data;
  users = (unsigned short int *)(data + 4);
  *_serial = *serial;
  *_users = *users;
  free(h);
  free(buf);
  free(s);
  return 1;
}


x86 assembly (clang, -O0):
<get_licenseinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
lea    -0xc0(%rbp),%rdi
lea    0xe3c(%rip),%rsi
mov    $0x28,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <normalize_key@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xd8(%rbp),%rdi
mov    %eax,%edx
lea    -0x30(%rbp),%rsi
call   1050 <base32_decode@plt>
mov    %rax,%rcx
mov    -0xd0(%rbp),%rax
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rcx
mov    (%rcx),%cl
mov    %cl,0xb(%rax)
movl   $0x1,-0x34(%rbp)
cmpl   $0x6,-0x38(%rbp)
jge    1287 <get_licenseinfo+0x117>
mov    -0xd0(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x34(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %edx,%rdx
mov    (%rcx,%rdx,1),%dl
mov    -0x38(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x38(%rbp)
movslq %ecx,%rcx
mov    %dl,-0x80(%rbp,%rcx,1)
mov    -0x30(%rbp),%rcx
movslq -0x34(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    122f <get_licenseinfo+0xbf>
mov    -0xd0(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x34(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %edx,%rdx
mov    (%rcx,%rdx,1),%cl
mov    %cl,0xf(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x34(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %edx,%rdx
mov    (%rcx,%rdx,1),%cl
mov    %cl,0x11(%rax)
movb   $0xa1,-0x7a(%rbp)
lea    -0x80(%rbp),%rdi
mov    $0x7,%esi
call   1080 <sha@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmpl   $0xffffffff,-0xc0(%rbp,%rax,4)
ff
je     136d <get_licenseinfo+0x1fd>
mov    -0xd0(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    -0xc0(%rbp,%rcx,4),%ecx
mov    %ecx,-0xc4(%rbp)
movslq -0xc4(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
mov    -0x58(%rbp),%rcx
movslq -0xc4(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0xff,%ecx
cmp    %ecx,%eax
je     135a <get_licenseinfo+0x1ea>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc8(%rbp)
jmp    13d3 <get_licenseinfo+0x263>
jmp    135f <get_licenseinfo+0x1ef>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12db <get_licenseinfo+0x16b>
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x88(%rbp)
mov    -0x90(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x88(%rbp),%rax
mov    (%rax),%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0xc8(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_licenseinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,0x38(%rsp)
mov    %rsi,0x30(%rsp)
mov    %rsp,0x40(%rsp)
call   1080 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <normalize_key@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1050 <base32_decode@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%cl
mov    %cl,0x6(%rsp)
mov    0x1(%rax),%cl
mov    %cl,0x10(%rsp)
mov    0x2(%rax),%r15b
mov    0x3(%rax),%cl
mov    %cl,0x11(%rsp)
mov    0x4(%rax),%r14b
mov    0x5(%rax),%cl
mov    %cl,0x12(%rsp)
mov    0x6(%rax),%r13b
mov    0x7(%rax),%cl
mov    %cl,0x13(%rsp)
mov    0x8(%rax),%r12b
mov    0x9(%rax),%cl
mov    %cl,0x14(%rsp)
mov    0xa(%rax),%bpl
mov    0xb(%rax),%cl
mov    %cl,0x15(%rsp)
mov    0xc(%rax),%cl
mov    %cl,0x7(%rsp)
mov    0xd(%rax),%cl
mov    %cl,0x5(%rsp)
mov    0xe(%rax),%al
mov    %al,0x4(%rsp)
movb   $0xa1,0x16(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x7,%esi
call   1070 <sha@plt>
mov    %rax,%rdi
cmp    0x2(%rax),%r15b
jne    1289 <get_licenseinfo+0x129>
cmp    0x4(%rdi),%r14b
jne    1289 <get_licenseinfo+0x129>
cmp    0x6(%rdi),%r13b
jne    1289 <get_licenseinfo+0x129>
cmp    0x8(%rdi),%r12b
jne    1289 <get_licenseinfo+0x129>
cmp    0xa(%rdi),%bpl
jne    1289 <get_licenseinfo+0x129>
mov    0x7(%rsp),%al
cmp    0xc(%rdi),%al
jne    1289 <get_licenseinfo+0x129>
mov    0x6(%rsp),%al
cmp    0xb(%rdi),%al
jne    1289 <get_licenseinfo+0x129>
mov    0x5(%rsp),%al
cmp    0xf(%rdi),%al
jne    1289 <get_licenseinfo+0x129>
mov    0x4(%rsp),%al
cmp    0x11(%rdi),%al
jne    1289 <get_licenseinfo+0x129>
mov    0x10(%rsp),%eax
mov    0x30(%rsp),%rcx
mov    %eax,(%rcx)
movzwl 0x14(%rsp),%eax
mov    0x38(%rsp),%rcx
mov    %ax,(%rcx)
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%ebp
jmp    1290 <get_licenseinfo+0x130>
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x40(%rsp),%rsp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA_DIGEST_LENGTH = global i32 0
@__const.get_licenseinfo.check_indexes = [10 x i32] [i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 11, i32 15, i32 17, i32 -1]
define i32 @get_licenseinfo(i8* %0, i32* %1, i16* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i16*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i8*
%16 = alloca [32 x i8]
%17 = alloca i16*
%18 = alloca i32*
%19 = alloca [10 x i32]
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i16* %2, i16** %7
%22 = load i32, i32* @SHA_DIGEST_LENGTH
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %13
%25 = alloca i8, i64 %23
store i64 %23, i64* %14
%26 = bitcast [10 x i32]* %19 to i8*
%27 = load i8*, i8** %5
%28 = call i8* @strdup(i8* %27)
store i8* %28, i8** %12
%29 = load i8*, i8** %12
%30 = call i32 @normalize_key(i8* %29)
%31 = load i8*, i8** %12
%32 = load i8*, i8** %12
%33 = call i32 @strlen(i8* %32)
%34 = call i64 @base32_decode(i8* %31, i8** %9, i32 %33)
store i64 %34, i64* %8
store i32 0, i32* %11
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = getelementptr inbounds i8, i8* %25, i64 11
store i8 %37, i8* %38
store i32 1, i32* %10
br label %39
39: ; preds = %61, %3
%40 = load i32, i32* %11
%41 = icmp slt i32 %40, 6
br i1 %41, label %42, label %64
42: ; preds = %39
%43 = load i8*, i8** %9
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = load i8, i8* %47
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 1
store i32 %50, i32* %11
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 %51
store i8 %48, i8* %52
%53 = load i8*, i8** %9
%54 = load i32, i32* %10
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %25, i64 %59
store i8 %57, i8* %60
br label %61
61: ; preds = %42
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %39
64: ; preds = %39
%65 = load i8*, i8** %9
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
%68 = sext i32 %66 to i64
%69 = getelementptr inbounds i8, i8* %65, i64 %68
%70 = load i8, i8* %69
%71 = getelementptr inbounds i8, i8* %25, i64 15
store i8 %70, i8* %71
%72 = load i8*, i8** %9
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
store i32 %74, i32* %10
%75 = sext i32 %73 to i64
%76 = getelementptr inbounds i8, i8* %72, i64 %75
%77 = load i8, i8* %76
%78 = getelementptr inbounds i8, i8* %25, i64 17
store i8 %77, i8* %78
%79 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 6
store i8 -95, i8* %79
%80 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%81 = call i8* @sha(i8* %80, i32 7)
store i8* %81, i8** %15
store i32 0, i32* %10
br label %82
82: ; preds = %113, %64
%83 = load i32, i32* %10
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [10 x i32], [10 x i32]* %19, i64 0, i64 %84
%86 = load i32, i32* %85
%87 = icmp ne i32 %86, -1
br i1 %87, label %88, label %116
88: ; preds = %82
%89 = load i32, i32* %10
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [10 x i32], [10 x i32]* %19, i64 0, i64 %90
%92 = load i32, i32* %91
store i32 %92, i32* %20
%93 = load i32, i32* %20
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %25, i64 %94
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = and i32 %97, 255
%99 = load i8*, i8** %15
%100 = load i32, i32* %20
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %99, i64 %101
%103 = load i8, i8* %102
%104 = sext i8 %103 to i32
%105 = and i32 %104, 255
%106 = icmp ne i32 %98, %105
br i1 %106, label %107, label %112
107: ; preds = %88
%108 = load i8*, i8** %15
%109 = call i32 @free(i8* %108)
%110 = load i8*, i8** %12
%111 = call i32 @free(i8* %110)
store i32 0, i32* %4
store i32 1, i32* %21
br label %134
112: ; preds = %88
br label %113
113: ; preds = %112
%114 = load i32, i32* %10
%115 = add nsw i32 %114, 1
store i32 %115, i32* %10
br label %82
116: ; preds = %82
%117 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%118 = bitcast i8* %117 to i32*
store i32* %118, i32** %18
%119 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%120 = getelementptr inbounds i8, i8* %119, i64 4
%121 = bitcast i8* %120 to i16*
store i16* %121, i16** %17
%122 = load i32*, i32** %18
%123 = load i32, i32* %122
%124 = load i32*, i32** %6
store i32 %123, i32* %124
%125 = load i16*, i16** %17
%126 = load i16, i16* %125
%127 = load i16*, i16** %7
store i16 %126, i16* %127
%128 = load i8*, i8** %15
%129 = call i32 @free(i8* %128)
%130 = load i8*, i8** %9
%131 = call i32 @free(i8* %130)
%132 = load i8*, i8** %12
%133 = call i32 @free(i8* %132)
store i32 1, i32* %4
store i32 1, i32* %21
br label %134
134: ; preds = %116, %107
%135 = load i8*, i8** %13
%136 = load i32, i32* %4
ret i32 %136
}

LLVM IR (-O2):
@SHA_DIGEST_LENGTH = global i32 0
define i32 @get_licenseinfo(i8* nocapture %0, i32* nocapture writeonly %1, i16* nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca [32 x i8]
%6 = bitcast i8** %4 to i8*
%7 = tail call i8* @llvm.stacksave()
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = tail call i8* @strdup(i8* %0)
%10 = tail call i32 @normalize_key(i8* %9)
%11 = tail call i32 @strlen(i8* %9)
%12 = call i64 @base32_decode(i8* %9, i8** %4, i32 %11)
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = load i8, i8* %15
store i8 %16, i8* %8
%17 = getelementptr inbounds i8, i8* %13, i64 2
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %13, i64 3
%20 = load i8, i8* %19
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 1
store i8 %20, i8* %21
%22 = getelementptr inbounds i8, i8* %13, i64 4
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %13, i64 5
%25 = load i8, i8* %24
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 2
store i8 %25, i8* %26
%27 = getelementptr inbounds i8, i8* %13, i64 6
%28 = load i8, i8* %27
%29 = getelementptr inbounds i8, i8* %13, i64 7
%30 = load i8, i8* %29
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 3
store i8 %30, i8* %31
%32 = getelementptr inbounds i8, i8* %13, i64 8
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %13, i64 9
%35 = load i8, i8* %34
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 4
store i8 %35, i8* %36
%37 = getelementptr inbounds i8, i8* %13, i64 10
%38 = load i8, i8* %37
%39 = getelementptr inbounds i8, i8* %13, i64 11
%40 = load i8, i8* %39
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 5
store i8 %40, i8* %41
%42 = getelementptr inbounds i8, i8* %13, i64 12
%43 = load i8, i8* %42
%44 = getelementptr inbounds i8, i8* %13, i64 13
%45 = load i8, i8* %44
%46 = getelementptr inbounds i8, i8* %13, i64 14
%47 = load i8, i8* %46
%48 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 6
store i8 -95, i8* %48
%49 = call i8* @sha(i8* %8, i32 7)
%50 = getelementptr inbounds i8, i8* %49, i64 2
%51 = load i8, i8* %50
%52 = icmp eq i8 %18, %51
br i1 %52, label %53, label %93
53: ; preds = %3
%54 = getelementptr inbounds i8, i8* %49, i64 4
%55 = load i8, i8* %54
%56 = icmp eq i8 %23, %55
br i1 %56, label %57, label %93
57: ; preds = %53
%58 = getelementptr inbounds i8, i8* %49, i64 6
%59 = load i8, i8* %58
%60 = icmp eq i8 %28, %59
br i1 %60, label %61, label %93
61: ; preds = %57
%62 = getelementptr inbounds i8, i8* %49, i64 8
%63 = load i8, i8* %62
%64 = icmp eq i8 %33, %63
br i1 %64, label %65, label %93
65: ; preds = %61
%66 = getelementptr inbounds i8, i8* %49, i64 10
%67 = load i8, i8* %66
%68 = icmp eq i8 %38, %67
br i1 %68, label %69, label %93
69: ; preds = %65
%70 = getelementptr inbounds i8, i8* %49, i64 12
%71 = load i8, i8* %70
%72 = icmp eq i8 %43, %71
br i1 %72, label %73, label %93
73: ; preds = %69
%74 = getelementptr inbounds i8, i8* %49, i64 11
%75 = load i8, i8* %74
%76 = icmp eq i8 %14, %75
br i1 %76, label %77, label %93
77: ; preds = %73
%78 = getelementptr inbounds i8, i8* %49, i64 15
%79 = load i8, i8* %78
%80 = icmp eq i8 %45, %79
br i1 %80, label %81, label %93
81: ; preds = %77
%82 = getelementptr inbounds i8, i8* %49, i64 17
%83 = load i8, i8* %82
%84 = icmp eq i8 %47, %83
br i1 %84, label %85, label %93
85: ; preds = %81
%86 = bitcast [32 x i8]* %5 to i32*
%87 = bitcast i8* %36 to i16*
%88 = load i32, i32* %86
store i32 %88, i32* %1
%89 = load i16, i16* %87
store i16 %89, i16* %2
%90 = call i32 @free(i8* %49)
%91 = load i8*, i8** %4
%92 = call i32 @free(i8* %91)
br label %95
93: ; preds = %81, %77, %73, %69, %65, %61, %57, %53, %3
%94 = call i32 @free(i8* %49)
br label %95
95: ; preds = %93, %85
%96 = phi i32 [ 0, %93 ], [ 1, %85 ]
%97 = call i32 @free(i8* %9)
ret i32 %96
}