// File: /workspace/github_c_makefile_star2_O1/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 0x5d12(%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 0x5cfc(%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 0x2720
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, -0x48(%rbp)
movl $0x1, %edi
movl $0x2, %esi
callq 0x2180
movq %rax, -0x50(%rbp)
leaq 0x5cd7(%rip), %rax      # 0xa1d8
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movl %ebx, -0x54(%rbp)
testl %ebx, %ebx
je 0x470c
leaq 0x2dae(%rip), %rcx      # 0x72c8
movq %r13, %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2db8(%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 0x2aaa(%rip), %rbx      # 0x7014
xorl %r15d, %r15d
movq %r13, %rdi
callq 0x2090
movl %eax, %r14d
cmpl $0x1f, %eax
jg 0x45e7
cmpl $0x9, %r14d
je 0x45fc
cmpl $0xa, %r14d
je 0x45f6
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x459d
movswl (%r13), %esi
testq %r13, %r13
je 0x45a7
movswl 0x2(%r13), %edx
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)
jmp 0x45fc
cmpl $0x107, %r14d           # imm = 0x107
je 0x45fc
cmpl $0x20, %r14d
jne 0x4589
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r15d
jne 0x456d
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 0x2cde(%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 0x29a9(%rip), %rbx      # 0x7014
xorl %r15d, %r15d
movq %r13, %rdi
callq 0x2090
movl %eax, %r14d
cmpl $0x1f, %eax
jg 0x46e8
cmpl $0x9, %r14d
je 0x46fd
cmpl $0xa, %r14d
je 0x46f7
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x469e
movswl (%r13), %esi
testq %r13, %r13
je 0x46a8
movswl 0x2(%r13), %edx
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 -0x48(%rbp), %r12
movb %r14b, (%r12,%rax)
movq %r12, %rdi
callq 0x20c0
leaq 0x2(%rax), %rsi
movq %r12, %rdi
callq 0x2200
movq %rax, -0x48(%rbp)
jmp 0x46fd
cmpl $0x107, %r14d           # imm = 0x107
je 0x46fd
cmpl $0x20, %r14d
jne 0x468a
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r15d
jne 0x466e
jmp 0x48a1
leaq 0x2b0a(%rip), %rcx      # 0x721d
movq %r13, %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2b13(%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
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %r13, %r13
je 0x4775
movswl (%r13), %r12d
testq %r13, %r13
je 0x477f
movswl 0x2(%r13), %r14d
movq %r13, %rdi
callq 0x2090
movl %eax, %ebx
cmpl $0x1f, %eax
jg 0x47e2
cmpl $0x9, %ebx
je 0x47f5
cmpl $0xa, %ebx
je 0x47ef
movq %r13, %rdi
movl %r12d, %esi
movl %r14d, %edx
leaq 0x286c(%rip), %rcx      # 0x7014
movl %ebx, %r8d
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2100
movslq %r15d, %rax
incl %r15d
movq -0x30(%rbp), %r14
movb %bl, (%r14,%rax)
movq %r14, %rdi
callq 0x20c0
leaq 0x2(%rax), %rsi
movq %r14, %rdi
callq 0x2200
movq %rax, -0x30(%rbp)
jmp 0x47f5
cmpl $0x107, %ebx            # imm = 0x107
je 0x47f5
cmpl $0x20, %ebx
jne 0x4798
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r15d
jne 0x475f
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 0x2a37(%rip), %rcx      # 0x7266
movq %r13, %rdi
movl $0x6, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2a2e(%rip), %rcx      # 0x7278
movq %r13, %rdi
movl $0x8, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2a2c(%rip), %rcx      # 0x7291
movq %r13, %rdi
movl $0xa, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x2a27(%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 0x276e
movq 0x5728(%rip), %rbx      # 0x9fe0
movq (%rbx), %rdi
callq 0x20a0
movq (%rbx), %rax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
movq -0x48(%rbp), %r15
je 0x48db
movswl (%rax), %r14d
testq %rax, %rax
movq -0x60(%rbp), %r12
je 0x48e8
movswl 0x2(%rax), %ebx
leaq 0x58ad(%rip), %rax      # 0xa19c
movl (%rax), %edi
callq 0x2866
movq 0x56e3(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x2230
leaq 0x5877(%rip), %rax      # 0xa188
cmpl $0x0, (%rax)
js 0x4bbf
movq $0x0, -0x40(%rbp)
leaq 0x586f(%rip), %rax      # 0xa198
cmpl $-0x1, (%rax)
je 0x4944
leaq 0x586f(%rip), %rax      # 0xa1a4
movl (%rax), %eax
addl $-0x2, %eax
cmpl %eax, -0x40(%rbp)
jl 0x4944
callq 0x35c0
movq 0x8(%r12), %r14
cmpq $0x0, 0x10(%r14)
movq -0x50(%rbp), %r15
movq %r12, -0x60(%rbp)
je 0x4b92
leaq 0x8(%r12), %rax
movq %rax, -0x70(%rbp)
leaq 0x10(%r14), %rax
xorl %r13d, %r13d
xorl %ebx, %ebx
movq -0x40(%rbp), %r12
movq %rax, -0x68(%rbp)
movzbl 0x8(%r14), %eax
cmpl $0x20, %eax
je 0x4985
cmpl $0xa, %eax
jne 0x49c3
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0x2190
testl %eax, %eax
je 0x49ea
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 0x4b70
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 0x4b70
movq %rbx, -0x38(%rbp)
leaq 0x5797(%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 0x5785(%rip), %rax      # 0xa19c
movl %r14d, (%rax)
cmpl $0x1, -0x54(%rbp)
jne 0x4b00
movq -0x30(%rbp), %rdi
callq 0x20c0
movq %rax, %r12
movq -0x38(%rbp), %rax
movl %eax, %r14d
testl %r12d, %r12d
movq -0x70(%rbp), %rbx
je 0x4a6e
movq %rbx, %rdi
callq 0x2577
testl %eax, %eax
jne 0x4a69
testl %r14d, %r14d
jle 0x4a69
decl %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2519
movq -0x38(%rbp), %rax
decl %eax
movq %rax, -0x38(%rbp)
decl %r12d
jne 0x4a40
movq %r15, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpb $0x0, (%rax)
je 0x4b83
xorl %r13d, %r13d
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r12
movsbl (%r15,%r13), %edi
movl %r12d, %esi
movl %r14d, %edx
callq 0x2b61
movl %eax, %ebx
leaq 0x56f1(%rip), %r15      # 0xa194
movl (%r15), %eax
addl $-0x3, %eax
cmpl %eax, %r14d
jge 0x4ad7
movl %r12d, %edi
callq 0x30b2
movl (%r15), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jl 0x4ac7
movl %ebx, %r12d
testl %ebx, %ebx
jne 0x4ada
incl %r14d
movq -0x38(%rbp), %rax
incl %eax
movl %eax, %ebx
movl %r14d, %r12d
jmp 0x4ada
movl %ebx, %r12d
incq %r13
movq -0x48(%rbp), %r15
movq %r15, %rdi
callq 0x20c0
movl %r12d, %r14d
movl %ebx, %ecx
movq %rcx, -0x38(%rbp)
cmpq %r13, %rax
movq -0x40(%rbp), %r12
ja 0x4a8a
jmp 0x4999
movq %r12, %rbx
movq %r15, %rdi
callq 0x20c0
movq -0x38(%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 0x42c9
movq 0x54ab(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
callq 0x2090
cmpb $0x9, %al
jne 0x4c72
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 -0x38(%rbp), %rbx
incl %ebx
leaq 0x10(%r14), %rax
cmpq $0x0, 0x10(%r14)
jne 0x4972
jmp 0x4b96
movq -0x38(%rbp), %rax
movl %eax, %ebx
movq -0x40(%rbp), %r12
jmp 0x4999
movq -0x40(%rbp), %r12
movq %r15, -0x50(%rbp)
movq %r12, %rdx
movq -0x60(%rbp), %r12
movq (%r12), %r12
leal 0x1(%rdx), %eax
leaq 0x55d9(%rip), %rcx      # 0xa188
cmpl (%rcx), %edx
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %r15
jl 0x4922
leaq 0x55c6(%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 0x55b0(%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 0x2720
movq %rax, %rbx
cmpl $0x0, -0x54(%rbp)
je 0x4c81
leaq 0x2782(%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 0x278b(%rip), %rcx      # 0x73ca
movq %rbx, %rdi
movl $0x6, %esi
movl $0x2, %edx
xorl %eax, %eax
callq 0x2110
leaq 0x555e(%rip), %rdi      # 0xa1b8
leaq 0x2796(%rip), %rsi      # 0x73f7
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
movq %r15, %r9
callq 0x508c
jmp 0x4cf0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x26b9(%rip), %rcx      # 0x7341
movq %rbx, %rdi
movl $0x3, %esi
movl $0x2, %edx
movq -0x30(%rbp), %r8
xorl %eax, %eax
callq 0x2110
leaq 0x26cf(%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 0x276e
movq 0x5309(%rip), %rbx      # 0x9fe0
movq (%rbx), %rdi
callq 0x20a0
leaq 0x54b6(%rip), %rax      # 0xa19c
movl (%rax), %edi
callq 0x2866
movq (%rbx), %rbx
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2100