// File: BrianEnigma[P]cryptoslam/src/cryptogram.cpp
// Function: Cryptogram::paintMessage(_win_st*)
void Cryptogram::paintMessage(WINDOW *w)
{
    // 911:enigma THIS NEEDS WORK!
    int here=0, newHere=0, max;
    char *line;
    // Print the message, interlaced...
    wclear(w);
    wmove(w, 0, 0);
    // Find next \n
    wcolor_set(w, 3, NULL);
    max = cyphertext.length();
    // Traverse the string, one line at a time
    while (here != max)
    {
        // Print plaintext line
        line = strdup(plaintext.c_str() + here);
        for (char *c = line; *c; c++)
            if (*c == '\n') *c = 0;
        wattron(w, A_BOLD);
        wprintw(w, "%s\n", line);
        wattroff(w, A_BOLD);
        free(line);
        // Print cyphertext line
        line = strdup(cyphertext.c_str() + here);
        for (char *c = line; *c; c++)
            if (*c == '\n') *c = 0;
        wattron(w, A_DIM);
        wprintw(w, "%s\n", line);
        wattroff(w, A_DIM);
        free(line);
        // Move on to next line
        newHere = cyphertext.find('\n', here);
        // If no more newlines, ensure we are at the end
        if (newHere == -1)
            newHere = max;
        else
            here = newHere + 1;
        //else
        //    here = newHere;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2240
movq -0x10(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x2260
movq -0x10(%rbp), %rdi
movl $0x3, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2390
movq -0x40(%rbp), %rdi
callq 0x23e0
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x1c(%rbp), %eax
je 0x3d91
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
callq 0x2100
movq %rax, %rdi
movslq -0x14(%rbp), %rax
addq %rax, %rdi
callq 0x2440
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpb $0x0, (%rax)
je 0x3c8a
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x3c7a
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
jmp 0x3c7c
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3c5e
movq -0x10(%rbp), %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %eax, %eax
movl %eax, %edx
callq 0x2130
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x25d9(%rip), %rsi      # 0x6284
movb $0x0, %al
callq 0x2040
movq -0x10(%rbp), %rdi
movl $0x200000, %esi         # imm = 0x200000
xorl %eax, %eax
movl %eax, %edx
callq 0x2350
movq -0x28(%rbp), %rdi
callq 0x2310
movq -0x40(%rbp), %rdi
callq 0x2100
movq %rax, %rdi
movslq -0x14(%rbp), %rax
addq %rax, %rdi
callq 0x2440
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpb $0x0, (%rax)
je 0x3d1d
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x3d0d
movq -0x38(%rbp), %rax
movb $0x0, (%rax)
jmp 0x3d0f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3cf1
movq -0x10(%rbp), %rdi
movl $0x100000, %esi         # imm = 0x100000
xorl %eax, %eax
movl %eax, %edx
callq 0x2130
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x2546(%rip), %rsi      # 0x6284
movb $0x0, %al
callq 0x2040
movq -0x10(%rbp), %rdi
movl $0x100000, %esi         # imm = 0x100000
xorl %eax, %eax
movl %eax, %edx
callq 0x2350
movq -0x28(%rbp), %rdi
callq 0x2310
movq -0x40(%rbp), %rdi
movslq -0x14(%rbp), %rdx
movl $0xa, %esi
callq 0x2360
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x3d83
movl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x3d8c
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3c2a
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)