// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq 0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq 0x28(%rbp), %r15
leaq 0x52d5(%rip), %rax      # 0xa1d8
pushq $0x2
popq %r13
xorl %edx, %edx
movq %r15, -0x48(%rbp)
leaq 0x5274(%rip), %rcx      # 0xa188
cmpl (%rcx), %edx
jg 0x50e7
movl %edx, -0x2c(%rbp)
movq (%rax), %rax
leaq 0x8(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq %rax, -0x40(%rbp)
movq 0x8(%rax), %rbx
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x2180
movq %rbx, %rdx
movq %rax, %rdi
xorl %esi, %esi
xorl %r14d, %r14d
xorl %ecx, %ecx
movq 0x10(%rdx), %r12
cmpl $0x1, %ecx
je 0x4f5c
testq %r12, %r12
je 0x50d9
cmpq $0x0, 0x10(%r12)
pushq $0x1
popq %rax
cmovel %eax, %ecx
cmpl $0x1, %ecx
je 0x4f7f
movzbl 0x8(%rdx), %eax
cmpl $0x20, %eax
je 0x4f7f
cmpl $0xa, %eax
jne 0x50b1
movq %rdx, -0x58(%rbp)
movl %ecx, -0x30(%rbp)
movq %rdi, -0x60(%rbp)
movq %r15, %rsi
callq 0x2190
testl %eax, %eax
jne 0x508a
leaq 0x51eb(%rip), %rax      # 0xa18c
movl (%rax), %eax
movl -0x2c(%rbp), %edx
movl %edx, %ecx
subl %eax, %ecx
addl $-0x5, %eax
addl $0x6, %ecx
cmpl %eax, %edx
movl $0x0, %eax
cmovll %eax, %ecx
leaq 0x51db(%rip), %rax      # 0xa19c
movl %ecx, (%rax)
movq %r15, %rdi
callq 0x20c0
movq %rax, %r12
movq -0x50(%rbp), %rbx
negl %r12d
incl %r12d
cmpl $0x1, %r12d
je 0x5002
movq %rbx, %rdi
callq 0x254c
testl %eax, %eax
jne 0x4fd5
testl %r14d, %r14d
jle 0x4fd5
decl %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x24ed
negl %r12d
jmp 0x4fd2
xorl %r15d, %r15d
movl %r14d, %r13d
movq -0x38(%rbp), %rdi
callq 0x20c0
cmpq %r15, %rax
jbe 0x5077
movq -0x38(%rbp), %rax
movsbl (%rax,%r15), %edi
movl -0x2c(%rbp), %ebx
movl %ebx, %esi
movl %r14d, %edx
callq 0x2aa9
movl %eax, %r12d
leaq 0x515e(%rip), %rcx      # 0xa194
movl (%rcx), %eax
addl $-0x3, %eax
cmpl %eax, %r14d
jge 0x5069
movl %ebx, %edi
movq %rcx, %rbx
callq 0x2fb6
movl (%rbx), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jl 0x505b
movl %r12d, %eax
testl %r12d, %r12d
jne 0x506c
incl %r14d
incl %r13d
movl %r14d, %r12d
movl %r13d, %eax
jmp 0x506c
movl %r12d, %eax
incq %r15
movl %r12d, %r14d
movl %eax, %r13d
jmp 0x5008
movq -0x58(%rbp), %rax
movq 0x10(%rax), %r12
movl %r13d, %r14d
movq -0x48(%rbp), %r15
pushq $0x2
popq %r13
movq -0x60(%rbp), %rdi
callq 0x2030
pushq $0x1
popq %rdi
movq %r13, %rsi
callq 0x2180
movq %rax, %rdi
xorl %esi, %esi
movl -0x30(%rbp), %ecx
incl %r14d
movq %r12, %rdx
jmp 0x4f4a
movslq %esi, %rcx
incl %esi
movb %al, (%rdi,%rcx)
leal 0x2(%r14), %eax
movl %esi, %r12d
movslq %eax, %rsi
movq %rdx, %rbx
callq 0x2200
movl %r12d, %esi
movq %rax, %rdi
movq 0x10(%rbx), %r12
xorl %ecx, %ecx
jmp 0x50a6
movl -0x2c(%rbp), %edx
incl %edx
movq -0x40(%rbp), %rax
jmp 0x4f0d
leaq 0x50ae(%rip), %rax      # 0xa19c
movl (%rax), %edi
callq 0x27dc
movq 0x4ee4(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2100