// File: /workspace/github_cpp_makefile_star2_O1/lianxings[P]ftp_benchmark/ftp_benchmark.cc
// Function: ftp2null_worker(ftpInfo*, int, bool)
void ftp2null_worker(ftpInfo * pFtp, int id, bool verify) 
{
    string srcPath, dstPath;
    int ioUnit = 256 << 10;
    char * dataBuf = new char[ioUnit];
    char printBuf[1024];
    char sizeStrBuf[128];
    ftplib::accesstype type = ftplib::fileread;
    ftplib::transfermode mode = ftplib::image;
    ftphandle *nData = NULL;

    ftplib * ftpClient = new ftplib();
    int ret = connect_and_login_ftp (ftpClient, pFtp, 0);
    if (ret < 0) {
        if (ret == -2)
            fprintf(stderr, "login ftp server %s failed.\n", pFtp->ftpServer);
        --liveWorkThread;
        return;
    }

    while((!tasksQueue.empty()) || (!exitFlag)) {
        task<fileInfo> taskTmp;
        if (get_task_from_queue(taskTmp) < 0) 
            continue;

        fileInfo srcInfo, dstInfo;
        srcInfo = taskTmp.src;
        dstInfo = taskTmp.dst;
        srcPath = srcInfo.name;
        dstPath = dstInfo.name;
        memset(printBuf, 0, sizeof(printBuf));
        memset(printBuf, 0, sizeof(sizeStrBuf));
        size_to_string(srcInfo.size, sizeStrBuf);
        // get ftp data connection 
        int ret = build_ftp_data_connection(srcPath, type, mode, ftpClient, pFtp, &nData);
        if (ret < 0) {
            ++failed;
            errorSize += srcInfo.size;
            if (ret == -1)
                sprintf(printBuf, "\nget ftp data connection failed: source: %s, destination: null, size: %s\n",\
                                                                                   srcPath.c_str(), sizeStrBuf);
            else
                sprintf(printBuf, "\nre-login ftp server %s failed: source: %s, destination: null, size: %s\n",\
                                                                pFtp->ftpServer , srcPath.c_str(), sizeStrBuf);
            fwrite(printBuf, 1, strlen(printBuf), errorFd);
            write(2, printBuf, strlen(printBuf));
            continue;
        }

		char checkSumBuf[33] = {'\0'};
		char tmp[3] = {'\0'};
        Md5Context md5Context;
        MD5_HASH md5;
        if (verify){
            memset(checkSumBuf, 0, sizeof(checkSumBuf));
            memset(tmp, 0, sizeof(tmp));
            Md5Initialise( &md5Context );
        }

        int readed = 0;
        long long file_size = 0;
        while ((readed = ftpClient->FtpRead(dataBuf, ioUnit, nData)) > 0) {
            finishSize += readed;
            file_size += readed;
            if (verify) {
                Md5Update( &md5Context, (const void*)dataBuf, readed);
            }
        }
        if (readed < 0) {
            ++failed;
            errorSize += srcInfo.size;
            sprintf(printBuf, "\nread source file failed: source: %s, destination: null, size: %s\n",\
                srcPath.c_str(), sizeStrBuf);
            fwrite(printBuf, 1, strlen(printBuf), errorFd);
            write(1, printBuf, strlen(printBuf));
        } else {
            ++finished;
            if (verify) {
                Md5Finalise( &md5Context, &md5);
                for(int j = 0; j < sizeof(md5); j++) {
                    sprintf( tmp,"%2.2x", md5.bytes[j]);
                    strcat(checkSumBuf, tmp);
                }
            }
        }

        ftpClient->FtpClose(nData);

        if(gFtpDebug)
            printf("Thread:%-8ld  sock:%-4d  read file size: %lld\n", syscall(SYS_gettid), nData->handle, file_size);

        if (readed >= 0 && verify) {
            string newSrcPath = srcPath + ".md5";
            int ret = build_ftp_data_connection(newSrcPath, type, mode, ftpClient, pFtp, &nData);
            if (ret < 0) {
                if (ret == -1)
                    sprintf(printBuf, "\nget ftp data connection failed: source: %s, destination: null\n", newSrcPath.c_str());
                else
                    sprintf(printBuf, "\nre-login ftp server %s failed: source: %s, destination: null\n",\
                                                                   pFtp->ftpServer , newSrcPath.c_str());
                fwrite(printBuf, 1, strlen(printBuf), errorFd);
                write(2, printBuf, strlen(printBuf));
                continue;
            }

            memset(dataBuf, 0, ioUnit);
            if (ftpClient->FtpRead(dataBuf, ioUnit, nData) <= 0) {
                ++verifyFailed;
                sprintf(printBuf, "\nread md5 file %s failed\n", newSrcPath.c_str());
                fwrite(printBuf, 1, strlen(printBuf), errorFd);
                //write(1, printBuf, strlen(printBuf));
            } else if (strncmp(checkSumBuf, dataBuf, 32) != 0) {
                ++verifyFailed;
				sprintf(printBuf, "\nverify file '%s' failed: upload md5: %s, download md5: %s\n", \
                                                           srcPath.c_str(), dataBuf, checkSumBuf);
                fwrite(printBuf, 1, strlen(printBuf), errorFd);
                write(1, printBuf, strlen(printBuf));
			}
            ftpClient->FtpClose(nData);
        }

        if (failed > 10) {
            --liveWorkThread;
            break;
        }
    }

    ftpClient->Quit();
    delete ftpClient;
    delete [] dataBuf;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6d8, %rsp            # imm = 0x6D8
movl %edx, %ebp
movq %rdi, 0x20(%rsp)
leaq 0x80(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x140(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movl $0x40000, %edi          # imm = 0x40000
callq 0x4030
movq %rax, %r14
movq $0x0, 0x18(%rsp)
movl $0x8, %edi
callq 0x43f0
movq %rax, %r15
movq %rax, %rdi
callq 0xe240
movq %r15, %rdi
movq 0x20(%rsp), %rsi
callq 0x5cc5
testl %eax, %eax
js 0x8b3c
movq %r15, 0x10(%rsp)
leaq 0x58(%rsp), %r12
leaq 0x2d0(%rsp), %r13
leaq 0xe0(%rsp), %rbx
movl %ebp, 0x94(%rsp)
movq %r14, 0x128(%rsp)
movq 0x10067(%rip), %rax     # 0x18430
cmpq 0x10040(%rip), %rax     # 0x18410
jne 0x83e0
movl 0x10118(%rip), %eax     # 0x184f0
testl %eax, %eax
jne 0x8b10
leaq 0x160(%rsp), %rax
movq %rax, 0x150(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x158(%rsp)
movb %cl, 0x160(%rsp)
movq %rcx, 0x170(%rsp)
leaq 0x188(%rsp), %rax
movq %rax, 0x178(%rsp)
movq %rcx, 0x180(%rsp)
movb %cl, 0x188(%rsp)
movq %rcx, 0x198(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x5d62
testl %eax, %eax
js 0x8694
movq %r12, 0x48(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x50(%rsp)
movb %cl, 0x58(%rsp)
movq %rcx, 0x68(%rsp)
leaq 0xa8(%rsp), %rax
movq %rax, 0x98(%rsp)
movq %rcx, 0xa0(%rsp)
movb %cl, 0xa8(%rsp)
movq %rcx, 0xb8(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x4200
movq 0x170(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x4200
movq 0x198(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x4200
leaq 0x130(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x4200
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
xorl %esi, %esi
callq 0x4210
movq 0x68(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0xdca2
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0xd3ee
movq %rbx, %rdi
movl $0x3, %esi
movl $0x49, %edx
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %r8
leaq 0x18(%rsp), %r9
callq 0x5e4c
movl %eax, %ebx
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x8577
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4400
testl %ebx, %ebx
js 0x86a6
xorps %xmm0, %xmm0
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
xorl %eax, %eax
movb %al, 0x120(%rsp)
movb %al, 0xe(%rsp)
movw $0x0, 0xc(%rsp)
testb %bpl, %bpl
je 0x85dc
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
xorl %eax, %eax
movb %al, 0x120(%rsp)
movb %al, 0xe(%rsp)
movw $0x0, 0xc(%rsp)
leaq 0x238(%rsp), %rdi
callq 0x10a74
xorl %r13d, %r13d
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movl $0x40000, %edx          # imm = 0x40000
callq 0xfad4
movl %eax, %ebx
testl %eax, %eax
jle 0x8622
movl %ebx, %eax
lock
addq %rax, 0xff22(%rip)      # 0x18528
addq %rax, %r13
testb %bpl, %bpl
je 0x85df
leaq 0x238(%rsp), %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x10a87
jmp 0x85df
js 0x86ef
lock
incq 0xfed8(%rip)            # 0x18508
testb %bpl, %bpl
leaq 0x100(%rsp), %rbp
leaq 0x9cbe(%rip), %r15      # 0x12300
leaq 0xc(%rsp), %r14
je 0x8761
leaq 0x238(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x1144b
xorl %r12d, %r12d
movzbl 0x1a0(%rsp,%r12), %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x40a0
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4700
incq %r12
cmpq $0x10, %r12
jne 0x8665
jmp 0x8761
leaq 0x150(%rsp), %rdi
callq 0xbe58
jmp 0x83c2
lock
incq 0xfe62(%rip)            # 0x18510
movq 0x68(%rsp), %rax
lock
addq %rax, 0xfe75(%rip)      # 0x18530
cmpl $-0x1, %ebx
je 0x8933
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movq 0x70(%rsp), %rcx
movq %r13, %rdi
leaq 0x9e4a(%rip), %rsi      # 0x12525
leaq 0x1b0(%rsp), %r8
xorl %eax, %eax
callq 0x40a0
jmp 0x8951
lock
incq 0xfe19(%rip)            # 0x18510
movq 0x68(%rsp), %rax
lock
addq %rax, 0xfe2c(%rip)      # 0x18530
movq 0x70(%rsp), %rdx
leaq 0x2d0(%rsp), %r12
movq %r12, %rdi
leaq 0x9e53(%rip), %rsi      # 0x1256e
leaq 0x1b0(%rsp), %rcx
xorl %eax, %eax
callq 0x40a0
movq %r12, %rdi
callq 0x4180
movq 0xfdaf(%rip), %rcx      # 0x184e8
movl $0x1, %esi
movq %r12, %rdi
movq %rax, %rdx
callq 0x4760
movq %r12, %rdi
callq 0x4180
movl $0x1, %edi
movq %r12, %rsi
movq %rax, %rdx
callq 0x4140
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0xfa02
cmpb $0x1, 0xfd61(%rip)      # 0x184d8
jne 0x87a1
movl $0xba, %edi
xorl %eax, %eax
callq 0x4070
movq 0x18(%rsp), %rcx
movl 0x10(%rcx), %edx
leaq 0x9e1d(%rip), %rdi      # 0x125b1
movq %rax, %rsi
movq %r13, %rcx
xorl %eax, %eax
callq 0x4060
testl %ebx, %ebx
setne %al
movl 0x94(%rsp), %ebp
movl %ebp, %ecx
xorb $0x1, %cl
orb %al, %cl
leaq 0x58(%rsp), %r12
movq 0x128(%rsp), %r14
jne 0x8a87
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0xd3ee
movq %rbx, %rdi
leaq 0x9b11(%rip), %rsi      # 0x12306
callq 0x4750
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0xd3ee
leaq 0xc0(%rsp), %rdi
movl $0x3, %esi
movl $0x49, %edx
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %r8
leaq 0x18(%rsp), %r9
callq 0x5e4c
movl %eax, %r13d
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x8872
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4400
testl %r13d, %r13d
js 0x898d
movl $0x40000, %edx          # imm = 0x40000
movq %r14, %rdi
xorl %esi, %esi
callq 0x4210
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movl $0x40000, %edx          # imm = 0x40000
callq 0xfad4
testl %eax, %eax
leaq 0x100(%rsp), %rdi
jle 0x89bb
movl $0x20, %edx
movq %r14, %rsi
callq 0x41b0
testl %eax, %eax
je 0x8a00
lock
incq 0xfc52(%rip)            # 0x18520
movq 0x70(%rsp), %rdx
leaq 0x2d0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x9bba(%rip), %rsi      # 0x1249f
movq %r14, %rcx
leaq 0x100(%rsp), %r8
xorl %eax, %eax
callq 0x40a0
movq %rbx, %rdi
callq 0x4180
movq 0xfbe2(%rip), %rcx      # 0x184e8
movl $0x1, %esi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x4760
movq %rbx, %rdi
callq 0x4180
movl $0x1, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4140
jmp 0x8a00
movq 0x70(%rsp), %rdx
movq %r13, %rdi
leaq 0x9b99(%rip), %rsi      # 0x124db
leaq 0x1b0(%rsp), %rcx
xorl %eax, %eax
callq 0x40a0
movq %r13, %rdi
callq 0x4180
movq 0xfb88(%rip), %rcx      # 0x184e8
movl $0x1, %esi
movq %r13, %rdi
movq %rax, %rdx
callq 0x4760
movq %r13, %rdi
callq 0x4180
movl $0x2, %edi
movq %r13, %rsi
movq %rax, %rdx
callq 0x4140
jmp 0x8aa7
cmpl $-0x1, %r13d
je 0x8a11
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movq 0x28(%rsp), %rcx
leaq 0x2d0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x9c6e(%rip), %rsi      # 0x12620
xorl %eax, %eax
callq 0x40a0
jmp 0x8a2f
lock
incq 0xfb5d(%rip)            # 0x18520
movq 0x28(%rsp), %rdx
leaq 0x2d0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x9aab(%rip), %rsi      # 0x12485
xorl %eax, %eax
callq 0x40a0
movq %rbx, %rdi
callq 0x4180
movq 0xfaf8(%rip), %rcx      # 0x184e8
movl $0x1, %esi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x4760
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0xfa02
jmp 0x8a66
movq 0x28(%rsp), %rdx
leaq 0x2d0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x9bb8(%rip), %rsi      # 0x125e0
xorl %eax, %eax
callq 0x40a0
movq %rbx, %rdi
callq 0x4180
movq 0xfaaa(%rip), %rcx      # 0x184e8
movl $0x1, %esi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x4760
movq %rbx, %rdi
callq 0x4180
movl $0x2, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4140
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x8a82
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4400
testl %r13d, %r13d
js 0x8b04
movq 0xfa82(%rip), %rax      # 0x18510
cmpq $0xb, %rax
leaq 0x2d0(%rsp), %r13
jl 0x8aa7
lock
decl 0xfa55(%rip)            # 0x184f8
movb $0x1, %bl
jmp 0x8aa9
xorl %ebx, %ebx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x8ace
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x4400
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x8ae5
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4400
leaq 0x150(%rsp), %rdi
callq 0xbe58
testb %bl, %bl
leaq 0xe0(%rsp), %rbx
je 0x83c2
jmp 0x8b10
xorl %ebx, %ebx
leaq 0x2d0(%rsp), %r13
jmp 0x8aa9
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x104c4
movq %rbx, %rdi
callq 0xe31a
movl $0x8, %esi
movq %rbx, %rdi
callq 0x4400
movq %r14, %rdi
callq 0x44e0
jmp 0x8b48
cmpl $-0x2, %eax
je 0x8ba1
lock
decl 0xf9b0(%rip)            # 0x184f8
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x8b6d
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x4400
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x8b8f
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4400
addq $0x6d8, %rsp            # imm = 0x6D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rdi
callq 0x4935
jmp 0x8b41
movq %rax, %rbx
movl $0x8, %esi
movq %r15, %rdi
callq 0x4400
jmp 0x8ca0
jmp 0x8bc6
jmp 0x8bc6
movq %rax, %rbx
jmp 0x8ca0
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x8c01
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4400
jmp 0x8c01
jmp 0x8bfe
jmp 0x8c41
jmp 0x8c54
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x8c44
movq 0x38(%rsp), %rsi
jmp 0x8c37
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x8c44
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4400
jmp 0x8c44
movq %rax, %rbx
leaq 0x58(%rsp), %r12
jmp 0x8c57
jmp 0x8c54
movq %rax, %rbx
jmp 0x8c93
jmp 0x8c54
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x8c7c
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x4400
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x8c93
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4400
leaq 0x150(%rsp), %rdi
callq 0xbe58
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x8cc5
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x4400
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x8ce7
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4400
movq %rbx, %rdi
callq 0x46f0