// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x186a0, -0x14(%rbp)   # imm = 0x186A0
movl $0x550, -0x18(%rbp)     # imm = 0x550
movl $0x9470, -0x1c(%rbp)    # imm = 0x9470
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x6a7d(%rip), %rdx      # 0x90d0
callq 0x23d0
movb %al, -0x45(%rbp)
movsbl %al, %eax
cmpl $-0x1, %eax
je 0x27e8
movsbl -0x45(%rbp), %eax
addl $-0x45, %eax
movl %eax, %ecx
movq %rcx, -0x210(%rbp)
subl $0x32, %eax
ja 0x27cd
movq -0x210(%rbp), %rax
leaq 0x6976(%rip), %rcx      # 0x9004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x993a(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2400
cmpl $0x0, %eax
jle 0x26c2
movq 0x9926(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2400
movl %eax, -0x214(%rbp)
jmp 0x26cb
movl -0x14(%rbp), %eax
movl %eax, -0x214(%rbp)
movl -0x214(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x27e3
movq 0x98f8(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2400
cmpl $0x200, %eax            # imm = 0x200
jle 0x271c
movq 0x98e2(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2400
cmpl $0xffff, %eax           # imm = 0xFFFF
jge 0x271c
movq 0x98cc(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2400
movl %eax, -0x218(%rbp)
jmp 0x2725
movl -0x18(%rbp), %eax
movl %eax, -0x218(%rbp)
movl -0x218(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x27e3
movq 0x989e(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2460
movq %rax, -0x30(%rbp)
jmp 0x27e3
movq 0x9886(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2400
cmpl $0x0, %eax
jle 0x2776
movq 0x9872(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2400
movl %eax, -0x21c(%rbp)
jmp 0x277f
movl -0x1c(%rbp), %eax
movl %eax, -0x21c(%rbp)
movl -0x21c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x27e3
movq 0x9847(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
callq 0x2460
movq %rax, -0x28(%rbp)
jmp 0x27e3
movl $0x1, -0x44(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x27b8
leaq 0x692b(%rip), %rax      # 0x90df
movq %rax, -0x28(%rbp)
jmp 0x27e3
movb $0x0, %al
callq 0x2b40
movl $0x1, %edi
callq 0x2410
jmp 0x27cd
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2b10
movl $0x1, %edi
callq 0x2410
jmp 0x2645
cmpl $0x3, -0x8(%rbp)
jge 0x2801
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2b10
xorl %edi, %edi
callq 0x2410
movq 0x97c8(%rip), %rax      # 0xbfd0
movl (%rax), %ecx
movl -0x8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8(%rbp)
movq 0x97b7(%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 0x285f
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3bc0
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
callq 0x3bc0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x2887
cmpq $0x0, -0x40(%rbp)
jne 0x289d
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2b10
movl $0x1, %edi
callq 0x2410
cmpl $0x0, -0x44(%rbp)
je 0x28af
leaq 0x6848(%rip), %rdi      # 0x90f2
callq 0x41f0
leaq -0x200(%rbp), %rdi
xorl %esi, %esi
movl $0x1b8, %edx            # imm = 0x1B8
callq 0x21a0
movl $0x1, -0x1a4(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x164(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3ee0
movq %rax, -0x208(%rbp)
cmpq $0x0, -0x208(%rbp)
je 0x2920
movq -0x208(%rbp), %rax
movq %rax, -0x228(%rbp)
jmp 0x2931
movq 0x96d1(%rip), %rax      # 0xbff8
movq (%rax), %rax
movq %rax, -0x228(%rbp)
movq -0x228(%rbp), %rax
movq %rax, -0x118(%rbp)
movl $0x0, -0x5c(%rbp)
leaq 0x993b(%rip), %rax      # 0xc288
movq %rax, -0x50(%rbp)
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
leaq -0x200(%rbp), %rdi
callq 0x4ac0
xorl %edi, %edi
callq 0x2410
nopw (%rax,%rax)