// File: /workspace/github_c_makefile_star2_O0/pencode-lab[P]Shoit/shoit_sender.c
// Function: each_round_fetch_bucket
static bool each_round_fetch_bucket(shoit_core_t *sender)
{

    size_t nread =0;
    bool retval=false;

    do{
        if(sender->useMmap) {

            if(sender->leftSize<=0) { retval =false; break;}

            size_t mapSize = (sender->leftSize/sender->bucketSize > 0) ? sender->bucketSize: sender->leftSize; 
            off_t offset= sender->bucketSize *((sender->fileSize-sender->leftSize)/sender->bucketSize); 
    

            sender->bucket= (char *)mmap(NULL,mapSize, PROT_READ, MAP_SHARED, sender->fromFd,offset); 
            if(sender->bucket==NULL){
                SHOIT_LOG("Mmap failed. %s\n",strerror(errno));
                retval = false;
                break;
            }
            sender->bucketSize = mapSize;
            sender->mapSize = mapSize;
            sender->leftSize -= mapSize;

            retval =true; /*first*/
            break; 
        }

        /*for stream*/
        nread = shoit_network_readn(sender->fromFd,sender->bucket,sender->bucketSize);
        if(nread<=0) break;
        if(nread!=sender->bucketSize){/*need recount the sender's parameter*/
            sender->bucketSize = nread;

            if (sender->bucketSize % sender->payloadSize == 0)                                                                               
            {                                                                                                                                
                sender->totalNumberOfPackets = sender->bucketSize/sender->payloadSize;                                                       
                sender->lastPayloadSize = sender->payloadSize;                                                                               
            }                                                                                                                                
            else                                                                                                                             
            {                                                                                                                                
                sender->totalNumberOfPackets = sender->bucketSize/sender->payloadSize + 1; /* the last packet is not full */                 
                sender->lastPayloadSize = sender->bucketSize - sender->payloadSize * (sender->totalNumberOfPackets - 1);                     
            }                                                                                                                                
            sender->sizeofErrorBitmap = sender->totalNumberOfPackets/8 + 2;                                                                  

        }
        retval = true;

    }while(0);
    
    return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x1a0(%rax)
je 0x647e
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
ja 0x6363
movl $0x0, -0x14(%rbp)
jmp 0x6583
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divq 0x8(%rcx)
cmpq $0x0, %rax
jbe 0x6389
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x6395
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
subq 0x18(%rcx), %rax
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divq 0x8(%rcx)
movq %rax, %rcx
movq -0x38(%rbp), %rax
imulq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0xf8(%rax), %r8d
movq -0x28(%rbp), %r9
xorl %eax, %eax
movl %eax, %edi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x20f0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x6447
jmp 0x640b
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rax, -0x40(%rbp)
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0x3533(%rip), %rsi      # 0x9967
movb $0x0, %al
callq 0x3df0
movl $0x0, -0x14(%rbp)
jmp 0x6583
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x18(%rax)
movl $0x1, -0x14(%rbp)
jmp 0x6583
movq -0x8(%rbp), %rax
movl 0xf8(%rax), %edi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x3940
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
ja 0x64ac
jmp 0x6583
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x657c
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x2c(%rcx), %ecx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x6513
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x2c(%rcx), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x30(%rax)
jmp 0x6561
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x2c(%rcx), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x2c(%rcx), %ecx
movq -0x8(%rbp), %rdx
movq 0x38(%rdx), %rdx
subq $0x1, %rdx
imulq %rdx, %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rcx
shrq $0x3, %rcx
addq $0x2, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xd8(%rax)
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)