// File: /workspace/github_c_makefile_star2_O0/pencode-lab[P]Shoit/shoit_sender.c
// Function: transfer_data_round_circle
static bool transfer_data_round_circle(shoit_core_t *sender)
{
    int done = 0;
    struct timeval curTime, startTime; 
    bool iMore;

    if(sender->verbose>1) SHOIT_LOG("call %s:0\n",__func__);

    /*
    * here need init this round variable,eg: sender->bucket...
    */
    iMore = each_round_transfer_init((void*)sender);
    if(!iMore) {
        if(sender->verbose>1) SHOIT_LOG("No more bucket to be send.\n");
        return iMore;
    }

    /*send buck info to reciever*/ 
    echo_to_receiver_on_tcp(sender,ROUND); 


    sem_wait(&sender->dataSem);/*be wakup:READY signal*/

    gettimeofday(&startTime, NULL);                                                                                                    
    while(iMore && !done && sender->runing){                                                                                                  
        if(sender->verbose>1) SHOIT_LOG("sending UDP packets");                                                                      
        blast_udp_sending(sender); 
        gettimeofday(&curTime, NULL);                                                                                                
                                                                                                                                     
        // send end of UDP signal                                                                                                    
        if(sender->verbose>1) SHOIT_LOG("send to socket %d an end signal.", sender->tcpSockfd);                    
        if(!echo_to_receiver_on_tcp(sender,UDPEND))
            SHOIT_LOG("send to socket %d an end signal error.", sender->tcpSockfd);                                                  
            
        // receive error list                                                                                                        
        sem_wait(&sender->dataSem); /*be wakeup:BITMAP signal*/
        char *errorBitmap = (char*)(sender->errorBitmap + sizeof(shoit_control_t));                                                  
        if ((unsigned char)errorBitmap[0] == 1)
        {
            done = 1;                                                                                                                
            sender->remainNumberOfPackets = 0;                                                                                       
            sender->sentNumberOfPackets = sender->totalNumberOfPackets;                                                              
            if(sender->mapSize>0){
                munmap(sender->bucket, sender->mapSize);
            }

        } else {
            /*
            Congestion Control Algorithms:
            The congestion control is optional.  The algorithm is
            if (lossRate > 0) {
                Rnew = Rold * (0.95 – lossRate);
            }
            */
            sender->remainNumberOfPackets = shoit_update_hash_table(sender,true);/*important!! update hashTable*/                    

            double lossRate = (double)sender->remainNumberOfPackets / (double)sender->totalNumberOfPackets;
            sender->usecsPerPacket = (int) ((double)sender->usecsPerPacket / (1.0 - lossRate - 0.05));
            SHOIT_LOG("loss rate = %.2f, and update send rate,usecsPerPacket(%d).",lossRate,sender->usecsPerPacket);

        }   
    }   


    if(!iMore){
        SHOIT_LOG("No more bucket will be send.\n");
    }
    return iMore;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x5ac1
jmp 0x5a9f
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x3dbf(%rip), %rsi      # 0x9870
leaq 0x3dc3(%rip), %rdx      # 0x987b
movb $0x0, %al
callq 0x3df0
jmp 0x5ac1
movq -0x10(%rbp), %rdi
callq 0x6040
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x5b05
movq -0x10(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x5afa
jmp 0x5adf
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x3da5(%rip), %rsi      # 0x9896
movb $0x0, %al
callq 0x3df0
jmp 0x5afa
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5d69
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x5d80
movq -0x10(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x2080
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
xorl %eax, %eax
cmpl $0x0, -0x3c(%rbp)
movb %al, -0x51(%rbp)
je 0x5b57
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x51(%rbp)
jne 0x5b57
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1a8(%rax)
setne %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x5b63
jmp 0x5d40
movq -0x10(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x5b8a
jmp 0x5b6f
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x3d31(%rip), %rsi      # 0x98b2
movb $0x0, %al
callq 0x3df0
jmp 0x5b8a
movq -0x10(%rbp), %rdi
callq 0x6080
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2180
movq -0x10(%rbp), %rax
cmpl $0x1, 0x5c(%rax)
jle 0x5bce
jmp 0x5bac
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %edx
leaq 0x3d01(%rip), %rsi      # 0x98c6
movb $0x0, %al
callq 0x3df0
jmp 0x5bce
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5d80
cmpl $0x0, %eax
jne 0x5c05
jmp 0x5be3
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %edx
leaq 0x3ceb(%rip), %rsi      # 0x98e7
movb $0x0, %al
callq 0x3df0
jmp 0x5c05
movq -0x10(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x2080
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
addq $0x1e, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x5c7b
movl $0x1, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jbe 0x5c76
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x2310
jmp 0x5d3b
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x2de0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %xmm0
movaps 0x395c(%rip), %xmm3     # 0x9600
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x3960(%rip), %xmm2     # 0x9610
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0x38(%rax), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl 0x58(%rax), %eax
cvtsi2sd %rax, %xmm0
movsd 0x3a0c(%rip), %xmm1     # 0x9700
subsd -0x50(%rbp), %xmm1
movsd 0x39f7(%rip), %xmm2     # 0x96f8
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
movsd -0x50(%rbp), %xmm0
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edx
leaq 0x3bdc(%rip), %rsi      # 0x990e
movb $0x1, %al
callq 0x3df0
jmp 0x5d3b
jmp 0x5b30
cmpl $0x0, -0x3c(%rbp)
jne 0x5d63
jmp 0x5d48
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x3bef(%rip), %rsi      # 0x9949
movb $0x0, %al
callq 0x3df0
jmp 0x5d63
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)