// File: /workspace/github_c_makefile_star2_O1/open-mesh-mirror[P]batmand/posix/tunnel.c
// Function: get_ip_addr
static struct gw_client *get_ip_addr(struct sockaddr_in *client_addr, struct hashtable_t **wip_hash, struct hashtable_t **vip_hash, struct list_head_first *free_ip_list, uint8_t next_free_ip[]) {

	struct gw_client *gw_client;
	struct free_ip *free_ip;
	struct list_head *list_pos, *list_pos_tmp;
	struct hashtable_t *swaphash;


	gw_client = ((struct gw_client *)hash_find(*wip_hash, &client_addr->sin_addr.s_addr));

	if (gw_client != NULL)
		return gw_client;

	gw_client = debugMalloc( sizeof(struct gw_client), 208 );

	gw_client->wip_addr = client_addr->sin_addr.s_addr;
	gw_client->client_port = client_addr->sin_port;
	gw_client->last_keep_alive = get_time_msec();
	gw_client->vip_addr = 0;
	gw_client->nat_warn = 0;

	list_for_each_safe(list_pos, list_pos_tmp, free_ip_list) {

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

		gw_client->vip_addr = free_ip->addr;

		list_del((struct list_head *)free_ip_list, list_pos, free_ip_list);
		debugFree(free_ip, 1216);

		break;
	}

	if (gw_client->vip_addr == 0) {

		gw_client->vip_addr = *(uint32_t *)next_free_ip;

		next_free_ip[3]++;

		if (next_free_ip[3] == 0)
			next_free_ip[2]++;
	}

	hash_add(*wip_hash, gw_client);
	hash_add(*vip_hash, gw_client);

	if ((*wip_hash)->elements * 4 > (*wip_hash)->size) {

		swaphash = hash_resize(*wip_hash, (*wip_hash)->size * 2);

		if (swaphash == NULL) {
			debug_output( 0, "Couldn't resize hash table \n" );
			restore_and_exit(0);
		}

		*wip_hash = swaphash;
		swaphash = hash_resize(*vip_hash, (*vip_hash)->size * 2);

		if (swaphash == NULL) {
			debug_output( 0, "Couldn't resize hash table \n" );
			restore_and_exit(0);
		}

		*vip_hash = swaphash;
	}

	return gw_client;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r12
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %rbp
movq (%rsi), %rdi
leaq 0x4(%rbp), %rsi
callq 0x668e
movq %rax, %r14
testq %rax, %rax
jne 0xd584
movl $0x14, %edi
movl $0xd0, %esi
callq 0x5d3e
movq %rax, %r14
movl 0x4(%rbp), %eax
movl %eax, (%r14)
movzwl 0x2(%rbp), %eax
movw %ax, 0x8(%r14)
callq 0xb0fc
movl %eax, 0xc(%r14)
movl $0x0, 0x4(%r14)
movb $0x0, 0x10(%r14)
movq (%r13), %rbp
cmpq %r13, %rbp
je 0xd51f
movl 0x8(%rbp), %eax
movl %eax, 0x4(%r14)
movq %r13, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x5bcf
movq %rbp, %rdi
movl $0x4c0, %esi            # imm = 0x4C0
callq 0x5f5b
cmpl $0x0, 0x4(%r14)
jne 0xd53a
movl (%r12), %eax
movl %eax, 0x4(%r14)
incb 0x3(%r12)
jne 0xd53a
incb 0x2(%r12)
movq (%r15), %rdi
movq %r14, %rsi
callq 0x65a4
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x65a4
movq (%r15), %rdi
movl 0x8(%rdi), %eax
movl 0xc(%rdi), %esi
shll $0x2, %eax
cmpl %esi, %eax
jle 0xd584
addl %esi, %esi
callq 0x67df
testq %rax, %rax
je 0xd596
movq %rax, (%r15)
movq (%rbx), %rdi
movl 0xc(%rdi), %esi
addl %esi, %esi
callq 0x67df
testq %rax, %rax
je 0xd596
movq %rax, (%rbx)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2aa9(%rip), %rsi      # 0x10046
xorl %edi, %edi
xorl %eax, %eax
callq 0xd5b0
xorl %edi, %edi
callq 0xbd8c
nopl (%rax)