// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x9eda
cmpq $0x0, -0x20(%rbp)
je 0x9eda
cmpq $0x0, -0x28(%rbp)
je 0x9eda
cmpq $0x0, -0x30(%rbp)
je 0x9eda
movq -0x10(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x2e, %eax
je 0x9eb9
movq -0x10(%rbp), %rax
movzbl 0x14(%rax), %eax
movq -0x30(%rbp), %rcx
movzbl 0x14(%rcx), %ecx
cmpl %ecx, %eax
jne 0x9eda
movq -0x10(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x2e, %eax
je 0x9ee3
movq -0x10(%rbp), %rax
movzbl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
movzbl 0x14(%rcx), %ecx
cmpl %ecx, %eax
je 0x9ee3
movb $-0x6, -0x1(%rbp)
jmp 0xa202
xorl %eax, %eax
cmpq $0x0, -0x20(%rbp)
movb %al, -0x47(%rbp)
je 0x9f00
movq -0x20(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
sete %al
movb %al, -0x47(%rbp)
movb -0x47(%rbp), %dl
movl $0x14, %eax
movl $0x28, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movw %ax, -0x42(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x41(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x9fbb
movq -0x18(%rbp), %rax
movzwl 0x12(%rax), %eax
movzwl -0x42(%rbp), %ecx
cmpl %ecx, %eax
jge 0x9f44
movb $-0x6, -0x1(%rbp)
jmp 0xa202
cmpq $0x0, -0x20(%rbp)
je 0x9f82
movq -0x20(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0x9f82
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
xorl %r9d, %r9d
movl %r9d, %ecx
movl %r9d, %r8d
movq %rax, (%rsp)
callq 0x1d560
movsbl %al, %eax
movl %eax, -0x4c(%rbp)
jmp 0x9faa
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
xorl %r9d, %r9d
movl %r9d, %ecx
movl %r9d, %r8d
movq %rax, (%rsp)
callq 0x19c10
movsbl %al, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
movb %al, -0x1(%rbp)
jmp 0xa202
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %eax
movzwl -0x42(%rbp), %ecx
addl %ecx, %eax
movzwl %ax, %eax
movq -0x18(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jge 0x9fe1
movb $-0x1, -0x1(%rbp)
jmp 0xa202
movq -0x18(%rbp), %rdi
movzwl -0x42(%rbp), %eax
movl %eax, %esi
callq 0x7780
cmpb $0x0, %al
je 0xa03d
movl $0x36, %edi
xorl %esi, %esi
movl $0x280, %edx            # imm = 0x280
callq 0x6e20
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0xa01d
jmp 0xa012
jmp 0xa014
movb $-0x1, -0x1(%rbp)
jmp 0xa202
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x0, %eax
je 0xa037
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x7e00
jmp 0xa039
jmp 0xa03b
jmp 0xa08d
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movzwl -0x42(%rbp), %eax
movl %eax, %esi
callq 0x7950
cmpb $0x0, %al
je 0xa08b
jmp 0xa05a
jmp 0xa05c
leaq 0x1d269(%rip), %rdi     # 0x272cc
leaq 0x1dca8(%rip), %rsi     # 0x27d12
movl $0x1e2, %edx            # imm = 0x1E2
leaq 0x1dc82(%rip), %rcx     # 0x27cf8
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0xa08d
cmpq $0x0, -0x20(%rbp)
je 0xa149
movq -0x20(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0xa149
movq -0x10(%rbp), %rax
movzbl 0x5a(%rax), %eax
cmpl $0x0, %eax
je 0xa149
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movb 0x40(%rax), %dl
movq -0x18(%rbp), %rax
movw 0x10(%rax), %ax
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %r8
movzbl %dl, %esi
movzwl %ax, %edx
callq 0x25900
movw %ax, -0x46(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x12(%rax), %eax
movq -0x10(%rbp), %rcx
movzwl 0x58(%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0xa12c
jmp 0xa0fd
leaq 0x1d1c8(%rip), %rdi     # 0x272cc
leaq 0x1dc2d(%rip), %rsi     # 0x27d38
movl $0x201, %edx            # imm = 0x201
leaq 0x1dbe1(%rip), %rcx     # 0x27cf8
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0xa12e
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movzwl 0x58(%rcx), %ecx
movslq %ecx, %rcx
movw -0x46(%rbp), %dx
movw %dx, (%rax,%rcx)
movq -0x10(%rbp), %rax
movb 0x33(%rax), %al
movb %al, -0x43(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xa1a6
movq -0x20(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x6, %eax
jne 0xa1a6
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
movb -0x43(%rbp), %cl
movq -0x10(%rbp), %rax
movb 0x32(%rax), %r8b
movq -0x10(%rbp), %rax
movb 0x40(%rax), %r9b
movq -0x28(%rbp), %rax
movzbl %cl, %ecx
movzbl %r8b, %r8d
movzbl %r9b, %r9d
movq %rax, (%rsp)
callq 0x1d560
movsbl %al, %eax
movl %eax, -0x50(%rbp)
jmp 0xa1e3
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
movb -0x43(%rbp), %cl
movq -0x10(%rbp), %rax
movb 0x32(%rax), %r8b
movq -0x10(%rbp), %rax
movb 0x40(%rax), %r9b
movq -0x28(%rbp), %rax
movzbl %cl, %ecx
movzbl %r8b, %r8d
movzbl %r9b, %r9d
movq %rax, (%rsp)
callq 0x19c10
movsbl %al, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movb %al, -0x31(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0xa1fc
movq -0x40(%rbp), %rdi
callq 0x7260
movb -0x31(%rbp), %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)