// File: /workspace/github_c_makefile_star2_O2/FH0[P]tun_direct/lwip-2.1.2/src/core/ipv6/nd6.c
// Function: nd6_send_ns
static void
nd6_send_ns(struct netif *netif, const ip6_addr_t *target_addr, u8_t flags)
{
  struct ns_header *ns_hdr;
  struct pbuf *p;
  const ip6_addr_t *src_addr;
  u16_t lladdr_opt_len;

  LWIP_ASSERT("target address is required", target_addr != NULL);

  if (!(flags & ND6_SEND_FLAG_ANY_SRC) &&
      ip6_addr_isvalid(netif_ip6_addr_state(netif,0))) {
    /* Use link-local address as source address. */
    src_addr = netif_ip6_addr(netif, 0);
    /* calculate option length (in 8-byte-blocks) */
    lladdr_opt_len = ((netif->hwaddr_len + 2) + 7) >> 3;
  } else {
    src_addr = IP6_ADDR_ANY6;
    /* Option "MUST NOT be included when the source IP address is the unspecified address." */
    lladdr_opt_len = 0;
  }

  /* Allocate a packet. */
  p = pbuf_alloc(PBUF_IP, sizeof(struct ns_header) + (lladdr_opt_len << 3), PBUF_RAM);
  if (p == NULL) {
    ND6_STATS_INC(nd6.memerr);
    return;
  }

  /* Set fields. */
  ns_hdr = (struct ns_header *)p->payload;

  ns_hdr->type = ICMP6_TYPE_NS;
  ns_hdr->code = 0;
  ns_hdr->chksum = 0;
  ns_hdr->reserved = 0;
  ip6_addr_copy_to_packed(ns_hdr->target_address, *target_addr);

  if (lladdr_opt_len != 0) {
    struct lladdr_option *lladdr_opt = (struct lladdr_option *)((u8_t*)p->payload + sizeof(struct ns_header));
    lladdr_opt->type = ND6_OPTION_TYPE_SOURCE_LLADDR;
    lladdr_opt->length = (u8_t)lladdr_opt_len;
    SMEMCPY(lladdr_opt->addr, netif->hwaddr, netif->hwaddr_len);
  }

  /* Generate the solicited node address for the target address. */
  if (flags & ND6_SEND_FLAG_MULTICAST_DEST) {
    ip6_addr_set_solicitednode(&multicast_address, target_addr->addr[3]);
    ip6_addr_assign_zone(&multicast_address, IP6_MULTICAST, netif);
    target_addr = &multicast_address;
  }

#if CHECKSUM_GEN_ICMP6
  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_ICMP6) {
    ns_hdr->chksum = ip6_chksum_pseudo(p, IP6_NEXTH_ICMP6, p->len, src_addr,
      target_addr);
  }
#endif /* CHECKSUM_GEN_ICMP6 */

  /* Send the packet out. */
  ND6_STATS_INC(nd6.xmit);
  ip6_output_if(p, (src_addr == IP6_ADDR_ANY6) ? NULL : src_addr, target_addr,
      ND6_HOPLIM, 0, IP6_NEXTH_ICMP6, netif);
  pbuf_free(p);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rsi, %rsi
je 0x125d7
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x41e9(%rip), %r13      # 0x16670
testb $0x4, %bpl
jne 0x12496
testb $0x10, 0x98(%rbx)
jne 0x1249b
xorl %r15d, %r15d
jmp 0x124af
leaq 0x50(%rbx), %r13
movzbl 0xea(%rbx), %r15d
addl $0x9, %r15d
shrl $0x3, %r15d
movzwl %r15w, %eax
leal 0x18(,%rax,8), %esi
pushq $0x36
popq %rdi
movl $0x280, %edx            # imm = 0x280
callq 0x4c47
testq %rax, %rax
je 0x125c8
movq %rax, %r12
movq %r13, 0x10(%rsp)
movq 0x8(%rax), %r13
movq $0x87, (%r13)
movl (%r14), %eax
movl %eax, 0x8(%r13)
movl 0x4(%r14), %eax
movl %eax, 0xc(%r13)
movl 0x8(%r14), %eax
movl %eax, 0x10(%r13)
movl 0xc(%r14), %eax
movl %eax, 0x14(%r13)
testw %r15w, %r15w
je 0x12529
movb $0x1, 0x18(%r13)
movb %r15b, 0x19(%r13)
leaq 0x1a(%r13), %rdi
leaq 0xe4(%rbx), %rsi
movzbl 0xea(%rbx), %edx
callq 0x2180
testb $0x1, %bpl
je 0x12568
movq $0x2ff, 0xba26(%rip) # imm = 0x2FF
movl $0x1000000, 0xba24(%rip) # imm = 0x1000000
movl $0xff, %eax
orl 0xc(%r14), %eax
leaq 0xba0c(%rip), %r14      # 0x1df60
movl %eax, 0xba12(%rip)      # 0x1df6c
movb 0xee(%rbx), %al
incb %al
movb %al, 0xba08(%rip)       # 0x1df70
movzwl 0x12(%r12), %edx
pushq $0x3a
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
movq 0x10(%rsp), %r15
movq %r15, %rcx
movq %r14, %r8
callq 0x13180
movw %ax, 0x2(%r13)
xorl %esi, %esi
cmpq 0xaa54(%rip), %r15      # 0x1cfe8
cmovneq %r15, %rsi
movq %rbx, (%rsp)
movq %r12, %rdi
movq %r14, %rdx
movl $0xff, %ecx
xorl %r8d, %r8d
movl %ebp, %r9d
callq 0xf908
movq %r12, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4e16
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cee(%rip), %rdi      # 0x142cc
leaq 0x4265(%rip), %rsi      # 0x1684a
leaq 0x4214(%rip), %rcx      # 0x16800
movl $0x4a4, %edx            # imm = 0x4A4
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050