// File: /workspace/github_c_makefile_star2_O1/pencode-lab[P]Shoit/shoit_sender.c
// Function: sender_run_loop
void sender_run_loop(shoit_core_t *sender,uint32_t sendRate,uint32_t packetSize)
{                                                                                                                                    

    catch_signal_init();
    shoit_init_synch(sender);

    memset(&progress,0,sizeof(progress_t));
    progress.total =0;

    sender->udpRemotePort = sender->tcpPort;
    sender->udpLocalPort = sender->udpRemotePort +1;

    /*ready for sender init
    *assignment value to sender                                                                                               
    */

    if(sender->callbacks->on_open_data(sender)==false){                                                                  
        SHOIT_LOG("callbacks open data storage return false,will return.");                                                                    
        return;                                                                                                                  
    }  

    int pageSize = (int)sysconf(_SC_PAGESIZE);//4096 or 8192..
    if(sender->iStream){
        sender->fileSize =0;/*stream,don't know file size*/
        sender->bucketSize = packetSize*pageSize*64;
        sender->bucket= (char *)malloc(sender->bucketSize);                                                                                  
        sender->useMmap=false;    

        if(sender->bucket==NULL){                                                                                                        
            SHOIT_LOG("bucket is NULL,error(%s)\n",strerror(errno));                                                                     
            return;                                                                                                                      
        }   

    }else if(sender->fileName!=NULL){
        uint64_t bucketSize = pageSize*packetSize*256*1;/*1G, pageSize 4096*/                                                        
        uint64_t fileSize = sender->fileSize;                                                                                        
        if(fileSize < bucketSize){                                                                                                       
            if(fileSize%pageSize)                                                                                                        
                bucketSize = fileSize;                                                                                                   
            else{                                                                                                                        
                bucketSize = pageSize*((fileSize/pageSize)+1);                                                                           
            }                                                                                                                            
            fileSize = bucketSize;                                                                                                       
        }                                                                                                                            
                                                                                                                                     
        sender->fileSize = fileSize;                                                                                                 
        sender->leftSize = sender->fileSize;                                                                                         
        sender->bucketSize = bucketSize;

        sender->bucket=NULL;                                                                                                         
        sender->useMmap=true; 

            
    }

    sender->sendRate = sendRate;
    sender->payloadSize =packetSize;
    sender->packetSize = sender->payloadSize + sizeof(shoit_udp_hdr);


    update_sender_bucket_infomation(sender);

    /*core loop*/
    _sender_run_loop(sender);                                                                           


    /*                                                                                                                               
    *free sender and return                                                                                                          
    */                                                                                                                               
    sender_free(sender);                                                                                                             
                                                                                                                                     
    return;                                                                                                                          
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
leaq 0x10f3(%rip), %rsi      # 0x4df4
movl $0xd, %edi
callq 0x2230
movq %rbx, %rdi
callq 0x2b31
xorps %xmm0, %xmm0
movups %xmm0, 0x55a3(%rip)     # 0x92c0
movups %xmm0, 0x558c(%rip)     # 0x92b0
movups %xmm0, 0x5575(%rip)     # 0x92a0
movq $0x0, 0x559a(%rip) # 0x92d0
movl 0x9c(%rbx), %eax
movl %eax, 0x98(%rbx)
incl %eax
movl %eax, 0xa0(%rbx)
movq 0x1b0(%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
testl %eax, %eax
je 0x3dd8
movl $0x1e, %edi
callq 0x23a0
cmpl $0x0, 0x1a4(%rbx)
je 0x3dfe
movq $0x0, 0x10(%rbx)
movl %ebp, %edi
imull %eax, %edi
shll $0x6, %edi
movq %rdi, 0x8(%rbx)
callq 0x22e0
movq %rax, (%rbx)
movl $0x0, 0x1a0(%rbx)
testq %rax, %rax
jne 0x3e56
movq 0xe8(%rbx), %rbx
callq 0x2060
movl (%rax), %edi
callq 0x2450
leaq 0x28ff(%rip), %rsi      # 0x66b9
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3741
movq 0xe8(%rbx), %rdi
leaq 0x289d(%rip), %rsi      # 0x6683
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3741
cmpq $0x0, 0xf0(%rbx)
je 0x3e56
movl %ebp, %esi
imull %eax, %esi
shll $0x8, %esi
movq 0x10(%rbx), %rcx
cmpq %rsi, %rcx
jae 0x3e39
movslq %eax, %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
movq %rcx, %rsi
testq %rdx, %rdx
jne 0x3e39
incq %rax
imulq %rdi, %rax
movq %rax, %rsi
movq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq %rcx, 0x18(%rbx)
movq %rsi, 0x8(%rbx)
movq $0x0, (%rbx)
movl $0x1, 0x1a0(%rbx)
movl %r14d, 0x28(%rbx)
movl %ebp, 0x2c(%rbx)
addl $0xc, %ebp
movl %ebp, 0x34(%rbx)
movq %rbx, %rdi
callq 0x3bb8
movl $0x1, 0x1a8(%rbx)
movq 0xe8(%rbx), %rdi
leaq 0x2850(%rip), %rsi      # 0x66d3
xorl %eax, %eax
callq 0x3741
cmpl $0x2, 0x5c(%rbx)
jl 0x3eb7
movq 0xe8(%rbx), %rdi
movq 0x70(%rbx), %rcx
movl 0x9c(%rbx), %r8d
leaq 0x287b(%rip), %rsi      # 0x6724
leaq 0x288e(%rip), %rdx      # 0x673e
xorl %eax, %eax
callq 0x3741
movq 0x70(%rbx), %rdi
movl 0x9c(%rbx), %esi
leaq 0xb4(%rbx), %rdx
callq 0x32ec
movl %eax, 0x6c(%rbx)
movq 0xe8(%rbx), %rdi
leaq 0x286f(%rip), %rsi      # 0x674d
xorl %eax, %eax
callq 0x3741
cmpl $-0x1, 0x6c(%rbx)
je 0x42a0
leaq 0xb8(%rbx), %rsi
leaq 0x78(%rbx), %rdx
movl $0x2, %edi
movl $0x20, %ecx
callq 0x2030
leaq 0x478(%rip), %rdx       # 0x4388
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
leaq 0x9b8(%rip), %rdx       # 0x48de
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
movl 0x6c(%rbx), %ecx
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %r15
movaps %xmm0, 0x70(%r15)
movaps %xmm0, 0x60(%r15)
movaps %xmm0, 0x50(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
leal 0x1(%rcx), %eax
movl %eax, 0x14(%rsp)
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movl %eax, %edx
andl $-0x40, %edx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x70(%rsp,%rax,8)
leaq 0x120(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x100(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0xf8(%rsp), %r13
leaq 0x60(%rsp), %r12
cmpl $0x0, 0x1a8(%rbx)
je 0x4268
movq %r12, %rbp
movq $0x5, 0x50(%rsp)
movq $0x0, 0x58(%rsp)
movl $0x10, %ecx
movq %r13, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %r14d, %r14d
movl 0x14(%rsp), %edi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x50(%rsp), %r8
callq 0x22a0
movl %eax, %r12d
testl %eax, %eax
jns 0x4036
movq %r15, %r14
movq 0xe8(%rbx), %r15
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r15, %rdi
movq %r14, %r15
leaq 0x2a0c(%rip), %rsi      # 0x6a32
movq %rax, %rdx
xorl %eax, %eax
callq 0x3741
movl $0x1, %r14d
testl %r12d, %r12d
jle 0x4224
movl 0x6c(%rbx), %edi
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
sarl $0x6, %eax
cltq
movq 0xf8(%rsp,%rax,8), %rax
btq %rdi, %rax
movq %rbp, %r12
jae 0x4227
xorps %xmm0, %xmm0
movups %xmm0, 0x3e(%rsp)
movaps %xmm0, 0x30(%rsp)
movl $0x1e, %edx
leaq 0x30(%rsp), %rsi
callq 0x344f
cmpq $0x1e, %rax
jne 0x413a
movl 0x30(%rsp), %edx
cmpl $0x5, %edx
je 0x417e
cmpl $0x3, %edx
je 0x4164
cmpl $0x1, %edx
jne 0x41bb
cmpl $0x2, 0x5c(%rbx)
jl 0x40c4
movq 0xe8(%rbx), %rdi
leaq 0x2995(%rip), %rsi      # 0x6a52
xorl %eax, %eax
callq 0x3741
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movl 0x4a(%rsp), %r12d
bswapl %r12d
testl %r12d, %r12d
jle 0x40f3
movl 0x6c(%rbx), %edi
movl %r12d, %r15d
movq %rbp, %rsi
movq %r15, %rdx
callq 0x344f
cmpq %r15, %rax
jne 0x4204
movq 0x60(%rbx), %r15
movslq %r12d, %rdx
addq $-0x4, %rdx
movq %rbp, %r12
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2070
testl %eax, %eax
je 0x4232
movq 0xe8(%rbx), %rdi
leaq 0x295d(%rip), %rsi      # 0x6a7f
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x3741
movl $0x1, %r14d
jmp 0x4261
movl $0x1, %r14d
cmpl $0x2, 0x5c(%rbx)
jl 0x4227
movq 0xe8(%rbx), %rdi
leaq 0x2a07(%rip), %rsi      # 0x6b5f
xorl %eax, %eax
callq 0x3741
jmp 0x4227
cmpl $0x2, 0x5c(%rbx)
jl 0x41f8
movq 0xe8(%rbx), %rdi
leaq 0x2959(%rip), %rsi      # 0x6ad5
jmp 0x41f1
cmpl $0x2, 0x5c(%rbx)
jl 0x4199
movq 0xe8(%rbx), %rdi
leaq 0x2960(%rip), %rsi      # 0x6af2
xorl %eax, %eax
callq 0x3741
movl 0x4a(%rsp), %eax
testl %eax, %eax
je 0x41d2
bswapl %eax
movl 0x6c(%rbx), %edi
movq 0xd0(%rbx), %rsi
addq $0x1e, %rsi
movslq %eax, %rdx
callq 0x344f
jmp 0x41dd
movq 0xe8(%rbx), %rdi
leaq 0x2956(%rip), %rsi      # 0x6b1f
xorl %eax, %eax
callq 0x3741
jmp 0x4227
movq 0xd0(%rbx), %rax
movb $0x1, 0x1e(%rax)
cmpl $0x2, 0x5c(%rbx)
jl 0x41f8
movq 0xe8(%rbx), %rdi
leaq 0x2910(%rip), %rsi      # 0x6b01
xorl %eax, %eax
callq 0x3741
movq 0x8(%rsp), %rdi
callq 0x21e0
jmp 0x4227
movq 0xe8(%rbx), %rdi
leaq 0x2850(%rip), %rsi      # 0x6a62
xorl %eax, %eax
callq 0x3741
movl $0x1, %r14d
leaq 0x70(%rsp), %r15
movq %rbp, %r12
testl %r14d, %r14d
je 0x3fb4
jmp 0x4268
movq 0x8(%rsp), %rdi
callq 0x21e0
movq 0x18(%rsp), %rdi
callq 0x21e0
cmpl $0x2, 0x5c(%rbx)
jl 0x4261
movq 0xe8(%rbx), %rdi
leaq 0x2849(%rip), %rsi      # 0x6aa3
xorl %eax, %eax
callq 0x3741
leaq 0x70(%rsp), %r15
jmp 0x4227
movl $0x0, 0x1a8(%rbx)
movq 0x8(%rsp), %rdi
callq 0x21e0
movq 0x18(%rsp), %rdi
callq 0x21e0
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
jmp 0x42b5
movq 0xe8(%rbx), %rdi
leaq 0x245e(%rip), %rsi      # 0x670c
xorl %eax, %eax
callq 0x3741
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x42d2
cmpl $0x0, 0x1a0(%rbx)
jne 0x42cb
callq 0x2040
movq $0x0, (%rbx)
movq 0x1b0(%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movl 0xfc(%rbx), %edi
cmpl $-0x1, %edi
je 0x42f9
callq 0x21b0
movl $0xffffffff, 0xfc(%rbx) # imm = 0xFFFFFFFF
movq 0x70(%rbx), %rdi
testq %rdi, %rdi
je 0x430f
callq 0x2040
movq $0x0, 0x70(%rbx)
movq 0xd0(%rbx), %rdi
testq %rdi, %rdi
je 0x432b
callq 0x2040
movq $0x0, 0xd0(%rbx)
movq 0xc8(%rbx), %rdi
testq %rdi, %rdi
je 0x4347
callq 0x2040
movq $0x0, 0xc8(%rbx)
movq %rbx, %rdi
callq 0x2b94
cmpl $0x0, 0x5c(%rbx)
jle 0x436a
movq 0xe8(%rbx), %rdi
leaq 0x2812(%rip), %rsi      # 0x6b75
xorl %eax, %eax
callq 0x3741
movq 0xe8(%rbx), %rdi
callq 0x37e0
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq