// File: /workspace/github_c_makefile_star2_O3/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 0x12c16
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3b1f(%rip), %r13      # 0x165e0
testb $0x4, %bpl
jne 0x12ad0
testb $0x10, 0x98(%rbx)
jne 0x12ad5
xorl %r15d, %r15d
jmp 0x12ae9
leaq 0x50(%rbx), %r13
movzbl 0xea(%rbx), %r15d
addl $0x9, %r15d
shrl $0x3, %r15d
movzwl %r15w, %eax
leal 0x18(,%rax,8), %esi
movl $0x36, %edi
movl $0x280, %edx            # imm = 0x280
callq 0x4df7
testq %rax, %rax
je 0x12c07
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 0x12b65
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 0x12ba4
movq $0x2ff, 0xa3da(%rip) # imm = 0x2FF
movl $0x1000000, 0xa3d8(%rip) # imm = 0x1000000
movl $0xff, %eax
orl 0xc(%r14), %eax
leaq 0xa3c0(%rip), %r14      # 0x1cf50
movl %eax, 0xa3c6(%rip)      # 0x1cf5c
movb 0xee(%rbx), %al
incb %al
movb %al, 0xa3bc(%rip)       # 0x1cf60
movzwl 0x12(%r12), %edx
movq %r12, %rdi
movl $0x3a, %esi
movq 0x10(%rsp), %r15
movq %r15, %rcx
movq %r14, %r8
callq 0x138e7
movw %ax, 0x2(%r13)
xorl %esi, %esi
cmpq 0x9418(%rip), %r15      # 0x1bfe8
cmovneq %r15, %rsi
movq %rbx, (%rsp)
movq %r12, %rdi
movq %r14, %rdx
movl $0xff, %ecx
xorl %r8d, %r8d
movl $0x3a, %r9d
callq 0xff25
movq %r12, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4fdf
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16af(%rip), %rdi      # 0x142cc
leaq 0x3bb6(%rip), %rsi      # 0x167da
leaq 0x3b65(%rip), %rcx      # 0x16790
movl $0x4a4, %edx            # imm = 0x4A4
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050