// File: /workspace/github_c_makefile_star2_O0/vasusharma7[P]Text-Editor/stdedit.c
// Function: backspace
int backspace(int y, int x){
    int i;
    point *temp = data.front;
    for(i = 0; i < y; i++){
        temp = temp->tail;  
    }
    char str[2] = {'\0'};
    //printw("%d",x);
    //refresh();  
    
    if(x == 0){
        if(temp->element.width >= (bx - 2))
            return (bx - 3);
        istack *temp2 = &(temp->tail->element);
        char *str = (char *)calloc(2,1);
        str[0] = '\0';
        char ch[2] = {'\0'};
        i = 0;
        while(!isEmptys(temp2)){

            ch[0] = ipops(temp2);
            i++;
            strcat(str,ch);
            str = realloc(str,strlen(str) +2);

        }
        int t = temp->element.width; 
        if(!isEmptys(&(temp->element))){
                while(ipops(&(temp->element)) != '\n');
            }   
        if(strlen(str)){
            
            while(i--){
                if(temp->element.width >= (bx - 3)){
                        ipushs(&(temp->element),'\n');
                     break;
                 }
                ipushs(&(temp->element),str[i]);
                
            }
            i++;
            if(i >=1 ){
                while(i--)
                    ipushs(&(temp->tail->element),str[i]);
            }
        }
        if(temp->tail->element.width == 0){
            dequeueloc(&data,y+1);
            lines--;
        }
        add_event(&states,"back",temp->element.width - strlen(str),y,"\n","");

        return (temp->element.width - strlen(str));   //check this well
        //return (temp->element.width - 1);
    }
    else if(!isEmptys(&(temp->element))){
        if(x == temp->element.width){
            str[0] = ipops(&(temp->element));
            add_event(&states,"back",x,y,str,"");
        }
        else if(!isEmptys(&(temp->element))){
            str[0] = ipoploc(&(temp->element),x-1);
            add_event(&states,"back",x,y,str,"");

        }
        
    }
    
    int n_x = temp->element.width;
    return n_x;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
leaq 0x967b(%rip), %rax      # 0xd1e0
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x3b91
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x3b73
leaq -0x1a(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2110
cmpl $0x0, -0xc(%rbp)
jne 0x3df8
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
leaq 0x95e3(%rip), %rcx      # 0xd19c
movl (%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jl 0x3bd6
leaq 0x95d3(%rip), %rax      # 0xd19c
movl (%rax), %eax
subl $0x3, %eax
movl %eax, -0x4(%rbp)
jmp 0x3eb2
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movl $0x2, %edi
movl $0x1, %esi
callq 0x2180
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
leaq -0x32(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2110
movl $0x0, -0x10(%rbp)
movq -0x28(%rbp), %rdi
callq 0x27c0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3c2d
jmp 0x3c76
movq -0x28(%rbp), %rdi
callq 0x2660
movb %al, -0x32(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x32(%rbp), %rsi
callq 0x2270
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
callq 0x20b0
movq -0x48(%rbp), %rdi
movq %rax, %rsi
addq $0x2, %rsi
callq 0x2210
movq %rax, -0x30(%rbp)
jmp 0x3c16
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
callq 0x27c0
cmpl $0x0, %eax
jne 0x3caa
jmp 0x3c94
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
callq 0x2660
cmpl $0xa, %eax
je 0x3ca8
jmp 0x3c94
jmp 0x3caa
movq -0x30(%rbp), %rdi
callq 0x20b0
cmpq $0x0, %rax
je 0x3d58
jmp 0x3cbf
movl -0x10(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x10(%rbp)
cmpl $0x0, %eax
je 0x3d15
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
leaq 0x94bf(%rip), %rcx      # 0xd19c
movl (%rcx), %ecx
subl $0x3, %ecx
cmpl %ecx, %eax
jl 0x3cfa
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
movl $0xa, %esi
callq 0x2460
jmp 0x3d15
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
movq -0x30(%rbp), %rax
movslq -0x10(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x2460
jmp 0x3cbf
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
cmpl $0x1, -0x10(%rbp)
jl 0x3d56
jmp 0x3d26
movl -0x10(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x10(%rbp)
cmpl $0x0, %eax
je 0x3d54
movq -0x18(%rbp), %rax
movq (%rax), %rdi
addq $0x8, %rdi
movq -0x30(%rbp), %rax
movslq -0x10(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x2460
jmp 0x3d26
jmp 0x3d56
jmp 0x3d58
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
jne 0x3d8c
movl -0x8(%rbp), %esi
addl $0x1, %esi
leaq 0x946e(%rip), %rdi      # 0xd1e0
callq 0x2a40
leaq 0x9412(%rip), %rax      # 0xd190
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x9406(%rip), %rax      # 0xd190
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movslq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x20b0
movq %rax, %rcx
movq -0x58(%rbp), %rax
subq %rcx, %rax
movl %eax, %edx
movl -0x8(%rbp), %ecx
leaq 0x9409(%rip), %rdi      # 0xd1c0
leaq 0x6252(%rip), %rsi      # 0xa010
leaq 0x66f4(%rip), %r8       # 0xa4b9
leaq 0x66ee(%rip), %r9       # 0xa4ba
callq 0x6b60
movq -0x18(%rbp), %rax
movslq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
callq 0x20b0
movq %rax, %rcx
movq -0x50(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x4(%rbp)
jmp 0x3eb2
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
callq 0x27c0
cmpl $0x0, %eax
jne 0x3ea0
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x3e50
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
callq 0x2660
movb %al, -0x1a(%rbp)
movl -0xc(%rbp), %edx
movl -0x8(%rbp), %ecx
leaq -0x1a(%rbp), %r8
leaq 0x9385(%rip), %rdi      # 0xd1c0
leaq 0x61ce(%rip), %rsi      # 0xa010
leaq 0x6671(%rip), %r9       # 0xa4ba
callq 0x6b60
jmp 0x3e9e
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
callq 0x27c0
cmpl $0x0, %eax
jne 0x3e9c
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
movl -0xc(%rbp), %esi
subl $0x1, %esi
callq 0x26d0
movb %al, -0x1a(%rbp)
movl -0xc(%rbp), %edx
movl -0x8(%rbp), %ecx
leaq -0x1a(%rbp), %r8
leaq 0x9337(%rip), %rdi      # 0xd1c0
leaq 0x6180(%rip), %rsi      # 0xa010
leaq 0x6623(%rip), %r9       # 0xa4ba
callq 0x6b60
jmp 0x3e9e
jmp 0x3ea0
jmp 0x3ea2
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)