// File: /workspace/github_c_makefile_star2_O1/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 %rcx, %r15
movq %rdx, %r12
testq %rdi, %rdi
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
testq %r15, %r15
sete %al
testq %r8, %r8
sete %dl
orb %al, %dl
orb %cl, %dl
movb $-0x6, %bpl
je 0x6448
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %r14
movq %rsi, %rbx
movq %rdi, %r13
movb 0x14(%rdi), %al
cmpb $0x2e, %al
jne 0x64d0
movb 0x14(%r12), %cl
cmpb $0x6, %cl
movl $0x28, %edx
movl $0x14, %eax
cmovel %edx, %eax
testb $0x2, 0x41(%r13)
jne 0x64f2
movzwl 0x10(%rbx), %ecx
movb $-0x1, %bpl
addw %ax, %cx
jb 0x6437
movzwl %ax, %esi
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
callq 0x5299
testb %al, %al
je 0x653d
movl $0x36, %edi
xorl %esi, %esi
movl $0x280, %edx            # imm = 0x280
callq 0x4e57
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x6437
cmpw $0x0, 0x10(%rbx)
je 0x6557
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x54fb
jmp 0x6557
cmpb 0x14(%r14), %al
jne 0x6437
cmpb $0x2e, %al
je 0x6458
cmpb 0x14(%r12), %al
jne 0x6437
jmp 0x6458
cmpw %ax, 0x12(%rbx)
jb 0x6437
cmpb $0x6, %cl
jne 0x651f
movq %r15, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x103a0
jmp 0x6439
movq %r15, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe5cf
jmp 0x6439
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x532c
movq %rbx, 0x10(%rsp)
testb %al, %al
jne 0x660b
cmpb $0x6, 0x14(%r12)
jne 0x6599
cmpb $0x0, 0x5a(%r13)
je 0x6599
movzbl 0x40(%r13), %esi
movzwl 0x10(%rbx), %edx
movq %rbx, %rdi
movq %r14, %rcx
movq %r12, %r8
callq 0x13f92
movzwl 0x12(%rbx), %edx
movzwl 0x58(%r13), %ecx
leal 0x2(%rcx), %esi
cmpl %edx, %esi
ja 0x6627
movq 0x8(%rbx), %rdx
movw %ax, (%rdx,%rcx)
movb 0x32(%r13), %al
movb 0x33(%r13), %cl
cmpb $0x6, 0x14(%r12)
movb 0x40(%r13), %dl
jne 0x65d1
movq %r15, (%rsp)
movzbl %cl, %ecx
movzbl %al, %r8d
movzbl %dl, %r9d
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x103a0
jmp 0x65f3
movq %r15, (%rsp)
movzbl %cl, %ecx
movzbl %al, %r8d
movzbl %dl, %r9d
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xe5cf
movl %eax, %ebp
cmpq %rbx, %r15
je 0x6437
movq %r15, %rdi
callq 0x5069
jmp 0x6437
leaq 0xecba(%rip), %rdi      # 0x152cc
leaq 0xf62d(%rip), %rsi      # 0x15c46
leaq 0xf60c(%rip), %rcx      # 0x15c2c
movl $0x1e2, %edx            # imm = 0x1E2
jmp 0x6641
leaq 0xec9e(%rip), %rdi      # 0x152cc
leaq 0xf637(%rip), %rsi      # 0x15c6c
leaq 0xf5f0(%rip), %rcx      # 0x15c2c
movl $0x201, %edx            # imm = 0x201
xorl %eax, %eax
callq 0x20d0
xorl %edi, %edi
callq 0x21b0
callq 0x2050