// File: /workspace/github_c_makefile_star2_O2/TeaInside[P]teavpn/src/teavpn/client/tcp.c
// Function: teavpn_tcp_client
__attribute__((force_align_arg_pointer)) uint8_t teavpn_tcp_client(client_config *config)
{
	fd_set rd_set;
	uint64_t seq = 0;
	int fd_ret, max_fd;
	teavpn_packet packet;
	register ssize_t nwrite, nread;

	/**
	 * To store config file buffer (parsing).
	 *
	 * Avoid to use heap as long as it
	 * is still eligible to use stack.
	 *
	 * (heap is slower than stack)
	 */
	char config_buffer[4096];

	/**
	 * Use packet buffer as struct sockadd_in.
	 */
	#define server_addr ((struct sockaddr_in *)&(packet.data.data))


	if (teavpn_tcp_client_init(config_buffer, config)) {
		return 1;
	}


	/**
	 * Prepare server address.
	 */
	memset(server_addr, 0, sizeof(struct sockaddr_in));
	server_addr->sin_family = AF_INET;
	server_addr->sin_port = htons(config->server_port);
	server_addr->sin_addr.s_addr = inet_addr(config->server_ip);



	/**
	 * Conncet to TeaVPN server.
	 */
	debug_log(0, "Connecting to %s:%d...", config->server_ip, config->server_port);
	if (connect(net_fd, (struct sockaddr *)server_addr, sizeof(struct sockaddr_in)) < 0) {
		debug_log(0, "Error on connect");
		perror("Error on connect");
		goto close;
	}


	/**
	 * Prepare auth packet.
	 */
	packet.info.type = TEAVPN_PACKET_AUTH;
	packet.info.len = OFFSETOF(teavpn_packet, data) + sizeof(struct teavpn_packet_auth);
	packet.data.auth.username_len = config->username_len;
	packet.data.auth.password_len = config->password_len;
	strcpy(packet.data.auth.username, config->username);
	strcpy(packet.data.auth.password, config->password);

	/**
	 * Debug only.
	 */
	#ifdef TEAVPN_DEBUG
	debug_log(3, "username: \"%s\"", packet.data.auth.username);
	debug_log(3, "password: \"%s\"", packet.data.auth.password);
	debug_log(3, "username_len: %d", packet.data.auth.username_len);
	debug_log(3, "password_len: %d", packet.data.auth.password_len);
	#endif

	/**
	 * Send auth packet to server.
	 */
	packet.info.seq = ++seq; // seq 1
	nwrite = write(net_fd, &packet, TEAVPN_PACK(sizeof(packet.data.auth)));

	debug_log(3, "[%ld] Write auth packet to server %ld bytes", seq, nwrite);

	if (nwrite == 0) {
		debug_log(0, "Connection reset by peer");
		goto close;
	}

	if (nwrite < 0) {
		debug_log(0, "Error write to net_fd");
		perror("Error write to net_fd");
		goto close;
	}



	/**
	 * Read server response.
	 */
	seq++; // seq 2
	nread = read(net_fd, &packet, sizeof(packet));

	debug_log(
		3,
		"[%ld] Read server signal %ld bytes (client_seq: %ld) (server_seq: %ld) (seq %s)",
		seq, nread, seq, packet.info.seq, (seq == packet.info.seq) ? "match" : "invalid"
	);

	if (nread == 0) {
		debug_log(0, "Connection reset by peer");
		goto close;
	}

	if (seq != packet.info.seq) {
		debug_log(0, "Invalid packet sequence (client_seq: %ld) (server_seq: %ld)",
			seq, packet.info.seq);
		goto close;
	}

	/**
	 * Check server response.
	 */
	if (packet.info.type == TEAVPN_PACKET_SIG) {
		if (packet.data.sig.sig == TEAVPN_SIG_AUTH_OK) {
			debug_log(0, "Auth OK");
		} else {
			print_err_sig(packet.data.sig.sig);
			goto close;
		}
	} else {
		debug_log(0, "Invalid server response");
		goto close;
	}



	/**
	 * Send sig ack to server.
	 */
	packet.info.type = TEAVPN_PACKET_SIG;
	packet.data.sig.sig = TEAVPN_SIG_ACK;
	packet.info.seq = ++seq; // seq 3

	printf("info.type: %d = %d\n", packet.info.type, TEAVPN_PACKET_SIG);
	printf("sig.sig: %d = %d\n", packet.data.sig.sig, TEAVPN_SIG_ACK);
	fflush(stdout);
	nwrite = write(net_fd, &packet, TEAVPN_PACK(sizeof(packet.data.sig)));

	debug_log(3, "[%ld] Write sig ack to server %ld bytes", seq, nwrite);

	if (nwrite == 0) {
		debug_log(0, "Connection reset by peer");
		goto close;
	}

	if (nwrite < 0) {
		debug_log(0, "Error write to net_fd");
		perror("Error write to net_fd");
		goto close;
	}



	/**
	 * Read network interface configuration.
	 */
	seq++; // seq 4
	nread = read(net_fd, &packet, sizeof(packet));

	if (seq != packet.info.seq) {
		debug_log(0, "Invalid packet sequence (client_seq: %ld) (server_seq: %ld)",
			seq, packet.info.seq);
		goto close;
	}

	if (packet.info.type != TEAVPN_PACKET_CONF) {
		debug_log(0, "Invalid packet");
		goto close;
	}

	/**
	 * Debug only.
	 */
	#ifdef TEAVPN_DEBUG
	debug_log(3, "inet4: \"%s\"\n", packet.data.conf.inet4);
	debug_log(3, "inet4_bc: \"%s\"\n", packet.data.conf.inet4_broadcast);
	#endif



	/**
	 * Apply network interface configuration to TUN/TAP interface.
	 */
	if (!teavpn_tcp_client_init_iface(config, &(packet.data.conf))) {
		debug_log(0, "Cannot init TUN/TAP interface\n");
		goto close;
	}



	/**
	 * Calculate maximum value between tap_fd and net_fd.
	 */
	max_fd = (tap_fd > net_fd) ? tap_fd : net_fd;

	packet.info.type = TEAVPN_PACKET_DATA;

	/**
	 * TeaVPN client event loop.
	 */
	while (true) {
		/**
		 * Set rd_set to zero.
		 *
		 * This is a compulsory step in using
		 * select(2) inside of an event loop.
		 */
		FD_ZERO(&rd_set);


		/**
		 * Add file descriptors to rd_set.
		 */
		FD_SET(net_fd, &rd_set);
		FD_SET(tap_fd, &rd_set);


		/**
		 * Block main process until there is one or more ready fd.
		 * Read `man 2 select_tut` for details.
		 */
		fd_ret = select(max_fd + 1, &rd_set, NULL, NULL, NULL);

		/**
		 * Got interrupt signal.
		 */
		if ((fd_ret < 0) && (errno == EINTR)) {
			debug_log(2, "select(2) got interrupt signal");
			continue;
		}

		/**
		 * Got an error.
		 */
		if (fd_ret < 0) {
			debug_log(0, "select(2) got an error");
			perror("select()");
			continue;
		}


		/**
		 * Read data from client TUN/TAP and write it to server fd.
		 */
		if (FD_ISSET(tap_fd, &rd_set)) {
			/**
			 * Read from TUN/TAP.
			 */
			nread = read(tap_fd, &(packet.data.data), TEAVPN_TAP_READ_SIZE);
			debug_log(4, "Read from tap_fd %ld bytes", nread);
			if (nread < 0) {
				debug_log(0, "Error read from tap_fd");
				perror("Error read from tap_fd");
				goto next_1;
			}

			/**
			 * Write to server fd.
			 */
			packet.info.seq = ++seq;
			packet.info.len = TEAVPN_PACK(nread);
			nwrite = write(net_fd, &packet, TEAVPN_PACK(nread));
			debug_log(3, "[%ld] Write data to server %ld bytes", seq, nwrite);
			if (nwrite == 0) {
				debug_log(0, "Connection reset by peer");
				goto close;
			}
			if (nwrite < 0) {
				debug_log(0, "Error write to net_fd");
				perror("Error write to net_fd");
				goto next_1;
			}
		}


		next_1:
		/**
		 * Read data from server and write it to TUN/TAP interface.
		 */
		if (FD_ISSET(net_fd, &rd_set)) {
			/**
			 * Read from server fd.
			 */
			seq++;
			nread = read(net_fd, &packet, sizeof(packet));

			if (nread == 0) {
				debug_log(0, "Connection reset by peer");
				goto close;
			}
			if (nread < 0) {
				debug_log(0, "Error read from net_fd");
				perror("Error read from net_fd");
				goto next_2;
			}

			if (packet.info.type == TEAVPN_PACKET_DATA) {

				while (nread < (packet.info.len)) {
					register ssize_t tmp_nread;

					debug_log(3, "Read extra %ld/%ld bytes", nread, packet.info.len);
					tmp_nread = read(
						net_fd,
						&(((char *)&packet)[nread]),
						packet.info.len - nread
					);

					if (tmp_nread < 0) {
						perror("Error read extra");

					} else {
						nread += tmp_nread;
					}
				}

				debug_log(3, "[%ld] Read data from server %ld bytes (client_seq: %ld) (server_seq: %ld) (seq %s)",
					seq, nread, seq, packet.info.seq, (seq == packet.info.seq) ? "match" : "invalid");

				/**
				 * Write to TUN/TAP.
				 */
				nwrite = write(tap_fd, &(packet.data.data), nread - OFFSETOF(teavpn_packet, data));
				debug_log(4, "Write to tap_fd %ld bytes", nwrite);
				if (nread < 0) {
					debug_log(0, "Error read from tap_fd");
					perror("Error read from tap_fd");
					goto next_2;
				}
			}
		}

		next_2:
		(void)1;
	}

close:
	close(tap_fd);
	close(net_fd);

	return 1;

	#undef server_addr
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
andq $-0x10, %rsp
subq $0x2130, %rsp           # imm = 0x2130
movq %rdi, %r14
movq %fs:0x28, %rax
movq %rax, 0x2120(%rsp)
cmpq $0x0, 0x8(%rdi)
je 0x34e4
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x2add
testb %al, %al
je 0x34fe
cmpq $0x0, 0x28(%r14)
je 0x350a
cmpb $0x40, 0x38(%r14)
jb 0x3516
leaq 0x429d(%rip), %rdi      # 0x7796
jmp 0x39c4
leaq 0x426a(%rip), %rdi      # 0x776f
jmp 0x39c4
leaq 0x426c(%rip), %rdi      # 0x777d
jmp 0x39c4
cmpq $0x0, 0x30(%r14)
je 0x39ab
cmpq $0x0, (%r14)
je 0x39b4
cmpw $0x0, 0x3a(%r14)
je 0x39bd
movb 0x3c(%r14), %al
leaq 0x7ee2(%rip), %r13      # 0xb424
movb %al, (%r13)
cmpb $0x2, %al
jb 0x3558
leaq 0x42ab(%rip), %rdi      # 0x77fc
xorl %eax, %eax
callq 0x5aec
movq 0x18(%r14), %rdi
pushq $0x1
popq %rsi
callq 0x5c06
movl %eax, 0x7dfa(%rip)      # 0xb364
movq 0x18(%r14), %rsi
testl %eax, %eax
js 0x39f3
leaq 0x42c9(%rip), %rdi      # 0x7846
xorl %eax, %eax
callq 0x5aec
cmpb $0x0, (%r13)
je 0x3599
leaq 0x42df(%rip), %rdi      # 0x7871
xorl %eax, %eax
callq 0x5aec
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x2410
movl %eax, 0x7db4(%rip)      # 0xb360
testl %eax, %eax
js 0x3a25
cmpb $0x0, (%r13)
je 0x35c9
leaq 0x42dd(%rip), %rdi      # 0x789f
xorl %eax, %eax
callq 0x5aec
leaq 0x1030(%rsp), %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movw $0x2, (%rbx)
movzwl 0x3a(%r14), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rbx)
movq (%r14), %rdi
callq 0x2210
movl %eax, 0x4(%rbx)
movq (%r14), %rsi
movzwl 0x3a(%r14), %edx
leaq 0x3e12(%rip), %rdi      # 0x7415
xorl %eax, %eax
callq 0x5aec
movl 0x7d50(%rip), %edi      # 0xb360
pushq $0x10
popq %rdx
movq %rbx, %rsi
callq 0x23a0
testl %eax, %eax
js 0x3a3e
leaq 0x1032(%rsp), %r15
movl $0x1, -0x12(%r15)
movw $0x212, -0xe(%r15)      # imm = 0x212
movb 0x38(%r14), %al
movb %al, -0x2(%r15)
movb 0x39(%r14), %al
movb %al, -0x1(%r15)
movq 0x28(%r14), %rsi
movq %r15, %rdi
callq 0x2070
leaq 0x1132(%rsp), %r12
movq 0x30(%r14), %rsi
movq %r12, %rdi
callq 0x2070
cmpb $0x3, (%r13)
jb 0x36d4
leaq 0x3dc5(%rip), %rdi      # 0x743d
movq %r15, %rsi
xorl %eax, %eax
callq 0x5aec
cmpb $0x3, (%r13)
jb 0x36d4
leaq 0x3dbc(%rip), %rdi      # 0x744c
movq %r12, %rsi
xorl %eax, %eax
callq 0x5aec
cmpb $0x3, (%r13)
jb 0x36d4
movzbl 0x1030(%rsp), %esi
leaq 0x3dab(%rip), %rdi      # 0x745b
xorl %eax, %eax
callq 0x5aec
cmpb $0x3, (%r13)
jb 0x36d4
movzbl 0x1031(%rsp), %esi
leaq 0x3d9f(%rip), %rdi      # 0x746c
xorl %eax, %eax
callq 0x5aec
leaq 0x1020(%rsp), %rsi
movq $0x1, 0x8(%rsi)
movl 0x7c76(%rip), %edi      # 0xb360
movl $0x212, %edx            # imm = 0x212
callq 0x20c0
movq %rax, %r15
cmpb $0x3, (%r13)
jb 0x3712
leaq 0x3d78(%rip), %rdi      # 0x747d
pushq $0x1
popq %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x5aec
testq %r15, %r15
je 0x3fa2
js 0x3a63
movl 0x7c39(%rip), %edi      # 0xb360
leaq 0x1020(%rsp), %rsi
movl $0x1010, %edx           # imm = 0x1010
callq 0x21d0
movq %rax, %r15
cmpb $0x3, (%r13)
leaq 0x3de0(%rip), %rax      # 0x7528
leaq 0x3ddf(%rip), %r9       # 0x752e
jb 0x3778
movq 0x1028(%rsp), %r8
cmpq $0x2, %r8
cmoveq %rax, %r9
leaq 0x3d70(%rip), %rdi      # 0x74d8
pushq $0x2
popq %rcx
movq %rcx, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x5aec
testq %r15, %r15
je 0x3fa2
movq 0x1028(%rsp), %rdx
cmpq $0x2, %rdx
jne 0x3a03
cmpl $0x4, 0x1020(%rsp)
jne 0x3a19
movl 0x1030(%rsp), %eax
cmpl $0x2, %eax
jne 0x3a47
leaq 0x3dba(%rip), %rdi      # 0x7572
xorl %eax, %eax
callq 0x5aec
leaq 0x1020(%rsp), %r15
movl $0x4, (%r15)
movl $0x10, 0x10(%r15)
movq $0x3, 0x8(%r15)
leaq 0x3dad(%rip), %rdi      # 0x7592
pushq $0x4
popq %rdx
movl %edx, %esi
xorl %eax, %eax
callq 0x2150
movl 0x10(%r15), %esi
leaq 0x3daa(%rip), %rdi      # 0x75a6
pushq $0x10
popq %rdx
xorl %eax, %eax
callq 0x2150
movq 0x77c3(%rip), %rax      # 0xafd0
movq (%rax), %rdi
callq 0x22d0
movl 0x7b45(%rip), %edi      # 0xb360
pushq $0x14
popq %rdx
movq %r15, %rsi
callq 0x20c0
movq %rax, %r15
cmpb $0x2, (%r13)
jbe 0x3844
leaq 0x3d81(%rip), %rdi      # 0x75b8
pushq $0x3
popq %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x5aec
testq %r15, %r15
je 0x3fa2
js 0x3a63
movl 0x7b07(%rip), %edi      # 0xb360
leaq 0x1020(%rsp), %r15
movl $0x1010, %edx           # imm = 0x1010
movq %r15, %rsi
callq 0x21d0
movq 0x8(%r15), %rdx
cmpq $0x4, %rdx
jne 0x3a8d
cmpl $0x8, 0x1020(%rsp)
jne 0x3a9b
cmpb $0x3, (%r13)
jb 0x38bf
leaq 0x3d57(%rip), %rdi      # 0x75ef
movq %rbx, %rsi
xorl %eax, %eax
callq 0x5aec
cmpb $0x3, (%r13)
jb 0x38bf
leaq 0x1043(%rsp), %rsi
leaq 0x3d44(%rip), %rdi      # 0x75fc
xorl %eax, %eax
callq 0x5aec
movq 0x18(%r14), %rdi
callq 0x25a0
movq %rax, %r12
movq %rbx, %rdi
callq 0x25a0
movq %rax, 0x10(%rsp)
leaq 0x1043(%rsp), %rdi
callq 0x25a0
movq %rax, %r15
movzwl 0x20(%r14), %ecx
leaq 0x4041(%rip), %rsi      # 0x7935
leaq 0x2030(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2390
cmpb $0x0, (%r13)
je 0x3923
leaq 0x4044(%rip), %rdi      # 0x7958
leaq 0x2030(%rsp), %rsi
xorl %eax, %eax
callq 0x5aec
leaq 0x2030(%rsp), %rdi
callq 0x2140
testl %eax, %eax
jne 0x3985
leaq 0x402c(%rip), %rsi      # 0x7967
movq %r15, 0x8(%rsp)
leaq 0x2030(%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %r8
xorl %eax, %eax
callq 0x2390
leaq 0x402a(%rip), %rdi      # 0x7990
movq %r15, %rsi
xorl %eax, %eax
callq 0x5aec
movq %r15, %rdi
movq 0x8(%rsp), %r15
callq 0x2140
testl %eax, %eax
je 0x3aa7
movq %r12, %rdi
callq 0x2030
movq 0x10(%rsp), %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2030
leaq 0x3c66(%rip), %rdi      # 0x760c
jmp 0x3fa9
leaq 0x3dfc(%rip), %rdi      # 0x77ae
jmp 0x39c4
leaq 0x3e0c(%rip), %rdi      # 0x77c7
jmp 0x39c4
leaq 0x3e1d(%rip), %rdi      # 0x77e1
xorl %eax, %eax
callq 0x5aec
movq %fs:0x28, %rax
cmpq 0x2120(%rsp), %rax
jne 0x3ff5
movb $0x1, %al
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e22(%rip), %rdi      # 0x781c
xorl %eax, %eax
callq 0x5aec
jmp 0x39cb
leaq 0x3b2c(%rip), %rdi      # 0x7536
pushq $0x2
popq %rsi
xorl %eax, %eax
callq 0x5aec
jmp 0x3fb0
leaq 0x3b5a(%rip), %rdi      # 0x757a
jmp 0x3fa9
movl 0x7939(%rip), %edi      # 0xb364
callq 0x21a0
leaq 0x3e51(%rip), %rdi      # 0x7888
callq 0x2350
jmp 0x39cb
leaq 0x39e7(%rip), %rbx      # 0x742c
jmp 0x3a6a
decb %al
cmpb $0x7, %al
ja 0x3a81
movzbl %al, %eax
leaq 0x4005(%rip), %rcx      # 0x7a5c
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
jmp 0x3fa9
leaq 0x3a58(%rip), %rbx      # 0x74c2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5aec
movq %rbx, %rdi
callq 0x2350
jmp 0x3fb0
leaq 0x3e9e(%rip), %rdi      # 0x7926
jmp 0x3fa9
leaq 0x3aa2(%rip), %rdi      # 0x7536
pushq $0x4
jmp 0x3a0c
leaq 0x3b3e(%rip), %rdi      # 0x75e0
jmp 0x3fa9
movq (%r14), %rdx
leaq 0x3eed(%rip), %rsi      # 0x799e
leaq 0x2030(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x2390
leaq 0x3ec6(%rip), %rdi      # 0x7990
movq %r15, %rsi
xorl %eax, %eax
callq 0x5aec
leaq 0x35b4(%rip), %rsi      # 0x708f
movq %r15, %rdi
callq 0x2330
movq %rax, %r15
leaq 0x20b0(%rsp), %rdi
pushq $0x63
popq %rsi
movq %rax, %rdx
callq 0x21e0
movq %rax, 0x18(%rsp)
movq %r15, %rdi
callq 0x2180
cmpq $0x0, 0x18(%rsp)
je 0x3fcb
leaq 0x3eb3(%rip), %rsi      # 0x79cc
leaq 0x20b0(%rsp), %rdi
callq 0x23e0
testq %rax, %rax
jne 0x3b48
leaq 0x3e9e(%rip), %rsi      # 0x79d0
leaq 0x20b0(%rsp), %rdi
callq 0x23e0
testq %rax, %rax
je 0x3fcb
pushq $0x4
popq %r15
cmpb $0x20, (%rax)
leaq 0x1(%rax), %rax
jne 0x3b4c
movq %rax, %rcx
cmpb $0x20, (%rcx)
leaq 0x1(%rcx), %rcx
jne 0x3b58
movb $0x0, -0x1(%rcx)
movq (%r14), %rdx
leaq 0x3e65(%rip), %rsi      # 0x79d4
leaq 0x2030(%rsp), %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x2390
cmpb $0x0, (%r13)
je 0x3b9e
leaq 0x3e01(%rip), %rdi      # 0x7990
leaq 0x2030(%rsp), %rsi
xorl %eax, %eax
callq 0x5aec
leaq 0x2030(%rsp), %rdi
callq 0x2140
testl %eax, %eax
je 0x3bc4
cmpb $0x3, (%r13)
jb 0x3bc4
leaq 0x3e37(%rip), %rdi      # 0x79f4
xorl %eax, %eax
callq 0x5aec
leaq 0x3e3f(%rip), %rsi      # 0x7a0a
leaq 0x3e5c(%rip), %rdx      # 0x7a2e
leaq 0x2030(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2390
leaq 0x3da5(%rip), %rdi      # 0x7990
movq %r14, %rsi
xorl %eax, %eax
callq 0x5aec
movq %r14, %rdi
callq 0x2140
testl %eax, %eax
je 0x3c16
cmpb $0x3, (%r13)
jb 0x3c16
leaq 0x3de5(%rip), %rdi      # 0x79f4
xorl %eax, %eax
callq 0x5aec
leaq 0x3e19(%rip), %rsi      # 0x7a36
leaq 0x3e0a(%rip), %rdx      # 0x7a2e
leaq 0x2030(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2390
leaq 0x3d53(%rip), %rdi      # 0x7990
movq %r14, %rsi
xorl %eax, %eax
callq 0x5aec
movq %r14, %rdi
callq 0x2140
testl %eax, %eax
je 0x3c68
cmpb $0x3, (%r13)
jb 0x3c68
leaq 0x3d93(%rip), %rdi      # 0x79f4
xorl %eax, %eax
callq 0x5aec
movq %r12, %rdi
callq 0x2030
movq 0x10(%rsp), %rdi
callq 0x2030
movq 0x8(%rsp), %rdi
callq 0x2030
movl 0x76da(%rip), %eax      # 0xb364
movl 0x76d0(%rip), %ecx      # 0xb360
cmpl %ecx, %eax
cmovgl %eax, %ecx
leaq 0x1020(%rsp), %rax
movl $0x2, (%rax)
incl %ecx
movl %ecx, 0x10(%rsp)
pushq $0x40
popq %r14
movq %r15, %r12
xorl %eax, %eax
movl 0x10(%rsp), %r15d
cmpq $0x10, %rax
jne 0x3d52
movl 0x7699(%rip), %ecx      # 0xb360
movl %ecx, %eax
cltd
idivl %r14d
movslq %eax, %rdx
shll $0x6, %eax
subl %eax, %ecx
pushq $0x1
popq %rsi
movq %rsi, %rax
shlq %cl, %rax
orq %rax, 0x2030(%rsp,%rdx,8)
movl 0x7678(%rip), %ecx      # 0xb364
movl %ecx, %eax
cltd
idivl %r14d
movslq %eax, %rdx
shll $0x6, %eax
subl %eax, %ecx
movq %rsi, %rax
shlq %cl, %rax
orq %rax, 0x2030(%rsp,%rdx,8)
movl %r15d, %edi
leaq 0x2030(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2290
testl %eax, %eax
jns 0x3d84
callq 0x2050
cmpl $0x4, (%rax)
jne 0x3d63
cmpb $0x2, (%r13)
movl $0x0, %eax
jb 0x3cb7
leaq 0x38e7(%rip), %rdi      # 0x762b
xorl %eax, %eax
callq 0x5aec
xorl %eax, %eax
jmp 0x3cb7
andq $0x0, 0x2030(%rsp,%rax,8)
incq %rax
jmp 0x3cb7
leaq 0x38e0(%rip), %rdi      # 0x764a
xorl %eax, %eax
callq 0x5aec
leaq 0x38e9(%rip), %rdi      # 0x7661
callq 0x2350
xorl %eax, %eax
jmp 0x3cb7
movl 0x75da(%rip), %edi      # 0xb364
movl %edi, %eax
cltd
idivl %r14d
cltq
movq 0x2030(%rsp,%rax,8), %rax
btq %rdx, %rax
jae 0x3e37
movl $0xbb8, %edx            # imm = 0xBB8
movq %rbx, %rsi
callq 0x21d0
movq %rax, %r15
cmpb $0x4, (%r13)
jb 0x3dcc
leaq 0x38a8(%rip), %rdi      # 0x766a
movq %r15, %rsi
xorl %eax, %eax
callq 0x5aec
testq %r15, %r15
js 0x3f66
incq %r12
movq %r12, 0x1028(%rsp)
addq $0x10, %r15
movw %r15w, 0x1024(%rsp)
movl 0x756d(%rip), %edi      # 0xb360
leaq 0x1020(%rsp), %rsi
movq %r15, %rdx
callq 0x20c0
movq %rax, %r15
cmpb $0x3, (%r13)
jb 0x3e21
leaq 0x3888(%rip), %rdi      # 0x769c
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x5aec
testq %r15, %r15
je 0x3fa2
leaq 0x3691(%rip), %r15      # 0x74c2
js 0x3f6d
movl 0x7523(%rip), %edi      # 0xb360
movl %edi, %eax
cltd
idivl %r14d
cltq
movq 0x2030(%rsp,%rax,8), %rax
btq %rdx, %rax
jae 0x3cb0
incq %r12
movl $0x1010, %edx           # imm = 0x1010
leaq 0x1020(%rsp), %rsi
callq 0x21d0
testq %rax, %rax
je 0x3fa2
js 0x3f84
cmpl $0x2, 0x1020(%rsp)
jne 0x3cb0
movq %rax, %r15
movq %r12, 0x8(%rsp)
leaq (%rsp,%r15), %r12
addq $0x1020, %r12           # imm = 0x1020
movzwl 0x1024(%rsp), %edx
movb (%r13), %al
cmpq %rdx, %r15
jge 0x3ef3
cmpb $0x3, %al
jb 0x3eca
leaq 0x3820(%rip), %rdi      # 0x76d8
movq %r15, %rsi
xorl %eax, %eax
callq 0x5aec
movzwl 0x1024(%rsp), %edx
movl 0x7490(%rip), %edi      # 0xb360
subq %r15, %rdx
movq %r12, %rsi
callq 0x21d0
testq %rax, %rax
jns 0x3eee
leaq 0x380a(%rip), %rdi      # 0x76f1
callq 0x2350
jmp 0x3e9c
addq %rax, %r15
jmp 0x3e91
cmpb $0x3, %al
movq 0x8(%rsp), %r12
jb 0x3f30
movq 0x1028(%rsp), %r8
cmpq %r8, %r12
leaq 0x3620(%rip), %r9       # 0x752e
leaq 0x3613(%rip), %rax      # 0x7528
cmoveq %rax, %r9
leaq 0x37e2(%rip), %rdi      # 0x7702
movq %r12, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x5aec
movl 0x742e(%rip), %edi      # 0xb364
addq $-0x10, %r15
movq %rbx, %rsi
movq %r15, %rdx
callq 0x20c0
cmpb $0x4, (%r13)
jb 0x3cb0
leaq 0x37fe(%rip), %rdi      # 0x7755
movq %rax, %rsi
xorl %eax, %eax
callq 0x5aec
jmp 0x3cb0
leaq 0x3718(%rip), %r15      # 0x7685
movq %r15, %rdi
xorl %eax, %eax
callq 0x5aec
movq %r15, %rdi
callq 0x2350
jmp 0x3e37
leaq 0x3736(%rip), %r15      # 0x76c1
movq %r15, %rdi
xorl %eax, %eax
callq 0x5aec
movq %r15, %rdi
callq 0x2350
jmp 0x3cb0
leaq 0x3500(%rip), %rdi      # 0x74a9
xorl %eax, %eax
callq 0x5aec
movl 0x73ae(%rip), %edi      # 0xb364
callq 0x21a0
movl 0x739f(%rip), %edi      # 0xb360
callq 0x21a0
jmp 0x39cb
leaq 0x39e2(%rip), %rdi      # 0x79b4
xorl %eax, %eax
callq 0x5aec
movq %r12, %rdi
callq 0x2030
movq 0x10(%rsp), %rdi
callq 0x2030
movq 0x8(%rsp), %rdi
jmp 0x399a
callq 0x2110
nop