// File: /workspace/github_c_makefile_star2_O0/icysunlight[P]miniftpd/ftpproto.c
// Function: do_stor
void do_stor(session_t *sess)
{
    //打开数据连接
    sess->datafd = get_datafd(sess);
    if ( -1 == sess->datafd )
    {
        ftp_reply(sess,FTP_BADSENDCONN,"Use port or pasv first");
        return;
    }

    //打开文件并加锁
    int filefd = open(sess->arg,O_WRONLY | O_CREAT , 0666);
    if ( -1 == filefd )
    {
        ftp_reply(sess,FTP_BADSENDFILE,"Create local file fail.");
        ERR_EXIT("open");
        return;
    }
    if ( -1 == file_wrlock(filefd)) 
    {
        ftp_reply(sess,FTP_BADSENDFILE,"Create local file fail.");
        close(filefd);
        return;
    }

    //定位ref
    if ( sess->rest_pos != 0)
        lseek(filefd,sess->rest_pos,SEEK_SET);
    else if ( sess->bappe ) 
    {
        lseek(filefd,0,SEEK_END);
    }
    else 
    {
        ftruncate(filefd,0);
    }
    
    //发送开始信息
    ftp_reply(sess,FTP_DATACONN,"OK to send data");

    int flag = 0;
    //发送文件
    if ( 0 == sess->bASCII)
    {
        while (1)
        {
            ratelim_init(sess);
            data_disconn_start();
            char buf[1024] = {0};
            int ret = read(sess->datafd,buf,1024);
            if ( -1 == ret && EINTR == errno )
                continue;
            if ( -1 == ret )
            {
                flag = 1;
                break;
            }
            if ( 0 == ret )
            {
                flag = 0;
                break;
            }

            b_dataconn = 1;
            ratelim_do(sess,tunable_upload_max_rate,ret); 
    
            if ( ret != writen(filefd,buf,ret) )
            {
                flag = 2;
                break;
            }
        }
    }

    switch (flag)
    {
        case 0:
            ftp_reply(sess,FTP_TRANSFEROK,"Transfer complete.");
            break;
        case 1:
            ftp_reply(sess,FTP_BADSENDNET,"Receive file failure.");
            break;
        case 2:
            ftp_reply(sess,FTP_BADSENDFILE,"Write local file failure.");
            break;
    }

    is_urg(sess);
    file_unlock(filefd);
    close(filefd);
    clear_transfer(sess);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6400
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0xc(%rcx), %eax
jne 0x6d39
movq -0x8(%rbp), %rdi
movl $0x1a9, %esi            # imm = 0x1A9
leaq 0x2894(%rip), %rdx      # 0x95c3
callq 0x5600
jmp 0x6fba
movq -0x8(%rbp), %rdi
addq $0x818, %rdi            # imm = 0x818
movl $0x41, %esi
movl $0x1b6, %edx            # imm = 0x1B6
movb $0x0, %al
callq 0x3450
movl %eax, -0xc(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0xc(%rbp), %eax
jne 0x6d8d
movq -0x8(%rbp), %rdi
movl $0x1c3, %esi            # imm = 0x1C3
leaq 0x28da(%rip), %rdx      # 0x964c
callq 0x5600
leaq 0x28e6(%rip), %rdi      # 0x9664
callq 0x3470
movl $0x1, %edi
callq 0x34e0
movl -0xc(%rbp), %edi
callq 0x3aa0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x6dc2
movq -0x8(%rbp), %rdi
movl $0x1c3, %esi            # imm = 0x1C3
leaq 0x289c(%rip), %rdx      # 0x964c
callq 0x5600
movl -0xc(%rbp), %edi
callq 0x3260
jmp 0x6fba
movq -0x8(%rbp), %rax
cmpq $0x0, 0xc30(%rax)
je 0x6de7
movl -0xc(%rbp), %edi
movq -0x8(%rbp), %rax
movq 0xc30(%rax), %rsi
xorl %edx, %edx
callq 0x31e0
jmp 0x6e12
movq -0x8(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0x6e04
movl -0xc(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x31e0
jmp 0x6e10
movl -0xc(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x31d0
jmp 0x6e12
movq -0x8(%rbp), %rdi
movl $0x96, %esi
leaq 0x2847(%rip), %rdx      # 0x9669
callq 0x5600
movl $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpl 0x10(%rcx), %eax
jne 0x6f2c
jmp 0x6e3f
movq -0x8(%rbp), %rdi
callq 0x4dc0
callq 0x5ed0
leaq -0x410(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x3220
movq -0x8(%rbp), %rax
movl 0xc(%rax), %edi
leaq -0x410(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x3280
movl %eax, -0x414(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x414(%rbp), %eax
jne 0x6e9e
callq 0x3050
movq %rax, %rcx
movl $0x4, %eax
cmpl (%rcx), %eax
jne 0x6e9e
jmp 0x6e3f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x414(%rbp), %eax
jne 0x6eb4
movl $0x1, -0x10(%rbp)
jmp 0x6f2a
xorl %eax, %eax
cmpl -0x414(%rbp), %eax
jne 0x6ec7
movl $0x0, -0x10(%rbp)
jmp 0x6f2a
movl $0x1, 0x67cf(%rip)      # 0xd6a0
movq -0x8(%rbp), %rdi
leaq 0x6408(%rip), %rax      # 0xd2e4
movl (%rax), %esi
movl -0x414(%rbp), %edx
callq 0x4e20
movslq -0x414(%rbp), %rax
movq %rax, -0x420(%rbp)
movl -0xc(%rbp), %edi
leaq -0x410(%rbp), %rsi
movslq -0x414(%rbp), %rdx
callq 0x46a0
movq %rax, %rcx
movq -0x420(%rbp), %rax
cmpq %rcx, %rax
je 0x6f25
movl $0x2, -0x10(%rbp)
jmp 0x6f2a
jmp 0x6e3f
jmp 0x6f2c
movl -0x10(%rbp), %eax
movl %eax, -0x424(%rbp)
testl %eax, %eax
je 0x6f55
jmp 0x6f3b
movl -0x424(%rbp), %eax
subl $0x1, %eax
je 0x6f6c
jmp 0x6f48
movl -0x424(%rbp), %eax
subl $0x2, %eax
je 0x6f83
jmp 0x6f98
movq -0x8(%rbp), %rdi
movl $0xe2, %esi
leaq 0x26c1(%rip), %rdx      # 0x9626
callq 0x5600
jmp 0x6f98
movq -0x8(%rbp), %rdi
movl $0x1aa, %esi            # imm = 0x1AA
leaq 0x26fd(%rip), %rdx      # 0x9679
callq 0x5600
jmp 0x6f98
movq -0x8(%rbp), %rdi
movl $0x1c3, %esi            # imm = 0x1C3
leaq 0x26fc(%rip), %rdx      # 0x968f
callq 0x5600
movq -0x8(%rbp), %rdi
callq 0x6110
movl -0xc(%rbp), %edi
callq 0x3ae0
movl -0xc(%rbp), %edi
callq 0x3260
movq -0x8(%rbp), %rdi
callq 0x4cc0
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
nopw %cs:(%rax,%rax)