// File: /workspace/github_c_makefile_star2_O1/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, %r14d
movq 0x6746(%rip), %rax      # 0x9fe0
movq (%rax), %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x38b4
movswl (%rax), %ecx
movl %ecx, -0x30(%rbp)
leaq 0x691d(%rip), %rcx      # 0xa1d8
testq %rax, %rax
je 0x38c4
movswl 0x2(%rax), %edx
movq (%rcx), %r13
leaq 0x68ce(%rip), %rax      # 0xa19c
movl (%rax), %eax
addl -0x30(%rbp), %eax
movl %edx, -0x34(%rbp)
jle 0x38e0
movq (%r13), %r13
decl %eax
jne 0x38d8
movl $0x64, %edi
movl $0x1, %esi
callq 0x2180
movq %rax, %rbx
addq $0x8, %r13
movq %r13, %rdi
callq 0x2577
testl %r14d, %r14d
movl %r14d, -0x40(%rbp)
jle 0x3965
testl %eax, %eax
jne 0x3965
movq $-0x5, %r15
leal -0x1(%r14), %r12d
movq %r13, %rdi
movl %r12d, %esi
callq 0x2519
cmpb $0x20, %al
je 0x3965
movb %al, 0x5(%rbx,%r15)
movq 0x66af(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl -0x34(%rbp), %edx
decl %edx
movl -0x30(%rbp), %esi
movl %edx, -0x34(%rbp)
callq 0x2230
testq %r15, %r15
je 0x3cc3
movq %r13, %rdi
callq 0x2577
cmpl $0x2, %r14d
jl 0x3965
incq %r15
movl %r12d, %r14d
testl %eax, %eax
je 0x3912
movq %r13, %rdi
callq 0x2577
xorl %edx, %edx
testl %eax, %eax
jne 0x39c3
movq %rbx, %rdi
callq 0x20c0
movq %rax, %r12
movl %r12d, %r13d
notl %r13d
movl -0x40(%rbp), %r15d
addl %r15d, %r13d
movq 0x664e(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl -0x30(%rbp), %r14d
movl %r14d, %esi
movl %r13d, %edx
callq 0x2230
leaq 0x67f1(%rip), %rax      # 0xa19c
movl (%rax), %esi
addl %r14d, %esi
subl %r12d, %r15d
movl $0x20, %edi
movl %r13d, %edx
callq 0x2b61
movl %r15d, %edx
movq 0x6616(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl -0x30(%rbp), %esi
callq 0x2230
movq %rbx, %rdi
callq 0x20c0
decl %eax
testl %eax, %eax
jle 0x3a09
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 0x39ea
movq %rbx, %rdi
callq 0x20c0
cmpq $0x2, %rax
jb 0x3d1d
movq %rax, %r15
movl $0x4, %edi
movl $0x8, %esi
callq 0x2180
movq %rax, -0x40(%rbp)
movl $0xc, %edi
movl $0x1, %esi
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 0x35ca(%rip), %rsi      # 0x7025
xorl %r14d, %r14d
movq %r12, %rdi
xorl %eax, %eax
callq 0x2280
leaq 0x35c2(%rip), %rsi      # 0x7031
movq %r12, %rdi
callq 0x2220
testq %rax, %rax
je 0x3d1d
movq %rax, %r13
movb 0x1(%rbx), %al
movb %al, -0x29(%rbp)
movb 0x2(%rbx), %al
movb %al, -0x2a(%rbp)
movb 0x3(%rbx), %al
movb %al, -0x2b(%rbp)
cmpq $0x1, %r15
movq %r15, %rax
adcq $0x0, %r15
movb 0x4(%rbx), %cl
movb %cl, -0x2c(%rbp)
movq %rax, -0x50(%rbp)
addq $-0x2, %rax
movq %rax, -0x48(%rbp)
movq %r13, %rdi
callq 0x3713
testq %rax, %rax
je 0x3c01
movq %rax, %r12
movq %rax, %rdi
movl $0xa, %esi
callq 0x20e0
testq %rax, %rax
jne 0x3ab2
xorl %eax, %eax
movb (%rbx,%rax), %cl
addb $-0x41, %cl
cmpb $0x19, %cl
ja 0x3aea
addb $-0x20, (%r12,%rax)
incq %rax
cmpq %rax, %r15
jne 0x3ada
movq -0x48(%rbp), %rax
cmpq $0x3, %rax
ja 0x3bec
leaq 0x34fd(%rip), %rcx      # 0x7004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r12, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3bec
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r12)
movq %r14, %rdx
je 0x3bdd
jmp 0x3bef
movq %r12, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3bec
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r12)
movq %r14, %rdx
jne 0x3bef
movb -0x2a(%rbp), %al
cmpb %al, 0x2(%r12)
jne 0x3bef
movb -0x2b(%rbp), %al
cmpb %al, 0x3(%r12)
je 0x3bdd
jmp 0x3bef
movq %r12, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3bec
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r12)
movq %r14, %rdx
jne 0x3bef
movb -0x2a(%rbp), %al
cmpb %al, 0x2(%r12)
jne 0x3bef
movb -0x2b(%rbp), %al
cmpb %al, 0x3(%r12)
jne 0x3bef
movb -0x2c(%rbp), %al
cmpb %al, 0x4(%r12)
je 0x3bdd
jmp 0x3bef
movq %r12, %rdi
movq %rbx, %rsi
callq 0x22d0
testq %rax, %rax
je 0x3bec
movb -0x29(%rbp), %al
cmpb %al, 0x1(%r12)
movq %r14, %rdx
jne 0x3bef
movb -0x2a(%rbp), %al
cmpb %al, 0x2(%r12)
jne 0x3bef
movslq %edx, %rax
incl %edx
movq -0x40(%rbp), %rcx
movq %r12, (%rcx,%rax,8)
jmp 0x3bef
movq %r14, %rdx
movq %rdx, %r14
cmpl $0x4, %edx
jne 0x3ab2
movl $0x4, %r14d
testl %r14d, %r14d
movq -0x50(%rbp), %rax
je 0x3cf9
movq %r13, -0x48(%rbp)
leal (%r14,%r14), %edi
movl -0x34(%rbp), %ecx
addl %eax, %ecx
movl $0x14, %esi
movl -0x30(%rbp), %edx
movq %r14, %r15
callq 0x2720
movq %rax, %r14
movq %rax, %rdi
movq -0x40(%rbp), %rsi
movl $0x1, %edx
movq %r15, %r13
movl %r15d, %ecx
callq 0x379a
movl $0x1, %r15d
movq %r14, %rdi
callq 0x2090
cmpl $0xa, %eax
je 0x3c8d
cmpl $0x102, %eax            # imm = 0x102
movq %r13, %rcx
je 0x3c76
cmpl $0x103, %eax            # imm = 0x103
jne 0x3c95
cmpl $0x1, %r15d
leal -0x1(%r15), %eax
cmovel %ecx, %eax
jmp 0x3c85
cmpl %ecx, %r15d
leal 0x1(%r15), %eax
movl $0x1, %edx
cmovel %edx, %eax
xorl %r12d, %r12d
movl %eax, %r15d
jmp 0x3c9b
movl %r15d, %r12d
movq %r13, %rcx
jmp 0x3c9b
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %r14, %rdi
movq -0x40(%rbp), %rsi
movl %r15d, %edx
callq 0x379a
testl %r12d, %r12d
je 0x3c4b
movq %r14, %rdi
cmpl $-0x1, %r12d
jne 0x3d03
callq 0x276e
movq -0x48(%rbp), %rdi
jmp 0x3cfc
movq %rbx, %rdi
callq 0x20c0
decl %eax
testl %eax, %eax
jle 0x3d1d
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 0x3cd8
jmp 0x3d1d
movq %r13, %rdi
callq 0x20b0
jmp 0x3d1d
callq 0x276e
movq -0x48(%rbp), %rdi
callq 0x20b0
movslq %r15d, %rax
movq -0x40(%rbp), %rcx
movq -0x8(%rcx,%rax,8), %rbx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq