// File: /workspace/github_c_makefile_star2_O1/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 0x4f09(%rip), %rax      # 0xa188
cmpl $0x0, (%rax)
js 0x54aa
movq 0x20(%rbp), %rbx
movq 0x28(%rbp), %r15
leaq 0x4f41(%rip), %rax      # 0xa1d8
xorl %r13d, %r13d
movq %r15, -0x60(%rbp)
movq %rbx, -0x48(%rbp)
movq (%rax), %rax
leaq 0x8(%rax), %rcx
movq %rcx, -0x58(%rbp)
movq %rax, -0x50(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x2, %edi
movl $0x1, %esi
callq 0x2180
movq %rax, %rdi
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %ecx, %ecx
movq %r13, -0x38(%rbp)
cmpl $0x1, %ecx
je 0x52eb
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x548f
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpq $0x0, 0x10(%rax)
movl $0x1, %eax
cmovel %eax, %ecx
cmpl $0x1, %ecx
je 0x531b
movq -0x30(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x20, %eax
je 0x531b
cmpl $0xa, %eax
jne 0x5424
movl %ecx, -0x3c(%rbp)
movq %rdi, -0x68(%rbp)
movq %r15, %rsi
callq 0x2190
testl %eax, %eax
je 0x5336
movl %r14d, %ecx
jmp 0x5453
leaq 0x4e4f(%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 0x4e40(%rip), %rax      # 0xa19c
movl %ecx, (%rax)
movq %r15, %rdi
callq 0x20c0
movq %rax, %r13
movl %r14d, %r12d
testl %r13d, %r13d
movq -0x58(%rbp), %rbx
je 0x539c
movq %rbx, %rdi
callq 0x2577
testl %eax, %eax
jne 0x5397
testl %r14d, %r14d
jle 0x5397
decl %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2519
decl %r12d
decl %r13d
jne 0x5375
movq -0x48(%rbp), %rbx
cmpb $0x0, (%rbx)
je 0x544c
xorl %r15d, %r15d
movq -0x38(%rbp), %r13
movsbl (%rbx,%r15), %edi
movl %r13d, %esi
movl %r14d, %edx
callq 0x2b61
movq %r13, %rdi
movl %eax, %r13d
leaq 0x4dc7(%rip), %rbx      # 0xa194
movl (%rbx), %eax
addl $-0x3, %eax
cmpl %eax, %r14d
jge 0x53fb
callq 0x30b2
movl (%rbx), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jl 0x53ed
movl %r13d, %eax
testl %r13d, %r13d
jne 0x53fe
incl %r14d
incl %r12d
movl %r14d, %r13d
movl %r12d, %eax
jmp 0x53fe
movl %r13d, %eax
incq %r15
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
movl %eax, %r14d
callq 0x20c0
movl %r14d, %ecx
movl %r14d, %r12d
movl %r13d, %r14d
cmpq %r15, %rax
movq -0x38(%rbp), %r13
ja 0x53b0
jmp 0x5453
movslq %r12d, %rcx
incl %r12d
movb %al, (%rdi,%rcx)
leal 0x2(%r14), %eax
movslq %eax, %rsi
callq 0x2200
movq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
xorl %ecx, %ecx
jmp 0x5487
movl %r12d, %ecx
movq -0x38(%rbp), %r13
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x68(%rbp), %rdi
movl %ecx, %r14d
callq 0x2030
movl $0x1, %edi
movl $0x2, %esi
callq 0x2180
movq %rax, %rdi
xorl %r12d, %r12d
movq -0x60(%rbp), %r15
movl -0x3c(%rbp), %ecx
incl %r14d
jmp 0x52d7
leal 0x1(%r13), %eax
leaq 0x4cee(%rip), %rcx      # 0xa188
cmpl (%rcx), %r13d
movl %eax, %r13d
movq -0x50(%rbp), %rax
jl 0x52a2
leaq 0x4ceb(%rip), %rax      # 0xa19c
movl (%rax), %edi
callq 0x2866
movq 0x4b21(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2100