// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movl %edi, %ebx
leaq 0x5d9a(%rip), %rax      # 0xa18c
movslq (%rax), %rax
imulq $0x55555556, %rax, %rdx # imm = 0x55555556
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x20, %rdx
addl %eax, %edx
leaq 0x5d84(%rip), %rax      # 0xa194
movslq (%rax), %rax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
addl %eax, %ecx
movl $0x10, %edi
movl $0x28, %esi
callq 0x2708
movq %rax, %r13
movl $0x2, %edi
movl $0x1, %esi
callq 0x2180
movq %rax, -0x30(%rbp)
movl $0x2, %edi
movl $0x1, %esi
callq 0x2180
movq %rax, -0x38(%rbp)
movl $0x1, %edi
movl $0x2, %esi
callq 0x2180
movq %rax, -0x50(%rbp)
leaq 0x5d5f(%rip), %rax      # 0xa1d8
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movl %ebx, -0x54(%rbp)
testl %ebx, %ebx
je 0x4679
leaq 0x2e36(%rip), %rcx      # 0x72c8
movq %r13, %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2e40(%rip), %rcx      # 0x72ed
movq %r13, %rdi
movl $0x4, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
movl $0x6, %esi
movl $0x1, %edx
callq 0x2230
movq %r13, %rdi
callq 0x2100
leaq 0x2b32(%rip), %rbx      # 0x7014
xorl %r15d, %r15d
movq %r13, %rdi
callq 0x2090
movl %eax, %r14d
cmpl $0x1f, %eax
jg 0x4503
cmpl $0x9, %r14d
je 0x456b
cmpl $0xa, %r14d
jne 0x4512
jmp 0x4575
cmpl $0x107, %r14d           # imm = 0x107
je 0x456b
cmpl $0x20, %r14d
je 0x4575
testq %r13, %r13
je 0x4523
movswl (%r13), %esi
movswl 0x2(%r13), %edx
jmp 0x452d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
movq %rbx, %rcx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
movslq %r15d, %rax
incl %r15d
movq -0x30(%rbp), %r12
movb %r14b, (%r12,%rax)
movq %r12, %rdi
callq 0x20c0
leaq 0x2(%rax), %rsi
movq %r12, %rdi
callq 0x2200
movq %rax, -0x30(%rbp)
cmpl $-0x1, %r15d
jne 0x44e5
movq %r13, %rdi
callq 0x20a0
subq $0x8, %rsp
xorl %eax, %eax
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rax
pushq %rax
pushq %rax
callq 0x2070
addq $0x20, %rsp
leaq 0x2d6f(%rip), %rcx      # 0x7314
movq %r13, %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
movq %r13, %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x2230
leaq 0x2a3a(%rip), %rbx      # 0x7014
xorl %r15d, %r15d
movq %r13, %rdi
callq 0x2090
movl %eax, %r14d
cmpl $0x1f, %eax
jg 0x45fe
cmpl $0x9, %r14d
je 0x466a
cmpl $0xa, %r14d
jne 0x4611
jmp 0x4808
cmpl $0x107, %r14d           # imm = 0x107
je 0x466a
cmpl $0x20, %r14d
je 0x4808
testq %r13, %r13
je 0x4622
movswl (%r13), %esi
movswl 0x2(%r13), %edx
jmp 0x462c
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r13, %rdi
movq %rbx, %rcx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
movslq %r15d, %rax
incl %r15d
movq -0x38(%rbp), %r12
movb %r14b, (%r12,%rax)
movq %r12, %rdi
callq 0x20c0
leaq 0x2(%rax), %rsi
movq %r12, %rdi
callq 0x2200
movq %rax, -0x38(%rbp)
cmpl $-0x1, %r15d
jne 0x45dd
jmp 0x4808
leaq 0x2b9d(%rip), %rcx      # 0x721d
movq %r13, %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2ba6(%rip), %rcx      # 0x7241
movq %r13, %rdi
movl $0x4, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
movl $0x6, %esi
movl $0x1, %edx
callq 0x2230
movq %r13, %rdi
callq 0x2100
xorl %r15d, %r15d
testq %r13, %r13
je 0x46dd
movswl (%r13), %r12d
movswl 0x2(%r13), %ebx
jmp 0x46e8
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %r13, %rdi
callq 0x2090
movl %eax, %r14d
cmpl $0x1f, %eax
jg 0x4706
cmpl $0x9, %r14d
je 0x475c
cmpl $0xa, %r14d
jne 0x4715
jmp 0x4766
cmpl $0x107, %r14d           # imm = 0x107
je 0x475c
cmpl $0x20, %r14d
je 0x4766
movq %r13, %rdi
movl %r12d, %esi
movl %ebx, %edx
leaq 0x28f0(%rip), %rcx      # 0x7014
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
movslq %r15d, %rax
incl %r15d
movq -0x30(%rbp), %rbx
movb %r14b, (%rbx,%rax)
movq %rbx, %rdi
callq 0x20c0
leaq 0x2(%rax), %rsi
movq %rbx, %rdi
callq 0x2200
movq %rax, -0x30(%rbp)
cmpl $-0x1, %r15d
jne 0x46cc
movq %r13, %rdi
callq 0x20a0
subq $0x8, %rsp
xorl %eax, %eax
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rax
pushq %rax
pushq %rax
callq 0x2070
addq $0x20, %rsp
leaq 0x2ad0(%rip), %rcx      # 0x7266
movq %r13, %rdi
movl $0x6, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2ac7(%rip), %rcx      # 0x7278
movq %r13, %rdi
movl $0x8, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2ac5(%rip), %rcx      # 0x7291
movq %r13, %rdi
movl $0xa, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2ac0(%rip), %rcx      # 0x72a7
movq %r13, %rdi
movl $0xc, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
callq 0x21a0
movq %r13, %rdi
callq 0x2100
movq %r13, %rdi
callq 0x2756
movq 0x57c1(%rip), %rbx      # 0x9fe0
movq (%rbx), %rdi
callq 0x20a0
movq (%rbx), %rax
testq %rax, %rax
je 0x4839
movswl (%rax), %ebx
movswl 0x2(%rax), %r14d
jmp 0x4844
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq -0x38(%rbp), %r15
movq -0x60(%rbp), %r12
leaq 0x5949(%rip), %rax      # 0xa19c
movl (%rax), %edi
callq 0x284e
movq 0x577f(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x2230
leaq 0x5913(%rip), %rax      # 0xa188
cmpl $0x0, (%rax)
js 0x4b23
movq $0x0, -0x48(%rbp)
leaq 0x590b(%rip), %rax      # 0xa198
cmpl $-0x1, (%rax)
je 0x48a8
leaq 0x590b(%rip), %rax      # 0xa1a4
movl (%rax), %eax
addl $-0x2, %eax
cmpl %eax, -0x48(%rbp)
jl 0x48a8
callq 0x3550
movq 0x8(%r12), %r14
cmpq $0x0, 0x10(%r14)
movq -0x50(%rbp), %r15
movq %r12, -0x60(%rbp)
je 0x4af6
leaq 0x8(%r12), %rax
movq %rax, -0x70(%rbp)
leaq 0x10(%r14), %rax
xorl %r13d, %r13d
xorl %ebx, %ebx
movq -0x48(%rbp), %r12
movq %rax, -0x68(%rbp)
movzbl 0x8(%r14), %eax
cmpl $0x20, %eax
je 0x48e9
cmpl $0xa, %eax
jne 0x4927
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0x2190
testl %eax, %eax
je 0x494e
movq %r15, -0x50(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %r14
movq -0x50(%rbp), %rdi
callq 0x2030
movl $0x1, %edi
movl $0x2, %esi
callq 0x2180
movq %rax, %r15
xorl %r13d, %r13d
jmp 0x4ad4
movslq %r13d, %rcx
incl %r13d
movb %al, (%r15,%rcx)
leal 0x2(%rbx), %eax
movslq %eax, %rsi
movq %r15, %rdi
callq 0x2200
movq %rax, %r15
movq -0x68(%rbp), %rax
movq (%rax), %r14
jmp 0x4ad4
movq %rbx, -0x40(%rbp)
leaq 0x5833(%rip), %rax      # 0xa18c
movl (%rax), %eax
movl %r12d, %r14d
subl %eax, %r14d
addl $-0x5, %eax
addl $0x6, %r14d
cmpl %eax, %r12d
movl $0x0, %eax
cmovll %eax, %r14d
leaq 0x5821(%rip), %rax      # 0xa19c
movl %r14d, (%rax)
cmpl $0x1, -0x54(%rbp)
jne 0x4a64
movq -0x30(%rbp), %rdi
callq 0x20c0
movq %rax, %r12
movq -0x40(%rbp), %rax
movl %eax, %r14d
testl %r12d, %r12d
movq -0x38(%rbp), %rbx
movq -0x70(%rbp), %r13
je 0x49d6
movq %r13, %rdi
callq 0x2565
testl %eax, %eax
jne 0x49d1
testl %r14d, %r14d
jle 0x49d1
decl %r14d
movq %r13, %rdi
movl %r14d, %esi
callq 0x250b
movq -0x40(%rbp), %rax
decl %eax
movq %rax, -0x40(%rbp)
decl %r12d
jne 0x49a8
movq %r15, -0x50(%rbp)
cmpb $0x0, (%rbx)
je 0x4ae7
xorl %r13d, %r13d
movq -0x38(%rbp), %r15
movq -0x48(%rbp), %r12
movsbl (%r15,%r13), %edi
movl %r12d, %esi
movl %r14d, %edx
callq 0x2b38
movl %eax, %ebx
leaq 0x578d(%rip), %r15      # 0xa194
movl (%r15), %eax
addl $-0x3, %eax
cmpl %eax, %r14d
jge 0x4a3b
movl %r12d, %edi
callq 0x305b
movl (%r15), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jl 0x4a2b
movl %ebx, %r12d
testl %ebx, %ebx
jne 0x4a3e
incl %r14d
movq -0x40(%rbp), %rax
incl %eax
movl %eax, %ebx
movl %r14d, %r12d
jmp 0x4a3e
movl %ebx, %r12d
incq %r13
movq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0x20c0
movl %r12d, %r14d
movl %ebx, %ecx
movq %rcx, -0x40(%rbp)
cmpq %r13, %rax
movq -0x48(%rbp), %r12
ja 0x49ee
jmp 0x48fd
movq %r12, %rbx
movq %r15, %rdi
callq 0x20c0
movq -0x40(%rbp), %rcx
movl %ecx, %r12d
subl %eax, %r12d
movq -0x30(%rbp), %rdi
callq 0x20c0
leal 0x1(%rax), %ecx
movl %r14d, %edi
movl %r12d, %esi
movl %ebx, %edx
callq 0x4242
movq 0x5547(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
callq 0x2090
cmpb $0x9, %al
jne 0x4bd6
movq %rbx, %r12
movq -0x68(%rbp), %rax
movq (%rax), %r14
movq %r15, %rdi
callq 0x2030
movl $0x2, %edi
movl $0x1, %esi
callq 0x2180
movq %rax, %r15
xorl %r13d, %r13d
movq -0x40(%rbp), %rbx
incl %ebx
leaq 0x10(%r14), %rax
cmpq $0x0, 0x10(%r14)
jne 0x48d6
jmp 0x4afa
movq -0x40(%rbp), %rax
movl %eax, %ebx
movq -0x48(%rbp), %r12
jmp 0x48fd
movq -0x48(%rbp), %r12
movq %r15, -0x50(%rbp)
movq %r12, %rdx
movq -0x60(%rbp), %r12
movq (%r12), %r12
leal 0x1(%rdx), %eax
leaq 0x5675(%rip), %rcx      # 0xa188
cmpl (%rcx), %edx
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %r15
jl 0x4886
leaq 0x5662(%rip), %rax      # 0xa18c
movslq (%rax), %rax
imulq $0x55555556, %rax, %rdx # imm = 0x55555556
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x20, %rdx
addl %eax, %edx
leaq 0x564c(%rip), %rax      # 0xa194
movslq (%rax), %rax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
addl %eax, %ecx
movl $0xa, %edi
movl $0x28, %esi
callq 0x2708
movq %rax, %rbx
cmpl $0x0, -0x54(%rbp)
je 0x4be5
leaq 0x281e(%rip), %rcx      # 0x739c
movq %rbx, %rdi
movl $0x3, %esi
movl $0x2, %edx
movq -0x30(%rbp), %r14
movq %r14, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x2110
leaq 0x2827(%rip), %rcx      # 0x73ca
movq %rbx, %rdi
movl $0x6, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x55fa(%rip), %rdi      # 0xa1b8
leaq 0x2832(%rip), %rsi      # 0x73f7
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
movq %r15, %r9
callq 0x4ff8
jmp 0x4c54
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2755(%rip), %rcx      # 0x7341
movq %rbx, %rdi
movl $0x3, %esi
movl $0x2, %edx
movq -0x30(%rbp), %r8
xorl %eax, %eax
callq 0x2110
leaq 0x276b(%rip), %rcx      # 0x7376
movq %rbx, %rdi
movl $0x6, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x2110
movq %rbx, %rdi
callq 0x2100
callq 0x21a0
movq %rbx, %rdi
callq 0x2756
movq 0x53a5(%rip), %rbx      # 0x9fe0
movq (%rbx), %rdi
callq 0x20a0
leaq 0x5552(%rip), %rax      # 0xa19c
movl (%rax), %edi
callq 0x284e
movq (%rbx), %rbx
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2100