// File: JohnPapad[P]Mini-Search-Engine/minisearch.cpp
// Function: underline(unsigned int, unsigned int&, int**, int&, bool)
void underline(unsigned int init_llen, unsigned int & curr_llen, int ** underline_info, int & underline_info_size, bool exit)
{//underlining words based on the underline info array

    cout<<endl;
    for(int i = 0; i < *underline_info[0]; i++)
    {//set cursor to the correct spot
        cout<<" ";
    }

    for(int i = 0; i <= underline_info_size - 2; i+=2)
    {
        unsigned int start_ul = *underline_info[i];
        unsigned int end_ul = *underline_info[i+1];

        for(unsigned int j = start_ul; j < end_ul; j++)
        {//underline word
            cout<<"^";
        }

        if(i != (underline_info_size - 2))
        {//if there are more than one words that needs underlining set cursor to the correct spot
            unsigned int start_sp = end_ul;
            unsigned int end_sp = *underline_info[i+2];

            for(unsigned int j = start_sp; j < end_sp; j++)
            {
                cout<<" ";
            }
        }
    }

    for(int i = 0; i < underline_info_size; i++)
    {
        free(underline_info[i]);
    }

    underline_info = NULL;
    underline_info_size = 0;

    if(exit == 0)
    {// if there are more words to be printed set cursor to the correct spot
        init_newline(init_llen, curr_llen);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %r8b, %al
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq 0x5aca(%rip), %rdi      # 0x8fd0
movq 0x5ab3(%rip), %rsi      # 0x8fc0
callq 0x2100
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
cmpl (%rcx), %eax
jge 0x3545
movq 0x5aa2(%rip), %rdi      # 0x8fd0
leaq 0x2fd0(%rip), %rsi      # 0x6505
callq 0x20c0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3519
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jg 0x361d
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x35b3
movq 0x5a34(%rip), %rdi      # 0x8fd0
leaq 0x2cf8(%rip), %rsi      # 0x629b
callq 0x20c0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x358d
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
je 0x360d
movl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x360b
movq 0x59dc(%rip), %rdi      # 0x8fd0
leaq 0x2f0a(%rip), %rsi      # 0x6505
callq 0x20c0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x35e5
jmp 0x360d
jmp 0x360f
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
jmp 0x354c
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x364b
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2130
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x3624
movq $0x0, -0x18(%rbp)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3676
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x3680
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)