#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 */
struct WaveletTree {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
struct WaveletTree *buildTree(char *, int, char *, int);
int /*<<< orphan*/ deleteTree(struct WaveletTree *);
char *extractAlphabetLetters(char *);
int /*<<< orphan*/ free(void *);
scalar_t__ malloc(int);
int /*<<< orphan*/ print(char *);
int rankOp(struct WaveletTree *, char *, int, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void testRanking() {
  char tmp[] = "Peter_Piper_picked_a_peck_of_pickled_peppers$";
  char *test = (char *)malloc((strlen(tmp) + 1) * sizeof(char));
  strcpy(test, tmp);
  char *used_alphabet = extractAlphabetLetters(test);
  struct WaveletTree *tree = buildTree(test, (int)strlen(test), used_alphabet,
                                       (int)strlen(used_alphabet));
  assert(rankOp(tree, used_alphabet, 5, 'e') == 2);
  assert(rankOp(tree, used_alphabet, 15, '$') == 0);
  assert(rankOp(tree, used_alphabet, 43, '$') == 0);
  assert(rankOp(tree, used_alphabet, 44, '$') == 1);
  assert(rankOp(tree, used_alphabet, 28, 'P') == 2);
  assert(rankOp(tree, used_alphabet, 33, 'P') == 2);
  assert(rankOp(tree, used_alphabet, 44, 'P') == 2);
  assert(rankOp(tree, used_alphabet, 38, 'p') == 5);
  assert(rankOp(tree, used_alphabet, 44, 't') == 1);
  print("Ranking tests [PASSED]");
  free((void *)test);
  deleteTree(tree);
}


x86 assembly (clang, -O0):
<testRanking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x30(%rbp),%rdi
lea    0xe3d(%rip),%rsi
mov    $0x2e,%edx
call   10b0 <memcpy@plt>
lea    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
call   1050 <extractAlphabetLetters@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x54(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    -0x50(%rbp),%rdx
mov    %eax,%ecx
call   10a0 <buildTree@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x5,%edx
mov    $0x65,%ecx
call   10d0 <rankOp@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0xf,%edx
mov    $0x24,%ecx
call   10d0 <rankOp@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x2b,%edx
mov    $0x24,%ecx
call   10d0 <rankOp@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x2c,%edx
mov    $0x24,%ecx
call   10d0 <rankOp@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x1c,%edx
mov    $0x50,%ecx
call   10d0 <rankOp@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x21,%edx
mov    $0x50,%ecx
call   10d0 <rankOp@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x2c,%edx
mov    $0x50,%ecx
call   10d0 <rankOp@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x26,%edx
mov    $0x70,%ecx
call   10d0 <rankOp@plt>
cmp    $0x5,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x2c,%edx
mov    $0x74,%ecx
call   10d0 <rankOp@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
lea    0xc89(%rip),%rdi
call   1080 <print@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1070 <deleteTree@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testRanking>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movups 0xe6d(%rip),%xmm0
movups %xmm0,0x1e(%rsp)
movaps 0xe53(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe37(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1050 <extractAlphabetLetters@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
call   10a0 <buildTree@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
mov    $0x65,%ecx
call   10c0 <rankOp@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0xf,%edx
mov    $0x24,%ecx
call   10c0 <rankOp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2b,%edx
mov    $0x24,%ecx
call   10c0 <rankOp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2c,%edx
mov    $0x24,%ecx
call   10c0 <rankOp@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1c,%edx
mov    $0x50,%ecx
call   10c0 <rankOp@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x21,%edx
mov    $0x50,%ecx
call   10c0 <rankOp@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2c,%edx
mov    $0x50,%ecx
call   10c0 <rankOp@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x26,%edx
mov    $0x70,%ecx
call   10c0 <rankOp@plt>
xor    %edi,%edi
cmp    $0x5,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2c,%edx
mov    $0x74,%ecx
call   10c0 <rankOp@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1090 <assert@plt>
lea    0xcd1(%rip),%rdi
call   1080 <print@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1070 <deleteTree@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.WaveletTree = type { i32 }
@__const.testRanking.tmp = [46 x i8] c"Peter_Piper_picked_a_peck_of_pickled_peppers$\00"
@.str = [23 x i8] c"Ranking tests [PASSED]\00"
define void @testRanking() {
%1 = alloca [46 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.WaveletTree*
%5 = bitcast [46 x i8]* %1 to i8*
%6 = getelementptr inbounds [46 x i8], [46 x i8]* %1, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 1
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %2
%14 = load i8*, i8** %2
%15 = getelementptr inbounds [46 x i8], [46 x i8]* %1, i64 0, i64 0
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = load i8*, i8** %2
%18 = call i8* @extractAlphabetLetters(i8* %17)
store i8* %18, i8** %3
%19 = load i8*, i8** %2
%20 = load i8*, i8** %2
%21 = call i32 @strlen(i8* %20)
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = call %struct.WaveletTree* @buildTree(i8* %19, i32 %21, i8* %22, i32 %24)
store %struct.WaveletTree* %25, %struct.WaveletTree** %4
%26 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%27 = load i8*, i8** %3
%28 = call i32 @rankOp(%struct.WaveletTree* %26, i8* %27, i32 5, i8 signext 101)
%29 = icmp eq i32 %28, 2
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%33 = load i8*, i8** %3
%34 = call i32 @rankOp(%struct.WaveletTree* %32, i8* %33, i32 15, i8 signext 36)
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%39 = load i8*, i8** %3
%40 = call i32 @rankOp(%struct.WaveletTree* %38, i8* %39, i32 43, i8 signext 36)
%41 = icmp eq i32 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%45 = load i8*, i8** %3
%46 = call i32 @rankOp(%struct.WaveletTree* %44, i8* %45, i32 44, i8 signext 36)
%47 = icmp eq i32 %46, 1
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%51 = load i8*, i8** %3
%52 = call i32 @rankOp(%struct.WaveletTree* %50, i8* %51, i32 28, i8 signext 80)
%53 = icmp eq i32 %52, 2
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%57 = load i8*, i8** %3
%58 = call i32 @rankOp(%struct.WaveletTree* %56, i8* %57, i32 33, i8 signext 80)
%59 = icmp eq i32 %58, 2
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%63 = load i8*, i8** %3
%64 = call i32 @rankOp(%struct.WaveletTree* %62, i8* %63, i32 44, i8 signext 80)
%65 = icmp eq i32 %64, 2
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%69 = load i8*, i8** %3
%70 = call i32 @rankOp(%struct.WaveletTree* %68, i8* %69, i32 38, i8 signext 112)
%71 = icmp eq i32 %70, 5
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
%74 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%75 = load i8*, i8** %3
%76 = call i32 @rankOp(%struct.WaveletTree* %74, i8* %75, i32 44, i8 signext 116)
%77 = icmp eq i32 %76, 1
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = call i32 @print(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%81 = load i8*, i8** %2
%82 = call i32 @free(i8* %81)
%83 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%84 = call i32 @deleteTree(%struct.WaveletTree* %83)
ret void
}

LLVM IR (-O2):
%struct.WaveletTree = type { i32 }
@__const.testRanking.tmp = [46 x i8] c"Peter_Piper_picked_a_peck_of_pickled_peppers$\00"
@.str = [23 x i8] c"Ranking tests [PASSED]\00"
define void @testRanking() {
%1 = alloca [46 x i8]
%2 = getelementptr inbounds [46 x i8], [46 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* %2)
%4 = add nsw i32 %3, 1
%5 = call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = call i32 @strcpy(i8* %6, i8* %2)
%8 = call i8* @extractAlphabetLetters(i8* %6)
%9 = call i32 @strlen(i8* %6)
%10 = call i32 @strlen(i8* %8)
%11 = call %struct.WaveletTree* @buildTree(i8* %6, i32 %9, i8* %8, i32 %10)
%12 = call i32 @rankOp(%struct.WaveletTree* %11, i8* %8, i32 5, i8 signext 101)
%13 = icmp eq i32 %12, 2
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @rankOp(%struct.WaveletTree* %11, i8* %8, i32 15, i8 signext 36)
%17 = icmp eq i32 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 @rankOp(%struct.WaveletTree* %11, i8* %8, i32 43, i8 signext 36)
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i32 @rankOp(%struct.WaveletTree* %11, i8* %8, i32 44, i8 signext 36)
%25 = icmp eq i32 %24, 1
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i32 @rankOp(%struct.WaveletTree* %11, i8* %8, i32 28, i8 signext 80)
%29 = icmp eq i32 %28, 2
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 @rankOp(%struct.WaveletTree* %11, i8* %8, i32 33, i8 signext 80)
%33 = icmp eq i32 %32, 2
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i32 @rankOp(%struct.WaveletTree* %11, i8* %8, i32 44, i8 signext 80)
%37 = icmp eq i32 %36, 2
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = call i32 @rankOp(%struct.WaveletTree* %11, i8* %8, i32 38, i8 signext 112)
%41 = icmp eq i32 %40, 5
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = call i32 @rankOp(%struct.WaveletTree* %11, i8* %8, i32 44, i8 signext 116)
%45 = icmp eq i32 %44, 1
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = call i32 @print(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%49 = call i32 @free(i8* %6)
%50 = call i32 @deleteTree(%struct.WaveletTree* %11)
ret void
}