// File: /workspace/github_c_makefile_star2_O2/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 0x615e
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 0x61e2
movb 0x14(%r12), %al
cmpb $0x6, %al
pushq $0x28
popq %rdx
pushq $0x14
popq %rcx
cmovel %edx, %ecx
testb $0x2, 0x41(%r13)
jne 0x61f9
movzwl 0x10(%rbx), %eax
movb $-0x1, %bpl
addw %cx, %ax
jb 0x614d
movzwl %cx, %esi
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
callq 0x504c
testb %al, %al
je 0x6243
pushq $0x36
popq %rdi
xorl %esi, %esi
movl $0x280, %edx            # imm = 0x280
callq 0x4c47
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x614d
cmpw $0x0, 0x10(%rbx)
je 0x625d
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x528b
jmp 0x625d
cmpb 0x14(%r14), %al
jne 0x614d
cmpb 0x14(%r12), %al
jne 0x614d
jmp 0x6179
cmpw %cx, 0x12(%rbx)
jb 0x614d
cmpb $0x6, %al
jne 0x6225
movq %r15, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xf908
jmp 0x614f
movq %r15, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xdd30
jmp 0x614f
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x50dd
movq %rbx, 0x10(%rsp)
testb %al, %al
jne 0x6317
cmpb $0x6, 0x14(%r12)
jne 0x62ad
cmpb $0x0, 0x5a(%r13)
je 0x62d7
movzbl 0x40(%r13), %esi
movzwl 0x10(%rbx), %edx
movq %rbx, %rdi
movq %r14, %rcx
movq %r12, %r8
callq 0x13180
movzwl 0x12(%rbx), %edx
movzwl 0x58(%r13), %ecx
leal 0x2(%rcx), %esi
cmpl %edx, %esi
ja 0x6333
movq 0x8(%rbx), %rdx
movw %ax, (%rdx,%rcx)
cmpb $0x6, 0x14(%r12)
movb 0x33(%r13), %al
jne 0x62b1
jmp 0x62db
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 0xdd30
jmp 0x62ff
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 0xf908
movl %eax, %ebp
cmpq %rbx, %r15
je 0x614d
movq %r15, %rdi
callq 0x4e16
jmp 0x614d
leaq 0xdfae(%rip), %rdi      # 0x142cc
leaq 0xe921(%rip), %rsi      # 0x14c46
leaq 0xe900(%rip), %rcx      # 0x14c2c
movl $0x1e2, %edx            # imm = 0x1E2
jmp 0x634d
leaq 0xdf92(%rip), %rdi      # 0x142cc
leaq 0xe92b(%rip), %rsi      # 0x14c6c
leaq 0xe8e4(%rip), %rcx      # 0x14c2c
movl $0x201, %edx            # imm = 0x201
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050