// File: /workspace/github_c_makefile_star2_O3/TeaInside[P]teavpn/src/teavpn/client/tcp.c
// Function: teavpn_tcp_client_init_iface
static bool teavpn_tcp_client_init_iface(client_config *config, struct teavpn_client_ip *ip)
{
	bool ret;
	char cmd[100],
		data[100],
		*escaped_dev,
		*escaped_inet4,
		*escaped_inet4_broadcast,
		*p, *q;
	FILE *fp = NULL;

	escaped_dev = escapeshellarg(config->dev);
	escaped_inet4 = escapeshellarg(ip->inet4);
	escaped_inet4_broadcast = escapeshellarg(ip->inet4_broadcast);

	/**
	 * Set interface up.
	 */
	sprintf(
		cmd,
		"/sbin/ip link set dev %s up mtu %d",
		escaped_dev,
		config->mtu
	);
	debug_log(1, "Executing: %s\n", cmd);
	if (system(cmd)) {
		ret = false;
		goto ret;
	}


	/**
	 * Assign private IP.
	 */
	sprintf(
		cmd,
		"/sbin/ip addr add dev %s %s broadcast %s",
		escaped_dev,
		escaped_inet4,
		escaped_inet4_broadcast
	);
	debug_log(0, "Executing: %s", cmd);
	if (system(cmd)) {
		ret = false;
		goto ret;
	}

	/**
	 * Get server route data.
	 */
	sprintf(cmd, "/sbin/ip route get %s", config->server_ip);
	debug_log(0, "Executing: %s", cmd);
	fp = popen(cmd, "r");
	q = fgets(data, 99, fp);
	pclose(fp);

	if (q == NULL) {
		debug_log(0, "Cannot get server route via");

		// Commented for debug only.
		ret = false;
		goto ret;
	}

	p = strstr(data, "via");
	if (p == NULL) {
		p = strstr(data, "src");
		if (p == NULL) {
			debug_log(0, "Cannot get server route via");

			// Commented for debug only.
			ret = false;
			goto ret;
		}
	}

	while ((*p) != ' ') p++;
	p++;
	q = p;
	while ((*q) != ' ') q++;
	*q = '\0';

	// Commented for debug only.
	sprintf(cmd, "/sbin/ip route add %s/32 via %s", config->server_ip, p);
	debug_log(1, "Executing: %s", cmd);
	if (system(cmd)) {
		debug_log(3, "Exit code is not zero");
	}

	sprintf(cmd, "/sbin/ip route add 0.0.0.0/1 via %s", "5.5.0.1");
	debug_log(0, "Executing: %s", cmd);

	if (system(cmd)) {
		debug_log(3, "Exit code is not zero");
		// ret = false;
		// goto ret;
	}

	sprintf(cmd, "/sbin/ip route add 128.0.0.0/1 via %s", "5.5.0.1");
	debug_log(0, "Executing: %s", cmd);

	if (system(cmd)) {
		debug_log(3, "Exit code is not zero");
		// ret = false;
		// goto ret;
	}

	ret = true;
ret:
	free(escaped_dev);
	free(escaped_inet4);
	free(escaped_inet4_broadcast);
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %r15
movq %rdi, %r12
movq %fs:0x28, %rax
movq %rax, -0x30(%rbp)
movq 0x18(%rdi), %rdi
callq 0x2a80
movq %rax, %rbx
movq %r15, %rdi
callq 0x2a80
movq %rax, %r14
addq $0x13, %r15
movq %r15, %rdi
callq 0x2a80
movq %rax, %r15
movzwl 0x20(%r12), %ecx
leaq 0x3693(%rip), %rsi      # 0x7935
leaq -0xa0(%rbp), %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2390
leaq 0x716a(%rip), %rax      # 0xb424
cmpb $0x0, (%rax)
je 0x42d4
leaq 0x3692(%rip), %rdi      # 0x7958
leaq -0xa0(%rbp), %rsi
xorl %eax, %eax
callq 0x5fb8
leaq -0xa0(%rbp), %rdi
callq 0x2140
testl %eax, %eax
je 0x42ec
xorl %r13d, %r13d
jmp 0x4551
leaq 0x3674(%rip), %rsi      # 0x7967
xorl %r13d, %r13d
movq %r14, -0x118(%rbp)
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rdx
movq -0x118(%rbp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x2390
leaq 0x366e(%rip), %rdi      # 0x7990
movq %r14, %rsi
xorl %eax, %eax
callq 0x5fb8
movq %r14, %rdi
movq -0x118(%rbp), %r14
callq 0x2140
testl %eax, %eax
jne 0x4551
movq %r15, -0x120(%rbp)
movq (%r12), %rdx
leaq 0x3649(%rip), %rsi      # 0x799e
xorl %r13d, %r13d
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2390
leaq 0x3620(%rip), %rdi      # 0x7990
movq %r14, %rsi
xorl %eax, %eax
callq 0x5fb8
leaq 0x2d0e(%rip), %rsi      # 0x708f
movq %r14, %rdi
callq 0x2330
movq %rax, %r14
leaq -0x110(%rbp), %rdi
movl $0x63, %esi
movq %rax, %rdx
callq 0x21e0
movq %rax, %r15
movq %r14, %rdi
callq 0x2180
leaq 0x3602(%rip), %rdi      # 0x79b4
testq %r15, %r15
je 0x43e6
leaq 0x360e(%rip), %rsi      # 0x79cc
leaq -0x110(%rbp), %rdi
callq 0x23e0
testq %rax, %rax
movq -0x118(%rbp), %r14
movq -0x120(%rbp), %r15
je 0x43f9
leaq 0x7040(%rip), %r13      # 0xb424
jmp 0x441c
movq -0x118(%rbp), %r14
movq -0x120(%rbp), %r15
jmp 0x454a
leaq 0x35d0(%rip), %rsi      # 0x79d0
leaq -0x110(%rbp), %rdi
callq 0x23e0
testq %rax, %rax
leaq 0x700e(%rip), %r13      # 0xb424
je 0x4540
cmpb $0x20, (%rax)
leaq 0x1(%rax), %rax
jne 0x441c
movq %rax, %rcx
cmpb $0x20, (%rcx)
leaq 0x1(%rcx), %rcx
jne 0x4428
movb $0x0, -0x1(%rcx)
movq (%r12), %rdx
leaq 0x3594(%rip), %rsi      # 0x79d4
leaq -0xa0(%rbp), %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x2390
cmpb $0x0, (%r13)
je 0x446d
leaq 0x3531(%rip), %rdi      # 0x7990
leaq -0xa0(%rbp), %rsi
xorl %eax, %eax
callq 0x5fb8
leaq -0xa0(%rbp), %rdi
callq 0x2140
testl %eax, %eax
je 0x4492
cmpb $0x3, (%r13)
jb 0x4492
leaq 0x3569(%rip), %rdi      # 0x79f4
xorl %eax, %eax
callq 0x5fb8
leaq 0x3571(%rip), %rsi      # 0x7a0a
leaq 0x358e(%rip), %rdx      # 0x7a2e
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2390
leaq 0x34d8(%rip), %rdi      # 0x7990
movq %r14, %rsi
xorl %eax, %eax
callq 0x5fb8
movq %r14, %rdi
callq 0x2140
testl %eax, %eax
je 0x44e3
cmpb $0x3, (%r13)
jb 0x44e3
leaq 0x3518(%rip), %rdi      # 0x79f4
xorl %eax, %eax
callq 0x5fb8
leaq 0x354c(%rip), %rsi      # 0x7a36
leaq 0x353d(%rip), %rdx      # 0x7a2e
movq %r14, %rdi
xorl %eax, %eax
callq 0x2390
leaq 0x348e(%rip), %rdi      # 0x7990
movq %r14, %rsi
xorl %eax, %eax
callq 0x5fb8
movq %r14, %rdi
callq 0x2140
movb $0x1, %r13b
testl %eax, %eax
je 0x4537
leaq 0x6f02(%rip), %rax      # 0xb424
cmpb $0x3, (%rax)
movq -0x118(%rbp), %r14
jb 0x4551
leaq 0x34bf(%rip), %rdi      # 0x79f4
jmp 0x454a
movq -0x118(%rbp), %r14
jmp 0x4551
xorl %r13d, %r13d
leaq 0x346a(%rip), %rdi      # 0x79b4
xorl %eax, %eax
callq 0x5fb8
movq %rbx, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2030
movq %fs:0x28, %rax
cmpq -0x30(%rbp), %rax
jne 0x458d
movl %r13d, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2110
nop