// File: /workspace/github_c_makefile_star2_O1/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 $0x478, %rsp            # imm = 0x478
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x2b31
movl $0x0, 0x1a8(%rbx)
xorl %eax, %eax
movq %rax, (%rbx)
movq %rax, 0x44cc(%rip)      # 0x9308
xorps %xmm0, %xmm0
movups %xmm0, 0x44b2(%rip)     # 0x92f8
movups %xmm0, 0x449b(%rip)     # 0x92e8
movups %xmm0, 0x4484(%rip)     # 0x92d8
cmpl $0x0, 0x1a4(%rbx)
je 0x4e63
movl %ebp, 0xfc(%rbx)
leaq 0x78(%rbx), %rdi
movl 0x9c(%rbx), %esi
callq 0x3218
movl %eax, 0x6c(%rbx)
cmpl $-0x1, %eax
je 0x553b
movl $0x1, 0x1a8(%rbx)
leaq 0x7e2(%rip), %rdx       # 0x5671
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
leaq 0xcc7(%rip), %rdx       # 0x5b6c
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
movl 0x6c(%rbx), %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0xe0(%rsp)
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)
leal 0x3f(%r15), %eax
testl %r15d, %r15d
cmovnsl %r15d, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %r15d, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0x70(%rsp,%rax,8)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x5e9b
testl %eax, %eax
je 0x5552
movq %r14, 0x18(%rsp)
incl %r15d
movq %r15, 0x28(%rsp)
leaq 0x120(%rbx), %r12
leaq 0x100(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0xf0(%rsp), %rbp
leaq 0x270(%rsp), %r15
cmpl $0x0, 0x1a8(%rbx)
je 0x552f
movq $0x5, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
movl $0x10, %ecx
movq %rbp, %rdi
leaq 0x70(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %r13d, %r13d
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x60(%rsp), %r8
callq 0x22a0
movl %eax, %r14d
testl %eax, %eax
jns 0x4fe0
movq 0xe8(%rbx), %r13
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r13, %rdi
leaq 0x1a62(%rip), %rsi      # 0x6a32
movq %rax, %rdx
xorl %eax, %eax
callq 0x3741
movl $0x1, %r13d
testl %r14d, %r14d
jle 0x517e
movl 0x6c(%rbx), %edi
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
sarl $0x6, %eax
cltq
movq 0xf0(%rsp,%rax,8), %rax
btq %rdi, %rax
jae 0x517e
movl $0x1e, %edx
leaq 0x40(%rsp), %rsi
callq 0x344f
cmpq $0x1e, %rax
jne 0x5143
cmpl $0x2, 0x5c(%rbx)
jl 0x5043
movq 0xe8(%rbx), %rdi
movl 0x40(%rsp), %edx
leaq 0x1d27(%rip), %rsi      # 0x6d63
xorl %eax, %eax
callq 0x3741
movl 0x40(%rsp), %eax
addl $-0x2, %eax
cmpl $0x5, %eax
ja 0x51dd
leaq 0x1b42(%rip), %rcx      # 0x6b9c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r12, (%rsp)
movq 0x52(%rsp), %rdi
callq 0x3800
movq %rax, 0x10(%rsp)
movq 0x4a(%rsp), %rdi
callq 0x3800
movq %rax, 0x8(%rsp)
movl 0x46(%rsp), %r14d
movl 0x5a(%rsp), %r12d
bswapl %r12d
movl $0x100, %edx            # imm = 0x100
leaq 0x170(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2190
movl 0x6c(%rbx), %edi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x344f
cmpq %r12, %rax
jne 0x51ed
bswapl %r14d
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rbx)
movq 0x8(%rsp), %rdi
movq %rdi, 0x8(%rbx)
movl %r14d, 0x2c(%rbx)
addl $0xc, %r14d
movl %r14d, 0x34(%rbx)
cmpl $0x0, 0x1a4(%rbx)
movq (%rbx), %rax
je 0x522a
testq %rax, %rax
movq (%rsp), %r12
leaq 0xf0(%rsp), %rbp
jne 0x53d7
callq 0x22e0
movq %rax, (%rbx)
movl $0x0, 0x1a0(%rbx)
testq %rax, %rax
jne 0x530e
movq 0xe8(%rbx), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r14, %rdi
leaq 0x151a(%rip), %rsi      # 0x6658
jmp 0x5500
movl 0x144(%rbx), %edi
movl $0x1, %edx
leaq 0x14c8(%rip), %rsi      # 0x661d
callq 0x20b0
testq %rax, %rax
js 0x5219
movq 0xe8(%rbx), %rdi
leaq 0x19ee(%rip), %rsi      # 0x6b5f
xorl %eax, %eax
callq 0x3741
movl $0x1, %r13d
testl %r13d, %r13d
je 0x4f64
jmp 0x552f
cmpl $0x2, 0x5c(%rbx)
jl 0x517e
movq 0xe8(%rbx), %rdi
leaq 0x1c23(%rip), %rsi      # 0x6dc3
xorl %eax, %eax
callq 0x3741
jmp 0x517e
movl 0x144(%rbx), %edi
movl $0x1, %edx
leaq 0x1462(%rip), %rsi      # 0x661d
callq 0x20b0
testq %rax, %rax
jns 0x517e
leaq 0x1c0a(%rip), %rdi      # 0x6dd6
callq 0x2390
jmp 0x517e
movq %r12, %rdi
callq 0x21e0
jmp 0x5178
movq 0xe8(%rbx), %rdi
leaq 0x1bf6(%rip), %rsi      # 0x6de1
jmp 0x5171
movq 0xe8(%rbx), %rdi
leaq 0x1b8a(%rip), %rsi      # 0x6d85
xorl %eax, %eax
callq 0x3741
movl $0x1, %r14d
movq (%rsp), %r12
leaq 0xf0(%rsp), %rbp
jmp 0x5510
leaq 0x1bb6(%rip), %rdi      # 0x6dd6
callq 0x2390
jmp 0x5163
testq %rax, %rax
movq (%rsp), %r12
leaq 0xf0(%rsp), %rbp
je 0x5292
movq 0x18(%rbx), %rax
movl $0x1, %r14d
testq %rax, %rax
je 0x5510
movq 0x8(%rbx), %r12
movq 0x10(%rbx), %r9
cmpq %rax, %r12
cmovaeq %rax, %r12
subq %rax, %r9
movl 0xfc(%rbx), %r8d
xorl %edi, %edi
movq %r12, %rsi
movl $0x3, %edx
movl $0x1, %ecx
callq 0x20f0
movq %rax, (%rbx)
cmpq $-0x1, %rax
je 0x52cf
movq %r12, 0x8(%rbx)
subq %r12, 0x18(%rbx)
movq %r12, 0x20(%rbx)
jmp 0x5300
movl $0x200, %edx            # imm = 0x200
movq %r15, %rdi
xorl %esi, %esi
callq 0x2190
movq 0x18(%rsp), %r14
testq %r14, %r14
je 0x5460
movq %r14, %rdi
callq 0x20d0
leaq 0x270(%rsp), %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2280
jmp 0x548d
movq 0xe8(%rbx), %r12
movq %rax, 0x8(%rsp)
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r12, %rdi
leaq 0x1b7d(%rip), %rsi      # 0x6e6e
movq %rax, %rdx
xorl %eax, %eax
callq 0x3741
movq 0x8(%rsp), %rax
cmpq $-0x1, %rax
movq (%rsp), %r12
je 0x5510
movq 0x8(%rbx), %rax
movl 0x2c(%rbx), %ecx
xorl %edx, %edx
divq %rcx
testq %rdx, %rdx
je 0x532a
incq %rax
movq %rax, 0x38(%rbx)
movl %edx, %ecx
jmp 0x532e
movq %rax, 0x38(%rbx)
movl %ecx, 0x30(%rbx)
movq $0x0, 0x48(%rbx)
movq 0x38(%rbx), %r14
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, 0xd0(%rbx)
leaq (,%r14,8), %rdi
callq 0x22e0
movq %rax, 0xc8(%rbx)
movl $0x1, 0xe0(%rbx)
cmpl $0x2, 0x5c(%rbx)
jl 0x539f
movq 0xe8(%rbx), %rdi
leaq 0x1ae9(%rip), %rsi      # 0x6e7e
movq %r14, %rdx
xorl %eax, %eax
callq 0x3741
cmpq $0x0, 0xd0(%rbx)
je 0x540c
movq 0xc8(%rbx), %rax
testq %rax, %rax
je 0x5446
cmpq $0x0, 0x38(%rbx)
je 0x53cf
xorl %ecx, %ecx
movq %rcx, (%rax,%rcx,8)
incq %rcx
cmpq 0x38(%rbx), %rcx
jb 0x53c2
movq %rbx, %rdi
callq 0x2be2
cmpl $0x2, 0x5c(%rbx)
jl 0x53f2
movq 0xe8(%rbx), %rdi
leaq 0x19b6(%rip), %rsi      # 0x6da1
xorl %eax, %eax
callq 0x3741
movq %r12, %rdi
callq 0x21e0
movq 0x20(%rsp), %rdi
callq 0x21e0
movl %r13d, %r14d
jmp 0x5510
movq 0xd8(%rbx), %r14
movq 0xe8(%rbx), %r12
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r12, %rdi
movq (%rsp), %r12
leaq 0x1a63(%rip), %rsi      # 0x6e97
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3741
jmp 0x550a
movq 0xe8(%rbx), %rdi
leaq 0x1216(%rip), %rsi      # 0x666a
xorl %eax, %eax
callq 0x3741
jmp 0x550a
xorl %edi, %edi
callq 0x2290
movl $0x1ff, %esi            # imm = 0x1FF
leaq 0x270(%rsp), %rdi
leaq 0x1995(%rip), %rdx      # 0x6e10
leaq 0x170(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2130
cmpl $0x0, 0x5c(%rbx)
movq %r15, %r14
jle 0x54b6
movq 0xe8(%rbx), %rdi
leaq 0x197e(%rip), %rsi      # 0x6e22
leaq 0x170(%rsp), %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x3741
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 0x54e3
movq 0x10(%rbx), %rsi
movl %eax, %edi
callq 0x2160
testl %eax, %eax
je 0x5518
movq 0xe8(%rbx), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r14, %rdi
leaq 0x1959(%rip), %rsi      # 0x6e59
movq %rax, %rdx
xorl %eax, %eax
callq 0x3741
movl $0x1, %r14d
movl %r14d, %r13d
jmp 0x517e
movl $0x1, 0x1a0(%rbx)
movq 0x10(%rbx), %rax
movq %rax, 0x18(%rbx)
jmp 0x523b
movl $0x0, 0x1a8(%rbx)
jmp 0x5567
movq 0xe8(%rbx), %rdi
leaq 0x166b(%rip), %rsi      # 0x6bb4
xorl %eax, %eax
callq 0x3741
jmp 0x5597
movq 0xe8(%rbx), %rdi
leaq 0x17dc(%rip), %rsi      # 0x6d3c
xorl %eax, %eax
callq 0x3741
leaq 0x120(%rbx), %rdi
callq 0x21e0
leaq 0x100(%rbx), %rdi
callq 0x21e0
movq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
movq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x55b4
cmpl $0x0, 0x1a0(%rbx)
jne 0x55ad
callq 0x2040
movq $0x0, (%rbx)
movl 0xf8(%rbx), %edi
cmpl $-0x1, %edi
je 0x55ce
callq 0x21b0
movl $0xffffffff, 0xf8(%rbx) # imm = 0xFFFFFFFF
movl 0xfc(%rbx), %edi
cmpl $-0x1, %edi
je 0x55e8
callq 0x21b0
movl $0xffffffff, 0xfc(%rbx) # imm = 0xFFFFFFFF
movq 0x70(%rbx), %rdi
testq %rdi, %rdi
je 0x55fe
callq 0x2040
movq $0x0, 0x70(%rbx)
movq 0xd0(%rbx), %rdi
testq %rdi, %rdi
je 0x561a
callq 0x2040
movq $0x0, 0xd0(%rbx)
movq 0xc8(%rbx), %rdi
testq %rdi, %rdi
je 0x5636
callq 0x2040
movq $0x0, 0xc8(%rbx)
movq %rbx, %rdi
callq 0x2b94
movq 0xe8(%rbx), %rdi
leaq 0x1529(%rip), %rsi      # 0x6b75
xorl %eax, %eax
callq 0x3741
movq 0xe8(%rbx), %rdi
callq 0x37e0
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq