// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/ipv4/icmp.c
// Function: icmp_send_response
static void
icmp_send_response(struct pbuf *p, u8_t type, u8_t code)
{
  struct pbuf *q;
  struct ip_hdr *iphdr;
  /* we can use the echo header here */
  struct icmp_echo_hdr *icmphdr;
  ip4_addr_t iphdr_src;
  struct netif *netif;

  /* increase number of messages attempted to send */
  MIB2_STATS_INC(mib2.icmpoutmsgs);

  /* ICMP header + IP header + 8 bytes of data */
  q = pbuf_alloc(PBUF_IP, sizeof(struct icmp_echo_hdr) + IP_HLEN + ICMP_DEST_UNREACH_DATASIZE,
                 PBUF_RAM);
  if (q == NULL) {
    LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded: failed to allocate pbuf for ICMP packet.\n"));
    MIB2_STATS_INC(mib2.icmpouterrors);
    return;
  }
  LWIP_ASSERT("check that first pbuf can hold icmp message",
              (q->len >= (sizeof(struct icmp_echo_hdr) + IP_HLEN + ICMP_DEST_UNREACH_DATASIZE)));

  iphdr = (struct ip_hdr *)p->payload;
  LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded from "));
  ip4_addr_debug_print_val(ICMP_DEBUG, iphdr->src);
  LWIP_DEBUGF(ICMP_DEBUG, (" to "));
  ip4_addr_debug_print_val(ICMP_DEBUG, iphdr->dest);
  LWIP_DEBUGF(ICMP_DEBUG, ("\n"));

  icmphdr = (struct icmp_echo_hdr *)q->payload;
  icmphdr->type = type;
  icmphdr->code = code;
  icmphdr->id = 0;
  icmphdr->seqno = 0;

  /* copy fields from original packet */
  SMEMCPY((u8_t *)q->payload + sizeof(struct icmp_echo_hdr), (u8_t *)p->payload,
          IP_HLEN + ICMP_DEST_UNREACH_DATASIZE);

  ip4_addr_copy(iphdr_src, iphdr->src);
#ifdef LWIP_HOOK_IP4_ROUTE_SRC
  {
    ip4_addr_t iphdr_dst;
    ip4_addr_copy(iphdr_dst, iphdr->dest);
    netif = ip4_route_src(&iphdr_dst, &iphdr_src);
  }
#else
  netif = ip4_route(&iphdr_src);
#endif
  if (netif != NULL) {
    /* calculate checksum */
    icmphdr->chksum = 0;
#if CHECKSUM_GEN_ICMP
    IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_ICMP) {
      icmphdr->chksum = inet_chksum(icmphdr, q->len);
    }
#endif
    ICMP_STATS_INC(icmp.xmit);
    ip4_output_if(q, NULL, &iphdr_src, ICMP_TTL, 0, IP_PROTO_ICMP, netif);
  }
  pbuf_free(q);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %dl, %al
movb %sil, %cl
movq %rdi, -0x8(%rbp)
movb %cl, -0x9(%rbp)
movb %al, -0xa(%rbp)
movl $0x36, %edi
movl $0x24, %esi
movl $0x280, %edx            # imm = 0x280
callq 0x6e20
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1954f
jmp 0x19548
jmp 0x1954a
jmp 0x19684
jmp 0x19551
movq -0x18(%rbp), %rax
movzwl 0x12(%rax), %eax
cmpq $0x24, %rax
jae 0x19590
jmp 0x19561
leaq 0xdd64(%rip), %rdi      # 0x272cc
leaq 0x10143(%rip), %rsi     # 0x296b2
movl $0x169, %edx            # imm = 0x169
leaq 0x100e5(%rip), %rcx     # 0x29660
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x19592
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x195a0
jmp 0x195a2
jmp 0x195a4
jmp 0x195a6
jmp 0x195a8
jmp 0x195aa
jmp 0x195ac
jmp 0x195ae
jmp 0x195b0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movb -0x9(%rbp), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movb -0xa(%rbp), %cl
movq -0x28(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x28(%rbp), %rax
movw $0x0, 0x4(%rax)
movq -0x28(%rbp), %rax
movw $0x0, 0x6(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x18(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x20(%rax)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x2c(%rbp)
leaq -0x2c(%rbp), %rdi
callq 0x196c0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x1967b
movq -0x28(%rbp), %rax
movw $0x0, 0x2(%rax)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movzwl 0x12(%rax), %esi
callq 0x25f20
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %esi
leaq -0x2c(%rbp), %rdx
movl $0x40, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
movq %rax, (%rsp)
callq 0x19c10
movq -0x18(%rbp), %rdi
callq 0x7260
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)