// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x4, %rsi
callq 0x83f0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x12228
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x123dd
movl $0x14, %edi
movl $0xd0, %esi
callq 0x7220
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movw 0x2(%rax), %cx
movq -0x38(%rbp), %rax
movw %cx, 0x8(%rax)
callq 0xf260
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x38(%rbp), %rax
movb $0x0, 0x10(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x122ce
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x6ed0
movq -0x40(%rbp), %rdi
movl $0x4c0, %esi            # imm = 0x4C0
callq 0x7720
movq -0x38(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x1230e
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rax
movb 0x3(%rax), %cl
addb $0x1, %cl
movb %cl, 0x3(%rax)
movq -0x30(%rbp), %rax
movzbl 0x3(%rax), %eax
cmpl $0x0, %eax
jne 0x1230c
movq -0x30(%rbp), %rax
movb 0x2(%rax), %cl
addb $0x1, %cl
movb %cl, 0x2(%rax)
jmp 0x1230e
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x8290
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x8290
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
shll $0x2, %eax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0xc(%rcx), %eax
jle 0x123d5
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl 0xc(%rax), %esi
shll %esi
callq 0x8620
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x12385
xorl %edi, %edi
leaq 0x2cd0(%rip), %rsi      # 0x15047
movb $0x0, %al
callq 0x123f0
xorl %edi, %edi
callq 0x10180
movq -0x58(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0xc(%rax), %esi
shll %esi
callq 0x8620
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x123ca
xorl %edi, %edi
leaq 0x2c8b(%rip), %rsi      # 0x15047
movb $0x0, %al
callq 0x123f0
xorl %edi, %edi
callq 0x10180
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)