// File: /workspace/github_c_makefile_star2_O2/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
movq $0x0, 0x18(%rsp)
movl $0x9470, 0x8(%rsp)      # imm = 0x9470
movl $0x550, 0x10(%rsp)      # imm = 0x550
movl $0x186a0, 0xc(%rsp)     # imm = 0x186A0
leaq 0x3a09(%rip), %rbx      # 0x6034
movq 0x69a6(%rip), %rbp      # 0x8fd8
leaq 0x39cb(%rip), %r14      # 0x6004
xorl %r15d, %r15d
movl $0x0, 0x14(%rsp)
movl %r13d, %edi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x23d0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
je 0x2723
sarl $0x18, %eax
leal -0x6c(%rax), %ecx
cmpl $0xb, %ecx
ja 0x2682
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbp), %rdi
callq 0x2460
movq %rax, %r15
jmp 0x2644
cmpl $0x45, %eax
je 0x2710
cmpl $0x64, %eax
jne 0x2729
movq 0x18(%rsp), %rax
testq %rax, %rax
leaq 0x39a0(%rip), %rcx      # 0x6043
cmoveq %rcx, %rax
movq %rax, 0x18(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x14(%rsp)
jmp 0x2644
movq (%rbp), %rdi
callq 0x2400
testl %eax, %eax
movl 0xc(%rsp), %ecx
cmovgl %eax, %ecx
movl %ecx, 0xc(%rsp)
jmp 0x2644
movq (%rbp), %rdi
callq 0x2400
testl %eax, %eax
movl 0x8(%rsp), %ecx
cmovgl %eax, %ecx
movl %ecx, 0x8(%rsp)
jmp 0x2644
movq (%rbp), %rdi
callq 0x2400
leal -0x201(%rax), %ecx
cmpl $0xfdfe, %ecx           # imm = 0xFDFE
movl 0x10(%rsp), %ecx
cmovbl %eax, %ecx
movl %ecx, 0x10(%rsp)
jmp 0x2644
movq (%rbp), %rdi
callq 0x2460
movq %rax, 0x18(%rsp)
jmp 0x2644
cmpl $0x2, %r13d
jg 0x2741
movq (%r12), %rdi
callq 0x293b
xorl %eax, %eax
callq 0x2954
pushq $0x1
popq %rdi
callq 0x2410
movq 0x6888(%rip), %rax      # 0x8fd0
movslq (%rax), %rax
leaq (%r12,%rax,8), %r14
cmpl %r13d, %eax
jne 0x275b
xorl %edi, %edi
xorl %r12d, %r12d
jmp 0x2766
movq (%r14), %r12
movq 0x8(%r14), %rdi
addq $0x10, %r14
callq 0x33b4
movq %rax, %rbx
movq %r12, %rdi
callq 0x33b4
movq %rax, %r13
testq %rbx, %rbx
setne %al
testq %r13, %r13
setne %cl
testb %cl, %al
je 0x282a
cmpl $0x0, 0x14(%rsp)
je 0x27a0
leaq 0x38bb(%rip), %rdi      # 0x6056
callq 0x36b7
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 %r15, 0x70(%r12)
movq %rbx, 0x60(%r12)
movl 0x8(%rsp), %eax
movl %eax, 0x9c(%r12)
movq 0x18(%rsp), %rdi
callq 0x359d
testq %rax, %rax
jne 0x27f4
movq 0x6807(%rip), %rax      # 0x8ff8
movq (%rax), %rax
movq %rax, 0x108(%rsp)
andl $0x0, 0x1c4(%rsp)
leaq 0x6a7d(%rip), %rax      # 0x9288
movq %rax, 0x1d0(%rsp)
movq %r12, %rdi
movl 0xc(%rsp), %esi
movl 0x10(%rsp), %edx
callq 0x3bbf
xorl %edi, %edi
callq 0x2410
movq (%r14), %rdi
callq 0x293b