// File: /workspace/github_c_makefile_star2_O3/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 0xa548(%rip), %rax      # 0x17310
movq (%rax), %r14
movl $0x100fea9, 0x20(%rsp)  # imm = 0x100FEA9
movl $0x10, 0x28(%rsp)
callq 0xb3f0
movl %eax, 0xc(%rsp)
movl $0xd2100002, 0x70(%rsp) # imm = 0xD2100002
leaq 0x58(%rsp), %rax
movq %rax, (%rax)
movq %rax, 0x8(%rax)
leaq 0x80(%rsp), %rdx
leaq 0x8(%rsp), %r8
leaq 0x2c(%rsp), %r9
movl $0x10, %ecx
movq %r14, %rdi
movl $0xfea9, %esi           # imm = 0xFEA9
callq 0x925b
testb %al, %al
js 0xd6c0
leaq 0x8a9(%rip), %rsi       # 0xd6d4
leaq 0x8ac(%rip), %rdx       # 0xd6de
movl $0x80, %edi
callq 0x6864
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0xd6c0
movq %rax, %rbx
leaq 0x8c8(%rip), %rsi       # 0xd71c
leaq 0x8cd(%rip), %rdx       # 0xd728
movl $0x80, %edi
callq 0x6864
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0xd5ae
movl 0x2c(%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 0x7cd4
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), %r12d
leal 0x3f(%r12), %edx
testl %r12d, %r12d
cmovnsl %r12d, %edx
movl %edx, %esi
andl $-0x40, %esi
movl %r12d, %ecx
subl %esi, %ecx
shlq %cl, %rax
sarl $0x6, %edx
movslq %edx, %rcx
orq %rax, 0xb0(%rsp,%rcx,8)
callq 0xbbdb
testb %al, %al
jne 0xd5e8
leaq 0xa363(%rip), %rax      # 0x172b9
cmpb $0x0, (%rax)
je 0xd5e8
cmpl %r12d, %ebx
cmovgl %ebx, %r12d
incl %r12d
leaq 0x1b0(%rsp), %r13
leaq 0x30(%rsp), %r15
movq %r12, 0x68(%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 %r12d, %edi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0xa0(%rsp), %r8
callq 0x22c0
movl %eax, %ebx
callq 0xb3f0
movl %eax, 0x4(%rsp)
testl %ebx, %ebx
js 0xd379
leaq 0x40(%rsp), %rbx
je 0xd4c0
movl 0x18(%r14), %edi
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
sarl $0x6, %eax
cltq
movq 0x130(%rsp,%rax,8), %rax
btq %rdi, %rax
jae 0xd3a3
movl $0x5dc, %edx            # imm = 0x5DC
movq %r13, %rsi
xorl %ecx, %ecx
movq %r15, %r8
leaq 0x28(%rsp), %r9
callq 0x2320
movq %rax, %rbp
testl %ebp, %ebp
jle 0xd38e
cmpl $0x1, %ebp
jne 0xd061
movl 0x34(%rsp), %edi
movq %rbx, %rsi
movl $0x10, %edx
callq 0xbbac
xorl %edi, %edi
leaq 0x58d5(%rip), %rsi      # 0x1291c
movq %rbx, %rdx
movl $0x1, %ecx
xorl %eax, %eax
callq 0xd88c
movl 0x18(%r14), %edi
movl $0x5dc, %edx            # imm = 0x5DC
jmp 0xd00b
movzbl 0x1b0(%rsp), %eax
cmpl $0x4, %eax
je 0xd27a
cmpl $0x2, %eax
je 0xd1df
cmpl $0x1, %eax
jne 0xd056
movq 0x10(%rsp), %rdi
leaq 0x1b9(%rsp), %rsi
callq 0x69d3
movq %rax, %rbx
movl 0x34(%rsp), %edi
testq %rax, %rax
je 0xd0b0
cmpl %edi, (%rbx)
je 0xd197
cmpb $0x0, 0x10(%rbx)
jne 0xd197
movb $0x3, 0x1b0(%rsp)
leaq 0x40(%rsp), %r15
movq %r15, %rsi
movl $0x10, %edx
callq 0xbbac
movzbl 0x1bd(%rsp), %ecx
movzbl 0x1be(%rsp), %r8d
movzbl 0x1bf(%rsp), %r9d
movzbl 0x1c0(%rsp), %r10d
subq $0x8, %rsp
xorl %edi, %edi
leaq 0x5861(%rip), %rsi      # 0x1295b
movq %r15, %rdx
xorl %eax, %eax
pushq %r10
callq 0xd88c
addq $0x10, %rsp
testq %rbx, %rbx
jne 0xd17f
leaq 0x30(%rsp), %rdi
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0x20(%rsp), %r8
callq 0xd767
movq %rax, %rbx
movl 0x4(%rax), %edi
leaq 0x40(%rsp), %r13
movq %r13, %rsi
movl $0x10, %edx
callq 0xbbac
movl 0x34(%rsp), %edi
leaq 0x90(%rsp), %r15
movq %r15, %rsi
movl $0x10, %edx
callq 0xbbac
movl $0x3, %edi
leaq 0x5840(%rip), %rsi      # 0x129aa
movq %r13, %rdx
movq %r15, %rcx
leaq 0x1b0(%rsp), %r13
xorl %eax, %eax
callq 0xd88c
xorl %edi, %edi
leaq 0x5855(%rip), %rsi      # 0x129dd
xorl %eax, %eax
callq 0xd88c
incb 0x10(%rbx)
leaq 0x30(%rsp), %r15
movl 0x8(%rsp), %edi
decl %ebp
leaq 0x1b1(%rsp), %rsi
movq %rbp, %rdx
callq 0x20f0
testq %rax, %rax
leaq 0x40(%rsp), %rbx
jns 0xd056
callq 0x2070
movl (%rax), %edi
callq 0x2480
xorl %edi, %edi
leaq 0x586d(%rip), %rsi      # 0x12a3d
movq %rax, %rdx
xorl %eax, %eax
callq 0xd88c
jmp 0xd056
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0x20(%rsp), %r8
callq 0xd767
movq %rax, %rbx
movl 0x4(%rax), %eax
movl %eax, 0x1b1(%rsp)
movl 0x18(%r14), %edi
movl $0x64, %edx
movq %r13, %rsi
xorl %ecx, %ecx
movq %r15, %r8
movl $0x10, %r9d
callq 0x21e0
testq %rax, %rax
js 0xd30f
movl 0x4(%rbx), %edi
leaq 0x40(%rsp), %r15
movq %r15, %rsi
movl $0x10, %edx
callq 0xbbac
movl 0x34(%rsp), %edi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
movl $0x10, %edx
callq 0xbbac
movl $0x3, %edi
leaq 0x58a9(%rip), %rsi      # 0x12b10
movq %r15, %rdx
movq %rbx, %rcx
movq %r15, %rbx
leaq 0x30(%rsp), %r15
jmp 0xd340
movq 0x18(%rsp), %rdi
leaq 0x34(%rsp), %rsi
callq 0x69d3
movb $0x3, 0x1b0(%rsp)
testq %rax, %rax
je 0xd2a5
movl 0x4(%rsp), %ecx
movl %ecx, 0xc(%rax)
movb $0x5, 0x1b0(%rsp)
movl 0x34(%rsp), %edi
movq %rbx, %rsi
movl $0x10, %edx
callq 0xbbac
movl 0x18(%r14), %edi
movl $0x64, %edx
movq %r13, %rsi
xorl %ecx, %ecx
movq %r15, %r8
movl $0x10, %r9d
callq 0x21e0
cmpb $0x5, 0x1b0(%rsp)
movq %rbx, %rbp
leaq 0x57be(%rip), %rbx      # 0x12aa2
leaq 0x57a6(%rip), %rcx      # 0x12a91
cmoveq %rcx, %rbx
testq %rax, %rax
js 0xd34c
movl $0x3, %edi
leaq 0x57b9(%rip), %rsi      # 0x12ab9
movq %rbx, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xd88c
jmp 0xd371
movl 0x34(%rsp), %edi
leaq 0x40(%rsp), %rbx
movq %rbx, %rsi
movl $0x10, %edx
callq 0xbbac
callq 0x2070
movl (%rax), %edi
callq 0x2480
xorl %edi, %edi
leaq 0x57a1(%rip), %rsi      # 0x12adb
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xd88c
jmp 0xd056
callq 0x2070
movl (%rax), %edi
callq 0x2480
xorl %edi, %edi
leaq 0x5705(%rip), %rsi      # 0x12a66
movq %rbx, %rdx
movq %rbp, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xd88c
movq %rbp, %rbx
jmp 0xd056
callq 0x2070
movl (%rax), %edi
cmpl $0x4, %edi
je 0xd4c0
jmp 0xd5bb
callq 0x2070
movl (%rax), %edi
cmpl $0xb, %edi
je 0xd4c0
jmp 0xd5c4
movl 0x8(%rsp), %edi
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
sarl $0x6, %eax
cltq
movq 0x130(%rsp,%rax,8), %rax
btq %rdi, %rax
jae 0xd4c0
movl $0x5db, %edx            # imm = 0x5DB
leaq 0x1b1(%rsp), %rsi
callq 0x2230
movq %rax, %rbx
testl %ebx, %ebx
jle 0xd4b0
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1bd(%rsp), %rsi
callq 0x69d3
testq %rax, %rax
je 0xd45d
movl (%rax), %ecx
movl %ecx, 0x74(%rsp)
movzwl 0x8(%rax), %eax
movw %ax, 0x72(%rsp)
movb $0x1, 0x1b0(%rsp)
movl 0x18(%r14), %edi
incl %ebx
movq %r13, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
leaq 0x70(%rsp), %r8
movl $0x10, %r9d
callq 0x21e0
testq %rax, %rax
jns 0xd48f
callq 0x2070
movl (%rax), %edi
callq 0x2480
xorl %edi, %edi
leaq 0x5714(%rip), %rsi      # 0x12b60
leaq 0x40(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xd88c
jmp 0xd48f
movl 0x1c1(%rsp), %edi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
movl $0x10, %edx
callq 0xbbac
movl $0x3, %edi
leaq 0x5708(%rip), %rsi      # 0x12b8d
movq %rbx, %rdx
xorl %eax, %eax
callq 0xd88c
movl 0x8(%rsp), %edi
movl $0x5db, %edx            # imm = 0x5DB
leaq 0x1b1(%rsp), %rsi
callq 0x2230
movq %rax, %rbx
testl %ebx, %ebx
jg 0xd3e8
callq 0x2070
movl (%rax), %edi
cmpl $0xb, %edi
jne 0xd5cd
movl 0x4(%rsp), %eax
subl 0xc(%rsp), %eax
addl $0xffff15a0, %eax       # imm = 0xFFFF15A0
testl %eax, %eax
jle 0xd593
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6741
testq %rax, %rax
je 0xd58b
movq %rax, %rbp
movl 0x4(%rsp), %r15d
addl $0xffecc620, %r15d      # imm = 0xFFECC620
movq 0x10(%rsp), %r12
movq 0x8(%rbp), %rax
movq (%rax), %r13
movl %r15d, %eax
subl 0xc(%r13), %eax
testl %eax, %eax
jle 0xd55c
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x6a25
movq %r12, %rdi
movq %r13, %rsi
callq 0x6a72
movl $0x38, %edi
movl $0xd2, %esi
callq 0x5d52
movq %rax, (%rax)
movl 0x4(%r13), %ecx
movl %ecx, 0x8(%rax)
movq %rax, %rdi
leaq 0x58(%rsp), %rsi
callq 0x5bcd
movq %r13, %rdi
movl $0x4c0, %esi            # imm = 0x4C0
callq 0x628b
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x6741
movq %rax, %rbp
testq %rax, %rax
jne 0xd501
movl 0x4(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x68(%rsp), %r12
leaq 0x1b0(%rsp), %r13
leaq 0x30(%rsp), %r15
jmp 0xd593
movl 0x4(%rsp), %eax
movl %eax, 0xc(%rsp)
callq 0xbbdb
testb %al, %al
jne 0xd5e8
leaq 0x9d16(%rip), %rax      # 0x172b9
cmpb $0x0, (%rax)
jne 0xcf7b
jmp 0xd5e8
movq %rbx, %rdi
callq 0x6718
jmp 0xd6c0
leaq 0x5333(%rip), %rbx      # 0x128f5
jmp 0xd5d4
leaq 0x556b(%rip), %rbx      # 0x12b36
jmp 0xd5d4
leaq 0x55e2(%rip), %rbx      # 0x12bb6
callq 0x2480
xorl %edi, %edi
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd88c
movl 0x2c(%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 0x7cd4
addq $0x20, %rsp
movl 0x8(%rsp), %edi
callq 0x9218
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6741
movq 0x10(%rsp), %r14
testq %rax, %rax
je 0xd67b
movq %rax, %r15
movq 0x8(%r15), %rax
movq (%rax), %r12
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6a25
movq %r14, %rdi
movq %r12, %rsi
callq 0x6a72
movq %r12, %rdi
movl $0x4c1, %esi            # imm = 0x4C1
callq 0x628b
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6741
movq %rax, %r15
testq %rax, %rax
jne 0xd63e
movq %rbx, %rdi
callq 0x6718
movq %r14, %rdi
callq 0x6718
movq 0x58(%rsp), %rbx
leaq 0x58(%rsp), %r15
cmpq %r15, %rbx
je 0xd6c0
movq (%rbx), %r14
movq %r15, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x5be3
movq %rbx, %rdi
movl $0x4c2, %esi            # imm = 0x4C2
callq 0x628b
movq %r14, %rbx
cmpq %r15, %r14
jne 0xd69a
xorl %eax, %eax
addq $0x798, %rsp            # imm = 0x798
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq