// File: /workspace/github_c_makefile_star2_O3/pencode-lab[P]Shoit/shoit_receiver.c
// Function: receiver_run_loop
void receiver_run_loop(shoit_core_t *receiver,char *recvFile,int toFd)
{
    do{
        /*init for thread syn*/
        shoit_init_synch(receiver);
        receiver->runing = false;
        receiver->bucket=NULL;
        memset(&progress,0,sizeof(progress));

        if(receiver->iStream) receiver->toFd = toFd;
    
        
        /*connect sender's tcp server*/
        receiver->tcpSockfd =shoit_network_connect_tcp(receiver->remoteHost,receiver->tcpPort);
        if(receiver->tcpSockfd==-1){
            SHOIT_LOG("connect remote tcp server failed.\n");        
            break;
        }


        receiver->runing = true; 
        /*create pthread*/
        //create data transfer thread base on udp
        pthread_t transfer_thid;
        pthread_create(&transfer_thid,NULL,(void*)transfer_thread_run,(void*)receiver);
        
        //create progress thread
        pthread_t prog_thid;
        pthread_create(&prog_thid,NULL,(void*)progress_thread_run,(void*)receiver);




        /*run tcp control loop*/
        _receiver_run_loop(receiver,recvFile);



        /*wait thread exit*/
        sem_post(&receiver->dataSem);
        sem_post(&receiver->progSem); 
        pthread_join(transfer_thid,NULL); 
        pthread_join(prog_thid,NULL); 

    }while(0);

    receiver_free(receiver);

    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
callq 0x2b1d
movl $0x0, 0x1a8(%rbx)
xorl %eax, %eax
movq %rax, (%rbx)
movq %rax, 0x44a0(%rip)      # 0x9308
xorps %xmm0, %xmm0
movups %xmm0, 0x4486(%rip)     # 0x92f8
movups %xmm0, 0x446f(%rip)     # 0x92e8
movups %xmm0, 0x4458(%rip)     # 0x92d8
cmpl $0x0, 0x1a4(%rbx)
je 0x4e8f
movl %ebp, 0xfc(%rbx)
leaq 0x78(%rbx), %rdi
movl 0x9c(%rbx), %esi
callq 0x3222
movl %eax, 0x6c(%rbx)
cmpl $-0x1, %eax
je 0x53a8
movl $0x1, 0x1a8(%rbx)
leaq 0x773(%rip), %rdx       # 0x562e
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
leaq 0xc3c(%rip), %rdx       # 0x5b0d
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
movl 0x6c(%rbx), %r14d
xorps %xmm0, %xmm0
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
leal 0x3f(%r14), %eax
testl %r14d, %r14d
cmovnsl %r14d, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %r14d, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x60(%rsp,%rax,8)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x5e3b
testl %eax, %eax
je 0x53c2
cmpl $0x0, 0x1a8(%rbx)
je 0x54ac
incl %r14d
leaq 0x120(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x100(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %r15
leaq 0x60(%rsp), %r13
leaq 0x30(%rsp), %rbp
movq %r14, 0x18(%rsp)
movq $0x5, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movl $0x10, %ecx
movq %r15, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl %r14d, %edi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbp, %r8
callq 0x22a0
testl %eax, %eax
js 0x53dc
je 0x5396
movl 0x6c(%rbx), %edi
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
sarl $0x6, %eax
cltq
movq 0xe0(%rsp,%rax,8), %rax
btq %rdi, %rax
jae 0x5396
movl $0x1e, %edx
leaq 0x40(%rsp), %rsi
callq 0x345f
cmpq $0x1e, %rax
jne 0x5408
cmpl $0x2, 0x5c(%rbx)
jl 0x5036
movq 0xe8(%rbx), %rdi
movl 0x40(%rsp), %edx
leaq 0x1d54(%rip), %rsi      # 0x6d83
xorl %eax, %eax
callq 0x374a
movl 0x40(%rsp), %eax
addl $-0x2, %eax
cmpl $0x5, %eax
ja 0x5444
leaq 0x1b6f(%rip), %rcx      # 0x6bbc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r12, %r15
movq 0x52(%rsp), %rdi
callq 0x3809
movq %rax, %r13
movq 0x4a(%rsp), %rdi
callq 0x3809
movq %rax, %r14
movl 0x46(%rsp), %ebp
movl 0x5a(%rsp), %r12d
bswapl %r12d
movl $0x100, %edx            # imm = 0x100
leaq 0x160(%rsp), %rdi
xorl %esi, %esi
callq 0x2190
movl 0x6c(%rbx), %edi
leaq 0x160(%rsp), %rsi
movq %r12, %rdx
callq 0x345f
cmpq %r12, %rax
jne 0x5454
bswapl %ebp
movq %r13, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movl %ebp, 0x2c(%rbx)
leal 0xc(%rbp), %eax
movl %eax, 0x34(%rbx)
cmpl $0x0, 0x1a4(%rbx)
movq (%rbx), %rax
je 0x5156
testq %rax, %rax
movq %r15, %r12
jne 0x5350
movq %r14, %rdi
callq 0x22e0
movq %rax, (%rbx)
movl $0x0, 0x1a0(%rbx)
testq %rax, %rax
jne 0x5284
jmp 0x55fe
movl 0x144(%rbx), %edi
movl $0x1, %edx
leaq 0x14ea(%rip), %rsi      # 0x65fd
callq 0x20b0
testq %rax, %rax
jns 0x5396
leaq 0x1cce(%rip), %rdi      # 0x6df6
callq 0x2390
jmp 0x5396
cmpl $0x2, 0x5c(%rbx)
jl 0x5396
movq 0xe8(%rbx), %rdi
leaq 0x1c99(%rip), %rsi      # 0x6de3
xorl %eax, %eax
callq 0x374a
jmp 0x5396
testq %rax, %rax
movq %r15, %r12
je 0x5167
movq 0x18(%rbx), %rax
jmp 0x5233
movl $0x200, %edx            # imm = 0x200
leaq 0x260(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2190
testq %r12, %r12
je 0x519b
movq %r12, %rdi
callq 0x20d0
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2280
jmp 0x51c3
xorl %edi, %edi
callq 0x2290
movl $0x1ff, %esi            # imm = 0x1FF
movq %r14, %rdi
leaq 0x1c7f(%rip), %rdx      # 0x6e30
leaq 0x160(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2130
cmpl $0x0, 0x5c(%rbx)
jle 0x51e9
movq 0xe8(%rbx), %rdi
leaq 0x1c6b(%rip), %rsi      # 0x6e42
leaq 0x160(%rsp), %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x374a
movq %r14, %rdi
movl $0x242, %esi            # imm = 0x242
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x2370
movl %eax, 0xfc(%rbx)
testl %eax, %eax
js 0x55df
movq 0x10(%rbx), %rsi
movl %eax, %edi
callq 0x2160
testl %eax, %eax
jne 0x55df
movl $0x1, 0x1a0(%rbx)
movq 0x10(%rbx), %r13
movq %r13, 0x18(%rbx)
movq %r13, %rax
testq %rax, %rax
je 0x54ac
movq 0x8(%rbx), %r14
cmpq %rax, %r14
cmovaeq %rax, %r14
subq %rax, %r13
movl 0xfc(%rbx), %r8d
xorl %edi, %edi
movq %r14, %rsi
movl $0x3, %edx
movl $0x1, %ecx
movq %r13, %r9
callq 0x20f0
movq %rax, (%rbx)
cmpq $-0x1, %rax
je 0x55c0
movq %r14, 0x8(%rbx)
subq %r14, 0x18(%rbx)
movq %r14, 0x20(%rbx)
movl 0x2c(%rbx), %ebp
movl %ebp, %ecx
movq %r14, %rax
xorl %edx, %edx
divq %rcx
xorl %r14d, %r14d
testq %rdx, %rdx
cmovel %ebp, %edx
setne %r14b
addq %rax, %r14
movq %r14, 0x38(%rbx)
movl %edx, 0x30(%rbx)
movq $0x0, 0x48(%rbx)
movq %r14, 0x40(%rbx)
movq %r14, %rdi
shrq $0x3, %rdi
leaq 0x2(%rdi), %rax
movq %rax, 0xd8(%rbx)
addq $0x20, %rdi
callq 0x22e0
movq %rax, %r13
movq %rax, 0xd0(%rbx)
leaq (,%r14,8), %rdi
callq 0x22e0
movq %rax, 0xc8(%rbx)
movl $0x1, 0xe0(%rbx)
cmpl $0x2, 0x5c(%rbx)
jl 0x5319
movq 0xe8(%rbx), %rdi
leaq 0x1b96(%rip), %rsi      # 0x6e9e
movq %r14, %rdx
xorl %eax, %eax
callq 0x374a
movq 0xd0(%rbx), %r13
testq %r13, %r13
je 0x5464
movq 0xc8(%rbx), %rax
testq %rax, %rax
je 0x5497
cmpq $0x0, 0x38(%rbx)
je 0x5348
xorl %ecx, %ecx
movq %rcx, (%rax,%rcx,8)
incq %rcx
cmpq 0x38(%rbx), %rcx
jb 0x533b
movq %rbx, %rdi
callq 0x2bce
cmpl $0x2, 0x5c(%rbx)
jl 0x536b
movq 0xe8(%rbx), %rdi
leaq 0x1a5d(%rip), %rsi      # 0x6dc1
xorl %eax, %eax
callq 0x374a
movq 0x8(%rsp), %rdi
callq 0x21e0
movq 0x10(%rsp), %rdi
callq 0x21e0
movq 0x18(%rsp), %r14
leaq 0xe0(%rsp), %r15
leaq 0x60(%rsp), %r13
leaq 0x30(%rsp), %rbp
cmpl $0x0, 0x1a8(%rbx)
jne 0x4f9c
jmp 0x54ac
movq 0xe8(%rbx), %rdi
leaq 0x181e(%rip), %rsi      # 0x6bd4
xorl %eax, %eax
callq 0x374a
jmp 0x54e6
movq 0xe8(%rbx), %rdi
leaq 0x198c(%rip), %rsi      # 0x6d5c
xorl %eax, %eax
callq 0x374a
jmp 0x54b6
movq 0xe8(%rbx), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2450
leaq 0x165c(%rip), %rsi      # 0x6a52
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x374a
jmp 0x54ac
movl 0x144(%rbx), %edi
leaq 0x11e8(%rip), %rsi      # 0x65fd
movl $0x1, %edx
callq 0x20b0
testq %rax, %rax
js 0x561d
movq 0xe8(%rbx), %rdi
leaq 0x1749(%rip), %rsi      # 0x6b7f
jmp 0x54a5
movq 0x8(%rsp), %rdi
callq 0x21e0
jmp 0x54ac
movq 0xe8(%rbx), %rdi
leaq 0x19af(%rip), %rsi      # 0x6e01
jmp 0x54a5
movq 0xe8(%rbx), %rdi
leaq 0x1943(%rip), %rsi      # 0x6da5
jmp 0x54a5
movq 0xd8(%rbx), %r14
movq 0xe8(%rbx), %r15
callq 0x2060
movl (%rax), %edi
callq 0x2450
leaq 0x1a32(%rip), %rsi      # 0x6eb7
movq %r15, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x374a
jmp 0x54ac
movq 0xe8(%rbx), %rdi
leaq 0x11e5(%rip), %rsi      # 0x668a
xorl %eax, %eax
callq 0x374a
movl $0x0, 0x1a8(%rbx)
leaq 0x120(%rbx), %rdi
callq 0x21e0
leaq 0x100(%rbx), %rdi
callq 0x21e0
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x5503
cmpl $0x0, 0x1a0(%rbx)
jne 0x54fc
callq 0x2040
movq $0x0, (%rbx)
movl 0xf8(%rbx), %edi
cmpl $-0x1, %edi
je 0x551d
callq 0x21b0
movl $0xffffffff, 0xf8(%rbx) # imm = 0xFFFFFFFF
movl 0xfc(%rbx), %edi
cmpl $-0x1, %edi
je 0x5537
callq 0x21b0
movl $0xffffffff, 0xfc(%rbx) # imm = 0xFFFFFFFF
movq 0x70(%rbx), %rdi
testq %rdi, %rdi
je 0x554d
callq 0x2040
movq $0x0, 0x70(%rbx)
movq 0xd0(%rbx), %rdi
testq %rdi, %rdi
je 0x5569
callq 0x2040
movq $0x0, 0xd0(%rbx)
movq 0xc8(%rbx), %rdi
testq %rdi, %rdi
je 0x5585
callq 0x2040
movq $0x0, 0xc8(%rbx)
movq %rbx, %rdi
callq 0x2b80
movq 0xe8(%rbx), %rdi
leaq 0x15fa(%rip), %rsi      # 0x6b95
xorl %eax, %eax
callq 0x374a
movq 0xe8(%rbx), %rdi
callq 0x37e9
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xe8(%rbx), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2450
leaq 0x18b4(%rip), %rsi      # 0x6e8e
jmp 0x53f6
movq 0xe8(%rbx), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2450
leaq 0x1880(%rip), %rsi      # 0x6e79
jmp 0x53f6
movq 0xe8(%rbx), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2450
leaq 0x1060(%rip), %rsi      # 0x6678
jmp 0x53f6
leaq 0x17d2(%rip), %rdi      # 0x6df6
callq 0x2390
jmp 0x5428