// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x9470, -0x24(%rbp)    # imm = 0x9470
movq $0x0, -0x30(%rbp)
movq $0x0, -0xc0(%rbp)
movl $0x0, -0xc4(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x6aa1(%rip), %rdx      # 0x90cc
callq 0x23b0
movb %al, -0xc5(%rbp)
movsbl %al, %eax
cmpl $-0x1, %eax
je 0x2746
movsbl -0xc5(%rbp), %eax
addl $-0x45, %eax
movl %eax, %ecx
movq %rcx, -0x298(%rbp)
subl $0x31, %eax
ja 0x272b
movq -0x298(%rbp), %rax
leaq 0x6998(%rip), %rcx      # 0x9004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x995c(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2440
movq %rax, %rdi
callq 0x3a90
movq %rax, -0x30(%rbp)
jmp 0x2741
movq 0x993c(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x23e0
cmpl $0x0, %eax
jle 0x26c0
movq 0x9928(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x23e0
movl %eax, -0x29c(%rbp)
jmp 0x26c9
movl -0x24(%rbp), %eax
movl %eax, -0x29c(%rbp)
movl -0x29c(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x2741
movq 0x98fd(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2440
movq %rax, %rdi
callq 0x3a90
movq %rax, -0xc0(%rbp)
jmp 0x2741
movb $0x0, %al
callq 0x2a10
movl $0x1, %edi
callq 0x23f0
movl $0x1, -0xc4(%rbp)
cmpq $0x0, -0xc0(%rbp)
jne 0x2727
leaq 0x69b7(%rip), %rax      # 0x90d7
movq %rax, -0xc0(%rbp)
jmp 0x2741
jmp 0x272b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x29a0
movl $0x1, %edi
callq 0x23f0
jmp 0x261d
cmpl $0x3, -0x8(%rbp)
jge 0x2762
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x29a0
movl $0x1, %edi
callq 0x23f0
movl $0x7, %edi
leaq 0x262(%rip), %rsi       # 0x29d0
callq 0x2230
movq 0x9856(%rip), %rax      # 0xbfd0
movl (%rax), %ecx
movl -0x8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8(%rbp)
movq 0x9845(%rip), %rax      # 0xbfd0
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x8(%rbp)
je 0x27d1
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq (%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x27df
cmpq $0x0, -0x18(%rbp)
jne 0x27f5
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x29a0
movl $0x1, %edi
callq 0x23f0
movq -0x20(%rbp), %rdi
callq 0x3a90
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3a90
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
leaq -0xb0(%rbp), %rdi
leaq -0xb4(%rbp), %rsi
movl $0x2, %r9d
xorl %eax, %eax
movl %r9d, %r8d
movl $0x0, (%rsp)
callq 0x2ef0
cmpl $0x0, %eax
je 0x2866
movq 0x97b1(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x6893(%rip), %rsi      # 0x90e8
movb $0x0, %al
callq 0x2250
movl $0x1, %edi
callq 0x23f0
cmpl $0x0, -0xc4(%rbp)
je 0x287b
leaq 0x68a0(%rip), %rdi      # 0x9116
callq 0x40c0
leaq -0x280(%rbp), %rdi
xorl %esi, %esi
movl $0x1b8, %edx            # imm = 0x1B8
callq 0x21a0
movl $0x1, -0x224(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x208(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x200(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x1f8(%rbp)
movl 0x18(%rax), %ecx
movl %ecx, -0x1f0(%rbp)
movw 0x1c(%rax), %cx
movw %cx, -0x1ec(%rbp)
movb 0x1e(%rax), %al
movb %al, -0x1ea(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x1e4(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x1e0(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e8(%rbp)
movq $0x0, -0x210(%rbp)
movl $0x0, -0xd8(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x3db0
movq %rax, -0x288(%rbp)
cmpq $0x0, -0x288(%rbp)
je 0x2944
movq -0x288(%rbp), %rax
movq %rax, -0x2a8(%rbp)
jmp 0x2955
movq 0x96ad(%rip), %rax      # 0xbff8
movq (%rax), %rax
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rax
movq %rax, -0x198(%rbp)
movl $0x0, -0xdc(%rbp)
movl $0xffffffff, -0x28c(%rbp) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rsi
movl -0x28c(%rbp), %edx
leaq -0x280(%rbp), %rdi
callq 0x65e0
movq -0x30(%rbp), %rdi
callq 0x2040
xorl %edi, %edi
callq 0x23f0
nopl (%rax)