// File: /workspace/github_c_makefile_star2_O3/pencode-lab[P]Shoit/sendstream.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;


    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:vTh")) != -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 'v':
                shoit_show_copyright();
                exit(1);
            case 'h':
            default:
                helpe(argv[0]);
                exit(1); 
        }
    }//while 

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

    argc -= optind;
    argv += optind;
    if (argc != 0){
        password = *argv++;
    }
    password = shoit_misc_nocr(password);
    if(!password ){ 
        helpe(argv[0]);
        exit(1);
    }

    //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 =true; 

    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 0x37ea(%rip), %rdx      # 0x6034
callq 0x23b0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x2886
movl $0x186a0, 0x8(%rsp)     # imm = 0x186A0
movl $0x9470, %r15d          # imm = 0x9470
movl $0x550, 0xc(%rsp)       # imm = 0x550
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x295d
movl $0x550, 0xc(%rsp)       # imm = 0x550
movl $0x9470, %r15d          # imm = 0x9470
movl $0x186a0, 0x8(%rsp)     # imm = 0x186A0
movq $0x0, 0x18(%rsp)
movq 0x672c(%rip), %rbx      # 0x8fd8
leaq 0x3781(%rip), %r14      # 0x6034
leaq 0x374a(%rip), %rbp      # 0x6004
movq $0x0, 0x10(%rsp)
sarl $0x18, %eax
leal -0x6c(%rax), %ecx
cmpl $0xb, %ecx
ja 0x28f9
movslq (%rbp,%rcx,4), %rax
addq %rbp, %rax
jmpq *%rax
movq (%rbx), %rdi
callq 0x23e0
leal -0x201(%rax), %ecx
cmpl $0xfdfe, %ecx           # imm = 0xFDFE
movl 0xc(%rsp), %ecx
cmovbl %eax, %ecx
movl %ecx, 0xc(%rsp)
jmp 0x2941
cmpl $0x45, %eax
jne 0x2963
movq (%rbx), %rdi
callq 0x2440
movq %rax, 0x10(%rsp)
jmp 0x2941
movq (%rbx), %rdi
callq 0x23e0
testl %eax, %eax
movl 0x8(%rsp), %ecx
cmovgl %eax, %ecx
movl %ecx, 0x8(%rsp)
jmp 0x2941
movq (%rbx), %rdi
callq 0x2440
movq %rax, 0x18(%rsp)
jmp 0x2941
movq (%rbx), %rdi
callq 0x23e0
testl %eax, %eax
cmovgl %eax, %r15d
movl %r13d, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x23b0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
jne 0x28c3
cmpl $0x1, %r13d
jg 0x296c
movq (%r12), %rdi
callq 0x2a66
movq 0x665d(%rip), %rax      # 0x8fd0
movslq (%rax), %rax
leaq (%r12,%rax,8), %rbx
cmpl %r13d, %eax
jne 0x2983
xorl %edi, %edi
jmp 0x298a
movq (%rbx), %rdi
addq $0x8, %rbx
callq 0x3498
testq %rax, %rax
jne 0x299c
movq (%rbx), %rdi
callq 0x2a66
movq %rax, %r12
leaq 0x20(%rsp), %r14
movl $0x1b0, %edx            # imm = 0x1B0
movq %r14, %rdi
xorl %esi, %esi
callq 0x2190
movl $0x1, %ebx
movl %ebx, 0x5c(%r14)
movq 0x18(%rsp), %rax
movq %rax, 0x70(%r14)
movq %r12, 0x60(%r14)
movl %r15d, 0x9c(%r14)
movq 0x10(%rsp), %rdi
callq 0x36b2
testq %rax, %rax
jne 0x29e9
movq 0x6612(%rip), %rax      # 0x8ff8
movq (%rax), %rax
movq %rax, 0x108(%rsp)
movl %ebx, 0x1c4(%rsp)
leaq 0x6879(%rip), %rax      # 0x9278
movq %rax, 0x1d0(%rsp)
movq %r14, %rdi
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
callq 0x3cc6
xorl %edi, %edi
callq 0x23f0
xorl %eax, %eax
callq 0x24e0
movl $0x1, %edi
callq 0x23f0