// File: /workspace/github_c_makefile_star2_O3/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 0x69d3
movq %rax, %r14
testq %rax, %rax
jne 0xd860
movl $0x14, %edi
movl $0xd0, %esi
callq 0x5d52
movq %rax, %r14
movl 0x4(%rbp), %eax
movl %eax, (%r14)
movzwl 0x2(%rbp), %eax
movw %ax, 0x8(%r14)
callq 0xb3f0
movl %eax, 0xc(%r14)
movl $0x0, 0x4(%r14)
movb $0x0, 0x10(%r14)
movq (%r13), %rbp
cmpq %r13, %rbp
je 0xd802
movl 0x8(%rbp), %eax
movl %eax, 0x4(%r14)
movq %r13, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x5be3
movq %rbp, %rdi
movl $0x4c0, %esi            # imm = 0x4C0
callq 0x628b
cmpl $0x0, 0x4(%r14)
jne 0xd816
movl (%r12), %eax
movl %eax, 0x4(%r14)
incb 0x3(%r12)
jne 0xd816
incb 0x2(%r12)
movq (%r15), %rdi
movq %r14, %rsi
callq 0x68f0
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x68f0
movq (%r15), %rdi
movl 0x8(%rdi), %eax
movl 0xc(%rdi), %esi
shll $0x2, %eax
cmpl %esi, %eax
jle 0xd860
addl %esi, %esi
callq 0x6b1a
testq %rax, %rax
je 0xd872
movq %rax, (%r15)
movq (%rbx), %rdi
movl 0xc(%rdi), %esi
addl %esi, %esi
callq 0x6b1a
testq %rax, %rax
je 0xd872
movq %rax, (%rbx)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x27cd(%rip), %rsi      # 0x10046
xorl %edi, %edi
xorl %eax, %eax
callq 0xd88c
xorl %edi, %edi
callq 0xc084
nopl (%rax)