// File: /workspace/github_c_makefile_star2_O3/pencode-lab[P]Shoit/sendfile.c
// Function: main
int main(int argc,char **argv)
{
    int sendRate = SEND_RATE;
    int packetSize = MTU; 
    int port = 38000;

    char *logFile =NULL;


    char *localhost=NULL;
    char *password=NULL;
    char *sendFile=NULL;

    bool needDaemon=false;


    static shoit_callbacks_t dataSource_callbacks = {&open_data_source,&close_data_source,NULL};

    /* resolve command line options and arguments */
    char ch;
    while ((ch = getopt(argc, argv, "w:l:s:p:E:vdTh")) != -1) {
        switch (ch) {
            case 'w': 
                sendRate = atoi(optarg)>0 ? atoi(optarg) : sendRate;
                break;
            case 'l':
                packetSize = (atoi(optarg)>512 && (atoi(optarg) < 65535)) ? atoi(optarg):packetSize;
                break;
            case 's':
                localhost = strdup(optarg);
                break;
            case 'p':
                port = atoi(optarg)>0 ? atoi(optarg):port;
                break;
            case 'E':/* event logging */
                logFile = strdup(optarg); 
                break;
            case 'd':
                needDaemon=true;
                if(logFile==NULL) logFile="./shoit_sender.log";                                                                    
                break;       
            case 'v':
                shoit_show_copyright();
                exit(1);
            case 'h':
            default:
                helpe(argv[0]);
                exit(1); 
        }
    }//while 

    if(argc <3){                                                                                                                     
        helpe(argv[0]);                                                                                                              
        exit(0);                                                                                                                     
    }    

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

    }

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

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

    //init sender
    shoit_core_t sender;
    bzero(&sender,sizeof(sender));

    sender.verbose= 1;
    sender.fileName = sendFile;

    sender.bindHost = localhost;
    sender.password = password; 

    /*bind local port,remote udpserver port will be control channel deliver from receiver*/
    sender.tcpPort = port;

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


    sender.iStream =false; 

    sender.callbacks = &dataSource_callbacks;

    /*run sender*/
    sender_run_loop(&sender,sendRate,packetSize);


    
    exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, %r12
movl %edi, %r13d
leaq 0x477a(%rip), %rdx      # 0x7034
callq 0x23d0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x28f4
movb $0x1, %bl
movl $0x9470, 0x4(%rsp)      # imm = 0x9470
movl $0x550, 0xc(%rsp)       # imm = 0x550
movl $0x186a0, 0x8(%rsp)     # imm = 0x186A0
xorl %r15d, %r15d
movq $0x0, 0x10(%rsp)
jmp 0x2a05
movq $0x0, 0x18(%rsp)
movl $0x186a0, 0x8(%rsp)     # imm = 0x186A0
movl $0x550, 0xc(%rsp)       # imm = 0x550
movl $0x9470, 0x4(%rsp)      # imm = 0x9470
movq 0x76bc(%rip), %rbp      # 0x9fd8
leaq 0x4711(%rip), %r14      # 0x7034
leaq 0x46da(%rip), %rbx      # 0x7004
movq $0x0, 0x10(%rsp)
xorl %r15d, %r15d
sarl $0x18, %eax
leal -0x6c(%rax), %ecx
cmpl $0xb, %ecx
ja 0x296c
movslq (%rbx,%rcx,4), %rax
addq %rbx, %rax
jmpq *%rax
movq (%rbp), %rdi
callq 0x2400
leal -0x201(%rax), %ecx
cmpl $0xfdfe, %ecx           # imm = 0xFDFE
movl 0xc(%rsp), %ecx
cmovbl %eax, %ecx
movl %ecx, 0xc(%rsp)
jmp 0x29e1
cmpl $0x45, %eax
je 0x29d5
cmpl $0x64, %eax
jne 0x2a0b
leaq 0x46c2(%rip), %rax      # 0x7043
testq %r15, %r15
je 0x2989
movq %r15, %rax
movl $0x1, %ecx
movq %rcx, 0x18(%rsp)
jmp 0x29de
movq (%rbp), %rdi
callq 0x2400
testl %eax, %eax
movl 0x8(%rsp), %ecx
cmovgl %eax, %ecx
movl %ecx, 0x8(%rsp)
jmp 0x29e1
movq (%rbp), %rdi
callq 0x2400
testl %eax, %eax
movl 0x4(%rsp), %ecx
cmovgl %eax, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x29e1
movq (%rbp), %rdi
callq 0x2460
movq %rax, 0x10(%rsp)
jmp 0x29e1
movq (%rbp), %rdi
callq 0x2460
movq %rax, %r15
movl %r13d, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x23d0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x2936
cmpl $0x0, 0x18(%rsp)
sete %bl
cmpl $0x2, %r13d
jg 0x2a14
movq (%r12), %rdi
callq 0x2bfc
movq 0x75b5(%rip), %rax      # 0x9fd0
movslq (%rax), %rax
leaq (%r12,%rax,8), %rbp
cmpl %r13d, %eax
jne 0x2a2e
xorl %edi, %edi
xorl %r12d, %r12d
jmp 0x2a3a
movq (%rbp), %r12
movq 0x8(%rbp), %rdi
addq $0x10, %rbp
callq 0x3630
movq %rax, %r14
movq %r12, %rdi
callq 0x3630
movq %rax, %r13
testq %r14, %r14
setne %al
testq %r13, %r13
setne %cl
testb %cl, %al
je 0x2b01
testb %bl, %bl
jne 0x2a71
leaq 0x45ea(%rip), %rdi      # 0x7056
callq 0x3966
leaq 0x20(%rsp), %r12
movl $0x1b0, %edx            # imm = 0x1B0
movq %r12, %rdi
xorl %esi, %esi
callq 0x2190
movl $0x1, 0x5c(%r12)
movq %r13, 0xf0(%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x70(%r12)
movq %r14, 0x60(%r12)
movl 0x4(%rsp), %eax
movl %eax, 0x9c(%r12)
movq %r15, %rdi
callq 0x384a
testq %rax, %rax
jne 0x2ac8
movq 0x7533(%rip), %rax      # 0x9ff8
movq (%rax), %rax
movq %rax, 0x108(%rsp)
movl $0x0, 0x1c4(%rsp)
leaq 0x77a6(%rip), %rax      # 0xa288
movq %rax, 0x1d0(%rsp)
movq %r12, %rdi
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
callq 0x3e5e
xorl %edi, %edi
callq 0x2410
movq (%rbp), %rdi
callq 0x2bfc
xorl %eax, %eax
callq 0x254a
movl $0x1, %edi
callq 0x2410