// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/ipv6/nd6.c
// Function: nd6_select_router
static s8_t
nd6_select_router(const ip6_addr_t *ip6addr, struct netif *netif)
{
  struct netif *router_netif;
  s8_t i, j, valid_router;
  static s8_t last_router;

  LWIP_UNUSED_ARG(ip6addr); /* @todo match preferred routes!! (must implement ND6_OPTION_TYPE_ROUTE_INFO) */

  /* @todo: implement default router preference */

  /* Look for valid routers. A reachable router is preferred. */
  valid_router = -1;
  for (i = 0; i < LWIP_ND6_NUM_ROUTERS; i++) {
    /* Is the router netif both set and apppropriate? */
    if (default_router_list[i].neighbor_entry != NULL) {
      router_netif = default_router_list[i].neighbor_entry->netif;
      if ((router_netif != NULL) && (netif != NULL ? netif == router_netif :
          (netif_is_up(router_netif) && netif_is_link_up(router_netif)))) {
        /* Is the router valid, i.e., reachable or probably reachable as per
         * RFC 4861 Sec. 6.3.6? Note that we will never return a router that
         * has no neighbor cache entry, due to the netif association tests. */
        if (default_router_list[i].neighbor_entry->state != ND6_INCOMPLETE) {
          /* Is the router known to be reachable? */
          if (default_router_list[i].neighbor_entry->state == ND6_REACHABLE) {
            return i; /* valid and reachable - done! */
          } else if (valid_router < 0) {
            valid_router = i; /* valid but not known to be reachable */
          }
        }
      }
    }
  }
  if (valid_router >= 0) {
    return valid_router;
  }

  /* Look for any router for which we have any information at all. */
  /* last_router is used for round-robin selection of incomplete routers, as
   * recommended in RFC 4861 Sec. 6.3.6 point (2). Advance only when picking a
   * route, to select the same router as next-hop target in the common case. */
  if ((netif == NULL) && (++last_router >= LWIP_ND6_NUM_ROUTERS)) {
    last_router = 0;
  }
  i = last_router;
  for (j = 0; j < LWIP_ND6_NUM_ROUTERS; j++) {
    if (default_router_list[i].neighbor_entry != NULL) {
      router_netif = default_router_list[i].neighbor_entry->netif;
      if ((router_netif != NULL) && (netif != NULL ? netif == router_netif :
          (netif_is_up(router_netif) && netif_is_link_up(router_netif)))) {
        return i;
      }
    }
    if (++i >= LWIP_ND6_NUM_ROUTERS) {
      i = 0;
    }
  }

  /* no suitable router found. */
  return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb $-0x1, -0x23(%rbp)
movb $0x0, -0x21(%rbp)
movsbl -0x21(%rbp), %eax
cmpl $0x3, %eax
jge 0x23b18
movsbq -0x21(%rbp), %rcx
leaq 0xc243(%rip), %rax      # 0x2fc50
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x23b09
movsbq -0x21(%rbp), %rcx
leaq 0xc226(%rip), %rax      # 0x2fc50
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x23b07
cmpq $0x0, -0x18(%rbp)
je 0x23a5d
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x23aa9
jmp 0x23b07
movq -0x20(%rbp), %rax
movzbl 0xeb(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x23a7b
movb $0x1, %al
testb $0x1, %al
jne 0x23a86
jmp 0x23b07
xorl %eax, %eax
testb $0x1, %al
jne 0x23a86
jmp 0x23b07
movq -0x20(%rbp), %rax
movzbl 0xeb(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x23aa1
movb $0x1, %al
testb $0x1, %al
jne 0x23aa9
jmp 0x23b07
xorl %eax, %eax
testb $0x1, %al
jne 0x23aa9
jmp 0x23b07
movsbq -0x21(%rbp), %rcx
leaq 0xc19b(%rip), %rax      # 0x2fc50
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movzbl 0x30(%rax), %eax
cmpl $0x1, %eax
je 0x23b05
movsbq -0x21(%rbp), %rcx
leaq 0xc17c(%rip), %rax      # 0x2fc50
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movzbl 0x30(%rax), %eax
cmpl $0x2, %eax
jne 0x23af2
movb -0x21(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x23c36
movsbl -0x23(%rbp), %eax
cmpl $0x0, %eax
jge 0x23b01
movb -0x21(%rbp), %al
movb %al, -0x23(%rbp)
jmp 0x23b03
jmp 0x23b05
jmp 0x23b07
jmp 0x23b09
jmp 0x23b0b
movb -0x21(%rbp), %al
addb $0x1, %al
movb %al, -0x21(%rbp)
jmp 0x239f4
movsbl -0x23(%rbp), %eax
cmpl $0x0, %eax
jl 0x23b2c
movb -0x23(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x23c36
cmpq $0x0, -0x18(%rbp)
jne 0x23b50
movb 0xc42f(%rip), %al       # 0x2ff68
addb $0x1, %al
movb %al, 0xc427(%rip)       # 0x2ff68
movsbl %al, %eax
cmpl $0x3, %eax
jl 0x23b50
movb $0x0, 0xc418(%rip)      # 0x2ff68
movb 0xc412(%rip), %al       # 0x2ff68
movb %al, -0x21(%rbp)
movb $0x0, -0x22(%rbp)
movsbl -0x22(%rbp), %eax
cmpl $0x3, %eax
jge 0x23c32
movsbq -0x21(%rbp), %rcx
leaq 0xc0da(%rip), %rax      # 0x2fc50
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x23c0f
movsbq -0x21(%rbp), %rcx
leaq 0xc0bd(%rip), %rax      # 0x2fc50
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x23c0d
cmpq $0x0, -0x18(%rbp)
je 0x23bbf
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x23c05
jmp 0x23c0d
movq -0x20(%rbp), %rax
movzbl 0xeb(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x23bda
movb $0x1, %al
testb $0x1, %al
jne 0x23be2
jmp 0x23c0d
xorl %eax, %eax
testb $0x1, %al
jne 0x23be2
jmp 0x23c0d
movq -0x20(%rbp), %rax
movzbl 0xeb(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x23bfd
movb $0x1, %al
testb $0x1, %al
jne 0x23c05
jmp 0x23c0d
xorl %eax, %eax
testb $0x1, %al
jne 0x23c05
jmp 0x23c0d
movb -0x21(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0x23c36
jmp 0x23c0f
movb -0x21(%rbp), %al
addb $0x1, %al
movb %al, -0x21(%rbp)
movsbl %al, %eax
cmpl $0x3, %eax
jl 0x23c23
movb $0x0, -0x21(%rbp)
jmp 0x23c25
movb -0x22(%rbp), %al
addb $0x1, %al
movb %al, -0x22(%rbp)
jmp 0x23b5d
movb $-0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
popq %rbp
retq
nopl (%rax,%rax)