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


    char *password=NULL;
    char *remoteHost=NULL;
    int port = 38000;
    char *saveFileName=NULL;//[SIZEOFFILENAME]={0};

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

    bool needDaemon=false;

    /* resolve command line options and arguments */
    char ch;
    while ((ch = getopt(argc, argv, "f:p:E:vdTh")) != -1) {
        switch (ch) {                                                                                                                   
            case 'f':                                                                                                                   
                saveFileName =shoit_misc_nocr(strdup(optarg));
                break;                                                                                                                  
            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 'd':                                                                                                                
                needDaemon=true;                                                                                                     
                if(logFile==NULL) logFile="./shoit_recv.log";
                break; 
            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);
    }


    if(needDaemon)
        shoit_misc_daemon("./");

     //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 = false;
    int toFd =-1;
    receiver_run_loop(&receiver,saveFileName,toFd);  
    free(saveFileName);


    exit(0);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rsi, %r15
movl %edi, %r12d
leaq 0x379a(%rip), %rdx      # 0x6004
callq 0x23b0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x288b
movb $0x1, %al
movl $0x9470, %r13d          # imm = 0x9470
xorl %ebp, %ebp
xorl %r14d, %r14d
jmp 0x2955
movq $0x0, 0x10(%rsp)
movl $0x9470, %ebx           # imm = 0x9470
movq 0x6738(%rip), %rbp      # 0x8fd8
leaq 0x375d(%rip), %r13      # 0x6004
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
sarl $0x18, %eax
cmpl $0x65, %eax
jle 0x28d9
cmpl $0x66, %eax
je 0x2913
cmpl $0x70, %eax
jne 0x2ab9
movq (%rbp), %rdi
callq 0x23e0
testl %eax, %eax
cmovgl %eax, %ebx
jmp 0x2929
cmpl $0x45, %eax
je 0x28fd
cmpl $0x64, %eax
jne 0x295b
testq %r14, %r14
leaq 0x3722(%rip), %rax      # 0x600f
cmoveq %rax, %r14
movl $0x1, %eax
movq %rax, 0x10(%rsp)
jmp 0x2929
movq (%rbp), %rdi
callq 0x2440
movq %rax, %rdi
callq 0x350c
movq %rax, %r14
jmp 0x2929
movq (%rbp), %rdi
callq 0x2440
movq %rax, %rdi
callq 0x350c
movq %rax, 0x8(%rsp)
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x23b0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x28b3
cmpl $0x0, 0x10(%rsp)
sete %al
movq 0x8(%rsp), %rbp
movl %ebx, %r13d
cmpl $0x2, %r12d
jg 0x2963
movq (%r15), %rdi
callq 0x2af0
movl %eax, %ebx
leaq 0x19d(%rip), %rsi       # 0x2b09
movl $0x7, %edi
callq 0x2230
movq 0x6653(%rip), %rax      # 0x8fd0
movslq (%rax), %rcx
leaq (%r15,%rcx,8), %rax
cmpl %r12d, %ecx
jne 0x2990
xorl %edi, %edi
xorl %r12d, %r12d
jmp 0x299b
movq (%rax), %rdi
movq 0x8(%rax), %r12
addq $0x10, %rax
testq %rdi, %rdi
setne %cl
testq %r12, %r12
setne %dl
testb %dl, %cl
je 0x2ab1
callq 0x350c
movq %rax, %r15
movq %r12, %rdi
callq 0x350c
movq %rax, %r12
movl $0x0, (%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
movq %r15, %rdx
movl %r13d, %ecx
movl $0x2, %r8d
movl $0x2, %r9d
callq 0x2d10
testl %eax, %eax
jne 0x2acb
movl %r13d, 0x8(%rsp)
testb %bl, %bl
jne 0x2a07
leaq 0x364c(%rip), %rdi      # 0x604e
callq 0x3849
leaq 0xa0(%rsp), %r13
movl $0x1b8, %edx            # imm = 0x1B8
movq %r13, %rdi
xorl %esi, %esi
callq 0x2190
movl $0x1, 0x5c(%r13)
movq %r12, 0x60(%r13)
movups (%r15), %xmm0
movups 0xf(%r15), %xmm1
movups %xmm0, 0x78(%r13)
movups %xmm1, 0x87(%r13)
movl 0x8(%rsp), %ebx
movl %ebx, 0x9c(%r13)
movl %ebx, 0xa0(%r13)
incl %ebx
movl %ebx, 0x98(%r13)
xorl %ebx, %ebx
movq $0x0, 0x70(%r13)
movl %ebx, 0x1a8(%r13)
movq %r14, %rdi
callq 0x372d
testq %rax, %rax
jne 0x2a83
movq 0x6578(%rip), %rax      # 0x8ff8
movq (%rax), %rax
movq %rax, 0x188(%rsp)
movl %ebx, 0x244(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4e08
movq %rbp, %rdi
callq 0x2040
xorl %edi, %edi
callq 0x23f0
movq (%rax), %rdi
callq 0x2af0
cmpl $0x76, %eax
jne 0x295b
xorl %eax, %eax
callq 0x2505
jmp 0x2ae6
movq 0x6526(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x3544(%rip), %rsi      # 0x6020
movq %r15, %rdx
xorl %eax, %eax
callq 0x2250
movl $0x1, %edi
callq 0x23f0