// File: /workspace/github_c_makefile_star2_O1/vasusharma7[P]Text-Editor/stdedit.c
// Function: readfile
int readfile(int fdw){
    char buffer[2];
    int x,y,mk;
    point *temp = data.front;
    clear();
    move(0,0);
    stline = 0;
    int count = 0;
    while(read(fdw,buffer,1)){
        getyx(stdscr,y,x);
        if(buffer[0] == '\t' || buffer[0] == '\r')
            continue;
        // if(stline > 0){
        //     display(stline);
        //     break;
        // }
        if(buffer[0] == '\n'){
            add_char(buffer[0],y+stline,x);
                y++;
                lines++;
                if(y >= (by - 4)){
                    stline++;
                    add_line(y+stline - 1);
                }
                else if(lines >= (by - 4)){
                    
                    add_line(y+stline);
                }
                else{
                    add_line(y + stline);
                }
                if(y >= (by - 4))
                    move(by - 5,0);
                else
                    move(y,0);
        }
        else{
            mk = add_char(buffer[0],y+stline,x);
                if( ((x >= (bx - 3)) || (getwidth(y+stline) >= bx-3)) && (mk != 0)){
                    y++;
                    if(y >= (by - 4)){
                        stline++;
                        move(by - 5,mk);
                    }
                    else{
                        move(y,mk);
                    }
                }
                else{
                    move(y,++x);
                }
        }
    }
    stline = 0;
    clear();
    display(0);
    refresh();
    move(0,0);
    refresh();
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
movq 0x6bfe(%rip), %r13      # 0x9fe0
movq (%r13), %rdi
callq 0x20a0
movq (%r13), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
leaq 0x6d9d(%rip), %rax      # 0xa19c
movl $0x0, (%rax)
leaq -0x2e(%rbp), %rsi
movl $0x1, %edx
movl %ebx, %edi
callq 0x2170
testq %rax, %rax
je 0x3570
movl %ebx, -0x2c(%rbp)
movq (%r13), %rax
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x343a
movswl (%rax), %r15d
testq %rax, %rax
je 0x3444
movswl 0x2(%rax), %r12d
movb -0x2e(%rbp), %r14b
movl %r14d, %eax
andb $-0x5, %al
cmpb $0x9, %al
je 0x3557
leaq 0x6d40(%rip), %rbx      # 0xa19c
movl (%rbx), %esi
addl %r15d, %esi
movsbl %r14b, %edi
movl %r12d, %edx
callq 0x2b61
cmpb $0xa, %r14b
jne 0x34c0
incl %r15d
leaq 0x6d0b(%rip), %rax      # 0xa188
incl (%rax)
leaq 0x6d06(%rip), %rax      # 0xa18c
movl (%rax), %eax
addl $-0x4, %eax
movl (%rbx), %edi
cmpl %eax, %r15d
jl 0x3497
leal 0x1(%rdi), %eax
movl %eax, (%rbx)
addl %r15d, %edi
callq 0x29cc
leaq 0x6ce6(%rip), %rax      # 0xa18c
movl (%rax), %esi
leal -0x4(%rsi), %eax
movq 0x6b2e(%rip), %r13      # 0x9fe0
movq (%r13), %rdi
cmpl %eax, %r15d
jge 0x3516
movl %r15d, %esi
jmp 0x3519
movl %eax, %r13d
leaq 0x6cca(%rip), %rbx      # 0xa194
movl (%rbx), %eax
addl $-0x3, %eax
cmpl %eax, %r12d
jge 0x34ee
leaq 0x6cc1(%rip), %rax      # 0xa19c
movl (%rax), %edi
addl %r15d, %edi
callq 0x30b2
movl (%rbx), %ecx
addl $-0x3, %ecx
cmpl %ecx, %eax
jl 0x351d
testl %r13d, %r13d
je 0x351d
incl %r15d
leaq 0x6c8f(%rip), %rax      # 0xa18c
movl (%rax), %esi
leal -0x4(%rsi), %eax
cmpl %eax, %r15d
jge 0x3533
movq 0x6ad2(%rip), %rbx      # 0x9fe0
movq (%rbx), %rdi
movl %r15d, %esi
jmp 0x3549
addl $-0x5, %esi
xorl %edx, %edx
jmp 0x354f
movq 0x6abc(%rip), %r13      # 0x9fe0
movq (%r13), %rdi
incl %r12d
movl %r15d, %esi
movl %r12d, %edx
jmp 0x354f
leaq 0x6c62(%rip), %rax      # 0xa19c
incl (%rax)
movq 0x6a9d(%rip), %rbx      # 0x9fe0
movq (%rbx), %rdi
addl $-0x5, %esi
movl %r13d, %edx
movq %rbx, %r13
callq 0x2230
movl -0x2c(%rbp), %ebx
movl $0x1, %edx
movl %ebx, %edi
leaq -0x2e(%rbp), %rsi
callq 0x2170
testq %rax, %rax
jne 0x3421
leaq 0x6c25(%rip), %rax      # 0xa19c
movl $0x0, (%rax)
movq (%r13), %rdi
callq 0x20a0
xorl %edi, %edi
callq 0x2866
movq (%r13), %rdi
callq 0x2100
movq (%r13), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
movq (%r13), %rdi
callq 0x2100
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq