#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 selectOp(struct WaveletTree *, char *, char, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void testSelecting() {
  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(selectOp(tree, used_alphabet, '$', 0) == -1);
  assert(selectOp(tree, used_alphabet, '$', 1) == 44);
  assert(selectOp(tree, used_alphabet, '$', 2) == -1);
  assert(selectOp(tree, used_alphabet, 'l', 1) == 33);
  assert(selectOp(tree, used_alphabet, 'o', 6) == -1);
  assert(selectOp(tree, used_alphabet, 'p', 2) == 12);
  print("Selecting tests [PASSED]");
  free((void *)test);
  deleteTree(tree);
}


x86 assembly (clang, -O0):
<testSelecting>:
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    $0x24,%edx
xor    %ecx,%ecx
call   10d0 <selectOp@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x24,%edx
mov    $0x1,%ecx
call   10d0 <selectOp@plt>
cmp    $0x2c,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x24,%edx
mov    $0x2,%ecx
call   10d0 <selectOp@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x6c,%edx
mov    $0x1,%ecx
call   10d0 <selectOp@plt>
cmp    $0x21,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x6f,%edx
mov    $0x6,%ecx
call   10d0 <selectOp@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x70,%edx
mov    $0x2,%ecx
call   10d0 <selectOp@plt>
cmp    $0xc,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
lea    0xd01(%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):
<testSelecting>:
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    $0x24,%edx
xor    %ecx,%ecx
call   10c0 <selectOp@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x24,%edx
mov    $0x1,%ecx
call   10c0 <selectOp@plt>
xor    %edi,%edi
cmp    $0x2c,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x24,%edx
mov    $0x2,%ecx
call   10c0 <selectOp@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x6c,%edx
mov    $0x1,%ecx
call   10c0 <selectOp@plt>
xor    %edi,%edi
cmp    $0x21,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x6f,%edx
mov    $0x6,%ecx
call   10c0 <selectOp@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1090 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x70,%edx
mov    $0x2,%ecx
call   10c0 <selectOp@plt>
xor    %edi,%edi
cmp    $0xc,%eax
sete   %dil
call   1090 <assert@plt>
lea    0xd3b(%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.testSelecting.tmp = [46 x i8] c"Peter_Piper_picked_a_peck_of_pickled_peppers$\00"
@.str = [25 x i8] c"Selecting tests [PASSED]\00"
define void @testSelecting() {
%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 @selectOp(%struct.WaveletTree* %26, i8* %27, i8 signext 36, i32 0)
%29 = icmp eq i32 %28, -1
%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 @selectOp(%struct.WaveletTree* %32, i8* %33, i8 signext 36, i32 1)
%35 = icmp eq i32 %34, 44
%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 @selectOp(%struct.WaveletTree* %38, i8* %39, i8 signext 36, i32 2)
%41 = icmp eq i32 %40, -1
%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 @selectOp(%struct.WaveletTree* %44, i8* %45, i8 signext 108, i32 1)
%47 = icmp eq i32 %46, 33
%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 @selectOp(%struct.WaveletTree* %50, i8* %51, i8 signext 111, i32 6)
%53 = icmp eq i32 %52, -1
%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 @selectOp(%struct.WaveletTree* %56, i8* %57, i8 signext 112, i32 2)
%59 = icmp eq i32 %58, 12
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = call i32 @print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%63 = load i8*, i8** %2
%64 = call i32 @free(i8* %63)
%65 = load %struct.WaveletTree*, %struct.WaveletTree** %4
%66 = call i32 @deleteTree(%struct.WaveletTree* %65)
ret void
}

LLVM IR (-O2):
%struct.WaveletTree = type { i32 }
@__const.testSelecting.tmp = [46 x i8] c"Peter_Piper_picked_a_peck_of_pickled_peppers$\00"
@.str = [25 x i8] c"Selecting tests [PASSED]\00"
define void @testSelecting() {
%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 @selectOp(%struct.WaveletTree* %11, i8* %8, i8 signext 36, i32 0)
%13 = icmp eq i32 %12, -1
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @selectOp(%struct.WaveletTree* %11, i8* %8, i8 signext 36, i32 1)
%17 = icmp eq i32 %16, 44
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 @selectOp(%struct.WaveletTree* %11, i8* %8, i8 signext 36, i32 2)
%21 = icmp eq i32 %20, -1
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i32 @selectOp(%struct.WaveletTree* %11, i8* %8, i8 signext 108, i32 1)
%25 = icmp eq i32 %24, 33
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i32 @selectOp(%struct.WaveletTree* %11, i8* %8, i8 signext 111, i32 6)
%29 = icmp eq i32 %28, -1
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 @selectOp(%struct.WaveletTree* %11, i8* %8, i8 signext 112, i32 2)
%33 = icmp eq i32 %32, 12
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i32 @print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @free(i8* %6)
%38 = call i32 @deleteTree(%struct.WaveletTree* %11)
ret void
}