// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/ipv6/nd6.c
// Function: nd6_new_router
static s8_t
nd6_new_router(const ip6_addr_t *router_addr, struct netif *netif)
{
  s8_t router_index;
  s8_t free_router_index;
  s8_t neighbor_index;

  IP6_ADDR_ZONECHECK_NETIF(router_addr, netif);

  /* Do we have a neighbor entry for this router? */
  neighbor_index = nd6_find_neighbor_cache_entry(router_addr);
  if (neighbor_index < 0) {
    /* Create a neighbor entry for this router. */
    neighbor_index = nd6_new_neighbor_cache_entry();
    if (neighbor_index < 0) {
      /* Could not create neighbor entry for this router. */
      return -1;
    }
    ip6_addr_set(&(neighbor_cache[neighbor_index].next_hop_address), router_addr);
    neighbor_cache[neighbor_index].netif = netif;
    neighbor_cache[neighbor_index].q = NULL;
    neighbor_cache[neighbor_index].state = ND6_INCOMPLETE;
    neighbor_cache[neighbor_index].counter.probes_sent = 1;
    nd6_send_neighbor_cache_probe(&neighbor_cache[neighbor_index], ND6_SEND_FLAG_MULTICAST_DEST);
  }

  /* Mark neighbor as router. */
  neighbor_cache[neighbor_index].isrouter = 1;

  /* Look for empty entry. */
  free_router_index = LWIP_ND6_NUM_ROUTERS;
  for (router_index = LWIP_ND6_NUM_ROUTERS - 1; router_index >= 0; router_index--) {
    /* check if router already exists (this is a special case for 2 netifs on the same subnet
       - e.g. wifi and cable) */
    if(default_router_list[router_index].neighbor_entry == &(neighbor_cache[neighbor_index])){ 
      return router_index; 
    } 
    if (default_router_list[router_index].neighbor_entry == NULL) {
      /* remember lowest free index to create a new entry */
      free_router_index = router_index;
    }
  }
  if (free_router_index < LWIP_ND6_NUM_ROUTERS) {
    default_router_list[free_router_index].neighbor_entry = &(neighbor_cache[neighbor_index]);
    return free_router_index;
  }

  /* Could not create a router entry. */

  /* Mark neighbor entry as not-router. Entry might be useful as neighbor still. */
  neighbor_cache[neighbor_index].isrouter = 0;

  /* router not found. */
  return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x210a0
movb %al, -0x1b(%rbp)
movsbl -0x1b(%rbp), %eax
cmpl $0x0, %eax
jge 0x21fbf
callq 0x21680
movb %al, -0x1b(%rbp)
movsbl -0x1b(%rbp), %eax
cmpl $0x0, %eax
jge 0x21e43
movb $-0x1, -0x1(%rbp)
jmp 0x220a0
jmp 0x21e45
cmpq $0x0, -0x10(%rbp)
jne 0x21e53
xorl %eax, %eax
movl %eax, -0x20(%rbp)
jmp 0x21e5c
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %ecx
movsbq -0x1b(%rbp), %rdx
leaq 0xdbb5(%rip), %rax      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
cmpq $0x0, -0x10(%rbp)
jne 0x21e82
xorl %eax, %eax
movl %eax, -0x24(%rbp)
jmp 0x21e8c
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movsbq -0x1b(%rbp), %rdx
leaq 0xdb85(%rip), %rax      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
cmpq $0x0, -0x10(%rbp)
jne 0x21eb3
xorl %eax, %eax
movl %eax, -0x28(%rbp)
jmp 0x21ebd
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %ecx
movsbq -0x1b(%rbp), %rdx
leaq 0xdb54(%rip), %rax      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
cmpq $0x0, -0x10(%rbp)
jne 0x21ee4
xorl %eax, %eax
movl %eax, -0x2c(%rbp)
jmp 0x21eee
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movsbq -0x1b(%rbp), %rdx
leaq 0xdb23(%rip), %rax      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
cmpq $0x0, -0x10(%rbp)
jne 0x21f15
xorl %eax, %eax
movl %eax, -0x30(%rbp)
jmp 0x21f20
movq -0x10(%rbp), %rax
movzbl 0x10(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movb %al, %cl
movsbq -0x1b(%rbp), %rdx
leaq 0xdaef(%rip), %rax      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x10(%rax)
movq -0x18(%rbp), %rcx
movsbq -0x1b(%rbp), %rdx
leaq 0xdad5(%rip), %rax      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movsbq -0x1b(%rbp), %rcx
leaq 0xdabe(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x28(%rax)
movsbq -0x1b(%rbp), %rcx
leaq 0xdaa3(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movb $0x1, 0x30(%rax)
movsbq -0x1b(%rbp), %rcx
leaq 0xda8c(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x34(%rax)
movsbq -0x1b(%rbp), %rax
leaq 0xda72(%rip), %rdi      # 0x2fa20
imulq $0x38, %rax, %rax
addq %rax, %rdi
movl $0x1, %esi
callq 0x23480
movsbq -0x1b(%rbp), %rcx
leaq 0xda55(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movb $0x1, 0x31(%rax)
movb $0x3, -0x1a(%rbp)
movb $0x2, -0x19(%rbp)
movsbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jl 0x2204b
movsbq -0x19(%rbp), %rcx
leaq 0xdc5d(%rip), %rax      # 0x2fc50
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movsbq -0x1b(%rbp), %rdx
leaq 0xda17(%rip), %rcx      # 0x2fa20
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jne 0x22020
movb -0x19(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x220a0
movsbq -0x19(%rbp), %rcx
leaq 0xdc24(%rip), %rax      # 0x2fc50
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0x2203f
movb -0x19(%rbp), %al
movb %al, -0x1a(%rbp)
jmp 0x22041
movb -0x19(%rbp), %al
addb $-0x1, %al
movb %al, -0x19(%rbp)
jmp 0x21fde
movsbl -0x1a(%rbp), %eax
cmpl $0x3, %eax
jge 0x22085
movsbq -0x1b(%rbp), %rax
leaq 0xd9c0(%rip), %rcx      # 0x2fa20
imulq $0x38, %rax, %rax
addq %rax, %rcx
movsbq -0x1a(%rbp), %rdx
leaq 0xdbdd(%rip), %rax      # 0x2fc50
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movb -0x1a(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x220a0
movsbq -0x1b(%rbp), %rcx
leaq 0xd98f(%rip), %rax      # 0x2fa20
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x31(%rax)
movb $-0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)