// File: /workspace/github_c_makefile_star2_O3/pencode-lab[P]Shoit/recvstream.c
// Function: main
int main(int argc,char **argv)
{

    char *password=NULL;
    char *remoteHost=NULL;
    int port = 38000;

    struct sockaddr_storage sa;
    socklen_t salen;
    char *logFile=NULL;


    static shoit_callbacks_t recv_callbacks={NULL,NULL,&on_receiver};

    /* resolve command line options and arguments */
    char ch;
    while ((ch = getopt(argc, argv, "f:p:E:vdTh")) != -1) {
        switch (ch) {                                                                                                                   
            case 'p':                                                                                                                   
                port = atoi(optarg)>0 ? atoi(optarg):port;                                                                              
                break;                                                                                                                  
            case 'E':
                logFile=shoit_misc_nocr(strdup(optarg));
                break;
            case 'v':                                                                                                                   
                shoit_show_copyright();                                                                                               
                exit(1);                                                                                                                
            case 'h':                                                                                                                   
            default:                                                                                                                    
                helpe(argv[0]);                                                                                                         
                exit(1);                                                                                                                
        }                                                                                                                               
    }//while   
    if (argc < 3)
    {   
        helpe(argv[0]);
        exit (1);
    }
 
    signal(SIGBUS,catch_signal);

    argc -= optind;                                                                                                                     
    argv += optind;                                                                                                                     
    if (argc != 0){                                                                                                                     
        remoteHost  = *argv++;
        password    = *argv++;
    }

    if(!remoteHost || !password) {
        helpe(argv[0]);
        exit(1);
    }
    remoteHost = shoit_misc_nocr(remoteHost);
    password = shoit_misc_nocr(password);

    
    if (shoit_network_resolve_address((struct sockaddr *)&sa, &salen, remoteHost, port, AF_INET, SOCK_DGRAM, 0) != 0){
        fprintf(stderr,"remote host<%s> is unknown, can't resolve...\n",remoteHost);
        exit(1);
    }



     //init sender                                                                                                                    
    shoit_core_t receiver;
    bzero(&receiver,sizeof(receiver));
    receiver.verbose=1;
    receiver.password = password;

    memcpy(receiver.remoteHost,remoteHost,sizeof(receiver.remoteHost)-1);
    receiver.tcpPort = port;

    /*bind local udp server*/
    receiver.udpLocalPort = port; 
    receiver.udpRemotePort = port+1;
    receiver.bindHost =NULL;
    receiver.runing = false;

    FILE *log = shoit_misc_open_log(logFile);
    receiver.log = (log!=NULL) ? log:stderr;/*if open logfile error,set default is stderr*/

    receiver.iStream = true;
    int toFd =1;

    receiver.callbacks = &recv_callbacks;

    receiver_run_loop(&receiver,NULL,toFd);  


    exit(0);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rsi, %r15
movl %edi, %ebp
leaq 0x379b(%rip), %rdx      # 0x6004
callq 0x23b0
shll $0x18, %eax
movl $0x9470, %ebx           # imm = 0x9470
xorl %r14d, %r14d
cmpl $0xff000000, %eax       # imm = 0xFF000000
je 0x28da
movq 0x6751(%rip), %r13      # 0x8fd8
leaq 0x3776(%rip), %r12      # 0x6004
sarl $0x18, %eax
cmpl $0x45, %eax
je 0x28af
cmpl $0x70, %eax
jne 0x2a16
movq (%r13), %rdi
callq 0x23e0
testl %eax, %eax
cmovgl %eax, %ebx
jmp 0x28c3
movq (%r13), %rdi
callq 0x2440
movq %rax, %rdi
callq 0x34a8
movq %rax, %r14
movl %ebp, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x23b0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x288e
cmpl $0x2, %ebp
jle 0x2a24
leaq 0x197(%rip), %rsi       # 0x2a81
movl $0x7, %edi
callq 0x2230
movq 0x66d5(%rip), %rax      # 0x8fd0
movslq (%rax), %rcx
leaq (%r15,%rcx,8), %rax
cmpl %ebp, %ecx
je 0x2a30
movq (%rax), %rdi
movq 0x8(%rax), %r12
testq %rdi, %rdi
setne %cl
testq %r12, %r12
setne %dl
testb %dl, %cl
je 0x2a2c
callq 0x34a8
movq %rax, %r15
movq %r12, %rdi
callq 0x34a8
movq %rax, %r13
movl $0x0, (%rsp)
leaq 0x1c8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movq %r15, %rdx
movl %ebx, %ecx
movl $0x2, %r8d
movl $0x2, %r9d
callq 0x2c88
testl %eax, %eax
jne 0x2a38
leaq 0x10(%rsp), %r12
movl $0x1b8, %edx            # imm = 0x1B8
movq %r12, %rdi
xorl %esi, %esi
callq 0x2190
movl $0x1, %ebp
movl %ebp, 0x5c(%r12)
movq %r13, 0x60(%r12)
movups (%r15), %xmm0
movups 0xf(%r15), %xmm1
movups %xmm0, 0x78(%r12)
movups %xmm1, 0x87(%r12)
movl %ebx, 0x9c(%r12)
movl %ebx, 0xa0(%r12)
incl %ebx
movl %ebx, 0x98(%r12)
movl $0x0, 0x1a8(%r12)
movq %r14, %rdi
callq 0x36c2
testq %rax, %rax
jne 0x29e2
movq 0x6619(%rip), %rax      # 0x8ff8
movq (%rax), %rax
movq %rax, 0xf8(%rsp)
movl %ebp, 0x1b4(%rsp)
leaq 0x6880(%rip), %rax      # 0x9278
movq %rax, 0x1c0(%rsp)
movq %r12, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x4dc0
xorl %edi, %edi
callq 0x23f0
cmpl $0x76, %eax
jne 0x2a24
xorl %eax, %eax
callq 0x2505
jmp 0x2a53
movq (%r15), %rdi
callq 0x2a68
addq $0x10, %rax
movq (%rax), %rdi
callq 0x2a68
movq 0x65b9(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x35c6(%rip), %rsi      # 0x600f
movq %r15, %rdx
xorl %eax, %eax
callq 0x2250
movl $0x1, %edi
callq 0x23f0