// File: /workspace/github_c_makefile_star2_O2/vasusharma7[P]Text-Editor/stdedit.c
// Function: find_replace
void find_replace(int ctrl){
    WINDOW *getwrd = create_newwin(16,40,by/3,bx/3);
    char *querry = (char *)calloc(2,1);
    char *rplmt = (char *)calloc(2,1);
    char ch[2] = {'\0'};
    int i,j,x,y,k,u,v,r,t,rpt = 0;
    char *str = (char *)calloc(1,2);
    point *temp = data.front;
    node *trace = NULL;
    if(ctrl == 0){   
        mvwprintw(getwrd,2  ,1,  "HEY ! YOU ARE IN SEARCH MODE : -  \n");
        mvwprintw(getwrd,4,1,  "ENTER WORD YOU WANT TO SEARCH : -  \n");
        wmove(getwrd,6,1);
        wrefresh(getwrd);
        int mg2 = 0,mg1;
        while(mg2 != -1){
            getyx(getwrd,u,v);
            mg1 = wgetch(getwrd);
            switch(mg1){
                case KEY_BACKSPACE:
                    break;
                case '\n':case ' ':
                    mg2 = -1;
                    break;
                case '\t':
                    break;
                default:
                    mvwprintw(getwrd,u,v++,"%c",mg1);
                    wrefresh(getwrd);
                    querry[mg2++] = mg1;
                    querry = realloc(querry,strlen(querry) + 2);
                    break;
            }
        }
        wclear(getwrd);
        box(getwrd, 0 , 0);
        mvwprintw(getwrd,6,1, "DURING SEARCH : \n");
        mvwprintw(getwrd,8,1, "PRESS TAB TO SEARCH NEXT");
        mvwprintw(getwrd,10,1, "PRESS ANY KEY TO EXIT");
        mvwprintw(getwrd,12,1, "PRESS ANY KEY NOW TO SEE RESULTS");
        wrefresh(getwrd);
        getchar();
    }
    else{
        mvwprintw(getwrd,2  ,1,  "HEY ! YOU ARE IN REPLACE MODE : -  \n");
        mvwprintw(getwrd,4,1,  "ENTER WORD YOU WANT TO REPLACE  : -  \n");
        wmove(getwrd,6,1);
        wrefresh(getwrd);
        int mg2 = 0,mg1;
        while(mg2 != -1){
            mg1 = wgetch(getwrd);
            switch(mg1){
                case KEY_BACKSPACE:
                    break;
                case '\n':case ' ':
                    mg2 = -1;
                    break;
                case '\t':
                    break;
                default:
                    getyx(getwrd,u,v);
                    mvwprintw(getwrd,u,v++,"%c",mg1);
                    wrefresh(getwrd);
                    querry[mg2++] = mg1;
                    querry = realloc(querry,strlen(querry) + 2);
                    break;
                }
        }
        wclear(getwrd);
        box(getwrd, 0 , 0);
        mvwprintw(getwrd,2,1, "ENTER THE WORD YOU WANT TO REPLACE WITH :- \n");
        wrefresh(getwrd);
        wmove(getwrd,4,1);
        mg2 = 0,mg1;
        while(mg2 != -1){
            mg1 = wgetch(getwrd);
            switch(mg1){
                case KEY_BACKSPACE:
                    break;
                case '\n':case ' ':
                    mg2 = -1;
                    break;
                case '\t':
                    break;
                default:
                    getyx(getwrd,u,v);
                    mvwprintw(getwrd,u,v++,"%c",mg1);
                    wrefresh(getwrd);
                    rplmt[mg2++] = mg1;
                    rplmt = realloc(rplmt,strlen(rplmt) + 2);
                    break;
                }
        }
        //strcat(rplmt," ");

    }
    wrefresh(getwrd);
    destroy_win(getwrd);
    clear();
    getyx(stdscr,y,x);
    display(stline);
    move(y,x);
    for(i = 0; i <= lines; i++){
        rpt = 0;
        j = 0;
        k = 0;
        if((fdr != -1) && (i >= (ftrack  - 2)))
                read_chunck();
        trace = temp->element.store;
        while(rpt == 1 || (trace->next != NULL)){
            getyx(stdscr,y,x);
            if((rpt == 1) || (trace->val == ' ') || (trace->val == '\n') ){
                k = 0;
                getyx(stdscr,y,x);
                if(!strcmp(str,querry)){
                    if(i >= (by - 5))
                            stline = i - (by - 5) + 1;
                        else
                            stline = 0;
                    if(ctrl == 1){
                            t = j;
                            r = strlen(querry);
                            while(r--){
                                if(!isEmptys(&(temp->element)) && t > 0){
                                    ipoploc(&(temp->element),t - 1);
                                    t--;
                                    j--;
                                }
                            }
                            for(r = 0; r < strlen(rplmt); r++) {
                                getyx(stdscr,y,x);
                                int mk = add_char(rplmt[r],i,t);
                                if( (t >= (bx - 3)) || (getwidth(i) >= (bx-3)) && mk != 0){
                                    t = mk;
                                    j = mk;
                                }
                                else{
                                    t++;
                                    j++;
                                }
                            }
                    }

                    else{
                        display_high(stline, j - strlen(str), i, strlen(querry) + 1);
                        ch[0] = getch();
                        if(ch[0] == '\t'){
                            trace = trace->next;
                            j++;
                            free(str);
                            str = (char *)calloc(2,1);
                            continue;            
                        }
                        else 
                            return;
                    }
                }
                trace = trace->next;
                j++;
                free(str);
                str = (char *)calloc(1,2);
                continue;            
            }
            str[k++] = trace->val;
            str = realloc(str,j+2);
            j++;
            trace = trace->next;

        }
        temp = temp->tail;
    }
    getwrd = create_newwin(10,40,by/3,bx/3);
    if(ctrl == 0){
        mvwprintw(getwrd, 3,2,"SEARCH FINISHED :\n No More Entries for the word '%s'",querry);
        mvwprintw(getwrd, 6,2,"press any key to exit search mode  :)");
    }
    else{
        mvwprintw(getwrd, 3,2,"REPLACE FINISHED :\n All %s replaced with '%s'",querry,rplmt);
        mvwprintw(getwrd, 6,2,"press any key to see the effect and exit  :)");
        add_event(&states,"replace",0,0,querry,rplmt);
        wrefresh(getwrd);
        return;
    }
    wrefresh(getwrd);
    getchar();
    getyx(stdscr,y,x);
    destroy_win(getwrd);
    clear();
    display(stline);
    refresh();
   // add_event(&states,"replace",0,0,querry,rplmt);
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edi, %r12d
leaq 0x5f8a(%rip), %rax      # 0xa18c
movl (%rax), %eax
pushq $0x3
popq %rsi
cltd
idivl %esi
movl %eax, %ecx
leaq 0x5f81(%rip), %rax      # 0xa194
movl (%rax), %eax
cltd
idivl %esi
pushq $0x10
popq %rdi
pushq $0x28
popq %rsi
movl %ecx, %edx
movl %eax, %ecx
callq 0x26cc
movq %rax, %r13
pushq $0x2
popq %rbx
pushq $0x1
popq %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2180
movq %rax, %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2180
movq %rax, -0x40(%rbp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2180
movq %rax, -0x50(%rbp)
leaq 0x5f74(%rip), %rax      # 0xa1d8
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movl %r12d, -0x44(%rbp)
testl %r12d, %r12d
movq %r15, -0x38(%rbp)
je 0x4459
pushq $-0x1
popq %r15
leaq 0x3041(%rip), %rcx      # 0x72c8
pushq $0x2
popq %rsi
pushq $0x1
popq %rbx
movq %r13, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x304d(%rip), %rcx      # 0x72ed
pushq $0x4
popq %rsi
movq %r13, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
pushq $0x6
popq %rsi
movq %r13, %rdi
movl %ebx, %edx
callq 0x2230
movq %r13, %rdi
callq 0x2100
leaq 0x2d49(%rip), %rbx      # 0x7014
xorl %r12d, %r12d
movq %r13, %rdi
cmpl $-0x1, %r12d
je 0x4362
callq 0x2090
cmpl $0x9, %eax
je 0x42ce
movl %eax, %r14d
cmpl $0x107, %eax            # imm = 0x107
je 0x42ce
cmpl $0x20, %r14d
je 0x42fb
cmpl $0xa, %r14d
jne 0x4300
movl %r15d, %r12d
jmp 0x42ce
movl %r15d, %esi
movl %r15d, %edx
testq %r13, %r13
je 0x4315
movswl (%r13), %esi
movswl 0x2(%r13), %edx
movq %r13, %rdi
movq %rbx, %rcx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
movslq %r12d, %rax
incl %r12d
movq %rbx, %r15
movq -0x38(%rbp), %rbx
movb %r14b, (%rbx,%rax)
movq %rbx, %rdi
callq 0x20c0
leaq 0x2(%rax), %rsi
movq %rbx, %rdi
movq %r15, %rbx
callq 0x2200
movq %rax, -0x38(%rbp)
pushq $-0x1
popq %r15
jmp 0x42ce
callq 0x20a0
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2070
leaq 0x2f84(%rip), %rcx      # 0x7314
pushq $0x2
popq %rsi
pushq $0x1
popq %rbx
movq %r13, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
pushq $0x4
popq %rsi
movq %r13, %rdi
movl %ebx, %edx
callq 0x2230
pushq $-0x1
popq %r15
leaq 0x2c52(%rip), %rbx      # 0x7014
xorl %r12d, %r12d
cmpl $-0x1, %r12d
je 0x45c4
movq %r13, %rdi
callq 0x2090
cmpl $0x9, %eax
je 0x43c5
movl %eax, %r14d
cmpl $0x107, %eax            # imm = 0x107
je 0x43c5
cmpl $0x20, %r14d
je 0x43f2
cmpl $0xa, %r14d
jne 0x43f7
movl %r15d, %r12d
jmp 0x43c5
movl %r15d, %esi
movl %r15d, %edx
testq %r13, %r13
je 0x440c
movswl (%r13), %esi
movswl 0x2(%r13), %edx
movq %r13, %rdi
movq %rbx, %rcx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
movslq %r12d, %rax
incl %r12d
movq %rbx, %r15
movq -0x40(%rbp), %rbx
movb %r14b, (%rbx,%rax)
movq %rbx, %rdi
callq 0x20c0
leaq 0x2(%rax), %rsi
movq %rbx, %rdi
movq %r15, %rbx
callq 0x2200
movq %rax, -0x40(%rbp)
pushq $-0x1
popq %r15
jmp 0x43c5
leaq 0x2dbd(%rip), %rcx      # 0x721d
pushq $0x2
popq %rsi
pushq $0x1
popq %rbx
movq %r13, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2dc8(%rip), %rcx      # 0x7241
pushq $0x4
popq %rsi
movq %r13, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
pushq $0x6
popq %rsi
movq %r13, %rdi
movl %ebx, %edx
callq 0x2230
movq %r13, %rdi
callq 0x2100
xorl %ebx, %ebx
cmpl $-0x1, %ebx
je 0x4532
pushq $-0x1
popq %r12
movl %r12d, %r14d
testq %r13, %r13
je 0x44be
movswl (%r13), %r14d
movswl 0x2(%r13), %r12d
movq %r13, %rdi
callq 0x2090
cmpl $0x9, %eax
je 0x449f
movl %eax, %r15d
cmpl $0x107, %eax            # imm = 0x107
je 0x449f
cmpl $0x20, %r15d
je 0x44e1
cmpl $0xa, %r15d
jne 0x44e6
pushq $-0x1
popq %rbx
jmp 0x449f
movq %r13, %rdi
movl %r14d, %esi
movl %r12d, %edx
leaq 0x2b1e(%rip), %rcx      # 0x7014
movl %r15d, %r8d
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
movslq %ebx, %rax
incl %ebx
movq -0x38(%rbp), %r14
movb %r15b, (%r14,%rax)
movq %r14, %rdi
callq 0x20c0
leaq 0x2(%rax), %rsi
movq %r14, %rdi
callq 0x2200
movq %rax, -0x38(%rbp)
jmp 0x449f
movq %r13, %rdi
callq 0x20a0
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2070
leaq 0x2d03(%rip), %rcx      # 0x7266
pushq $0x6
popq %rsi
pushq $0x1
popq %rbx
movq %r13, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2cfc(%rip), %rcx      # 0x7278
pushq $0x8
popq %rsi
movq %r13, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2cff(%rip), %rcx      # 0x7291
pushq $0xa
popq %rsi
movq %r13, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2cff(%rip), %rcx      # 0x72a7
pushq $0xc
popq %rsi
movq %r13, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
callq 0x21a0
movq -0x40(%rbp), %r15
movq %r13, %rdi
callq 0x2100
movq %r13, %rdi
callq 0x271c
movq 0x5a01(%rip), %rbx      # 0x9fe0
movq (%rbx), %rdi
callq 0x20a0
movq (%rbx), %rax
testq %rax, %rax
je 0x45f9
movswl (%rax), %ebx
movswl 0x2(%rax), %r14d
jmp 0x45ff
pushq $-0x1
popq %rbx
movl %ebx, %r14d
movq -0x38(%rbp), %r12
leaq 0x5b92(%rip), %rax      # 0xa19c
movl (%rax), %edi
callq 0x27dc
movq 0x59c8(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x2230
movl $0x0, -0x2c(%rbp)
movq -0x58(%rbp), %rbx
movq -0x50(%rbp), %rdi
movq %r15, -0x40(%rbp)
leaq 0x5b49(%rip), %rax      # 0xa188
movl -0x2c(%rbp), %ecx
cmpl (%rax), %ecx
jg 0x488f
leaq 0x5b47(%rip), %rax      # 0xa198
cmpl $-0x1, (%rax)
je 0x4672
leaq 0x5b47(%rip), %rax      # 0xa1a4
movl (%rax), %eax
addl $-0x2, %eax
cmpl %eax, -0x2c(%rbp)
jl 0x4672
movq %rdi, %r14
callq 0x3465
movq %r14, %rdi
leaq 0x8(%rbx), %rax
movq %rax, -0x68(%rbp)
movq %rbx, -0x58(%rbp)
movq 0x8(%rbx), %rax
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x10(%rax), %r15
testq %r15, %r15
je 0x486d
movq %rax, -0x60(%rbp)
movzbl 0x8(%rax), %eax
cmpl $0x20, %eax
je 0x46ab
cmpl $0xa, %eax
jne 0x473c
movq %rdi, -0x50(%rbp)
movq %r12, %rsi
callq 0x2190
testl %eax, %eax
jne 0x47e0
leaq 0x5ac6(%rip), %rax      # 0xa18c
movl (%rax), %eax
movl -0x2c(%rbp), %ecx
movl %ecx, %r15d
subl %eax, %r15d
addl $-0x5, %eax
addl $0x6, %r15d
cmpl %eax, %ecx
movl $0x0, %eax
cmovll %eax, %r15d
leaq 0x5ab2(%rip), %rax      # 0xa19c
movl %r15d, (%rax)
cmpl $0x1, -0x44(%rbp)
jne 0x4805
movq %r12, %rdi
callq 0x20c0
movq %rax, %r12
movq -0x40(%rbp), %r15
movq -0x68(%rbp), %rbx
negl %r12d
incl %r12d
cmpl $0x1, %r12d
je 0x4761
movq %rbx, %rdi
callq 0x254c
testl %eax, %eax
jne 0x470d
testl %r13d, %r13d
jle 0x470d
movq %r13, %rsi
decl %esi
movq %rbx, %rdi
movq %rsi, %r13
callq 0x24ed
negl %r12d
jmp 0x470a
movslq %r14d, %rcx
incl %r14d
movb %al, (%rdi,%rcx)
leal 0x2(%r13), %eax
movslq %eax, %rsi
callq 0x2200
movq %rax, %rdi
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
jmp 0x47fd
xorl %r14d, %r14d
movl %r13d, %r12d
movq %r15, %rdi
callq 0x20c0
cmpq %r14, %rax
jbe 0x47d4
movsbl (%r15,%r14), %edi
movl -0x2c(%rbp), %esi
movl %r12d, %edx
callq 0x2aa9
movl %eax, %r15d
leaq 0x5a06(%rip), %rcx      # 0xa194
movl (%rcx), %eax
addl $-0x3, %eax
cmpl %eax, %r12d
jge 0x47c2
movl -0x2c(%rbp), %edi
movq %rcx, %rbx
callq 0x2fb6
movl (%rbx), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jl 0x47b4
movl %r15d, %eax
testl %r15d, %r15d
jne 0x47c5
incl %r12d
incl %r13d
movl %r13d, %r15d
movl %r12d, %eax
jmp 0x47c5
movl %r15d, %eax
incq %r14
movl %r15d, %r13d
movl %eax, %r12d
movq -0x40(%rbp), %r15
jmp 0x4767
movq -0x60(%rbp), %rax
movq 0x10(%rax), %r15
movq -0x38(%rbp), %r12
movq -0x50(%rbp), %rdi
callq 0x2030
pushq $0x1
popq %rdi
pushq $0x2
popq %rsi
callq 0x2180
movq %rax, %rdi
xorl %r14d, %r14d
movq %r15, %rax
incl %r13d
jmp 0x4688
movq -0x50(%rbp), %r14
movq %r14, %rdi
callq 0x20c0
movq %r12, %rdi
movl %r13d, %r12d
subl %eax, %r12d
callq 0x20c0
leal 0x1(%rax), %ecx
movl %r15d, %edi
movl %r12d, %esi
movl -0x2c(%rbp), %edx
callq 0x406e
movq 0x57a9(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
callq 0x2090
cmpb $0x9, %al
jne 0x4880
movq -0x60(%rbp), %r15
movq 0x10(%r15), %r15
movq %r14, %rdi
callq 0x2030
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
callq 0x2180
movq %rax, %rdi
movq %r15, %rax
xorl %r14d, %r14d
movq -0x38(%rbp), %r12
jmp 0x47fd
movq -0x58(%rbp), %rbx
movq (%rbx), %rbx
incl -0x2c(%rbp)
movq -0x40(%rbp), %r15
jmp 0x4638
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x58f6(%rip), %rax      # 0xa18c
movl (%rax), %eax
cltd
pushq $0x3
popq %rsi
idivl %esi
movl %eax, %ecx
leaq 0x58ed(%rip), %rax      # 0xa194
movl (%rax), %eax
cltd
idivl %esi
pushq $0xa
popq %rdi
pushq $0x28
popq %rsi
movl %ecx, %edx
movl %eax, %ecx
callq 0x26cc
movq %rax, %rbx
cmpl $0x0, -0x44(%rbp)
je 0x491b
leaq 0x2ad1(%rip), %rcx      # 0x739c
pushq $0x3
popq %rsi
pushq $0x2
popq %r14
movq %rbx, %rdi
movl %r14d, %edx
movq %r12, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x2110
leaq 0x2ade(%rip), %rcx      # 0x73ca
pushq $0x6
popq %rsi
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x58b5(%rip), %rdi      # 0xa1b8
leaq 0x2aed(%rip), %rsi      # 0x73f7
xorl %edx, %edx
xorl %ecx, %ecx
movq %r12, %r8
movq %r15, %r9
callq 0x4cfc
jmp 0x4985
leaq 0x2a1f(%rip), %rcx      # 0x7341
pushq $0x3
popq %rsi
pushq $0x2
popq %r14
movq %rbx, %rdi
movl %r14d, %edx
movq %r12, %r8
xorl %eax, %eax
callq 0x2110
leaq 0x2a36(%rip), %rcx      # 0x7376
pushq $0x6
popq %rsi
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x2110
movq %rbx, %rdi
callq 0x2100
callq 0x21a0
movq %rbx, %rdi
callq 0x271c
movq 0x5674(%rip), %rbx      # 0x9fe0
movq (%rbx), %rdi
callq 0x20a0
leaq 0x5821(%rip), %rax      # 0xa19c
movl (%rax), %edi
callq 0x27dc
movq (%rbx), %rbx
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2100