// File: /workspace/github_c_makefile_star2_O0/pencode-lab[P]Shoit/shoit_sender.c
// Function: update_sender_bucket_infomation
void update_sender_bucket_infomation(shoit_core_t *sender)
{
    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->remainNumberOfPackets = sender->totalNumberOfPackets;                                                                    
                                                                                                                                     
    /*this control send rate*/                                                                                                       
    sender->usecsPerPacket = 8 * sender->payloadSize * 1000 / sender->sendRate;                                                      
    sender->sizeofErrorBitmap = sender->totalNumberOfPackets/8 + 2;                                                                  

    if(sender->errorBitmap){
        free(sender->errorBitmap);
        sender->errorBitmap = NULL;
    } 
    sender->errorBitmap = (char *)malloc(sender->sizeofErrorBitmap+sizeof(shoit_control_t));                                                        
    if (sender->errorBitmap == NULL)
    {                                                   
        SHOIT_LOG("malloc error(%s)\n",strerror(errno));
        return;
    } 

    if(sender->hashTable){
        free(sender->hashTable);
        sender->hashTable = NULL;
    }
    sender->hashTable = (uint64_t *)malloc(sender->totalNumberOfPackets * sizeof(uint64_t));                                         
    if (sender->hashTable == NULL)                                                                                                   
    {                                                                                                                                
        SHOIT_LOG("malloc hashTable failed\n");                                                                                      
        return ;                                                                                                                     
    }                                                                                                                                

    sender->sentNumberOfPackets = 0;
    sender->isFirstBlast = true;
    for (uint64_t i=0; i<sender->totalNumberOfPackets; i++)
    {                            
        sender->hashTable[i] = i;
    }
    shoit_init_error_bitmap(sender);

                     
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
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 0x4785
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 0x47d3
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
movq -0x8(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %eax
shll $0x3, %eax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divl 0x28(%rcx)
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rcx
shrq $0x3, %rcx
addq $0x2, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x484d
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rdi
callq 0x2040
movq -0x8(%rbp), %rax
movq $0x0, 0xd0(%rax)
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rdi
addq $0x1e, %rdi
callq 0x22e0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
jne 0x48b4
jmp 0x487f
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rax, -0x18(%rbp)
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq -0x18(%rbp), %rdi
movq %rax, %rdx
leaq 0x4e60(%rip), %rsi      # 0x9708
movb $0x0, %al
callq 0x3df0
jmp 0x4989
movq -0x8(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
je 0x48e1
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0x2040
movq -0x8(%rbp), %rax
movq $0x0, 0xc8(%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
shlq $0x3, %rdi
callq 0x22e0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
jne 0x492b
jmp 0x4910
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rdi
leaq 0x4df8(%rip), %rsi      # 0x971a
movb $0x0, %al
callq 0x3df0
jmp 0x4989
movq -0x8(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0xe0(%rax)
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x4980
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x494d
movq -0x8(%rbp), %rdi
callq 0x2c20
addq $0x20, %rsp
popq %rbp
retq
nop