// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rdi, %rbx
callq 0x290c
andl $0x0, 0x1a8(%rbx)
andq $0x0, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x47dd(%rip)     # 0x92f8
andq $0x0, 0x47e5(%rip)      # 0x9308
movups %xmm0, 0x47be(%rip)     # 0x92e8
movups %xmm0, 0x47a7(%rip)     # 0x92d8
cmpl $0x0, 0x1a4(%rbx)
je 0x4b40
movl %ebp, 0xfc(%rbx)
leaq 0x78(%rbx), %rdi
movl 0x9c(%rbx), %esi
callq 0x2fc4
movl %eax, 0x6c(%rbx)
cmpl $-0x1, %eax
je 0x51f1
movl $0x1, 0x1a8(%rbx)
leaq 0x7a9(%rip), %rdx       # 0x5315
xorl %r14d, %r14d
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
leaq 0xc0b(%rip), %rdx       # 0x5790
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2340
movl 0x6c(%rbx), %ebp
cmpq $0x10, %r14
je 0x4ba8
andq $0x0, 0x70(%rsp,%r14,8)
incq %r14
jmp 0x4b97
pushq $0x40
popq %rcx
movl %ebp, %eax
cltd
idivl %ecx
movslq %eax, %rdx
shll $0x6, %eax
movl %ebp, %ecx
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, 0x70(%rsp,%rdx,8)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x5a7e
testl %eax, %eax
je 0x5208
movq %r15, 0x30(%rsp)
incl %ebp
leaq 0x120(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x100(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0xf0(%rsp), %r12
leaq 0x70(%rsp), %r14
leaq 0x8(%rsp), %r15
xorl %r13d, %r13d
testl %r13d, %r13d
jne 0x51e8
cmpl $0x0, 0x1a8(%rbx)
je 0x51e8
movq $0x5, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
pushq $0x10
popq %rcx
movq %r12, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl %ebp, %edi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x22a0
testl %eax, %eax
js 0x4db6
movl $0x0, %r13d
je 0x4c0c
movl 0x6c(%rbx), %edi
movl %edi, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
cltq
movq 0xf0(%rsp,%rax,8), %rax
btq %rdx, %rax
jae 0x4c0c
leaq 0x50(%rsp), %rsi
pushq $0x1e
popq %rdx
callq 0x3206
cmpq $0x1e, %rax
jne 0x4de6
cmpl $0x2, 0x5c(%rbx)
jl 0x4caf
movq 0xe8(%rbx), %rdi
movl 0x50(%rsp), %edx
leaq 0x20ab(%rip), %rsi      # 0x6d53
xorl %eax, %eax
callq 0x34b1
movl 0x50(%rsp), %eax
addl $-0x2, %eax
cmpl $0x5, %eax
ja 0x4e8b
leaq 0x1ec6(%rip), %rcx      # 0x6b8c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x62(%rsp), %rdi
callq 0x356e
movq %rax, 0x18(%rsp)
movq 0x5a(%rsp), %rdi
callq 0x356e
movq %rax, 0x28(%rsp)
movl 0x56(%rsp), %r15d
movl 0x6a(%rsp), %r13d
bswapl %r13d
movl $0x100, %edx            # imm = 0x100
leaq 0x170(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2190
movl 0x6c(%rbx), %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3206
cmpq %r13, %rax
jne 0x4e9e
bswapl %r15d
movq 0x18(%rsp), %r9
movq %r9, 0x10(%rbx)
movq 0x28(%rsp), %r13
movq %r13, 0x8(%rbx)
movl %r15d, 0x2c(%rbx)
leal 0xc(%r15), %eax
movl %eax, 0x34(%rbx)
cmpl $0x0, 0x1a4(%rbx)
movq (%rbx), %rax
je 0x4ed7
testq %rax, %rax
leaq 0x70(%rsp), %r14
jne 0x51af
movq %r13, %rdi
callq 0x22e0
movq %rax, (%rbx)
andl $0x0, 0x1a0(%rbx)
testq %rax, %rax
jne 0x4f4a
movq 0xe8(%rbx), %r13
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r13, %rdi
leaq 0x18aa(%rip), %rsi      # 0x6648
movq %rax, %rdx
xorl %eax, %eax
callq 0x34b1
pushq $0x1
popq %r13
leaq 0x8(%rsp), %r15
jmp 0x4c0c
movq 0xe8(%rbx), %r13
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r13, %rdi
leaq 0x1c4f(%rip), %rsi      # 0x6a22
movq %rax, %rdx
xorl %eax, %eax
callq 0x34b1
pushq $0x1
popq %r13
jmp 0x4c0c
movl 0x144(%rbx), %edi
leaq 0x180a(%rip), %rsi      # 0x65fd
pushq $0x1
popq %rdx
callq 0x20b0
testq %rax, %rax
js 0x4ec6
movq 0xe8(%rbx), %rdi
leaq 0x1d3d(%rip), %rsi      # 0x6b4f
xorl %eax, %eax
callq 0x34b1
pushq $0x1
popq %r13
jmp 0x4c0c
cmpl $0x2, 0x5c(%rbx)
movl $0x0, %r13d
jl 0x4c0c
movq 0xe8(%rbx), %rdi
xorl %r13d, %r13d
leaq 0x1f70(%rip), %rsi      # 0x6db3
xorl %eax, %eax
callq 0x34b1
jmp 0x4c0c
movl 0x144(%rbx), %edi
leaq 0x17a1(%rip), %rsi      # 0x65fd
pushq $0x1
popq %rdx
callq 0x20b0
movl $0x0, %r13d
testq %rax, %rax
jns 0x4c0c
jmp 0x5185
movq 0x20(%rsp), %rdi
callq 0x21e0
pushq $0x1
popq %r13
jmp 0x4c0c
movq 0xe8(%rbx), %rdi
leaq 0x1f38(%rip), %rsi      # 0x6dd1
jmp 0x4e12
movq 0xe8(%rbx), %rdi
leaq 0x1ec9(%rip), %rsi      # 0x6d75
xorl %eax, %eax
callq 0x34b1
pushq $0x1
popq %r13
leaq 0x70(%rsp), %r14
leaq 0x8(%rsp), %r15
jmp 0x4c0c
leaq 0x1ef9(%rip), %rdi      # 0x6dc6
callq 0x2390
jmp 0x4e04
testq %rax, %rax
leaq 0x70(%rsp), %r14
leaq 0x270(%rsp), %rdi
je 0x500d
movq 0x18(%rbx), %rax
leaq 0x8(%rsp), %r15
pushq $0x1
popq %r13
testq %rax, %rax
je 0x4c0c
movq 0x8(%rbx), %r15
cmpq %rax, %r15
cmovaeq %rax, %r15
subq %rax, %r9
movl 0xfc(%rbx), %r8d
xorl %edi, %edi
movq %r15, %rsi
pushq $0x3
popq %rdx
movl %r13d, %ecx
callq 0x20f0
movq %rax, (%rbx)
cmpq $-0x1, %rax
je 0x5095
movq %r15, 0x8(%rbx)
subq %r15, 0x18(%rbx)
movq %r15, 0x20(%rbx)
movl 0x2c(%rbx), %eax
movq %r15, %r13
movq %rax, %r15
movl %r15d, %ecx
movq %r13, %rax
xorl %edx, %edx
divq %rcx
movq %r15, %rcx
xorl %r15d, %r15d
testq %rdx, %rdx
cmovel %ecx, %edx
setne %r15b
addq %rax, %r15
movq %r15, 0x38(%rbx)
movl %edx, 0x30(%rbx)
andq $0x0, 0x48(%rbx)
movq %r15, 0x40(%rbx)
movq %r15, %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 (,%r15,8), %rdi
callq 0x22e0
movq %rax, 0xc8(%rbx)
movl $0x1, 0xe0(%rbx)
cmpl $0x2, 0x5c(%rbx)
jl 0x4fe0
movq 0xe8(%rbx), %rdi
leaq 0x1e9f(%rip), %rsi      # 0x6e6e
movq %r15, %rdx
xorl %eax, %eax
callq 0x34b1
movq 0xd0(%rbx), %r13
testq %r13, %r13
leaq 0x8(%rsp), %r15
je 0x5054
movq 0xc8(%rbx), %rax
testq %rax, %rax
jne 0x5196
movq 0xe8(%rbx), %rdi
leaq 0x1652(%rip), %rsi      # 0x665a
jmp 0x4e12
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x2190
movq 0x30(%rsp), %r13
testq %r13, %r13
leaq 0x8(%rsp), %r15
je 0x50c6
movq %r13, %rdi
callq 0x20d0
leaq 0x270(%rsp), %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x2280
leaq 0x270(%rsp), %r13
jmp 0x50f6
movq 0xd8(%rbx), %rax
movq %rax, 0x18(%rsp)
movq 0xe8(%rbx), %r13
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r13, %rdi
leaq 0x1e0a(%rip), %rsi      # 0x6e87
movq 0x18(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x34b1
pushq $0x1
popq %r13
jmp 0x4c0c
movq 0xe8(%rbx), %r15
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r15, %rdi
leaq 0x1dac(%rip), %rsi      # 0x6e5e
movq %rax, %rdx
xorl %eax, %eax
callq 0x34b1
leaq 0x8(%rsp), %r15
jmp 0x4c0c
xorl %edi, %edi
callq 0x2290
movl $0x1ff, %esi            # imm = 0x1FF
leaq 0x270(%rsp), %r13
movq %r13, %rdi
leaq 0x1d1c(%rip), %rdx      # 0x6e00
leaq 0x170(%rsp), %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2130
cmpl $0x0, 0x5c(%rbx)
jle 0x511c
movq 0xe8(%rbx), %rdi
leaq 0x1d08(%rip), %rsi      # 0x6e12
leaq 0x170(%rsp), %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x34b1
movq %r13, %rdi
movl $0x242, %esi            # imm = 0x242
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x2370
movl %eax, 0xfc(%rbx)
testl %eax, %eax
js 0x5149
movq 0x10(%rbx), %rsi
movl %eax, %edi
callq 0x2160
testl %eax, %eax
je 0x516b
movq 0xe8(%rbx), %r13
callq 0x2060
movl (%rax), %edi
callq 0x2450
movq %r13, %rdi
leaq 0x1ce3(%rip), %rsi      # 0x6e49
jmp 0x4dd3
movl $0x1, 0x1a0(%rbx)
movq 0x10(%rbx), %r9
movq %r9, 0x18(%rbx)
movq %r9, %rax
jmp 0x4ef6
leaq 0x1c3a(%rip), %rdi      # 0x6dc6
callq 0x2390
jmp 0x4c09
xorl %ecx, %ecx
cmpq 0x38(%rbx), %rcx
jae 0x51a7
movq %rcx, (%rax,%rcx,8)
incq %rcx
jmp 0x5198
movq %rbx, %rdi
callq 0x29bd
cmpl $0x2, 0x5c(%rbx)
leaq 0x8(%rsp), %r15
jl 0x51cf
movq 0xe8(%rbx), %rdi
leaq 0x1bc9(%rip), %rsi      # 0x6d91
xorl %eax, %eax
callq 0x34b1
movq 0x20(%rsp), %rdi
callq 0x21e0
movq 0x38(%rsp), %rdi
callq 0x21e0
jmp 0x4c09
andl $0x0, 0x1a8(%rbx)
jmp 0x521d
movq 0xe8(%rbx), %rdi
leaq 0x19a5(%rip), %rsi      # 0x6ba4
xorl %eax, %eax
callq 0x34b1
jmp 0x524d
movq 0xe8(%rbx), %rdi
leaq 0x1b16(%rip), %rsi      # 0x6d2c
xorl %eax, %eax
callq 0x34b1
leaq 0x120(%rbx), %rdi
callq 0x21e0
leaq 0x100(%rbx), %rdi
callq 0x21e0
movq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
movq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x2430
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x5267
cmpl $0x0, 0x1a0(%rbx)
jne 0x5263
callq 0x2040
andq $0x0, (%rbx)
movl 0xf8(%rbx), %edi
cmpl $-0x1, %edi
je 0x527e
callq 0x21b0
orl $-0x1, 0xf8(%rbx)
movl 0xfc(%rbx), %edi
cmpl $-0x1, %edi
je 0x5295
callq 0x21b0
orl $-0x1, 0xfc(%rbx)
movq 0x70(%rbx), %rdi
testq %rdi, %rdi
je 0x52a8
callq 0x2040
andq $0x0, 0x70(%rbx)
movq 0xd0(%rbx), %rdi
testq %rdi, %rdi
je 0x52c1
callq 0x2040
andq $0x0, 0xd0(%rbx)
movq 0xc8(%rbx), %rdi
testq %rdi, %rdi
je 0x52da
callq 0x2040
andq $0x0, 0xc8(%rbx)
movq %rbx, %rdi
callq 0x296f
movq 0xe8(%rbx), %rdi
leaq 0x1875(%rip), %rsi      # 0x6b65
xorl %eax, %eax
callq 0x34b1
movq 0xe8(%rbx), %rdi
callq 0x354e
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq