// File: /workspace/github_c_makefile_star2_O3/FH0[P]tun_direct/lwip-2.1.2/src/core/raw.c
// Function: raw_sendto_if_src
err_t
raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
                  struct netif *netif, const ip_addr_t *src_ip)
{
  err_t err;
  struct pbuf *q; /* q will be sent down the stack */
  u16_t header_size;
  u8_t ttl;

  LWIP_ASSERT_CORE_LOCKED();

  if ((pcb == NULL) || (dst_ip == NULL) || (netif == NULL) || (src_ip == NULL) ||
      !IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
    return ERR_VAL;
  }

  header_size = (
#if LWIP_IPV4 && LWIP_IPV6
                  IP_IS_V6(dst_ip) ? IP6_HLEN : IP_HLEN);
#elif LWIP_IPV4
                  IP_HLEN);
#else
                  IP6_HLEN);
#endif

  /* Handle the HDRINCL option as an exception: none of the code below applies
   * to this case, and sending the packet needs to be done differently too. */
  if (pcb->flags & RAW_FLAGS_HDRINCL) {
    /* A full header *must* be present in the first pbuf of the chain, as the
     * output routines may access its fields directly. */
    if (p->len < header_size) {
      return ERR_VAL;
    }
    /* @todo multicast loop support, if at all desired for this scenario.. */
    NETIF_SET_HINTS(netif, &pcb->netif_hints);
    err = ip_output_if_hdrincl(p, src_ip, dst_ip, netif);
    NETIF_RESET_HINTS(netif);
    return err;
  }

  /* packet too large to add an IP header without causing an overflow? */
  if ((u16_t)(p->tot_len + header_size) < p->tot_len) {
    return ERR_MEM;
  }
  /* not enough space to add an IP header to first pbuf in given p chain? */
  if (pbuf_add_header(p, header_size)) {
    /* allocate header in new pbuf */
    q = pbuf_alloc(PBUF_IP, 0, PBUF_RAM);
    /* new header pbuf could not be allocated? */
    if (q == NULL) {
      LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("raw_sendto: could not allocate header\n"));
      return ERR_MEM;
    }
    if (p->tot_len != 0) {
      /* chain header q in front of given pbuf p */
      pbuf_chain(q, p);
    }
    /* { first pbuf q points to header pbuf } */
    LWIP_DEBUGF(RAW_DEBUG, ("raw_sendto: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
  } else {
    /* first pbuf q equals given pbuf */
    q = p;
    if (pbuf_remove_header(q, header_size)) {
      LWIP_ASSERT("Can't restore header we just removed!", 0);
      return ERR_MEM;
    }
  }

#if IP_SOF_BROADCAST
  if (IP_IS_V4(dst_ip)) {
    /* broadcast filter? */
    if (!ip_get_option(pcb, SOF_BROADCAST) && ip_addr_isbroadcast(dst_ip, netif)) {
      LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
      /* free any temporary header pbuf allocated by pbuf_header() */
      if (q != p) {
        pbuf_free(q);
      }
      return ERR_VAL;
    }
  }
#endif /* IP_SOF_BROADCAST */

  /* Multicast Loop? */
#if LWIP_MULTICAST_TX_OPTIONS
  if (((pcb->flags & RAW_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
    q->flags |= PBUF_FLAG_MCASTLOOP;
  }
#endif /* LWIP_MULTICAST_TX_OPTIONS */

#if LWIP_IPV6
  /* If requested, based on the IPV6_CHECKSUM socket option per RFC3542,
     compute the checksum and update the checksum in the payload. */
  if (IP_IS_V6(dst_ip) && pcb->chksum_reqd) {
    u16_t chksum = ip6_chksum_pseudo(p, pcb->protocol, p->tot_len, ip_2_ip6(src_ip), ip_2_ip6(dst_ip));
    LWIP_ASSERT("Checksum must fit into first pbuf", p->len >= (pcb->chksum_offset + 2));
    SMEMCPY(((u8_t *)p->payload) + pcb->chksum_offset, &chksum, sizeof(u16_t));
  }
#endif

  /* Determine TTL to use */
#if LWIP_MULTICAST_TX_OPTIONS
  ttl = (ip_addr_ismulticast(dst_ip) ? raw_get_multicast_ttl(pcb) : pcb->ttl);
#else /* LWIP_MULTICAST_TX_OPTIONS */
  ttl = pcb->ttl;
#endif /* LWIP_MULTICAST_TX_OPTIONS */

  NETIF_SET_HINTS(netif, &pcb->netif_hints);
  err = ip_output_if(q, src_ip, dst_ip, ttl, pcb->tos, pcb->protocol, netif);
  NETIF_RESET_HINTS(netif);

  /* did we chain a header earlier? */
  if (q != p) {
    /* free the header */
    pbuf_free(q);
  }
  return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %xmm0
movq %rdi, %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movq %r8, %xmm0
movq %rcx, %xmm2
punpcklqdq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0]
pxor %xmm0, %xmm0
pcmpeqd %xmm0, %xmm2
pcmpeqd %xmm0, %xmm1
movdqa %xmm1, %xmm0
shufps $0xdd, %xmm2, %xmm0     # xmm0 = xmm0[1,3],xmm2[1,3]
shufps $0x88, %xmm2, %xmm1     # xmm1 = xmm1[0,2],xmm2[0,2]
andps %xmm0, %xmm1
movmskps %xmm1, %eax
movb $-0x6, %bpl
testl %eax, %eax
je 0x6367
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r13
movb 0x14(%rdi), %al
cmpb $0x2e, %al
jne 0x63f5
movb 0x14(%r12), %al
cmpb $0x6, %al
movl $0x28, %edx
movl $0x14, %ecx
cmovel %edx, %ecx
testb $0x2, 0x41(%r13)
jne 0x640f
movzwl 0x10(%rbx), %eax
movb $-0x1, %bpl
addw %cx, %ax
jb 0x6356
movzwl %cx, %esi
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
callq 0x5208
testb %al, %al
je 0x6459
movl $0x36, %edi
xorl %esi, %esi
movl $0x280, %edx            # imm = 0x280
callq 0x4df7
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x6356
cmpw $0x0, 0x10(%rbx)
je 0x6473
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x5474
jmp 0x6473
cmpb 0x14(%r14), %al
jne 0x6356
cmpb 0x14(%r12), %al
jne 0x6356
jmp 0x6382
cmpw %cx, 0x12(%rbx)
jb 0x6356
cmpb $0x6, %al
jne 0x643b
movq %r15, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xff25
jmp 0x6358
movq %r15, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe33b
jmp 0x6358
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x529b
movq %rbx, 0x10(%rsp)
testb %al, %al
jne 0x652d
cmpb $0x6, 0x14(%r12)
jne 0x64c3
cmpb $0x0, 0x5a(%r13)
je 0x64ed
movzbl 0x40(%r13), %esi
movzwl 0x10(%rbx), %edx
movq %rbx, %rdi
movq %r14, %rcx
movq %r12, %r8
callq 0x138e7
movzwl 0x12(%rbx), %edx
movzwl 0x58(%r13), %ecx
leal 0x2(%rcx), %esi
cmpl %edx, %esi
ja 0x6549
movq 0x8(%rbx), %rdx
movw %ax, (%rdx,%rcx)
cmpb $0x6, 0x14(%r12)
movb 0x33(%r13), %al
jne 0x64c7
jmp 0x64f1
movb 0x33(%r13), %al
movzbl 0x32(%r13), %r8d
movzbl 0x40(%r13), %r9d
movq %r15, (%rsp)
movzbl %al, %ecx
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xe33b
jmp 0x6515
movb 0x33(%r13), %al
movzbl 0x32(%r13), %r8d
movzbl 0x40(%r13), %r9d
movq %r15, (%rsp)
movzbl %al, %ecx
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xff25
movl %eax, %ebp
cmpq %rbx, %r15
je 0x6356
movq %r15, %rdi
callq 0x4fdf
jmp 0x6356
leaq 0xdd98(%rip), %rdi      # 0x142cc
leaq 0xe6f4(%rip), %rsi      # 0x14c2f
leaq 0xe6d3(%rip), %rcx      # 0x14c15
movl $0x1e2, %edx            # imm = 0x1E2
jmp 0x6563
leaq 0xdd7c(%rip), %rdi      # 0x142cc
leaq 0xe6fe(%rip), %rsi      # 0x14c55
leaq 0xe6b7(%rip), %rcx      # 0x14c15
movl $0x201, %edx            # imm = 0x201
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050