// File: /workspace/github_c_makefile_star2_O0/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
subq $0x130, %rsp            # imm = 0x130
movq %fs:0x28, %rax
movq %rax, -0x8(%rbp)
movq %rdi, -0xe8(%rbp)
movq %rsi, -0xf0(%rbp)
movq $0x0, -0x128(%rbp)
movq -0xe8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2600
movq %rax, -0x100(%rbp)
movq -0xf0(%rbp), %rdi
callq 0x2600
movq %rax, -0x108(%rbp)
movq -0xf0(%rbp), %rdi
addq $0x13, %rdi
callq 0x2600
movq %rax, -0x110(%rbp)
leaq -0x70(%rbp), %rdi
movq -0x100(%rbp), %rdx
movq -0xe8(%rbp), %rax
movzwl 0x20(%rax), %ecx
leaq 0x5765(%rip), %rsi      # 0xa914
movb $0x0, %al
callq 0x23a0
leaq 0x9267(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jg 0x51db
leaq -0x70(%rbp), %rsi
leaq 0x5763(%rip), %rdi      # 0xa937
movb $0x0, %al
callq 0x84c0
leaq -0x70(%rbp), %rdi
callq 0x2130
cmpl $0x0, %eax
je 0x51f5
movb $0x0, -0xf1(%rbp)
jmp 0x554a
leaq -0x70(%rbp), %rdi
movq -0x100(%rbp), %rdx
movq -0x108(%rbp), %rcx
movq -0x110(%rbp), %r8
leaq 0x5731(%rip), %rsi      # 0xa946
movb $0x0, %al
callq 0x23a0
leaq 0x9201(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x523e
leaq -0x70(%rbp), %rsi
leaq 0x5738(%rip), %rdi      # 0xa96f
movb $0x0, %al
callq 0x84c0
leaq -0x70(%rbp), %rdi
callq 0x2130
cmpl $0x0, %eax
je 0x5258
movb $0x0, -0xf1(%rbp)
jmp 0x554a
leaq -0x70(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq (%rax), %rdx
leaq 0x5710(%rip), %rsi      # 0xa97d
movb $0x0, %al
callq 0x23a0
leaq 0x91a9(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x5296
leaq -0x70(%rbp), %rsi
leaq 0x56e0(%rip), %rdi      # 0xa96f
movb $0x0, %al
callq 0x84c0
leaq -0x70(%rbp), %rdi
leaq 0x4def(%rip), %rsi      # 0xa090
callq 0x2340
movq %rax, -0x128(%rbp)
leaq -0xe0(%rbp), %rdi
movq -0x128(%rbp), %rdx
movl $0x63, %esi
callq 0x21e0
movq %rax, -0x120(%rbp)
movq -0x128(%rbp), %rdi
callq 0x2180
cmpq $0x0, -0x120(%rbp)
jne 0x530c
leaq 0x913b(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x5300
leaq 0x569a(%rip), %rdi      # 0xa993
movb $0x0, %al
callq 0x84c0
movb $0x0, -0xf1(%rbp)
jmp 0x554a
leaq -0xe0(%rbp), %rdi
leaq 0x5691(%rip), %rsi      # 0xa9ab
callq 0x23f0
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0x5380
leaq -0xe0(%rbp), %rdi
leaq 0x5671(%rip), %rsi      # 0xa9af
callq 0x23f0
movq %rax, -0x118(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0x537e
leaq 0x90c9(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x5372
leaq 0x5628(%rip), %rdi      # 0xa993
movb $0x0, %al
callq 0x84c0
movb $0x0, -0xf1(%rbp)
jmp 0x554a
jmp 0x5380
jmp 0x5382
movq -0x118(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0x53a5
movq -0x118(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x118(%rbp)
jmp 0x5382
movq -0x118(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0x53e8
movq -0x120(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x120(%rbp)
jmp 0x53c5
movq -0x120(%rbp), %rax
movb $0x0, (%rax)
leaq -0x70(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq (%rax), %rdx
movq -0x118(%rbp), %rcx
leaq 0x55a5(%rip), %rsi      # 0xa9b3
movb $0x0, %al
callq 0x23a0
leaq 0x9008(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jg 0x543a
leaq -0x70(%rbp), %rsi
leaq 0x553c(%rip), %rdi      # 0xa96f
movb $0x0, %al
callq 0x84c0
leaq -0x70(%rbp), %rdi
callq 0x2130
cmpl $0x0, %eax
je 0x546b
leaq 0x8fd5(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
movl $0x3, %eax
cmpl %ecx, %eax
jg 0x5469
leaq 0x5571(%rip), %rdi      # 0xa9d3
movb $0x0, %al
callq 0x84c0
jmp 0x546b
leaq -0x70(%rbp), %rdi
leaq 0x5573(%rip), %rsi      # 0xa9e9
leaq 0x5590(%rip), %rdx      # 0xaa0d
movb $0x0, %al
callq 0x23a0
leaq 0x8f99(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x54a6
leaq -0x70(%rbp), %rsi
leaq 0x54d0(%rip), %rdi      # 0xa96f
movb $0x0, %al
callq 0x84c0
leaq -0x70(%rbp), %rdi
callq 0x2130
cmpl $0x0, %eax
je 0x54d7
leaq 0x8f69(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
movl $0x3, %eax
cmpl %ecx, %eax
jg 0x54d5
leaq 0x5505(%rip), %rdi      # 0xa9d3
movb $0x0, %al
callq 0x84c0
jmp 0x54d7
leaq -0x70(%rbp), %rdi
leaq 0x5533(%rip), %rsi      # 0xaa15
leaq 0x5524(%rip), %rdx      # 0xaa0d
movb $0x0, %al
callq 0x23a0
leaq 0x8f2d(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x5512
leaq -0x70(%rbp), %rsi
leaq 0x5464(%rip), %rdi      # 0xa96f
movb $0x0, %al
callq 0x84c0
leaq -0x70(%rbp), %rdi
callq 0x2130
cmpl $0x0, %eax
je 0x5543
leaq 0x8efd(%rip), %rax      # 0xe424
movzbl (%rax), %ecx
movl $0x3, %eax
cmpl %ecx, %eax
jg 0x5541
leaq 0x5499(%rip), %rdi      # 0xa9d3
movb $0x0, %al
callq 0x84c0
jmp 0x5543
movb $0x1, -0xf1(%rbp)
movq -0x100(%rbp), %rdi
callq 0x2030
movq -0x108(%rbp), %rdi
callq 0x2030
movq -0x110(%rbp), %rdi
callq 0x2030
movb -0xf1(%rbp), %al
movb %al, -0x129(%rbp)
movq %fs:0x28, %rax
movq -0x8(%rbp), %rcx
cmpq %rcx, %rax
jne 0x559d
movb -0x129(%rbp), %al
andb $0x1, %al
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
callq 0x2100
nopw %cs:(%rax,%rax)
nopl (%rax)