// File: BrianEnigma[P]cryptoslam/src/cryptogram.cpp
// Function: Cryptogram::letterDistribution(char*, int*)
void Cryptogram::letterDistribution(char letters[], int counts[])
{
    char letter;
    for (char c = 'A'; c <= 'Z'; c++)
    {
        letters[c-'A'] = c;
        counts[c-'A'] = 0;
    }
    for (string::iterator t = cyphertext.begin(); t != cyphertext.end(); t++)
    {
        letter = normalize(*t);
        if (isKey(letter))
            counts[letter-'A']++;
    }
    // BUBBLESORT!  YEAY!
    int tempInt;
    char tempChar;
    for (int i=0; i < 26; i++)
        for (int j = i; j < 26; j++)
            if (counts[j] > counts[i])
            {
                tempChar = letters[i];
                letters[i] = letters[j];
                letters[j] = tempChar;
                tempInt = counts[i];
                counts[i] = counts[j];
                counts[j] = tempInt;
            }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movb $0x41, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
cmpl $0x5a, %eax
jg 0x310c
movb -0x1a(%rbp), %dl
movq -0x10(%rbp), %rax
movsbl -0x1a(%rbp), %ecx
subl $0x41, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
movsbl -0x1a(%rbp), %ecx
subl $0x41, %ecx
movslq %ecx, %rcx
movl $0x0, (%rax,%rcx,4)
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0x30d0
movq -0x50(%rbp), %rdi
callq 0x21f0
movq %rax, -0x28(%rbp)
movq -0x50(%rbp), %rdi
callq 0x2160
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4040
testb $0x1, %al
jne 0x3139
jmp 0x3186
leaq -0x28(%rbp), %rdi
callq 0x4080
movsbl (%rax), %edi
callq 0x2d10
movb %al, -0x19(%rbp)
movsbl -0x19(%rbp), %edi
callq 0x2d50
testb $0x1, %al
jne 0x315c
jmp 0x3173
movq -0x18(%rbp), %rax
movsbl -0x19(%rbp), %ecx
subl $0x41, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x3175
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x40a0
movq %rax, -0x38(%rbp)
jmp 0x3119
movl $0x0, -0x44(%rbp)
cmpl $0x1a, -0x44(%rbp)
jge 0x3243
movl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x1a, -0x48(%rbp)
jge 0x3233
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movslq -0x44(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x3223
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x3d(%rbp)
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb %dl, (%rax,%rcx)
movb -0x3d(%rbp), %dl
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %edx
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x3225
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x319d
jmp 0x3235
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x318d
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)