// File: /workspace/github_c_makefile_star2_O0/xiaowenhuyuehu[P]remote_access/src/core/remote_terminal.c
// Function: sda_run_loop
int sda_run_loop (void)
{
    char *buf = NULL, *buf_hdr = NULL, *session_id = NULL, *tmp_buf = NULL;
    int ret = 0, tmp = 0, tmp_fd = 0, payload = 0, tmp_index = 0, timeout = 0;
    struct timeval tv;
    ConnectInfo_t connInfo;
    fd_set rfds;
    int socketfd_local[DEFAULT_SESSION_COUNT] = {0};
    RemoteTerminalMsgHeader hdr;
    
    buf = malloc(DEFAULT_MSG_BUFFER_LEN);
    if(!buf){
        log_error("failed to alloc memory  "); 
        goto _exit;
    }

    ret = sda_connect_to_cloud();
    if (0 != ret) {
        goto _exit;
    }

    memset(&connInfo, 0x0, sizeof(ConnectInfo_t));
    ret = rd_net_get_conn_info(&g_network, NULL, &connInfo);
    if (0 != ret) {
        log_error("get cloud connect info failed ");
        goto _exit;
    }
    _init_local_fd_array(socketfd_local, DEFAULT_SESSION_COUNT);
    log_info("connect to cloud success, socketfd: %d ", connInfo.sockfd);
    while (g_is_running) {
        tv.tv_sec = 0;
        tv.tv_usec = 500*1000L;
        _add_select_array(connInfo.sockfd, socketfd_local, DEFAULT_SESSION_COUNT, &rfds);

        ret = select(_get_max_socketfd(connInfo.sockfd, socketfd_local, DEFAULT_SESSION_COUNT), &rfds, NULL, NULL, &tv);

        memset(buf, 0, DEFAULT_MSG_BUFFER_LEN);
        if (ret == 0) {
            nopoll_conn_send_ping (g_network.handle);
            if(++timeout >= 30*60){
                log_info("there is no package received in 30 min, close current connection...");
                break;
            } 
        }else if(ret < 0){
            log_error("failed to select: %s , close current connection", strerror(errno));
            _send_error_resp(ERR_CONNECTION_CLOSE, "device network error.", NULL, NULL, buf);
            break;
        }

		//local service
		if(ret > 0)
		{
			int index = _get_active_socketfd_index(socketfd_local, DEFAULT_SESSION_COUNT, &rfds);
			if(index != -1){
				char *token = get_session_id_by_socketfd(socketfd_local + index);
				if(token == NULL){
					log_error("can not find session id for socketfd: %d, close it.", socketfd_local[index]);
					_del_socketfd_by_index(index, socketfd_local, DEFAULT_SESSION_COUNT);
					close(socketfd_local[index]);
					continue;
				}

				ret = recv(socketfd_local[index], buf, DEFAULT_MSG_BUFFER_LEN - DEFAULT_MSG_HDR_LEN, 0);
				timeout = 0; 
				log_debug("recv msg comes from sshd, socketfd: %d, index: %d, len:%d ", socketfd_local[index], index, ret);
				//dump_hex(buf, ret);
				if (ret > 0) {
					buf_hdr = sda_gen_msg_header(MSG_SERVICE_PROVIDER_RAW_PROTOCOL, ret, NULL, token);
					memmove(buf + strlen(buf_hdr), buf, ret);
					memmove(buf, buf_hdr, strlen(buf_hdr));
					tmp = rd_net_write(&g_network, NULL, buf, ret + strlen(buf_hdr), 0);
					log_debug("resend to cloud, len:%d", tmp);
				} else {
					log_error("local service exit:  %s ", strerror(errno));
					free_session(get_session_id_by_socketfd(socketfd_local + index));
					_del_socketfd_by_index(index, socketfd_local, DEFAULT_SESSION_COUNT);
					close(socketfd_local[index]);
					_send_error_resp(ERR_SERVICE_EXIT, "local service exit", NULL, token, buf);
				}
			}
		}
		
		//cloud service
        {
            ret = _read_msg_hdr(buf, DEFAULT_MSG_BUFFER_LEN);
			if(ret < 0)
				continue;
            
            timeout = 0;
            if(0 == get_msg_header(buf, &hdr)){
                log_error("read wrong format data, pending data len: %d", rd_net_read(&g_network, NULL, buf, DEFAULT_MSG_BUFFER_LEN, 0));
                _send_error_resp(ERR_PARAM_INVALID, "cloud msg format is invalid", NULL, NULL, buf);
                continue;
            }
            if(hdr.msg_type == MSG_SERVICE_CONSUMER_NEW_SESSION){
                rd_net_read(&g_network, NULL, buf + strlen(buf), hdr.payload_len + 4, 0);//FIXME, deal with service port
                if(0 == is_session_avalibe()){
                    log_error("session is too much...  ");
                    _send_error_resp(ERR_SESSION_LIMIT, "no available session to be allocated", hdr.msg_id, NULL, buf);
                    continue;
                }

                tmp_fd = sda_connect_to_local_service();
                if(tmp_fd == -1){
                    log_error("failed to connect to local service\n");
                    _send_error_resp(ERR_SERVICE_UNAVALIBE, "local service is not available", hdr.msg_id, NULL, buf);
                    continue;
                }
                tmp_index = _add_localfd(tmp_fd, socketfd_local, DEFAULT_SESSION_COUNT);
                if(tmp_index == DEFAULT_SESSION_COUNT){
                    _send_error_resp(ERR_SESSION_CREATE_FAILED, "socketfd insert error", hdr.msg_id, NULL, buf);
                    close(tmp_fd);
                    log_error("failed to add socketfd");
                    continue;
                }

                session_id = alloc_new_session(socketfd_local + tmp_index);
                if(session_id == NULL){
                    close(tmp_fd);
                    log_error("failed to alloc new session");
                    _send_error_resp(ERR_SESSION_CREATE_FAILED, "memory error", hdr.msg_id, NULL, buf);
                    continue;
                }
                char data[128] = {0};
                snprintf(data, sizeof(data) - 1, "{\"session_id\": \"%s\"}", session_id);
                tmp_buf  = sda_gen_payload_msg(0, data, "new session response");

                buf_hdr = sda_gen_msg_header(MSG_RESP_OK , strlen(tmp_buf), hdr.msg_id, session_id);
                memset(buf, 0, DEFAULT_MSG_BUFFER_LEN);
                snprintf(buf, DEFAULT_MSG_BUFFER_LEN, "%s%s", buf_hdr, tmp_buf); 
                rd_net_write(&g_network, NULL, buf, strlen(buf), 0);
                log_debug("send new session respose to cloud, socketfd: %d, index: %d, %s ", socketfd_local[tmp_index], tmp_index, buf);
                free(session_id);
            } else if(hdr.msg_type == MSG_SERVICE_CONSUMER_RELEASE_SESSION){//TODO
                rd_net_read(&g_network, NULL, buf + strlen(buf), hdr.payload_len, 0);//FIXME, deal with service port
                int _socketfd = get_socketfd_by_session_id(hdr.token);
                if(_socketfd < 0){
                    _send_error_resp(ERR_SESSION_NONEXISTENT, "cannot find local connection by session id", hdr.msg_id, hdr.token, buf);
                    log_error("session is not exist");
                    continue; 
                }
                _del_socketfd_by_id(_socketfd, socketfd_local, DEFAULT_SESSION_COUNT);
                close(_socketfd);

                free_session(hdr.token);

                char data[128] = {0};
                snprintf(data, sizeof(data) - 1, "{\"session_id\": \"%s\"}", hdr.token);
                tmp_buf  = sda_gen_payload_msg(0, data, "release session response");

                buf_hdr = sda_gen_msg_header(MSG_RESP_OK , strlen(tmp_buf), hdr.msg_id, hdr.token);
                memset(buf, 0, DEFAULT_MSG_BUFFER_LEN);
                snprintf(buf, DEFAULT_MSG_BUFFER_LEN, "%s%s", buf_hdr, tmp_buf); 
                rd_net_write(&g_network, NULL, buf, strlen(buf), 0);
                log_debug("send release session respose to cloud, socketfd: %d,  %s ", _socketfd, buf); 
            } else if(hdr.msg_type == MSG_SERVICE_CONSUMER_RAW_PROTOCOL){
                int _socketfd = get_socketfd_by_session_id(hdr.token);
                if(_socketfd < 0){
                    _send_error_resp(ERR_SESSION_NONEXISTENT, "cannot find local connection by session id", hdr.msg_id, hdr.token, buf);
                    log_error("session is not exist"); 
                    continue; 
                }

                int n = 0, nwritten = 0, nread = 0, m = 0;
                log_debug("send payload %d start, session id: %s\n", hdr.payload_len, hdr.token);
                memset(buf, 0, DEFAULT_MSG_BUFFER_LEN);
                while(nread < hdr.payload_len){
                    memset(buf, 0, DEFAULT_MSG_BUFFER_LEN);
                    n = nopoll_conn_read(g_network.handle, buf, hdr.payload_len - nread > DEFAULT_MSG_BUFFER_LEN ? DEFAULT_MSG_BUFFER_LEN : hdr.payload_len - nread, nopoll_true, 1000);
                    if(n == -1)
                        continue;
                    nread += n;
                    //dump_hex(buf, n);
                    nwritten = 0;
                    while(nwritten < n){
                        m = send(_socketfd, buf + nwritten, n - nwritten, 0);
                        nwritten += m;
                        if(m == -1){
                            log_info("resend to local service FAILED, len: %d, payload: %d ", n, payload);
                            free_session(hdr.token);
                            _del_socketfd_by_id(_socketfd, socketfd_local, DEFAULT_SESSION_COUNT);
                            close(_socketfd);
                            _send_error_resp(ERR_SERVICE_EXIT, "local service exit", hdr.msg_id, hdr.token, buf);
                            break;
                        }
                    }
                }
                log_debug("send payload %d done\n", hdr.payload_len);
            } else if(hdr.msg_type == MSG_RESP_OK){
                ret = rd_net_read(&g_network, NULL, buf + strlen(buf), hdr.payload_len, 0);//FIXME, deal with service port
                log_debug("login response: %d %s\n", ret, buf);
                if((0 == strcmp(hdr.msg_id, DEFAULT_MSG_ID_HDSK)) && 
                        (0 == is_login_ok(buf + hdr.hdr_len, hdr.payload_len))){
                    log_error("login to cloud failed ");
                    goto _exit;
                }
            }
        } 
    }

_exit:
    deinit_session_system();
    rd_net_destroy(&g_network);
    _close_all_conn(socketfd_local, DEFAULT_SESSION_COUNT);

    if(buf != NULL)
        free(buf);

    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3c0, %rsp            # imm = 0x3C0
movq $0x0, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
leaq -0x170(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x2090
movl $0x2000, %edi           # imm = 0x2000
callq 0x2140
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x7058
movl $0x3, %edi
leaq 0x45a7(%rip), %rsi      # 0xb5e0
leaq 0x45a6(%rip), %rdx      # 0xb5e6
movl $0x17e, %ecx            # imm = 0x17E
leaq 0x45b5(%rip), %r8       # 0xb601
movb $0x0, %al
callq 0x4f90
jmp 0x7e6d
callq 0x7eb0
movl %eax, -0x24(%rbp)
xorl %eax, %eax
cmpl -0x24(%rbp), %eax
je 0x706c
jmp 0x7e6d
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x2090
leaq 0x8305(%rip), %rdi      # 0xf388
xorl %eax, %eax
movl %eax, %esi
leaq -0x70(%rbp), %rdx
callq 0x2b60
movl %eax, -0x24(%rbp)
xorl %eax, %eax
cmpl -0x24(%rbp), %eax
je 0x70c5
movl $0x3, %edi
leaq 0x453a(%rip), %rsi      # 0xb5e0
leaq 0x4539(%rip), %rdx      # 0xb5e6
movl $0x18a, %ecx            # imm = 0x18A
leaq 0x4561(%rip), %r8       # 0xb61a
movb $0x0, %al
callq 0x4f90
jmp 0x7e6d
leaq -0x170(%rbp), %rdi
movl $0x20, %esi
callq 0x8110
movl -0x70(%rbp), %r9d
movl $0x1, %edi
leaq 0x4553(%rip), %rsi      # 0xb639
leaq 0x44f9(%rip), %rdx      # 0xb5e6
movl $0x18e, %ecx            # imm = 0x18E
leaq 0x4546(%rip), %r8       # 0xb63f
movb $0x0, %al
callq 0x4f90
cmpl $0x0, 0x8231(%rip)      # 0xf338
je 0x7e6b
movq $0x0, -0x48(%rbp)
movq $0x7a120, -0x40(%rbp)   # imm = 0x7A120
movl -0x70(%rbp), %edi
leaq -0x170(%rbp), %rsi
movl $0x20, %edx
leaq -0xf0(%rbp), %rcx
callq 0x8150
movl -0x70(%rbp), %edi
leaq -0x170(%rbp), %rsi
movl $0x20, %edx
callq 0x8270
movl %eax, %edi
leaq -0xf0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x48(%rbp), %r8
movq %rcx, %rdx
callq 0x20f0
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0x2090
cmpl $0x0, -0x24(%rbp)
jne 0x71c7
movq 0x823b(%rip), %rdi      # 0xf3c0
callq 0x21a0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0x708, %eax            # imm = 0x708
jl 0x71c5
movl $0x1, %edi
leaq 0x4493(%rip), %rsi      # 0xb639
leaq 0x4439(%rip), %rdx      # 0xb5e6
movl $0x19a, %ecx            # imm = 0x19A
leaq 0x44ae(%rip), %r8       # 0xb667
movb $0x0, %al
callq 0x4f90
jmp 0x7e6b
jmp 0x7225
cmpl $0x0, -0x24(%rbp)
jge 0x7223
callq 0x23e0
movl (%rax), %edi
callq 0x2320
movq %rax, %r9
movl $0x3, %edi
leaq 0x43f8(%rip), %rsi      # 0xb5e0
leaq 0x43f7(%rip), %rdx      # 0xb5e6
movl $0x19e, %ecx            # imm = 0x19E
leaq 0x44b0(%rip), %r8       # 0xb6ab
movb $0x0, %al
callq 0x4f90
movq -0x8(%rbp), %r8
movl $0x18ce6, %edi          # imm = 0x18CE6
leaq 0x44c9(%rip), %rsi      # 0xb6db
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x82f0
jmp 0x7e6b
jmp 0x7225
cmpl $0x0, -0x24(%rbp)
jle 0x74f7
leaq -0x170(%rbp), %rdi
movl $0x20, %esi
leaq -0xf0(%rbp), %rdx
callq 0x83b0
movl %eax, -0x214(%rbp)
cmpl $-0x1, -0x214(%rbp)
je 0x74f5
leaq -0x170(%rbp), %rdi
movslq -0x214(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0xa7a0
movq %rax, -0x220(%rbp)
cmpq $0x0, -0x220(%rbp)
jne 0x72e9
movslq -0x214(%rbp), %rax
movl -0x170(%rbp,%rax,4), %r9d
movl $0x3, %edi
leaq 0x4340(%rip), %rsi      # 0xb5e0
leaq 0x433f(%rip), %rdx      # 0xb5e6
movl $0x1aa, %ecx            # imm = 0x1AA
leaq 0x443e(%rip), %r8       # 0xb6f1
movb $0x0, %al
callq 0x4f90
movl -0x214(%rbp), %edi
leaq -0x170(%rbp), %rsi
movl $0x20, %edx
callq 0x8480
movslq -0x214(%rbp), %rax
movl -0x170(%rbp,%rax,4), %edi
callq 0x20c0
jmp 0x7100
movslq -0x214(%rbp), %rax
movl -0x170(%rbp,%rax,4), %edi
movq -0x8(%rbp), %rsi
movl $0x1c00, %edx           # imm = 0x1C00
xorl %ecx, %ecx
callq 0x2160
movl %eax, -0x24(%rbp)
movl $0x0, -0x38(%rbp)
movslq -0x214(%rbp), %rax
movl -0x170(%rbp,%rax,4), %r9d
movl -0x214(%rbp), %r10d
movl -0x24(%rbp), %eax
xorl %edi, %edi
leaq 0x3cd1(%rip), %rsi      # 0xb004
leaq 0x42ac(%rip), %rdx      # 0xb5e6
movl $0x1b2, %ecx            # imm = 0x1B2
leaq 0x43df(%rip), %r8       # 0xb725
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x4f90
cmpl $0x0, -0x24(%rbp)
jle 0x7452
movl -0x24(%rbp), %esi
movq -0x220(%rbp), %rcx
movl $0x15, %edi
xorl %eax, %eax
movl %eax, %edx
callq 0x9100
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x370(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2260
movq -0x370(%rbp), %rdi
addq %rax, %rdi
movq -0x8(%rbp), %rsi
movslq -0x24(%rbp), %rdx
callq 0x2390
movq -0x8(%rbp), %rax
movq %rax, -0x368(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x360(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2260
movq -0x368(%rbp), %rdi
movq -0x360(%rbp), %rsi
movq %rax, %rdx
callq 0x2390
movq -0x8(%rbp), %rax
movq %rax, -0x358(%rbp)
movslq -0x24(%rbp), %rax
movq %rax, -0x350(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2260
movq -0x358(%rbp), %rdx
movq %rax, %rcx
movq -0x350(%rbp), %rax
addq %rcx, %rax
movl %eax, %ecx
leaq 0x7f71(%rip), %rdi      # 0xf388
xorl %eax, %eax
movl %eax, %esi
xorl %r8d, %r8d
callq 0x27a0
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %r9d
xorl %edi, %edi
leaq 0x3bd1(%rip), %rsi      # 0xb004
leaq 0x41ac(%rip), %rdx      # 0xb5e6
movl $0x1b9, %ecx            # imm = 0x1B9
leaq 0x431a(%rip), %r8       # 0xb760
movb $0x0, %al
callq 0x4f90
jmp 0x74f3
callq 0x23e0
movl (%rax), %edi
callq 0x2320
movq %rax, %r9
movl $0x3, %edi
leaq 0x4173(%rip), %rsi      # 0xb5e0
leaq 0x4172(%rip), %rdx      # 0xb5e6
movl $0x1bb, %ecx            # imm = 0x1BB
leaq 0x42f8(%rip), %r8       # 0xb778
movb $0x0, %al
callq 0x4f90
leaq -0x170(%rbp), %rdi
movslq -0x214(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0xa7a0
movq %rax, %rdi
callq 0xa700
movl -0x214(%rbp), %edi
leaq -0x170(%rbp), %rsi
movl $0x20, %edx
callq 0x8480
movslq -0x214(%rbp), %rax
movl -0x170(%rbp,%rax,4), %edi
callq 0x20c0
movq -0x220(%rbp), %rcx
movq -0x8(%rbp), %r8
movl $0x18ce5, %edi          # imm = 0x18CE5
leaq 0x42a7(%rip), %rsi      # 0xb791
xorl %eax, %eax
movl %eax, %edx
callq 0x82f0
jmp 0x74f5
jmp 0x74f7
movq -0x8(%rbp), %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x84b0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x7513
jmp 0x7100
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x8650
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x7598
movq -0x8(%rbp), %rdx
leaq 0x7e4b(%rip), %rdi      # 0xf388
xorl %eax, %eax
movl %eax, %esi
movl $0x2000, %ecx           # imm = 0x2000
xorl %r8d, %r8d
callq 0x2700
movl %eax, %r9d
movl $0x3, %edi
leaq 0x4083(%rip), %rsi      # 0xb5e0
leaq 0x4082(%rip), %rdx      # 0xb5e6
movl $0x1cc, %ecx            # imm = 0x1CC
leaq 0x4234(%rip), %r8       # 0xb7a4
movb $0x0, %al
callq 0x4f90
movq -0x8(%rbp), %r8
movl $0x18ce1, %edi          # imm = 0x18CE1
leaq 0x424a(%rip), %rsi      # 0xb7d1
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x82f0
jmp 0x7100
cmpl $0x4, -0x210(%rbp)
jne 0x78a3
movq -0x8(%rbp), %rax
movq %rax, -0x378(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2260
movq -0x378(%rbp), %rdx
addq %rax, %rdx
movl -0x208(%rbp), %ecx
addl $0x4, %ecx
leaq 0x7db5(%rip), %rdi      # 0xf388
xorl %eax, %eax
movl %eax, %esi
xorl %r8d, %r8d
callq 0x2700
movb $0x0, %al
callq 0xa3e0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x763d
movl $0x3, %edi
leaq 0x3fe6(%rip), %rsi      # 0xb5e0
leaq 0x3fe5(%rip), %rdx      # 0xb5e6
movl $0x1d3, %ecx            # imm = 0x1D3
leaq 0x41e0(%rip), %r8       # 0xb7ed
movb $0x0, %al
callq 0x4f90
leaq -0x210(%rbp), %rdx
addq $0xc, %rdx
movq -0x8(%rbp), %r8
movl $0x18ce2, %edi          # imm = 0x18CE2
leaq 0x41d7(%rip), %rsi      # 0xb806
xorl %eax, %eax
movl %eax, %ecx
callq 0x82f0
jmp 0x7100
callq 0x8980
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0x769a
movl $0x3, %edi
leaq 0x3f89(%rip), %rsi      # 0xb5e0
leaq 0x3f88(%rip), %rdx      # 0xb5e6
movl $0x1da, %ecx            # imm = 0x1DA
leaq 0x41c1(%rip), %r8       # 0xb82b
movb $0x0, %al
callq 0x4f90
leaq -0x210(%rbp), %rdx
addq $0xc, %rdx
movq -0x8(%rbp), %r8
movl $0x18ce4, %edi          # imm = 0x18CE4
leaq 0x41c3(%rip), %rsi      # 0xb84f
xorl %eax, %eax
movl %eax, %ecx
callq 0x82f0
jmp 0x7100
movl -0x2c(%rbp), %edi
leaq -0x170(%rbp), %rsi
movl $0x20, %edx
callq 0x8ae0
movl %eax, -0x34(%rbp)
cmpl $0x20, -0x34(%rbp)
jne 0x770e
leaq -0x210(%rbp), %rdx
addq $0xc, %rdx
movq -0x8(%rbp), %r8
movl $0x18ce4, %edi          # imm = 0x18CE4
leaq 0x419c(%rip), %rsi      # 0xb86e
xorl %eax, %eax
movl %eax, %ecx
callq 0x82f0
movl -0x2c(%rbp), %edi
callq 0x20c0
movl $0x3, %edi
leaq 0x3ef1(%rip), %rsi      # 0xb5e0
leaq 0x3ef0(%rip), %rdx      # 0xb5e6
movl $0x1e2, %ecx            # imm = 0x1E2
leaq 0x4182(%rip), %r8       # 0xb884
movb $0x0, %al
callq 0x4f90
jmp 0x7100
leaq -0x170(%rbp), %rdi
movslq -0x34(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0xa410
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x7787
movl -0x2c(%rbp), %edi
callq 0x20c0
movl $0x3, %edi
leaq 0x3e9c(%rip), %rsi      # 0xb5e0
leaq 0x3e9b(%rip), %rdx      # 0xb5e6
movl $0x1e9, %ecx            # imm = 0x1E9
leaq 0x4144(%rip), %r8       # 0xb89b
movb $0x0, %al
callq 0x4f90
leaq -0x210(%rbp), %rdx
addq $0xc, %rdx
movq -0x8(%rbp), %r8
movl $0x18ce4, %edi          # imm = 0x18CE4
leaq 0x413e(%rip), %rsi      # 0xb8b7
xorl %eax, %eax
movl %eax, %ecx
callq 0x82f0
jmp 0x7100
leaq -0x2a0(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x2090
leaq -0x2a0(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x7f, %esi
leaq 0x4113(%rip), %rdx      # 0xb8c4
movb $0x0, %al
callq 0x20b0
leaq -0x2a0(%rbp), %rsi
xorl %edi, %edi
leaq 0x4111(%rip), %rdx      # 0xb8d9
callq 0x91f0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2260
movl %eax, %esi
leaq -0x210(%rbp), %rdx
addq $0xc, %rdx
movq -0x18(%rbp), %rcx
xorl %edi, %edi
callq 0x9100
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0x2090
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x2000, %esi           # imm = 0x2000
leaq 0x40d0(%rip), %rdx      # 0xb8ee
movb $0x0, %al
callq 0x20b0
movq -0x8(%rbp), %rax
movq %rax, -0x380(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2260
movq -0x380(%rbp), %rdx
movl %eax, %ecx
leaq 0x7b3f(%rip), %rdi      # 0xf388
xorl %eax, %eax
movl %eax, %esi
xorl %r8d, %r8d
callq 0x27a0
movslq -0x34(%rbp), %rax
movl -0x170(%rbp,%rax,4), %r9d
movl -0x34(%rbp), %r10d
movq -0x8(%rbp), %rax
xorl %edi, %edi
leaq 0x3792(%rip), %rsi      # 0xb004
leaq 0x3d6d(%rip), %rdx      # 0xb5e6
movl $0x1f5, %ecx            # imm = 0x1F5
leaq 0x406e(%rip), %r8       # 0xb8f3
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x4f90
movq -0x18(%rbp), %rdi
callq 0x2240
jmp 0x7e66
cmpl $0x5, -0x210(%rbp)
jne 0x7aa1
movq -0x8(%rbp), %rax
movq %rax, -0x388(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2260
movq -0x388(%rbp), %rdx
addq %rax, %rdx
movl -0x208(%rbp), %ecx
leaq 0x7aad(%rip), %rdi      # 0xf388
xorl %eax, %eax
movl %eax, %esi
xorl %r8d, %r8d
callq 0x2700
leaq -0x210(%rbp), %rdi
addq $0x58, %rdi
callq 0xa8c0
movl %eax, -0x2a4(%rbp)
cmpl $0x0, -0x2a4(%rbp)
jge 0x795c
leaq -0x210(%rbp), %rdx
addq $0xc, %rdx
leaq -0x210(%rbp), %rcx
addq $0x58, %rcx
movq -0x8(%rbp), %r8
movl $0x18ce3, %edi          # imm = 0x18CE3
leaq 0x4007(%rip), %rsi      # 0xb933
callq 0x82f0
movl $0x3, %edi
leaq 0x3ca3(%rip), %rsi      # 0xb5e0
leaq 0x3ca2(%rip), %rdx      # 0xb5e6
movl $0x1fc, %ecx            # imm = 0x1FC
leaq 0x400e(%rip), %r8       # 0xb95e
movb $0x0, %al
callq 0x4f90
jmp 0x7100
movl -0x2a4(%rbp), %edi
leaq -0x170(%rbp), %rsi
movl $0x20, %edx
callq 0x8b70
movl -0x2a4(%rbp), %edi
callq 0x20c0
leaq -0x210(%rbp), %rdi
addq $0x58, %rdi
callq 0xa700
leaq -0x330(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x2090
leaq -0x330(%rbp), %rdi
leaq -0x210(%rbp), %rcx
addq $0x58, %rcx
movl $0x7f, %esi
leaq 0x3f05(%rip), %rdx      # 0xb8c4
movb $0x0, %al
callq 0x20b0
leaq -0x330(%rbp), %rsi
xorl %edi, %edi
leaq 0x3f9d(%rip), %rdx      # 0xb973
callq 0x91f0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2260
movl %eax, %esi
leaq -0x210(%rbp), %rdx
addq $0xc, %rdx
leaq -0x210(%rbp), %rcx
addq $0x58, %rcx
xorl %edi, %edi
callq 0x9100
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0x2090
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x2000, %esi           # imm = 0x2000
leaq 0x3ebb(%rip), %rdx      # 0xb8ee
movb $0x0, %al
callq 0x20b0
movq -0x8(%rbp), %rax
movq %rax, -0x390(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2260
movq -0x390(%rbp), %rdx
movl %eax, %ecx
leaq 0x792a(%rip), %rdi      # 0xf388
xorl %eax, %eax
movl %eax, %esi
xorl %r8d, %r8d
callq 0x27a0
movl -0x2a4(%rbp), %r9d
movq -0x8(%rbp), %rax
xorl %edi, %edi
leaq 0x3586(%rip), %rsi      # 0xb004
leaq 0x3b61(%rip), %rdx      # 0xb5e6
movl $0x20c, %ecx            # imm = 0x20C
leaq 0x3efb(%rip), %r8       # 0xb98c
movq %rax, (%rsp)
movb $0x0, %al
callq 0x4f90
jmp 0x7e64
cmpl $0x16, -0x210(%rbp)
jne 0x7d81
leaq -0x210(%rbp), %rdi
addq $0x58, %rdi
callq 0xa8c0
movl %eax, -0x334(%rbp)
cmpl $0x0, -0x334(%rbp)
jge 0x7b23
leaq -0x210(%rbp), %rdx
addq $0xc, %rdx
leaq -0x210(%rbp), %rcx
addq $0x58, %rcx
movq -0x8(%rbp), %r8
movl $0x18ce3, %edi          # imm = 0x18CE3
leaq 0x3e40(%rip), %rsi      # 0xb933
callq 0x82f0
movl $0x3, %edi
leaq 0x3adc(%rip), %rsi      # 0xb5e0
leaq 0x3adb(%rip), %rdx      # 0xb5e6
movl $0x211, %ecx            # imm = 0x211
leaq 0x3e47(%rip), %r8       # 0xb95e
movb $0x0, %al
callq 0x4f90
jmp 0x7100
movl $0x0, -0x338(%rbp)
movl $0x0, -0x33c(%rbp)
movl $0x0, -0x340(%rbp)
movl $0x0, -0x344(%rbp)
movl -0x208(%rbp), %r9d
leaq -0x210(%rbp), %rax
addq $0x58, %rax
xorl %edi, %edi
leaq 0x349e(%rip), %rsi      # 0xb004
leaq 0x3a79(%rip), %rdx      # 0xb5e6
movl $0x216, %ecx            # imm = 0x216
leaq 0x3e4d(%rip), %r8       # 0xb9c6
movq %rax, (%rsp)
movb $0x0, %al
callq 0x4f90
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0x2090
movl -0x340(%rbp), %eax
cmpl -0x208(%rbp), %eax
jae 0x7d52
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0x2090
movq 0x7803(%rip), %rax      # 0xf3c0
movq %rax, -0x3a0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x398(%rbp)
movl -0x208(%rbp), %eax
subl -0x340(%rbp), %eax
cmpl $0x2000, %eax           # imm = 0x2000
jbe 0x7bef
movl $0x2000, %eax           # imm = 0x2000
movl %eax, -0x3a4(%rbp)
jmp 0x7c01
movl -0x208(%rbp), %eax
subl -0x340(%rbp), %eax
movl %eax, -0x3a4(%rbp)
movq -0x398(%rbp), %rsi
movq -0x3a0(%rbp), %rdi
movl -0x3a4(%rbp), %edx
movl $0x1, %ecx
movl $0x3e8, %r8d            # imm = 0x3E8
callq 0x2220
movl %eax, -0x338(%rbp)
cmpl $-0x1, -0x338(%rbp)
jne 0x7c39
jmp 0x7b94
movl -0x338(%rbp), %eax
addl -0x340(%rbp), %eax
movl %eax, -0x340(%rbp)
movl $0x0, -0x33c(%rbp)
movl -0x33c(%rbp), %eax
cmpl -0x338(%rbp), %eax
jge 0x7d4d
movl -0x334(%rbp), %edi
movq -0x8(%rbp), %rsi
movslq -0x33c(%rbp), %rax
addq %rax, %rsi
movl -0x338(%rbp), %eax
subl -0x33c(%rbp), %eax
movslq %eax, %rdx
xorl %ecx, %ecx
callq 0x2430
movl %eax, -0x344(%rbp)
movl -0x344(%rbp), %eax
addl -0x33c(%rbp), %eax
movl %eax, -0x33c(%rbp)
cmpl $-0x1, -0x344(%rbp)
jne 0x7d48
movl -0x338(%rbp), %r9d
movl -0x30(%rbp), %eax
movl $0x1, %edi
leaq 0x396d(%rip), %rsi      # 0xb639
leaq 0x3913(%rip), %rdx      # 0xb5e6
movl $0x224, %ecx            # imm = 0x224
leaq 0x3d0e(%rip), %r8       # 0xb9ed
movl %eax, (%rsp)
movb $0x0, %al
callq 0x4f90
leaq -0x210(%rbp), %rdi
addq $0x58, %rdi
callq 0xa700
movl -0x334(%rbp), %edi
leaq -0x170(%rbp), %rsi
movl $0x20, %edx
callq 0x8b70
movl -0x334(%rbp), %edi
callq 0x20c0
leaq -0x210(%rbp), %rdx
addq $0xc, %rdx
leaq -0x210(%rbp), %rcx
addq $0x58, %rcx
movq -0x8(%rbp), %r8
movl $0x18ce5, %edi          # imm = 0x18CE5
leaq 0x3a50(%rip), %rsi      # 0xb791
callq 0x82f0
jmp 0x7d4d
jmp 0x7c55
jmp 0x7b94
movl -0x208(%rbp), %r9d
xorl %edi, %edi
leaq 0x32a2(%rip), %rsi      # 0xb004
leaq 0x387d(%rip), %rdx      # 0xb5e6
movl $0x22d, %ecx            # imm = 0x22D
leaq 0x3cae(%rip), %r8       # 0xba23
movb $0x0, %al
callq 0x4f90
jmp 0x7e62
cmpl $0x0, -0x210(%rbp)
jne 0x7e60
movq -0x8(%rbp), %rax
movq %rax, -0x3b0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2260
movq -0x3b0(%rbp), %rdx
addq %rax, %rdx
movl -0x208(%rbp), %ecx
leaq 0x75cf(%rip), %rdi      # 0xf388
xorl %eax, %eax
movl %eax, %esi
xorl %r8d, %r8d
callq 0x2700
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %r9d
movq -0x8(%rbp), %rax
xorl %edi, %edi
leaq 0x322b(%rip), %rsi      # 0xb004
leaq 0x3806(%rip), %rdx      # 0xb5e6
movl $0x230, %ecx            # imm = 0x230
leaq 0x3c4d(%rip), %r8       # 0xba39
movq %rax, (%rsp)
movb $0x0, %al
callq 0x4f90
leaq -0x210(%rbp), %rdi
addq $0xc, %rdi
leaq 0x3c47(%rip), %rsi      # 0xba50
callq 0x2420
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x7e5e
movq -0x8(%rbp), %rdi
movl -0x178(%rbp), %eax
addq %rax, %rdi
movl -0x208(%rbp), %esi
callq 0x8bd0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x7e5e
movl $0x3, %edi
leaq 0x379e(%rip), %rsi      # 0xb5e0
leaq 0x379d(%rip), %rdx      # 0xb5e6
movl $0x233, %ecx            # imm = 0x233
leaq 0x3c10(%rip), %r8       # 0xba65
movb $0x0, %al
callq 0x4f90
jmp 0x7e6d
jmp 0x7e60
jmp 0x7e62
jmp 0x7e64
jmp 0x7e66
jmp 0x7100
jmp 0x7e6d
movb $0x0, %al
callq 0xa3a0
leaq 0x750d(%rip), %rdi      # 0xf388
callq 0x2840
leaq -0x170(%rbp), %rdi
movl $0x20, %esi
callq 0x8c80
cmpq $0x0, -0x8(%rbp)
je 0x7ea1
movq -0x8(%rbp), %rdi
callq 0x2240
movl -0x24(%rbp), %eax
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbp
retq
nopl (%rax)