// File: /workspace/github_c_makefile_star2_O2/xiaowenhuyuehu[P]remote_access/src/core/remote_terminal.c
// Function: main
int main (int argc, char **argv)
{
    int times = 0;
 
    struct sigaction sig_int;
    memset(&sig_int, 0, sizeof(struct sigaction));
    sigemptyset(&sig_int.sa_mask);
    sig_int.sa_handler = _sig_int_handler;
    sigaction(SIGINT, &sig_int, NULL); 
    
    printf("%s compiled at %s\n", argv[0], __DATE__);
    if(argc == 4){
        g_cfg = init_cfg(argv[1], argv[2], argv[3]); 
        _clear_arguments(argc, argv); 
    } else if(argc == 1){
        g_cfg = init_cfg(NULL, NULL, NULL); 
    } else{
        log_info("./remote_terminal <product key>  <device name> <device secret> to startup ");
        return 0;
    }
  
    if(g_cfg == NULL || !g_cfg->pk || !g_cfg->dn || !g_cfg->ds){
        log_error("failed to init config\n"); 
        return 0;
    }

    _singleton();

    srand(time(NULL));
    while(g_is_running) {
        if( -1 == init_session_system()){
            sleep(1);
            continue;
        }
        sda_run_loop();
        log_info("reconnect: try %d times ", ++times);
        sleep(1);
    }

    deinit_cfg();
    deinit_session_system();
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x8(%rsp), %r14
movl $0x98, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x2090
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x2500
leaq 0x23f(%rip), %rax       # 0x6a6f
movq %rax, -0x8(%r15)
pushq $0x2
popq %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2340
movq (%rbx), %rsi
leaq 0x2251(%rip), %rdi      # 0x8a9c
leaq 0x225d(%rip), %rdx      # 0x8aaf
xorl %eax, %eax
callq 0x2080
cmpl $0x1, %ebp
je 0x68ae
cmpl $0x4, %ebp
jne 0x6a29
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
callq 0x6d90
movq %rax, %r14
movq %rax, 0x5b1e(%rip)      # 0xc3a0
pushq $0x1
popq %r15
cmpq $0x4, %r15
je 0x68c3
movq (%rbx,%r15,8), %rdi
callq 0x2270
movl %eax, %eax
testl %eax, %eax
jle 0x68a9
movq (%rbx,%r15,8), %rcx
movb $0x20, -0x1(%rcx,%rax)
decq %rax
jmp 0x6897
incq %r15
jmp 0x6886
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6d90
movq %rax, %r14
movq %rax, 0x5add(%rip)      # 0xc3a0
testq %r14, %r14
je 0x6a0a
cmpq $0x0, 0x18(%r14)
je 0x6a0a
cmpq $0x0, 0x20(%r14)
je 0x6a0a
cmpq $0x0, 0x28(%r14)
je 0x6a0a
callq 0x21c0
leaq 0x170b(%rip), %rsi      # 0x8004
leaq 0x1d06(%rip), %rbx      # 0x8606
leaq 0x23f2(%rip), %r8       # 0x8cf9
xorl %edi, %edi
movq %rbx, %rdx
movl $0x248, %ecx            # imm = 0x248
movl %eax, %r9d
xorl %eax, %eax
callq 0x403f
leaq 0xd4(%rsp), %r14
movl $0x1cc, %edx            # imm = 0x1CC
movq %r14, %rdi
xorl %esi, %esi
callq 0x2090
movups 0x23d2(%rip), %xmm0     # 0x8d0b
movaps %xmm0, -0x34(%r14)
movups 0x23d6(%rip), %xmm0     # 0x8d1b
movaps %xmm0, -0x24(%r14)
movups 0x23da(%rip), %xmm0     # 0x8d2b
movaps %xmm0, -0x14(%r14)
movl $0x6c6c75, -0x4(%r14)   # imm = 0x6C6C75
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
callq 0x2180
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
callq 0x2090
callq 0x21c0
leaq 0x23b6(%rip), %rdx      # 0x8d3f
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x20b0
movq %r14, %rdi
callq 0x2180
xorl %edi, %edi
callq 0x25c0
movl %eax, %edi
callq 0x2470
pushq $0x1
popq %rbp
leaq 0x1c9f(%rip), %r14      # 0x8659
leaq 0x215c(%rip), %r15      # 0x8b1d
xorl %r12d, %r12d
cmpb $0x0, 0x59cd(%rip)      # 0xc398
jne 0x6a5f
xorl %eax, %eax
callq 0x77a4
cmpl $-0x1, %eax
jne 0x69e6
movl %ebp, %edi
callq 0x2310
jmp 0x69c4
callq 0x5471
incl %r12d
movl %ebp, %edi
movq %r14, %rsi
movq %rbx, %rdx
movl $0x280, %ecx            # imm = 0x280
movq %r15, %r8
movl %r12d, %r9d
xorl %eax, %eax
callq 0x403f
jmp 0x69dd
leaq 0x1bef(%rip), %rsi      # 0x8600
leaq 0x1bee(%rip), %rdx      # 0x8606
leaq 0x20e7(%rip), %r8       # 0x8b06
pushq $0x3
popq %rdi
movl $0x273, %ecx            # imm = 0x273
jmp 0x6a46
leaq 0x1c29(%rip), %rsi      # 0x8659
leaq 0x1bcf(%rip), %rdx      # 0x8606
leaq 0x207d(%rip), %r8       # 0x8abb
pushq $0x1
popq %rdi
movl $0x26e, %ecx            # imm = 0x26E
xorl %eax, %eax
callq 0x403f
xorl %eax, %eax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
callq 0x772b
xorl %eax, %eax
callq 0x7806
jmp 0x6a4d