// File: /workspace/github_c_makefile_star2_O2/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, %r15d
leaq 0x6aad(%rip), %rax      # 0xa1d8
movq 0x68ae(%rip), %rcx      # 0x9fe0
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x3744
movswl (%rcx), %edx
movswl 0x2(%rcx), %r12d
jmp 0x374a
pushq $-0x1
popq %rdx
movl %edx, %r12d
movq (%rax), %r13
leaq 0x6a48(%rip), %rax      # 0xa19c
movl (%rax), %ecx
addl %edx, %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovgl %ecx, %eax
subl $0x1, %eax
jb 0x376a
movq (%r13), %r13
jmp 0x375f
movl %edx, -0x30(%rbp)
pushq $0x64
popq %rdi
pushq $0x1
popq %rsi
callq 0x2180
movq %rax, %rbx
addq $0x8, %r13
movl %r12d, %eax
negl %eax
cltq
decl %r12d
pushq $-0x6
popq %r14
movl %r15d, -0x38(%rbp)
movq %rax, -0x48(%rbp)
movq %r13, %rdi
callq 0x254c
testl %r15d, %r15d
jle 0x380d
testl %eax, %eax
jne 0x380d
decl %r15d
movq %r13, %rdi
movl %r15d, %esi
callq 0x24ed
cmpb $0x20, %al
je 0x380d
movb %al, 0x6(%rbx,%r14)
movq 0x681c(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl -0x30(%rbp), %esi
movl %r12d, %edx
callq 0x2230
movq -0x48(%rbp), %rax
incq %rax
decl %r12d
incq %r14
jne 0x3791
movq %rbx, %rdi
callq 0x20c0
decl %eax
xorl %ecx, %ecx
cltq
cmpq %rax, %rcx
jge 0x3b5f
movb (%rbx,%rcx), %dl
movb (%rbx,%rax), %sil
movb %sil, (%rbx,%rcx)
movb %dl, (%rbx,%rax)
incq %rcx
decl %eax
jmp 0x37ed
movq %r13, %rdi
callq 0x254c
xorl %edx, %edx
testl %eax, %eax
movl -0x30(%rbp), %r13d
jne 0x3869
movq %rbx, %rdi
callq 0x20c0
movq %rax, %r15
movl %r15d, %r12d
notl %r12d
movl -0x38(%rbp), %r14d
addl %r14d, %r12d
movq 0x67a2(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x2230
leaq 0x6949(%rip), %rax      # 0xa19c
movl (%rax), %esi
addl %r13d, %esi
subl %r15d, %r14d
pushq $0x20
popq %rdi
movl %r12d, %edx
callq 0x2aa9
movl %r14d, %edx
movq 0x6770(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl %r13d, %esi
callq 0x2230
movq %rbx, %rdi
callq 0x20c0
decl %eax
xorl %ecx, %ecx
cltq
cmpq %rax, %rcx
jge 0x38a3
movb (%rbx,%rcx), %dl
movb (%rbx,%rax), %sil
movb %sil, (%rbx,%rcx)
movb %dl, (%rbx,%rax)
incq %rcx
decl %eax
jmp 0x3887
movq %rbx, %rdi
callq 0x20c0
cmpq $0x2, %rax
jb 0x3b5f
movq %rax, %r15
pushq $0x4
popq %rdi
pushq $0x8
popq %rsi
callq 0x2180
movq %rax, -0x40(%rbp)
pushq $0xc
popq %rdi
pushq $0x1
popq %rsi
callq 0x2180
movq %rax, %r12
movsbl (%rbx), %eax
leal -0x41(%rax), %ecx
movl %eax, %edx
orl $0x20, %edx
cmpb $0x1a, %cl
cmovael %eax, %edx
leaq 0x3738(%rip), %rsi      # 0x7025
xorl %r14d, %r14d
movq %r12, %rdi
xorl %eax, %eax
callq 0x2280
leaq 0x3730(%rip), %rsi      # 0x7031
movq %r12, %rdi
callq 0x2220
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x3b5f
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(%r15), %rax
movq %rax, %r12
movq -0x38(%rbp), %rdi
callq 0x35bf
testq %rax, %rax
je 0x3a7f
movq %rax, %r13
movq %rax, %rdi
pushq $0xa
popq %rsi
callq 0x20e0
testq %rax, %rax
jne 0x3935
xorl %eax, %eax
movq %r14, %rdx
cmpq %rax, %r15
je 0x397a
movb (%rbx,%rax), %cl
addb $-0x41, %cl
cmpb $0x19, %cl
ja 0x3975
addb $-0x20, (%r13,%rax)
incq %rax
jmp 0x395f
movq %r12, %rax
cmpq $0x3, %r12
ja 0x3a6b
leaq 0x3676(%rip), %rcx      # 0x7004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r13, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3a65
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r13)
movq %r14, %rdx
je 0x3a56
jmp 0x3a68
movq %r13, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3a65
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r13)
movq %r14, %rdx
jne 0x3a68
movb -0x2a(%rbp), %al
cmpb %al, 0x2(%r13)
jne 0x3a68
movb -0x2b(%rbp), %al
cmpb %al, 0x3(%r13)
je 0x3a56
jmp 0x3a68
movq %r13, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3a65
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r13)
movq %r14, %rdx
jne 0x3a68
movb -0x2a(%rbp), %al
cmpb %al, 0x2(%r13)
jne 0x3a68
movb -0x2b(%rbp), %al
cmpb %al, 0x3(%r13)
jne 0x3a68
movb -0x2c(%rbp), %al
cmpb %al, 0x4(%r13)
je 0x3a56
jmp 0x3a68
movq %r13, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3a65
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r13)
movq %r14, %rdx
jne 0x3a68
movb -0x2a(%rbp), %al
cmpb %al, 0x2(%r13)
jne 0x3a68
movslq %edx, %rax
incl %edx
movq -0x40(%rbp), %rcx
movq %r13, (%rcx,%rax,8)
jmp 0x3a68
movq %r14, %rdx
movq %r12, %rax
movq %rdx, %r14
cmpl $0x4, %edx
jne 0x3932
pushq $0x4
popq %rax
movl %eax, %r14d
jmp 0x3a88
testl %r14d, %r14d
je 0x3b56
leal (%r14,%r14), %edi
subl -0x48(%rbp), %r15d
pushq $0x14
popq %rsi
movl -0x30(%rbp), %edx
movl %r15d, %ecx
movq %r14, %r15
callq 0x26cc
movq %rax, %r14
pushq $0x1
popq %r13
movq %rax, %rdi
movq -0x40(%rbp), %rsi
movl %r13d, %edx
movq %r15, %r12
movl %r15d, %ecx
callq 0x363a
movl %r13d, %r15d
movq %r14, %rdi
callq 0x2090
cmpl $0xa, %eax
je 0x3b00
cmpl $0x102, %eax            # imm = 0x102
movq %r12, %rcx
je 0x3aeb
cmpl $0x103, %eax            # imm = 0x103
jne 0x3b3f
cmpl $0x1, %r15d
leal -0x1(%r15), %eax
cmovel %ecx, %eax
jmp 0x3af8
cmpl %ecx, %r15d
leal 0x1(%r15), %eax
pushq $0x1
popq %rdx
cmovel %edx, %eax
xorl %r13d, %r13d
movl %eax, %r15d
jmp 0x3b06
movl %r15d, %r13d
movq %r12, %rcx
movq %r14, %rdi
movq -0x40(%rbp), %rsi
movl %r15d, %edx
callq 0x363a
testl %r13d, %r13d
je 0x3ac0
cmpl $-0x1, %r13d
je 0x3b4e
movq %r14, %rdi
callq 0x271c
movq -0x38(%rbp), %rdi
callq 0x20b0
movslq %r15d, %rax
movq -0x40(%rbp), %rcx
movq -0x8(%rcx,%rax,8), %rbx
jmp 0x3b5f
movq %r14, %rdi
movq -0x40(%rbp), %rsi
movl %r15d, %edx
callq 0x363a
movq %r14, %rdi
callq 0x271c
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