// File: /workspace/github_c_makefile_star2_O1/open-mesh-mirror[P]batmand/posix/tunnel.c
// Function: gw_listen
void *gw_listen(void *BATMANUNUSED(arg)) {

	struct batman_if *batman_if = (struct batman_if *)if_list.next;
	struct timeval tv;
	struct sockaddr_in addr, client_addr;
	struct gw_client *gw_client;
	char gw_addr[16], str[16], tun_dev[IFNAMSIZ];
	unsigned char buff[1501];
	int32_t res, max_sock, buff_len, tun_fd, tun_ifi;
	uint32_t addr_len, client_timeout, current_time;
	uint8_t my_tun_ip[4] ALIGN_WORD, next_free_ip[4] ALIGN_WORD;
	struct hashtable_t *wip_hash, *vip_hash;
	struct list_head_first free_ip_list;
	fd_set wait_sockets, tmp_wait_sockets;
	struct hash_it_t *hashit;
	struct free_ip *free_ip;
	struct list_head *list_pos, *list_pos_tmp;


	my_tun_ip[0] = next_free_ip[0] = 169;
	my_tun_ip[1] = next_free_ip[1] = 254;
	my_tun_ip[2] = next_free_ip[2] = 0;
	my_tun_ip[3] = 0;
	next_free_ip[3] = 1;

	addr_len = sizeof (struct sockaddr_in);
	client_timeout = get_time_msec();

	client_addr.sin_family = AF_INET;
	client_addr.sin_port = htons(PORT + 1);

	INIT_LIST_HEAD_FIRST(free_ip_list);

	if (add_dev_tun(batman_if, *(uint32_t *)my_tun_ip, tun_dev, sizeof(tun_dev), &tun_fd, &tun_ifi) < 0)
		return NULL;

	if (NULL == ( wip_hash = hash_new(128, compare_wip, choose_wip)))
		return NULL;

	if (NULL == (vip_hash = hash_new(128, compare_vip, choose_vip))) {
		hash_destroy(wip_hash);
		return NULL;
	}

	add_del_route(*(uint32_t *)my_tun_ip, 16, 0, 0, tun_ifi, tun_dev, 254, ROUTE_TYPE_UNICAST, ROUTE_ADD);


	FD_ZERO(&wait_sockets);
	FD_SET(batman_if->udp_tunnel_sock, &wait_sockets);
	FD_SET(tun_fd, &wait_sockets);

	max_sock = (batman_if->udp_tunnel_sock > tun_fd ? batman_if->udp_tunnel_sock : tun_fd);

	while ((!is_aborted()) && (gateway_class > 0)) {

		tv.tv_sec = 0;
		tv.tv_usec = 250;
		memcpy(&tmp_wait_sockets, &wait_sockets, sizeof(fd_set));

		res = select(max_sock + 1, &tmp_wait_sockets, NULL, NULL, &tv);

		current_time = get_time_msec();

		if ((res < 0) && (errno != EINTR)) {
			debug_output(0, "Error - can't select (gw_listen): %s \n", strerror(errno));
			break;
		}

		if (res <= 0)
			goto after_incoming_packet;

		/* traffic coming from the tunnel client via UDP */
		if (FD_ISSET(batman_if->udp_tunnel_sock, &tmp_wait_sockets)) {

			while ((buff_len = recvfrom(batman_if->udp_tunnel_sock, buff, sizeof(buff) - 1, 0, (struct sockaddr *)&addr, &addr_len)) > 0) {

				if (buff_len < 2) {
					addr_to_string(addr.sin_addr.s_addr, str, sizeof(str));
					debug_output(0, "Error - ignoring client packet from %s: packet too small (%i)\n", str, buff_len);
					continue;
				}

				switch(buff[0]) {
				/* client sends us data that should to the internet */
				case TUNNEL_DATA:
					/* compare_vip() adds 4 bytes, hence buff + 9 */
					gw_client = ((struct gw_client *)hash_find(vip_hash, buff + 9));

					/* check whether client IP is known */
					if ((gw_client == NULL) || ((gw_client->wip_addr != addr.sin_addr.s_addr) && (gw_client->nat_warn == 0))) {

						buff[0] = TUNNEL_IP_INVALID;
						addr_to_string(addr.sin_addr.s_addr, str, sizeof(str));

						debug_output(0, "Error - got packet from unknown client: %s (tunnelled sender ip %i.%i.%i.%i) \n", str, (uint8_t)buff[13], (uint8_t)buff[14], (uint8_t)buff[15], (uint8_t)buff[16]);

						if (gw_client == NULL) {

							/* TODO: only send refresh if the IP comes from 169.254.x.y ?? */
							/*if (sendto(batman_if->udp_tunnel_sock, buff, buff_len, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0)
								debug_output(0, "Error - can't send invalid ip information to client (%s): %s \n", str, strerror(errno));*/

							/* auto assign a dummy address to output the NAT warning only once */
							gw_client = get_ip_addr(&addr, &wip_hash, &vip_hash, &free_ip_list, next_free_ip);

							addr_to_string(gw_client->vip_addr, str, sizeof(str));
							addr_to_string(addr.sin_addr.s_addr, gw_addr, sizeof(gw_addr));
							debug_output(3, "Gateway - assigned %s to unregistered client: %s \n", str, gw_addr);

						}

						debug_output(0, "Either enable NAT on the client or make sure this host has a route back to the sender address.\n");
						gw_client->nat_warn++;
					}

					if (write(tun_fd, buff + 1, buff_len - 1) < 0)
						debug_output(0, "Error - can't write packet into tun: %s\n", strerror(errno));

					break;
				/* client asks us to refresh the IP lease */
				case TUNNEL_KEEPALIVE_REQUEST:
					gw_client = ((struct gw_client *)hash_find(wip_hash, &addr.sin_addr.s_addr));

					buff[0] = TUNNEL_IP_INVALID;

					if (gw_client != NULL) {
						gw_client->last_keep_alive = current_time;
						buff[0] = TUNNEL_KEEPALIVE_REPLY;
					}

					addr_to_string(addr.sin_addr.s_addr, str, sizeof(str));

					if (sendto(batman_if->udp_tunnel_sock, buff, 100, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
						debug_output(0, "Error - can't send %s to client (%s): %s \n", (buff[0] == TUNNEL_KEEPALIVE_REPLY ? "keep alive reply" : "invalid ip information"), str, strerror(errno));
						continue;
					}

					debug_output(3, "Gateway - send %s to client: %s \n", (buff[0] == TUNNEL_KEEPALIVE_REPLY ? "keep alive reply" : "invalid ip information"), str);
					break;
				/* client requests a fresh IP */
				case TUNNEL_IP_REQUEST:
					gw_client = get_ip_addr(&addr, &wip_hash, &vip_hash, &free_ip_list, next_free_ip);

					memcpy(buff + 1, (char *)&gw_client->vip_addr, 4);

					if (sendto(batman_if->udp_tunnel_sock, buff, 100, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
						addr_to_string(addr.sin_addr.s_addr, str, sizeof (str));
						debug_output(0, "Error - can't send requested ip to client (%s): %s \n", str, strerror(errno));
						continue;
					}

					addr_to_string(gw_client->vip_addr, str, sizeof(str));
					addr_to_string(addr.sin_addr.s_addr, gw_addr, sizeof(gw_addr));
					debug_output(3, "Gateway - assigned %s to client: %s \n", str, gw_addr);
					break;
				}

			}

			if (errno != EWOULDBLOCK) {
				debug_output(0, "Error - gateway can't receive packet: %s\n", strerror(errno));
				break;
			}

		/* traffic coming from the internet that needs to be sent back to the client */
		} else if (FD_ISSET(tun_fd, &tmp_wait_sockets)) {

			while ((buff_len = read(tun_fd, buff + 1, sizeof(buff) - 2 )) > 0) {

				gw_client = ((struct gw_client *)hash_find(vip_hash, buff + 13));

				if (gw_client != NULL) {

					client_addr.sin_addr.s_addr = gw_client->wip_addr;
					client_addr.sin_port = gw_client->client_port;

					buff[0] = TUNNEL_DATA;

					if (sendto(batman_if->udp_tunnel_sock, buff, buff_len + 1, 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr_in)) < 0)
						debug_output(0, "Error - can't send data to client (%s): %s \n", str, strerror(errno));

				} else {

					addr_to_string( *(uint32_t *)(buff + 17), gw_addr, sizeof(gw_addr));
					debug_output(3, "Gateway - could not resolve packet: %s \n", gw_addr);

				}

			}

			if (errno != EWOULDBLOCK) {
				debug_output(0, "Error - gateway can't read tun data: %s\n", strerror(errno));
				break;
			}

		}

after_incoming_packet:

		/* close unresponsive client connections (free unused IPs) */
		if ((int)(current_time - (client_timeout + 60000)) > 0) {

			client_timeout = current_time;

			hashit = NULL;

			while (NULL != (hashit = hash_iterate(wip_hash, hashit))) {

				gw_client = hashit->bucket->data;

				if ((int)(current_time - (gw_client->last_keep_alive + IP_LEASE_TIMEOUT + GW_STATE_UNKNOWN_TIMEOUT)) > 0) {

					hash_remove_bucket(wip_hash, hashit);
					hash_remove(vip_hash, gw_client);

					free_ip = debugMalloc(sizeof(struct neigh_node), 210);

					INIT_LIST_HEAD(&free_ip->list);
					free_ip->addr = gw_client->vip_addr;

					list_add_tail( &free_ip->list, &free_ip_list );

					debugFree(gw_client, 1216);

				}

			}

		}

	}

	/* delete tun device and routes on exit */
	my_tun_ip[3] = 0;
	add_del_route( *(uint32_t *)my_tun_ip, 16, 0, 0, tun_ifi, tun_dev, 254, ROUTE_TYPE_UNICAST, ROUTE_DEL );

	del_dev_tun( tun_fd );

	hashit = NULL;

	while (NULL != (hashit = hash_iterate(wip_hash, hashit))) {

		gw_client = hashit->bucket->data;

		hash_remove_bucket(wip_hash, hashit);
		hash_remove(vip_hash, gw_client);

		debugFree(gw_client, 1217);

	}

	hash_destroy(wip_hash);
	hash_destroy(vip_hash);

	list_for_each_safe(list_pos, list_pos_tmp, &free_ip_list) {

		free_ip = list_entry(list_pos, struct free_ip, list);

		list_del((struct list_head *)&free_ip_list, list_pos, &free_ip_list);

		debugFree(free_ip, 1218);

	}

	return NULL;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x798, %rsp            # imm = 0x798
leaq 0xa84b(%rip), %rax      # 0x17310
movq (%rax), %r14
movl $0x100fea9, 0x30(%rsp)  # imm = 0x100FEA9
movl $0x10, 0x38(%rsp)
callq 0xb0fc
movl %eax, %ebp
movl $0xd2100002, 0x70(%rsp) # imm = 0xD2100002
leaq 0x60(%rsp), %rax
movq %rax, (%rax)
movq %rax, 0x8(%rax)
leaq 0x80(%rsp), %rdx
leaq 0x8(%rsp), %r8
leaq 0x3c(%rsp), %r9
movl $0x10, %ecx
movq %r14, %rdi
movl $0xfea9, %esi           # imm = 0xFEA9
callq 0x8efb
testb %al, %al
js 0xd3e4
leaq 0x8d2(%rip), %rsi       # 0xd3f8
leaq 0x8d5(%rip), %rdx       # 0xd402
movl $0x80, %edi
callq 0x6518
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0xd3e4
movq %rax, %rbx
leaq 0x8f1(%rip), %rsi       # 0xd440
leaq 0x8f6(%rip), %rdx       # 0xd44c
movl $0x80, %edi
callq 0x6518
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0xd2d0
movl 0x3c(%rsp), %r8d
subq $0x8, %rsp
xorl %eax, %eax
leaq 0x88(%rsp), %r9
movl $0xfea9, %edi           # imm = 0xFEA9
movl $0x10, %esi
xorl %edx, %edx
xorl %ecx, %ecx
pushq %rax
pushq %rax
pushq $0xfe
callq 0x79b0
addq $0x20, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x120(%rsp)
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movl 0x18(%r14), %ebx
leal 0x3f(%rbx), %eax
testl %ebx, %ebx
cmovnsl %ebx, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %ebx, %ecx
subl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
sarl $0x6, %eax
cltq
orq %rdx, 0xb0(%rsp,%rax,8)
movl $0x1, %eax
movl 0x8(%rsp), %r15d
leal 0x3f(%r15), %edx
testl %r15d, %r15d
cmovnsl %r15d, %edx
movl %edx, %esi
andl $-0x40, %esi
movl %r15d, %ecx
subl %esi, %ecx
shlq %cl, %rax
sarl $0x6, %edx
movslq %edx, %rcx
orq %rax, 0xb0(%rsp,%rcx,8)
callq 0xb8e7
testb %al, %al
jne 0xd30a
leaq 0xa669(%rip), %rax      # 0x172b9
cmpb $0x0, (%rax)
je 0xd30a
cmpl %r15d, %ebx
cmovgl %ebx, %r15d
incl %r15d
leaq 0x1b0(%rsp), %r12
leaq 0x18(%rsp), %r13
movq %r15, 0x58(%rsp)
movq $0x0, 0xa0(%rsp)
movq $0xfa, 0xa8(%rsp)
movl $0x10, %ecx
leaq 0x130(%rsp), %rax
movq %rax, %rdi
leaq 0xb0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movl %r15d, %edi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0xa0(%rsp), %r8
callq 0x22c0
movl %eax, %ebx
callq 0xb0fc
movl %eax, 0xc(%rsp)
testl %ebx, %ebx
jns 0xccde
callq 0x2070
movl (%rax), %edi
cmpl $0x4, %edi
jne 0xd2e6
testl %ebx, %ebx
jle 0xd1e5
movl 0x18(%r14), %eax
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rcx
movq 0x130(%rsp,%rcx,8), %rcx
btq %rax, %rcx
jae 0xd0b3
movl 0x18(%r14), %edi
movl $0x5dc, %edx            # imm = 0x5DC
movq %r12, %rsi
xorl %ecx, %ecx
movq %r13, %r8
leaq 0x38(%rsp), %r9
callq 0x2320
movq %rax, %rbx
testl %ebx, %ebx
jle 0xd09e
cmpl $0x1, %ebx
jne 0xcd65
movl 0x1c(%rsp), %edi
leaq 0x40(%rsp), %rbx
movq %rbx, %rsi
movl $0x10, %edx
callq 0xb8b8
xorl %edi, %edi
leaq 0x5b24(%rip), %rsi      # 0x12878
movq %rbx, %rdx
movl $0x1, %ecx
xorl %eax, %eax
callq 0xd5b0
jmp 0xcd0a
movzbl 0x1b0(%rsp), %eax
cmpl $0x4, %eax
je 0xcf91
cmpl $0x2, %eax
je 0xcef3
cmpl $0x1, %eax
jne 0xcd0a
movq 0x10(%rsp), %rdi
leaq 0x1b9(%rsp), %rsi
callq 0x668e
movq %rax, %r12
testq %rax, %rax
je 0xcdb8
movl (%r12), %eax
cmpl 0x1c(%rsp), %eax
je 0xcea8
cmpb $0x0, 0x10(%r12)
jne 0xcea8
movb $0x3, 0x1b0(%rsp)
movl 0x1c(%rsp), %edi
leaq 0x40(%rsp), %r13
movq %r13, %rsi
movl $0x10, %edx
callq 0xb8b8
movzbl 0x1bd(%rsp), %ecx
movzbl 0x1be(%rsp), %r8d
movzbl 0x1bf(%rsp), %r9d
movzbl 0x1c0(%rsp), %r10d
subq $0x8, %rsp
xorl %edi, %edi
leaq 0x5ab1(%rip), %rsi      # 0x128b7
movq %r13, %rdx
xorl %eax, %eax
pushq %r10
callq 0xd5b0
addq $0x10, %rsp
testq %r12, %r12
jne 0xce8e
leaq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x60(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0xd48b
movq %rax, %r12
movl 0x4(%rax), %edi
leaq 0x40(%rsp), %r15
movq %r15, %rsi
movl $0x10, %edx
callq 0xb8b8
movl 0x1c(%rsp), %edi
movl %ebp, %r13d
leaq 0x90(%rsp), %rbp
movq %rbp, %rsi
movl $0x10, %edx
callq 0xb8b8
movl $0x3, %edi
leaq 0x5a8d(%rip), %rsi      # 0x12906
movq %r15, %rdx
movq 0x58(%rsp), %r15
movq %rbp, %rcx
movl %r13d, %ebp
xorl %eax, %eax
callq 0xd5b0
xorl %edi, %edi
leaq 0x5aa2(%rip), %rsi      # 0x12939
xorl %eax, %eax
callq 0xd5b0
incb 0x10(%r12)
leaq 0x18(%rsp), %r13
movl 0x8(%rsp), %edi
decl %ebx
leaq 0x1b1(%rsp), %rsi
movq %rbx, %rdx
callq 0x20f0
testq %rax, %rax
leaq 0x1b0(%rsp), %r12
jns 0xcd0a
callq 0x2070
movl (%rax), %edi
callq 0x2480
xorl %edi, %edi
leaq 0x5ab5(%rip), %rsi      # 0x12999
movq %rax, %rdx
xorl %eax, %eax
callq 0xd5b0
jmp 0xcd0a
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x60(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0xd48b
movq %rax, %rbx
movl 0x4(%rax), %eax
movl %eax, 0x1b1(%rsp)
movl 0x18(%r14), %edi
movl $0x64, %edx
movq %r12, %rsi
xorl %ecx, %ecx
movq %r13, %r8
movl $0x10, %r9d
callq 0x21e0
testq %rax, %rax
js 0xd032
movl 0x4(%rbx), %edi
movq %r15, %r13
leaq 0x40(%rsp), %r15
movq %r15, %rsi
movl $0x10, %edx
callq 0xb8b8
movl 0x1c(%rsp), %edi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
movl $0x10, %edx
callq 0xb8b8
movl $0x3, %edi
leaq 0x5aee(%rip), %rsi      # 0x12a6c
movq %r15, %rdx
movq %r13, %r15
leaq 0x18(%rsp), %r13
movq %rbx, %rcx
jmp 0xd063
movq 0x28(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x668e
movb $0x3, 0x1b0(%rsp)
testq %rax, %rax
je 0xcfbc
movl 0xc(%rsp), %ecx
movl %ecx, 0xc(%rax)
movb $0x5, 0x1b0(%rsp)
movl 0x1c(%rsp), %edi
leaq 0x40(%rsp), %r13
movq %r13, %rsi
movl $0x10, %edx
callq 0xb8b8
movl 0x18(%r14), %edi
movl $0x64, %edx
movq %r12, %rsi
xorl %ecx, %ecx
leaq 0x18(%rsp), %r8
movl $0x10, %r9d
callq 0x21e0
cmpb $0x5, 0x1b0(%rsp)
leaq 0x59ff(%rip), %rbx      # 0x129fe
leaq 0x59e7(%rip), %rcx      # 0x129ed
cmoveq %rcx, %rbx
testq %rax, %rax
js 0xd06f
movl $0x3, %edi
leaq 0x59fa(%rip), %rsi      # 0x12a15
movq %rbx, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xd5b0
leaq 0x18(%rsp), %r13
jmp 0xcd0a
movl 0x1c(%rsp), %edi
leaq 0x40(%rsp), %rbx
movq %rbx, %rsi
movl $0x10, %edx
callq 0xb8b8
callq 0x2070
movl (%rax), %edi
callq 0x2480
xorl %edi, %edi
leaq 0x59da(%rip), %rsi      # 0x12a37
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xd5b0
jmp 0xcd0a
callq 0x2070
movl (%rax), %edi
callq 0x2480
xorl %edi, %edi
leaq 0x593e(%rip), %rsi      # 0x129c2
movq %rbx, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xd5b0
leaq 0x18(%rsp), %r13
jmp 0xcd0a
callq 0x2070
movl (%rax), %edi
cmpl $0xb, %edi
je 0xd1e5
jmp 0xd2dd
movl 0x8(%rsp), %eax
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rcx
movq 0x130(%rsp,%rcx,8), %rcx
btq %rax, %rcx
jae 0xd1e5
movl 0x8(%rsp), %edi
movl $0x5db, %edx            # imm = 0x5DB
leaq 0x1b1(%rsp), %rsi
callq 0x2230
movq %rax, %r12
testl %r12d, %r12d
jle 0xd1cd
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
leaq 0x1bd(%rsp), %rsi
callq 0x668e
testq %rax, %rax
je 0xd179
movl (%rax), %ecx
movl %ecx, 0x74(%rsp)
movzwl 0x8(%rax), %eax
movw %ax, 0x72(%rsp)
movb $0x1, 0x1b0(%rsp)
movl 0x18(%r14), %edi
incl %r12d
leaq 0x1b0(%rsp), %rsi
movq %r12, %rdx
xorl %ecx, %ecx
leaq 0x70(%rsp), %r8
movl $0x10, %r9d
callq 0x21e0
testq %rax, %rax
jns 0xd1ab
callq 0x2070
movl (%rax), %edi
callq 0x2480
xorl %edi, %edi
leaq 0x5954(%rip), %rsi      # 0x12abc
leaq 0x40(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xd5b0
jmp 0xd1ab
movl 0x1c1(%rsp), %edi
leaq 0x90(%rsp), %r12
movq %r12, %rsi
movl $0x10, %edx
callq 0xb8b8
movl $0x3, %edi
leaq 0x5948(%rip), %rsi      # 0x12ae9
movq %r12, %rdx
xorl %eax, %eax
callq 0xd5b0
movl 0x8(%rsp), %edi
movl $0x5db, %edx            # imm = 0x5DB
leaq 0x1b1(%rsp), %rsi
callq 0x2230
movq %rax, %r12
testl %r12d, %r12d
jg 0xd0fe
callq 0x2070
movl (%rax), %edi
cmpl $0xb, %edi
leaq 0x1b0(%rsp), %r12
jne 0xd2ef
movl 0xc(%rsp), %eax
subl %ebp, %eax
addl $0xffff15a0, %eax       # imm = 0xFFFF15A0
testl %eax, %eax
jle 0xd2b5
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6416
testq %rax, %rax
je 0xd2a9
movq %rax, %r12
movl 0xc(%rsp), %r15d
addl $0xffecc620, %r15d      # imm = 0xFFECC620
movq 0x10(%rsp), %r13
movq 0x8(%r12), %rax
movq (%rax), %rbp
movl %r15d, %eax
subl 0xc(%rbp), %eax
testl %eax, %eax
jle 0xd27e
movq %rbx, %rdi
movq %r12, %rsi
callq 0x66e0
movq %r13, %rdi
movq %rbp, %rsi
callq 0x672d
movl $0x38, %edi
movl $0xd2, %esi
callq 0x5d3e
movq %rax, (%rax)
movl 0x4(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq %rax, %rdi
leaq 0x60(%rsp), %rsi
callq 0x5bb9
movq %rbp, %rdi
movl $0x4c0, %esi            # imm = 0x4C0
callq 0x5f5b
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6416
movq %rax, %r12
testq %rax, %rax
jne 0xd224
movl 0xc(%rsp), %ebp
movq 0x58(%rsp), %r15
leaq 0x1b0(%rsp), %r12
leaq 0x18(%rsp), %r13
jmp 0xd2b5
movl 0xc(%rsp), %ebp
leaq 0x1b0(%rsp), %r12
callq 0xb8e7
testb %al, %al
jne 0xd30a
leaq 0x9ff4(%rip), %rax      # 0x172b9
cmpb $0x0, (%rax)
jne 0xcc75
jmp 0xd30a
movq %rbx, %rdi
callq 0x63ed
jmp 0xd3e4
leaq 0x57ae(%rip), %rbx      # 0x12a92
jmp 0xd2f6
leaq 0x5564(%rip), %rbx      # 0x12851
jmp 0xd2f6
leaq 0x581c(%rip), %rbx      # 0x12b12
callq 0x2480
xorl %edi, %edi
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd5b0
movl 0x3c(%rsp), %r8d
subq $0x8, %rsp
leaq 0x88(%rsp), %r9
movl $0xfea9, %edi           # imm = 0xFEA9
movl $0x10, %esi
xorl %edx, %edx
xorl %ecx, %ecx
pushq $0x1
pushq $0x0
pushq $0xfe
callq 0x79b0
addq $0x20, %rsp
movl 0x8(%rsp), %edi
callq 0x8eb8
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6416
testq %rax, %rax
je 0xd39d
movq %rax, %r14
movq 0x10(%rsp), %r15
movq 0x8(%r14), %rax
movq (%rax), %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x66e0
movq %r15, %rdi
movq %r12, %rsi
callq 0x672d
movq %r12, %rdi
movl $0x4c1, %esi            # imm = 0x4C1
callq 0x5f5b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6416
movq %rax, %r14
testq %rax, %rax
jne 0xd360
movq %rbx, %rdi
callq 0x63ed
movq 0x10(%rsp), %rdi
callq 0x63ed
movq 0x60(%rsp), %rbx
leaq 0x60(%rsp), %r15
cmpq %r15, %rbx
je 0xd3e4
movq (%rbx), %r14
movq %r15, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x5bcf
movq %rbx, %rdi
movl $0x4c2, %esi            # imm = 0x4C2
callq 0x5f5b
movq %r14, %rbx
cmpq %r15, %r14
jne 0xd3be
xorl %eax, %eax
addq $0x798, %rsp            # imm = 0x798
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq