// File: /workspace/github_c_makefile_star2_O3/vasusharma7[P]Text-Editor/stdedit.c
// Function: dict
char* dict(int t){
    point *temp = data.front;
    int y,x;
    getyx(stdscr,y,x);
    int i,j,k;
    for(i = 0; i < (stline + y); i++){
        temp = temp->tail;
    }
    char *str = (char *)calloc(100,1);
    char ch;
    i = 0;
    k = t;
    while( !isEmptys(&(temp->element)) && (t > 0) && ((ch = ipoploc(&(temp->element),t-1)) != ' ')){
        str[i++] = ch;
        move(y,--x);
        if(i > 5){
            for(j = 0, k = strlen(str) - 1; j < k; j++, k--){
                ch = str[j];
                str[j] = str[k];
                str[k] = ch;
            }
            return str;
        }
        t--;
    }
    
    if(isEmptys(&(temp->element)))
        move(y,0);
    else{
        k = k - strlen(str) - 1; 
        move(y,k);
        add_char(' ', y+stline, k++);
        move(y,k);
    }
    for(j = 0, k = strlen(str) - 1; j < k; j++, k--){
        ch = str[j];
        str[j] = str[k];
        str[k] = ch;
    }
    
    if(strlen(str) <= 1)
        return str;
    k = 1;
    char *word;
    char **dict = (char **)calloc(4,sizeof(char *));
    i = 0;
    char *filename = (char *)calloc(12,1);

    if (str[0] >= 65 && str[0] <= 90){
        sprintf(filename,"dict/%c.txt",str[0] + 32);
    }
    else{
        sprintf(filename,"dict/%c.txt",str[0]);
    }
    FILE *fp = fopen(filename,"r+");
    if(!fp)
        return str;
    int q;
    while(word = get_word(fp)){ 
        if(strstr(word,"\n"))
            continue;
        for(q = 0; q < strlen(str); q++){
            if (str[q] >= 65 && str[q] <= 90){
                word[q] = word[q] - 32;         
            }
        }
        if(strlen(str) == 2){
            if(strstr(word,str) && word[1] == str[1]){
                dict[i++] = word;
            }
        }
        else if(strlen(str) == 3){
            if(strstr(word,str) && word[1] == str[1] && word[2] == str[2]){
                dict[i++] = word;
            }
        }
        else if(strlen(str) == 4){
            if(strstr(word,str) && word[1] == str[1] && word[2] == str[2] && word[3] == str[3]){
                dict[i++] = word;
            }
        }
        else if(strlen(str) == 5){
            if(strstr(word,str) && word[1] == str[1] && word[2] == str[2] && word[3] == str[3] && word[4] == str[4]){
                dict[i++] = word;
            }
        }
        if(i == 4)
            break;
    }
    int count = i;
    if (count == 0){
        fclose(fp);
        return str;
    }
    WINDOW  *dict_win = create_newwin(count*2, 20,y,x+strlen(str));
    int g,mark = 1,choice = 0;
    printopt(dict_win,dict,mark,count);
    while(1){
        g = wgetch(dict_win);
        switch(g){
            case KEY_UP:
                if(mark == 1)
                    mark = count;  
                else
                    mark--;
                break;
            case KEY_DOWN:
                if(mark == count)
                    mark = 1;  
                else
                    mark++;
                break;
            case 10:
                choice = mark;
                break;
            
            default:
                choice = -1;
                break;
        }
        printopt(dict_win,dict,mark,count);
        if(choice != 0)
            break;
    }
    if(choice == -1){
        destroy_win(dict_win);
        fclose(fp);
        return str;
    }
    else{
        destroy_win(dict_win);
        fclose(fp);
        return dict[mark-1];

    }
    fclose(fp);
    destroy_win(dict_win);
    return str;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, %r12d
leaq 0x69a4(%rip), %rax      # 0xa1d8
movq 0x67a5(%rip), %rcx      # 0x9fe0
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x384e
movswl (%rcx), %r14d
movswl 0x2(%rcx), %r15d
jmp 0x385a
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq (%rax), %r13
leaq 0x6938(%rip), %rax      # 0xa19c
movl (%rax), %eax
addl %r14d, %eax
jle 0x3873
movq (%r13), %r13
decl %eax
jne 0x386b
movl $0x64, %edi
movl $0x1, %esi
callq 0x2180
movq %rax, %rbx
addq $0x8, %r13
movq %r13, %rdi
callq 0x2565
testl %r12d, %r12d
movl %r14d, -0x3c(%rbp)
movl %r15d, -0x40(%rbp)
movl %r12d, -0x38(%rbp)
jle 0x3906
testl %eax, %eax
jne 0x3906
movq $-0x5, %r12
movl -0x38(%rbp), %eax
movl %eax, %r15d
leal -0x1(%r15), %r14d
movq %r13, %rdi
movl %r14d, %esi
callq 0x250b
cmpb $0x20, %al
je 0x3906
movb %al, 0x5(%rbx,%r12)
movq 0x670e(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl -0x40(%rbp), %edx
decl %edx
movl -0x3c(%rbp), %esi
movl %edx, -0x40(%rbp)
callq 0x2230
testq %r12, %r12
je 0x3c51
movq %r13, %rdi
callq 0x2565
cmpl $0x2, %r15d
jb 0x3906
incq %r12
movl %r14d, %r15d
testl %eax, %eax
je 0x38b3
movq %r13, %rdi
callq 0x2565
xorl %edx, %edx
testl %eax, %eax
movl -0x3c(%rbp), %r15d
jne 0x3964
movq %rbx, %rdi
callq 0x20c0
movq %rax, %r14
movl %r14d, %r13d
notl %r13d
movl -0x38(%rbp), %r12d
addl %r12d, %r13d
movq 0x66a9(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x2230
leaq 0x6850(%rip), %rax      # 0xa19c
movl (%rax), %esi
addl %r15d, %esi
subl %r14d, %r12d
movl $0x20, %edi
movl %r13d, %edx
callq 0x2b38
movl %r12d, %edx
movq 0x6675(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl %r15d, %esi
callq 0x2230
movq %rbx, %rdi
callq 0x20c0
decl %eax
testl %eax, %eax
jle 0x39aa
movl %eax, %eax
decq %rax
xorl %ecx, %ecx
movb (%rbx,%rcx), %dl
movb 0x1(%rbx,%rax), %sil
movb %sil, (%rbx,%rcx)
movb %dl, 0x1(%rbx,%rax)
incq %rcx
leaq -0x1(%rax), %rdx
cmpq %rax, %rcx
movq %rdx, %rax
jl 0x398b
movq %rbx, %rdi
callq 0x20c0
cmpq $0x2, %rax
jb 0x3ca7
movq %rax, %r12
movl $0x4, %edi
movl $0x8, %esi
callq 0x2180
movq %rax, -0x48(%rbp)
movl $0xc, %edi
movl $0x1, %esi
callq 0x2180
movq %rax, %r14
movsbl (%rbx), %eax
leal -0x41(%rax), %ecx
movl %eax, %edx
orl $0x20, %edx
cmpb $0x1a, %cl
cmovael %eax, %edx
leaq 0x3629(%rip), %rsi      # 0x7025
xorl %r15d, %r15d
movq %r14, %rdi
xorl %eax, %eax
callq 0x2280
leaq 0x3621(%rip), %rsi      # 0x7031
movq %r14, %rdi
callq 0x2220
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x3ca7
movb 0x1(%rbx), %al
movb %al, -0x29(%rbp)
movb 0x2(%rbx), %al
movb %al, -0x2a(%rbp)
movb 0x3(%rbx), %al
movb %al, -0x2b(%rbp)
movb 0x4(%rbx), %al
movb %al, -0x2c(%rbp)
leaq -0x2(%r12), %r13
movq -0x38(%rbp), %rdi
callq 0x36ad
testq %rax, %rax
je 0x3b8c
movq %rax, %r14
movq %rax, %rdi
movl $0xa, %esi
callq 0x20e0
testq %rax, %rax
jne 0x3a42
xorl %eax, %eax
movb (%rbx,%rax), %cl
addb $-0x41, %cl
cmpb $0x19, %cl
ja 0x3a7b
addb $-0x20, (%r14,%rax)
incq %rax
cmpq %rax, %r12
jne 0x3a6b
cmpq $0x3, %r13
ja 0x3b75
leaq 0x3570(%rip), %rcx      # 0x7004
movslq (%rcx,%r13,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3b75
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r14)
movq %r15, %rcx
je 0x3b60
jmp 0x3b78
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3b75
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r14)
movq %r15, %rcx
jne 0x3b78
movb -0x2a(%rbp), %al
cmpb %al, 0x2(%r14)
jne 0x3b78
movb -0x2b(%rbp), %al
cmpb %al, 0x3(%r14)
je 0x3b60
jmp 0x3b78
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3b75
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r14)
movq %r15, %rcx
jne 0x3b78
movb -0x2a(%rbp), %al
cmpb %al, 0x2(%r14)
jne 0x3b78
movb -0x2b(%rbp), %al
cmpb %al, 0x3(%r14)
jne 0x3b78
movb -0x2c(%rbp), %al
cmpb %al, 0x4(%r14)
je 0x3b60
jmp 0x3b78
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3b75
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r14)
movq %r15, %rcx
jne 0x3b78
movb -0x2a(%rbp), %al
cmpb %al, 0x2(%r14)
jne 0x3b78
movslq %ecx, %rax
incl %ecx
movq %rcx, %rdx
movq -0x48(%rbp), %rcx
movq %r14, (%rcx,%rax,8)
movq %rdx, %rcx
jmp 0x3b78
movq %r15, %rcx
movq %rcx, %r15
cmpl $0x4, %ecx
jne 0x3a42
movl $0x4, %r15d
jmp 0x3b95
testl %r15d, %r15d
je 0x3c9e
leal (%r15,%r15), %edi
movl -0x40(%rbp), %ecx
addl %r12d, %ecx
movl $0x14, %esi
movl -0x3c(%rbp), %edx
callq 0x2708
movq %rax, %r14
movq %rax, %rdi
movq -0x48(%rbp), %rsi
movl $0x1, %edx
movq %r15, %r13
movl %r15d, %ecx
callq 0x3734
movl $0x1, %r15d
movq %r14, %rdi
callq 0x2090
cmpl $0xa, %eax
je 0x3c12
cmpl $0x102, %eax            # imm = 0x102
movq %r13, %rcx
je 0x3bfb
cmpl $0x103, %eax            # imm = 0x103
jne 0x3c87
cmpl $0x1, %r15d
leal -0x1(%r15), %eax
cmovel %ecx, %eax
jmp 0x3c0a
cmpl %ecx, %r15d
leal 0x1(%r15), %eax
movl $0x1, %edx
cmovel %edx, %eax
xorl %r12d, %r12d
movl %eax, %r15d
jmp 0x3c18
movl %r15d, %r12d
movq %r13, %rcx
movq %r14, %rdi
movq -0x48(%rbp), %rsi
movl %r15d, %edx
callq 0x3734
testl %r12d, %r12d
je 0x3bcc
cmpl $-0x1, %r12d
je 0x3c96
movq %r14, %rdi
callq 0x2756
movq -0x38(%rbp), %rdi
callq 0x20b0
movslq %r15d, %rax
movq -0x48(%rbp), %rcx
movq -0x8(%rcx,%rax,8), %rbx
jmp 0x3ca7
movq %rbx, %rdi
callq 0x20c0
decl %eax
testl %eax, %eax
jle 0x3ca7
movl %eax, %eax
decq %rax
xorl %ecx, %ecx
movb (%rbx,%rcx), %dl
movb 0x1(%rbx,%rax), %sil
movb %sil, (%rbx,%rcx)
movb %dl, 0x1(%rbx,%rax)
incq %rcx
leaq -0x1(%rax), %rdx
cmpq %rax, %rcx
movq %rdx, %rax
jl 0x3c66
jmp 0x3ca7
movq %r14, %rdi
movq -0x48(%rbp), %rsi
movl %r15d, %edx
callq 0x3734
movq %r14, %rdi
callq 0x2756
movq -0x38(%rbp), %rdi
callq 0x20b0
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq