// File: /workspace/github_c_makefile_star2_O1/pencode-lab[P]Shoit/shoit_sender.c
// Function: progress_thread_run
static void progress_thread_run(void *argv)
{
    shoit_core_t *sender = (shoit_core_t *)argv;
    int done=0;
    int prog=0;
    struct timeval curTime, startTime;


    if(sender->verbose >1) SHOIT_LOG("start progress thread and block sem wait.\n");
    sem_wait(&sender->progSem);
    if(sender->verbose >1) SHOIT_LOG("start progress thread and unblock sem wait.runing[%d]\n",sender->runing);
    if(!sender->runing) pthread_exit(0);


    if(sender->iStream){
        shoit_progress_init(&progress, "", 100, PROGRESS_NUM_STYLE);
        SHOIT_LOG("Mbit/s      Sent(Kbytes)  time(s)\n") ;

        gettimeofday(&startTime, NULL);
        while(!done && sender->runing){
            gettimeofday(&curTime, NULL); 
            progress.utime = (curTime.tv_sec - startTime.tv_sec) + 1e-6*(curTime.tv_usec - startTime.tv_usec);
            shoit_progress_for_stream(sender->log,&progress,0);  
            usleep(1000000);

        }
        
    }else{
        shoit_progress_init(&progress, "", 100, PROGRESS_NUM_STYLE);
        SHOIT_LOG("Mbit/s      sent/total(Kbytes)  time(s)     progress\n") ;
        uint64_t timeout=0;
        gettimeofday(&startTime, NULL);
        while(!done && sender->runing){

            prog = (float)progress.total/ (float) sender->fileSize * 100;
            gettimeofday(&curTime, NULL);
            progress.utime =(curTime.tv_sec - startTime.tv_sec) + 1e-6*(curTime.tv_usec - startTime.tv_usec);
            shoit_progress_show_all(sender->log,&progress,(int)prog/100.0f,(long)(sender->fileSize >>10));       
            usleep(1000000);
            if(((curTime.tv_sec - startTime.tv_sec)/TIMEOUT )> timeout ){
                timeout  = (curTime.tv_sec - startTime.tv_sec)/TIMEOUT;
                echo_to_receiver_on_tcp(sender,HEART);
            }
                                                                                                                                     
        }       
    }


    gettimeofday(&curTime, NULL);                                                                                                    
    SHOIT_LOG("\n");                                                                                                            
    {//show complete info                                                                                                            
                                                                                                                                     
        float dt = (curTime.tv_sec - startTime.tv_sec) +                                                                             
                 1e-6*(curTime.tv_usec - startTime.tv_usec - 1000000);                                                                         
        uint64_t sent = progress.total; 
        float mbps = 1e-6 * 8*sent / (dt == 0 ? .01 : dt);
        if(sender->iStream)
            SHOIT_LOG("\nComplete transfer %dK in %.2fs (%g Mbit/s)",(sent>>10), dt, mbps);                                                  
        else
            SHOIT_LOG("\nComplete transfer %d/%dK in %.2fs (%g Mbit/s)",(sent>>10),(sender->bucketSize>>10), dt, mbps); 
        
    }                                                                                                                                

    shoit_progress_destroy(&progress);
    pthread_exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
cmpl $0x2, 0x5c(%rdi)
jl 0x490a
movq 0xe8(%rbx), %rdi
leaq 0x2019(%rip), %rsi      # 0x691c
xorl %eax, %eax
callq 0x3741
leaq 0x100(%rbx), %rdi
callq 0x2080
cmpl $0x2, 0x5c(%rbx)
jl 0x4937
movq 0xe8(%rbx), %rdi
movl 0x1a8(%rbx), %edx
leaq 0x2017(%rip), %rsi      # 0x6947
xorl %eax, %eax
callq 0x3741
cmpl $0x0, 0x1a8(%rbx)
je 0x4c7a
movl 0x1a4(%rbx), %ebp
leaq 0x494f(%rip), %rdi      # 0x92a0
leaq 0x189d(%rip), %rsi      # 0x61f5
movl $0x64, %edx
xorl %ecx, %ecx
callq 0x38dc
movq 0xe8(%rbx), %rdi
testl %ebp, %ebp
jne 0x4ada
leaq 0x2027(%rip), %rsi      # 0x69a1
xorl %eax, %eax
callq 0x3741
movq %rsp, %rdi
xorl %esi, %esi
callq 0x2170
cmpl $0x0, 0x1a8(%rbx)
je 0x4b7a
movq (%rsp), %rbp
movq 0x8(%rsp), %r14
xorl %r15d, %r15d
movq 0x491d(%rip), %rax      # 0x92c8
testq %rax, %rax
js 0x49ba
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
jmp 0x49d2
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
movq 0x10(%rbx), %rax
testq %rax, %rax
js 0x49e5
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x49fd
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
divss %xmm0, %xmm1
movss 0x1b2f(%rip), %xmm0     # 0x6538
mulss %xmm0, %xmm1
movaps %xmm1, 0x20(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x2170
movq 0x10(%rsp), %r12
subq %rbp, %r12
movq 0x18(%rsp), %rax
subq %r14, %rax
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x1c0a(%rip), %xmm1     # 0x6650
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x4877(%rip)     # 0x92d0
movq 0x10(%rbx), %rdx
movq 0xe8(%rbx), %rdi
cvttps2dq 0x20(%rsp), %xmm0
cvtdq2ps %xmm0, %xmm0
divss 0x1ac3(%rip), %xmm0     # 0x6538
shrq $0xa, %rdx
leaq 0x4820(%rip), %rsi      # 0x92a0
callq 0x39a2
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x24a0
movq %r12, %rax
movabsq $-0x7777777777777777, %rcx # imm = 0x8888888888888889
imulq %rcx
movq %rdx, %r13
addq %r12, %r13
movq %r13, %rax
shrq $0x3f, %rax
sarq $0x4, %r13
addq %rax, %r13
cmpq %r15, %r13
jbe 0x4ac8
movq %rbx, %rdi
movl $0x6, %esi
callq 0x4c81
movq %r13, %r15
cmpl $0x0, 0x1a8(%rbx)
jne 0x49a4
jmp 0x4b7a
leaq 0x1e9d(%rip), %rsi      # 0x697e
xorl %eax, %eax
callq 0x3741
movq %rsp, %rdi
xorl %esi, %esi
callq 0x2170
cmpl $0x0, 0x1a8(%rbx)
je 0x4b7a
movq (%rsp), %r12
movq 0x8(%rsp), %r13
leaq 0x10(%rsp), %r14
leaq 0x4790(%rip), %r15      # 0x92a0
movq %r14, %rdi
xorl %esi, %esi
callq 0x2170
movq 0x10(%rsp), %rax
subq %r12, %rax
movq 0x18(%rsp), %rcx
subq %r13, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x1b0e(%rip), %xmm1     # 0x6650
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x477b(%rip)     # 0x92d0
movq 0xe8(%rbx), %rdi
xorps %xmm0, %xmm0
movq %r15, %rsi
callq 0x3ae4
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x24a0
cmpl $0x0, 0x1a8(%rbx)
jne 0x4b10
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2170
movq 0xe8(%rbx), %rdi
leaq 0x165d(%rip), %rsi      # 0x61f4
xorl %eax, %eax
callq 0x3741
movq (%r14), %rax
subq (%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq 0x8(%r14), %rax
subq 0x8(%rsp), %rax
addq $-0xf4240, %rax         # imm = 0xFFF0BDC0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x1a84(%rip), %xmm1     # 0x6650
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movq 0x46ea(%rip), %rdx      # 0x92c8
movq %rdx, %xmm2
punpckldq 0x1965(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x196d(%rip), %xmm2     # 0x6560
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
mulsd 0x1941(%rip), %xmm1     # 0x6548
xorpd %xmm2, %xmm2
ucomiss %xmm2, %xmm0
cvtss2sd %xmm0, %xmm0
movaps %xmm0, %xmm2
jne 0x4c24
movaps %xmm0, %xmm2
jp 0x4c24
movsd 0x191c(%rip), %xmm2     # 0x6540
divsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
shrq $0xa, %rdx
cmpl $0x0, 0x1a4(%rbx)
movq 0xe8(%rbx), %rdi
jne 0x4c5c
movq 0x8(%rbx), %rcx
shrq $0xa, %rcx
cvtss2sd %xmm1, %xmm1
leaq 0x1db0(%rip), %rsi      # 0x6a03
movb $0x2, %al
callq 0x3741
jmp 0x4c6e
cvtss2sd %xmm1, %xmm1
leaq 0x1d70(%rip), %rsi      # 0x69d7
movb $0x2, %al
callq 0x3741
leaq 0x462b(%rip), %rdi      # 0x92a0
callq 0x3bac
xorl %edi, %edi
callq 0x22d0