// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x501c
jmp 0x5001
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x49d7(%rip), %rsi      # 0x99ea
movb $0x0, %al
callq 0x3df0
jmp 0x501c
movq -0x10(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
callq 0x2080
movq -0x10(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x505d
jmp 0x5038
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x1a8(%rax), %edx
leaq 0x49c1(%rip), %rsi      # 0x9a15
movb $0x0, %al
callq 0x3df0
jmp 0x505d
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1a8(%rax)
jne 0x5073
xorl %eax, %eax
movl %eax, %edi
callq 0x22d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1a4(%rax)
je 0x515a
leaq 0x7215(%rip), %rdi      # 0xc2a0
leaq 0x422b(%rip), %rsi      # 0x92bd
movl $0x64, %edx
xorl %ecx, %ecx
callq 0x41d0
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x499c(%rip), %rsi      # 0x9a4c
movb $0x0, %al
callq 0x3df0
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x55(%rbp)
jne 0x50e0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1a8(%rax)
setne %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x50e9
jmp 0x5155
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
movq -0x28(%rbp), %rax
subq -0x38(%rbp), %rax
cvtsi2sd %rax, %xmm1
movq -0x20(%rbp), %rax
subq -0x30(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x45d8(%rip), %xmm2     # 0x96f0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x71a4(%rip)     # 0xc2d0
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x7162(%rip), %rsi      # 0xc2a0
xorps %xmm0, %xmm0
callq 0x45b0
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x24a0
jmp 0x50c4
jmp 0x5332
leaq 0x713f(%rip), %rdi      # 0xc2a0
leaq 0x4155(%rip), %rsi      # 0x92bd
movl $0x64, %edx
xorl %ecx, %ecx
callq 0x41d0
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x48e9(%rip), %rsi      # 0x9a6f
movb $0x0, %al
callq 0x3df0
movq $0x0, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x56(%rbp)
jne 0x51be
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1a8(%rax)
setne %al
movb %al, -0x56(%rbp)
movb -0x56(%rbp), %al
testb $0x1, %al
jne 0x51ca
jmp 0x5330
movq 0x70f7(%rip), %rax      # 0xc2c8
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x60(%rbp)
testq %rax, %rax
movss %xmm0, -0x5c(%rbp)
js 0x5206
movss -0x60(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x68(%rbp)
testq %rax, %rax
movss %xmm0, -0x64(%rbp)
js 0x524d
movss -0x68(%rbp), %xmm0
movss %xmm0, -0x64(%rbp)
movss -0x6c(%rbp), %xmm0
movss -0x64(%rbp), %xmm1
divss %xmm1, %xmm0
movss 0x4381(%rip), %xmm1     # 0x95e4
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x18(%rbp)
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
movq -0x28(%rbp), %rax
subq -0x38(%rbp), %rax
cvtsi2sd %rax, %xmm1
movq -0x20(%rbp), %rax
subq -0x30(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x4453(%rip), %xmm2     # 0x96f0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x701f(%rip)     # 0xc2d0
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
cvtsi2ssl -0x18(%rbp), %xmm0
movss 0x431b(%rip), %xmm1     # 0x95e4
divss %xmm1, %xmm0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
shrq $0xa, %rdx
leaq 0x6fc0(%rip), %rsi      # 0xc2a0
callq 0x4410
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x24a0
movq -0x28(%rbp), %rax
subq -0x38(%rbp), %rax
movl $0x1e, %ecx
cqto
idivq %rcx
cmpq -0x40(%rbp), %rax
jbe 0x532b
movq -0x28(%rbp), %rax
subq -0x38(%rbp), %rax
movl $0x1e, %ecx
cqto
idivq %rcx
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movl $0x6, %esi
callq 0x5d80
jmp 0x51a2
jmp 0x5332
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x3f6b(%rip), %rsi      # 0x92bc
movb $0x0, %al
callq 0x3df0
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rcx
subq %rsi, %rdx
cvtsi2sd %rdx, %xmm1
subq %rcx, %rax
addq $-0xf4240, %rax         # imm = 0xFFF0BDC0
cvtsi2sd %rax, %xmm0
movsd 0x436a(%rip), %xmm2     # 0x96f0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
movq 0x6f2a(%rip), %rax      # 0xc2c8
movq %rax, -0x50(%rbp)
movaps 0x4257(%rip), %xmm0     # 0x9600
movq -0x50(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x4256(%rip), %xmm0     # 0x9610
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x4217(%rip), %xmm0     # 0x95e8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movss -0x44(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x53f8
jp 0x53f8
movsd 0x41ff(%rip), %xmm0     # 0x95f0
movsd %xmm0, -0x80(%rbp)
jmp 0x5406
movss -0x44(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x78(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1a4(%rax)
je 0x5461
jmp 0x542c
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
movq -0x50(%rbp), %rdx
shrq $0xa, %rdx
movss -0x44(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x54(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x464d(%rip), %rsi      # 0x9aa5
movb $0x2, %al
callq 0x3df0
jmp 0x54a4
jmp 0x5463
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
movq -0x50(%rbp), %rdx
shrq $0xa, %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0xa, %rcx
movss -0x44(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x54(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x4636(%rip), %rsi      # 0x9ad1
movb $0x2, %al
callq 0x3df0
jmp 0x54a4
leaq 0x6df5(%rip), %rdi      # 0xc2a0
callq 0x4710
xorl %eax, %eax
movl %eax, %edi
callq 0x22d0
nopl (%rax)