// File: /workspace/github_c_makefile_star2_O3/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 %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
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 0x26e(%rip), %rax       # 0x6fd6
movq %rax, -0x8(%r15)
movl $0x2, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2340
movq (%rbx), %rsi
leaq 0x2d37(%rip), %rdi      # 0x9abc
leaq 0x2d43(%rip), %rdx      # 0x9acf
xorl %eax, %eax
callq 0x2080
cmpl $0x1, %ebp
je 0x6df4
cmpl $0x4, %ebp
jne 0x6f29
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
callq 0x730c
movq %rax, %r14
movq %rax, 0x65e4(%rip)      # 0xd3a0
movl $0x1, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x2270
testl %eax, %eax
jle 0x6de9
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
incq %rax
movq (%rbx,%r15,8), %rcx
movb $0x20, -0x2(%rcx,%rax)
decq %rax
cmpq $0x1, %rax
ja 0x6dd7
incq %r15
cmpq $0x4, %r15
jne 0x6dc2
jmp 0x6e09
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x730c
movq %rax, %r14
movq %rax, 0x6597(%rip)      # 0xd3a0
testq %r14, %r14
je 0x6f08
cmpq $0x0, 0x18(%r14)
je 0x6f08
cmpq $0x0, 0x20(%r14)
je 0x6f08
cmpq $0x0, 0x28(%r14)
je 0x6f08
callq 0x21c0
leaq 0x21c5(%rip), %rsi      # 0x9004
leaq 0x27e0(%rip), %rdx      # 0x9626
leaq 0x2ecc(%rip), %r8       # 0x9d19
xorl %edi, %edi
movl $0x248, %ecx            # imm = 0x248
movl %eax, %r9d
xorl %eax, %eax
callq 0x42c5
leaq 0xd4(%rsp), %rbx
movl $0x1cc, %edx            # imm = 0x1CC
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2090
movups 0x2eaf(%rip), %xmm0     # 0x9d2b
movaps %xmm0, -0x34(%rbx)
movups 0x2eb4(%rip), %xmm0     # 0x9d3b
movaps %xmm0, -0x24(%rbx)
movups 0x2eb9(%rip), %xmm0     # 0x9d4b
movaps %xmm0, -0x14(%rbx)
movl $0x6c6c75, -0x4(%rbx)   # imm = 0x6C6C75
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
callq 0x2180
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2090
callq 0x21c0
leaq 0x2e97(%rip), %rdx      # 0x9d5f
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x20b0
movq %rbx, %rdi
callq 0x2180
xorl %edi, %edi
callq 0x25c0
movl %eax, %edi
callq 0x2470
cmpb $0x0, 0x64a2(%rip)      # 0xd398
je 0x6f5f
xorl %eax, %eax
callq 0x7d0e
xorl %eax, %eax
callq 0x7e09
jmp 0x6f4f
leaq 0x2711(%rip), %rsi      # 0x9620
leaq 0x2710(%rip), %rdx      # 0x9626
leaq 0x2c09(%rip), %r8       # 0x9b26
movl $0x3, %edi
movl $0x273, %ecx            # imm = 0x273
jmp 0x6f48
leaq 0x2749(%rip), %rsi      # 0x9679
leaq 0x26ef(%rip), %rdx      # 0x9626
leaq 0x2b9d(%rip), %r8       # 0x9adb
movl $0x1, %edi
movl $0x26e, %ecx            # imm = 0x26E
xorl %eax, %eax
callq 0x42c5
xorl %eax, %eax
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2713(%rip), %rbx      # 0x9679
leaq 0x26b9(%rip), %r14      # 0x9626
leaq 0x2bc9(%rip), %r15      # 0x9b3d
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x7d9c
cmpl $-0x1, %eax
jne 0x6f9a
movl $0x1, %edi
callq 0x2310
cmpb $0x0, 0x6405(%rip)      # 0xd398
je 0x6f76
jmp 0x6ef8
callq 0x5771
incl %ebp
movl $0x1, %edi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x280, %ecx            # imm = 0x280
movq %r15, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x42c5
movl $0x1, %edi
callq 0x2310
cmpb $0x1, 0x63c9(%rip)      # 0xd398
jne 0x6f76
jmp 0x6ef8