// File: /workspace/github_c_makefile_star2_O3/vasusharma7[P]Text-Editor/undo.c
// Function: undo_replace
void undo_replace(event e){

    int rpt, j, k,i,y,x,t,r;
        point *temp = data.front;
        node *trace = temp->element.store;
        char *rplmt = e.p3;
        char *querry = e.p4;
        for(i = 0; i <= lines; i++){
            rpt = 0;
            j = 0;
            k = 0;
            trace = temp->element.store;
            char *str = (char *)calloc(2,1);
            while(rpt == 1 || (trace->next != NULL)){
                getyx(stdscr,y,x);
                if(trace->next->next == NULL)
                    rpt = 1;
                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;
                        
                            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++;
                                }
                            }
                        
                    }
                    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;
    }
    display(stline);
    refresh();
    x = y;
    y = x;
    return;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq 0x4f9d(%rip), %rax      # 0xa188
cmpl $0x0, (%rax)
js 0x541f
movq 0x20(%rbp), %rbx
movq 0x28(%rbp), %r12
leaq 0x4fd5(%rip), %rax      # 0xa1d8
movq %rax, -0x30(%rbp)
xorl %r13d, %r13d
movq %r12, -0x60(%rbp)
movq %rbx, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq 0x8(%rax), %r14
movl $0x2, %edi
movl $0x1, %esi
callq 0x2180
movq %rax, %rdi
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x5408
movq %r14, %rdx
movq -0x30(%rbp), %rcx
addq $0x8, %rcx
movq %rcx, -0x58(%rbp)
xorl %ecx, %ecx
xorl %r14d, %r14d
xorl %esi, %esi
movq %r13, -0x40(%rbp)
cmpq $0x0, 0x10(%rax)
movl $0x1, %eax
cmovel %eax, %ecx
cmpl $0x1, %ecx
je 0x527e
movzbl 0x8(%rdx), %eax
cmpl $0x20, %eax
je 0x527e
cmpl $0xa, %eax
jne 0x538b
movl %ecx, -0x44(%rbp)
movq %rdx, -0x38(%rbp)
movq %rdi, -0x68(%rbp)
movq %r12, %rsi
callq 0x2190
testl %eax, %eax
je 0x529d
movl %r14d, %ecx
jmp 0x53ba
leaq 0x4ee8(%rip), %rax      # 0xa18c
movl (%rax), %eax
movl %r13d, %ecx
subl %eax, %ecx
addl $-0x5, %eax
addl $0x6, %ecx
cmpl %eax, %r13d
movl $0x0, %eax
cmovll %eax, %ecx
leaq 0x4ed9(%rip), %rax      # 0xa19c
movl %ecx, (%rax)
movq %r12, %rdi
callq 0x20c0
movq %rax, %r13
movl %r14d, %r12d
testl %r13d, %r13d
movq -0x58(%rbp), %rbx
je 0x5303
movq %rbx, %rdi
callq 0x2565
testl %eax, %eax
jne 0x52fe
testl %r14d, %r14d
jle 0x52fe
decl %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x250b
decl %r12d
decl %r13d
jne 0x52dc
movq -0x50(%rbp), %rbx
cmpb $0x0, (%rbx)
je 0x53b3
xorl %r15d, %r15d
movq -0x40(%rbp), %r13
movsbl (%rbx,%r15), %edi
movl %r13d, %esi
movl %r14d, %edx
callq 0x2b38
movq %r13, %rdi
movl %eax, %r13d
leaq 0x4e60(%rip), %rbx      # 0xa194
movl (%rbx), %eax
addl $-0x3, %eax
cmpl %eax, %r14d
jge 0x5362
callq 0x305b
movl (%rbx), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jl 0x5354
movl %r13d, %eax
testl %r13d, %r13d
jne 0x5365
incl %r14d
incl %r12d
movl %r14d, %r13d
movl %r12d, %eax
jmp 0x5365
movl %r13d, %eax
incq %r15
movq -0x50(%rbp), %rbx
movq %rbx, %rdi
movl %eax, %r14d
callq 0x20c0
movl %r14d, %ecx
movl %r14d, %r12d
movl %r13d, %r14d
cmpq %r15, %rax
movq -0x40(%rbp), %r13
ja 0x5317
jmp 0x53ba
movslq %esi, %rcx
incl %esi
movl %esi, -0x38(%rbp)
movb %al, (%rdi,%rcx)
leal 0x2(%r14), %eax
movslq %eax, %rsi
movq %rdx, %r15
callq 0x2200
movl -0x38(%rbp), %esi
movq %rax, %rdi
movq 0x10(%r15), %rdx
xorl %ecx, %ecx
jmp 0x53ef
movl %r12d, %ecx
movq -0x40(%rbp), %r13
movq -0x38(%rbp), %r14
movq 0x10(%r14), %r14
movq -0x68(%rbp), %rdi
movl %ecx, %r15d
callq 0x2030
movl $0x1, %edi
movl $0x2, %esi
callq 0x2180
movq %r14, %rdx
movq %rax, %rdi
xorl %esi, %esi
movl %r15d, %r14d
movq -0x60(%rbp), %r12
movl -0x44(%rbp), %ecx
incl %r14d
movq 0x10(%rdx), %rax
cmpl $0x1, %ecx
je 0x525a
testq %rax, %rax
jne 0x525a
leal 0x1(%r13), %eax
leaq 0x4d75(%rip), %rcx      # 0xa188
cmpl (%rcx), %r13d
movl %eax, %r13d
jl 0x5212
leaq 0x4d76(%rip), %rax      # 0xa19c
movl (%rax), %edi
callq 0x284e
movq 0x4bac(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2100