// File: /workspace/github_c_makefile_star2_O2/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 $0x168, %rsp            # imm = 0x168
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
leaq 0xfe4(%rip), %rsi       # 0x4ac3
pushq $0xd
popq %rdi
callq 0x2230
movq %rbx, %rdi
callq 0x290c
xorps %xmm0, %xmm0
movups %xmm0, 0x57c7(%rip)     # 0x92c0
movups %xmm0, 0x57b0(%rip)     # 0x92b0
movups %xmm0, 0x5799(%rip)     # 0x92a0
andq $0x0, 0x57c1(%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 0x3ba9
pushq $0x1e
popq %rdi
callq 0x23a0
cmpl $0x0, 0x1a4(%rbx)
je 0x3bcf
andq $0x0, 0x10(%rbx)
movl %ebp, %edi
imull %eax, %edi
shll $0x6, %edi
movq %rdi, 0x8(%rbx)
callq 0x22e0
movq %rax, (%rbx)
andl $0x0, 0x1a0(%rbx)
testq %rax, %rax
jne 0x3c24
movq 0xe8(%rbx), %rbx
callq 0x2060
movl (%rax), %edi
callq 0x2450
leaq 0x2b1e(%rip), %rsi      # 0x66a9
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34b1
movq 0xe8(%rbx), %rdi
leaq 0x2abc(%rip), %rsi      # 0x6673
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34b1
cmpq $0x0, 0xf0(%rbx)
je 0x3c24
movl %ebp, %esi
imull %eax, %esi
shll $0x8, %esi
movq 0x10(%rbx), %rcx
cmpq %rsi, %rcx
jae 0x3c0a
movslq %eax, %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
movq %rcx, %rsi
testq %rdx, %rdx
jne 0x3c0a
incq %rax
imulq %rdi, %rax
movq %rax, %rsi
movq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq %rcx, 0x18(%rbx)
movq %rsi, 0x8(%rbx)
andq $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 0x39a4
movl $0x1, 0x1a8(%rbx)
movq 0xe8(%rbx), %rdi
leaq 0x2a72(%rip), %rsi      # 0x66c3
xorl %eax, %eax
callq 0x34b1
cmpl $0x2, 0x5c(%rbx)
jl 0x3c85
movq 0xe8(%rbx), %rdi
movq 0x70(%rbx), %rcx
movl 0x9c(%rbx), %r8d
leaq 0x2a9d(%rip), %rsi      # 0x6714
leaq 0x2ab0(%rip), %rdx      # 0x672e
xorl %eax, %eax
callq 0x34b1
movq 0x70(%rbx), %rdi
movl 0x9c(%rbx), %esi
leaq 0xb4(%rbx), %rdx
callq 0x3090
movl %eax, 0x6c(%rbx)
movq 0xe8(%rbx), %rdi
leaq 0x2a91(%rip), %rsi      # 0x673d
xorl %eax, %eax
callq 0x34b1
cmpl $-0x1, 0x6c(%rbx)
je 0x3f4e
leaq 0xb8(%rbx), %rsi
leaq 0x78(%rbx), %rdx
pushq $0x2
popq %rdi
pushq $0x20
popq %rcx
callq 0x2030
leaq 0x40f(%rip), %rdx       # 0x40e9
xorl %r14d, %r14d
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
leaq 0x91b(%rip), %rdx       # 0x460e
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
movl 0x6c(%rbx), %ecx
cmpq $0x10, %r14
je 0x3d16
andq $0x0, 0x68(%rsp,%r14,8)
incq %r14
jmp 0x3d05
leal 0x1(%rcx), %ebp
pushq $0x40
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
movslq %eax, %rdx
shll $0x6, %eax
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, 0x68(%rsp,%rdx,8)
leaq 0x120(%rbx), %r14
leaq 0x100(%rbx), %r12
leaq 0xe8(%rsp), %r13
leaq 0x20(%rsp), %r15
movq %r14, (%rsp)
movq %r12, 0x8(%rsp)
cmpl $0x0, 0x1a8(%rbx)
je 0x3f90
movq $0x5, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
pushq $0x10
popq %rcx
movq %r13, %rdi
leaq 0x68(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movl %ebp, %edi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x22a0
testl %eax, %eax
js 0x3f65
je 0x3d58
movl 0x6c(%rbx), %edi
movl %edi, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
cltq
movq 0xe8(%rsp,%rax,8), %rax
btq %rdx, %rax
jae 0x3d58
xorps %xmm0, %xmm0
movups %xmm0, 0x3e(%rsp)
movaps %xmm0, 0x30(%rsp)
leaq 0x30(%rsp), %rsi
pushq $0x1e
popq %rdx
callq 0x3206
cmpq $0x1e, %rax
jne 0x4083
movl 0x30(%rsp), %edx
cmpl $0x5, %edx
je 0x3ec4
cmpl $0x3, %edx
je 0x3eaa
cmpl $0x1, %edx
jne 0x3f01
cmpl $0x2, 0x5c(%rbx)
jl 0x3e16
movq 0xe8(%rbx), %rdi
leaq 0x2c33(%rip), %rsi      # 0x6a42
xorl %eax, %eax
callq 0x34b1
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movl 0x4a(%rsp), %r14d
bswapl %r14d
testl %r14d, %r14d
leaq 0x50(%rsp), %r15
jle 0x3e4a
movl 0x6c(%rbx), %edi
movl %r14d, %r12d
movq %r15, %rsi
movq %r12, %rdx
callq 0x3206
cmpq %r12, %rax
jne 0x40c6
movq 0x60(%rbx), %r12
movslq %r14d, %rdx
addq $-0x4, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2070
testl %eax, %eax
jne 0x40a7
movq (%rsp), %r14
movq %r14, %rdi
callq 0x21e0
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x21e0
cmpl $0x2, 0x5c(%rbx)
leaq 0x20(%rsp), %r15
jl 0x3d58
movq 0xe8(%rbx), %rdi
leaq 0x2bf5(%rip), %rsi      # 0x6a93
xorl %eax, %eax
callq 0x34b1
jmp 0x3d58
cmpl $0x2, 0x5c(%rbx)
jl 0x3f41
movq 0xe8(%rbx), %rdi
leaq 0x2c03(%rip), %rsi      # 0x6ac5
jmp 0x3f3a
cmpl $0x2, 0x5c(%rbx)
jl 0x3edf
movq 0xe8(%rbx), %rdi
leaq 0x2c0a(%rip), %rsi      # 0x6ae2
xorl %eax, %eax
callq 0x34b1
movl 0x4a(%rsp), %eax
testl %eax, %eax
je 0x3f1b
bswapl %eax
movl 0x6c(%rbx), %edi
movq 0xd0(%rbx), %rsi
addq $0x1e, %rsi
movslq %eax, %rdx
callq 0x3206
jmp 0x3f26
movq 0xe8(%rbx), %rdi
leaq 0x2c00(%rip), %rsi      # 0x6b0f
xorl %eax, %eax
callq 0x34b1
jmp 0x3d58
movq 0xd0(%rbx), %rax
movb $0x1, 0x1e(%rax)
cmpl $0x2, 0x5c(%rbx)
jl 0x3f41
movq 0xe8(%rbx), %rdi
leaq 0x2bb7(%rip), %rsi      # 0x6af1
xorl %eax, %eax
callq 0x34b1
movq %r14, %rdi
callq 0x21e0
jmp 0x3d58
movq 0xe8(%rbx), %rdi
leaq 0x27a0(%rip), %rsi      # 0x66fc
xorl %eax, %eax
callq 0x34b1
jmp 0x3fbf
movq 0xe8(%rbx), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2450
leaq 0x2aa3(%rip), %rsi      # 0x6a22
movq %r14, %rdi
movq (%rsp), %r14
movq %rax, %rdx
xorl %eax, %eax
callq 0x34b1
andl $0x0, 0x1a8(%rbx)
movq %r14, %rdi
callq 0x21e0
movq %r12, %rdi
callq 0x21e0
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
movq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x3fd9
cmpl $0x0, 0x1a0(%rbx)
jne 0x3fd5
callq 0x2040
andq $0x0, (%rbx)
movq 0x1b0(%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movl 0xfc(%rbx), %edi
cmpl $-0x1, %edi
je 0x3ffd
callq 0x21b0
orl $-0x1, 0xfc(%rbx)
movq 0x70(%rbx), %rdi
testq %rdi, %rdi
je 0x4010
callq 0x2040
andq $0x0, 0x70(%rbx)
movq 0xd0(%rbx), %rdi
testq %rdi, %rdi
je 0x4029
callq 0x2040
andq $0x0, 0xd0(%rbx)
movq 0xc8(%rbx), %rdi
testq %rdi, %rdi
je 0x4042
callq 0x2040
andq $0x0, 0xc8(%rbx)
movq %rbx, %rdi
callq 0x296f
cmpl $0x0, 0x5c(%rbx)
jle 0x4065
movq 0xe8(%rbx), %rdi
leaq 0x2b07(%rip), %rsi      # 0x6b65
xorl %eax, %eax
callq 0x34b1
movq 0xe8(%rbx), %rdi
callq 0x354e
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, 0x5c(%rbx)
jl 0x3f90
movq 0xe8(%rbx), %rdi
leaq 0x2ab4(%rip), %rsi      # 0x6b4f
xorl %eax, %eax
callq 0x34b1
jmp 0x3f90
movq 0xe8(%rbx), %rdi
leaq 0x29ba(%rip), %rsi      # 0x6a6f
leaq 0x50(%rsp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x34b1
jmp 0x40db
movq 0xe8(%rbx), %rdi
leaq 0x297e(%rip), %rsi      # 0x6a52
xorl %eax, %eax
callq 0x34b1
movq 0x8(%rsp), %r12
movq (%rsp), %r14
jmp 0x3f90