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

    sem_wait(&receiver->progSem);
    if(!receiver->runing) pthread_exit(0);

    shoit_progress_init(&progress, "", 100, PROGRESS_NUM_STYLE);
    if(receiver->iStream){
        SHOIT_LOG("Mbit/s      Recv(Kbytes)  time(s)\n") ;
        gettimeofday(&startTime, NULL);
        while(!done && receiver->runing){
            gettimeofday(&curTime, NULL);
            progress.utime = (curTime.tv_sec - startTime.tv_sec) + 1e-6*(curTime.tv_usec - startTime.tv_usec);
            shoit_progress_for_stream(receiver->log,&progress,0);
            usleep(1000000);
        }                                                                                                                            
                                                                                                                                     
    }else{    

        SHOIT_LOG("Mbit/s      recv/total(Kbytes)  time(s)     progress\n") ;
        gettimeofday(&startTime, NULL);
        while(!done && receiver->runing){
            prog = (float) progress.total / (float) receiver->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(receiver->log,&progress,(int)prog/100.0f,(long)(receiver->fileSize >>10));
            usleep(1000000);
        }
    }

    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 got =progress.total; 
        float mbps = 1e-6 * 8 * got / (dt==0 ? .01 : dt);                                                                        

        if(receiver->iStream)
            SHOIT_LOG("\nComplete transfer %dK in %.2fs (%g Mbit/s)",(long)(got>>10), dt, mbps);
        else
            SHOIT_LOG("\nComplete transfer %d/%dK in %.2fs (%g Mbit/s)",(long)(got>>10), (long)(receiver->bucketSize>>10), dt, mbps);
    }
    shoit_progress_destroy(&progress);
    pthread_exit(0);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
addq $0x100, %rdi            # imm = 0x100
callq 0x2080
cmpl $0x0, 0x1a8(%rbx)
je 0x5e34
leaq 0x379b(%rip), %rdi      # 0x92d8
leaq 0x6b1(%rip), %rsi       # 0x61f5
movl $0x64, %edx
xorl %ecx, %ecx
callq 0x38e0
cmpl $0x0, 0x1a4(%rbx)
movq 0xe8(%rbx), %rdi
jne 0x5c96
leaq 0x10af(%rip), %rsi      # 0x6c1a
xorl %eax, %eax
callq 0x374a
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2170
cmpl $0x0, 0x1a8(%rbx)
movq (%r14), %r12
je 0x5d37
movq 0x18(%rsp), %r13
leaq 0x373b(%rip), %r14      # 0x92d8
movq %rsp, %r15
movq 0x3759(%rip), %rax      # 0x9300
testq %rax, %rax
js 0x5bb6
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
jmp 0x5bce
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 0x5be1
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x5bf9
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
divss %xmm0, %xmm1
movss 0x913(%rip), %xmm0      # 0x6518
mulss %xmm0, %xmm1
movaps %xmm1, 0x20(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x2170
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %r13, %rcx
subq %r12, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0xa31(%rip), %xmm1      # 0x6670
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x36b6(%rip)     # 0x9308
movq 0x10(%rbx), %rdx
movq 0xe8(%rbx), %rdi
cvttps2dq 0x20(%rsp), %xmm0
cvtdq2ps %xmm0, %xmm0
divss 0x8aa(%rip), %xmm0      # 0x6518
shrq $0xa, %rdx
movq %r14, %rsi
callq 0x39a6
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x24a0
cmpl $0x0, 0x1a8(%rbx)
jne 0x5ba0
jmp 0x5d37
leaq 0xf5a(%rip), %rsi       # 0x6bf7
xorl %eax, %eax
callq 0x374a
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2170
cmpl $0x0, 0x1a8(%rbx)
movq (%r14), %r12
je 0x5d37
movq 0x18(%rsp), %r13
movq %rsp, %r14
leaq 0x360a(%rip), %r15      # 0x92d8
movq %r14, %rdi
xorl %esi, %esi
callq 0x2170
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %r13, %rcx
subq %r12, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x971(%rip), %xmm1      # 0x6670
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x35f6(%rip)     # 0x9308
movq 0xe8(%rbx), %rdi
xorps %xmm0, %xmm0
movq %r15, %rsi
callq 0x3ac3
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x24a0
cmpl $0x0, 0x1a8(%rbx)
jne 0x5cce
movq %rsp, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2170
movq 0xe8(%rbx), %rdi
leaq 0x4a2(%rip), %rsi       # 0x61f4
xorl %eax, %eax
callq 0x374a
movq (%r14), %rax
subq %r12, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq 0x8(%r14), %rax
subq 0x18(%rsp), %rax
addq $-0xf4240, %rax         # imm = 0xFFF0BDC0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x8ea(%rip), %xmm1      # 0x6670
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movq 0x3568(%rip), %rdx      # 0x9300
movq %rdx, %xmm2
punpckldq 0x78b(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x793(%rip), %xmm2      # 0x6540
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
mulsd 0x767(%rip), %xmm1      # 0x6528
xorpd %xmm2, %xmm2
ucomiss %xmm2, %xmm0
cvtss2sd %xmm0, %xmm0
movaps %xmm0, %xmm2
jne 0x5dde
movaps %xmm0, %xmm2
jp 0x5dde
movsd 0x742(%rip), %xmm2      # 0x6520
divsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
shrq $0xa, %rdx
cmpl $0x0, 0x1a4(%rbx)
movq 0xe8(%rbx), %rdi
jne 0x5e16
movq 0x8(%rbx), %rcx
shrq $0xa, %rcx
cvtss2sd %xmm1, %xmm1
leaq 0xc16(%rip), %rsi       # 0x6a23
movb $0x2, %al
callq 0x374a
jmp 0x5e28
cvtss2sd %xmm1, %xmm1
leaq 0xbd6(%rip), %rsi       # 0x69f7
movb $0x2, %al
callq 0x374a
leaq 0x34a9(%rip), %rdi      # 0x92d8
callq 0x3b8b
xorl %edi, %edi
callq 0x22d0