// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/tcp.c
// Function: tcp_close_shutdown
static err_t
tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
{
  LWIP_ASSERT("tcp_close_shutdown: invalid pcb", pcb != NULL);

  if (rst_on_unacked_data && ((pcb->state == ESTABLISHED) || (pcb->state == CLOSE_WAIT))) {
    if ((pcb->refused_data != NULL) || (pcb->rcv_wnd != TCP_WND_MAX(pcb))) {
      /* Not all data received by application, send RST to tell the remote
         side about this. */
      LWIP_ASSERT("pcb->flags & TF_RXCLOSED", pcb->flags & TF_RXCLOSED);

      /* don't call tcp_abort here: we must not deallocate the pcb since
         that might not be expected when calling tcp_close */
      tcp_rst(pcb, pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
              pcb->local_port, pcb->remote_port);

      tcp_pcb_purge(pcb);
      TCP_RMV_ACTIVE(pcb);
      /* Deallocate the pcb since we already sent a RST for it */
      if (tcp_input_pcb == pcb) {
        /* prevent using a deallocated pcb: free it from tcp_input later */
        tcp_trigger_input_pcb_close();
      } else {
        tcp_free(pcb);
      }
      return ERR_OK;
    }
  }

  /* - states which free the pcb are handled here,
     - states which send FIN and change state are handled in tcp_close_shutdown_fin() */
  switch (pcb->state) {
    case CLOSED:
      /* Closing a pcb in the CLOSED state might seem erroneous,
       * however, it is in this state once allocated and as yet unused
       * and the user needs some way to free it should the need arise.
       * Calling tcp_close() with a pcb that has already been closed, (i.e. twice)
       * or for a pcb that has been used and then entered the CLOSED state
       * is erroneous, but this should never happen as the pcb has in those cases
       * been freed, and so any remaining handles are bogus. */
      if (pcb->local_port != 0) {
        TCP_RMV(&tcp_bound_pcbs, pcb);
      }
      tcp_free(pcb);
      break;
    case LISTEN:
      tcp_listen_closed(pcb);
      tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb);
      tcp_free_listen(pcb);
      break;
    case SYN_SENT:
      TCP_PCB_REMOVE_ACTIVE(pcb);
      tcp_free(pcb);
      MIB2_STATS_INC(mib2.tcpattemptfails);
      break;
    default:
      return tcp_close_shutdown_fin(pcb);
  }
  return ERR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xb39a
jmp 0xb36b
leaq 0x1bf5a(%rip), %rdi     # 0x272cc
leaq 0x1d08d(%rip), %rsi     # 0x28406
movl $0x15e, %edx            # imm = 0x15E
leaq 0x1c9e6(%rip), %rcx     # 0x27d6b
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0xb39c
movzbl -0x11(%rbp), %eax
cmpl $0x0, %eax
je 0xb513
movq -0x10(%rbp), %rax
cmpl $0x4, 0x48(%rax)
je 0xb3c1
movq -0x10(%rbp), %rax
cmpl $0x7, 0x48(%rax)
jne 0xb513
movq -0x10(%rbp), %rax
cmpq $0x0, 0xc0(%rax)
jne 0xb3e2
movq -0x10(%rbp), %rax
movzwl 0x60(%rax), %eax
cmpl $0x8000, %eax           # imm = 0x8000
je 0xb511
jmp 0xb3e4
movq -0x10(%rbp), %rax
movzwl 0x52(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0xb425
jmp 0xb3f6
leaq 0x1becf(%rip), %rdi     # 0x272cc
leaq 0x1d022(%rip), %rsi     # 0x28426
movl $0x164, %edx            # imm = 0x164
leaq 0x1c95b(%rip), %rcx     # 0x27d6b
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0xb427
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x88(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %edx
movq -0x10(%rbp), %rcx
movq -0x10(%rbp), %r8
addq $0x18, %r8
movq -0x10(%rbp), %rax
movw 0x4e(%rax), %r9w
movq -0x10(%rbp), %rax
movzwl %r9w, %r9d
movzwl 0x50(%rax), %eax
movl %eax, (%rsp)
callq 0x16110
movq -0x10(%rbp), %rdi
callq 0xd2b0
jmp 0xb470
movq 0x24491(%rip), %rax     # 0x2f908
cmpq -0x10(%rbp), %rax
jne 0xb491
movq 0x24484(%rip), %rax     # 0x2f908
movq 0x38(%rax), %rax
movq %rax, 0x24479(%rip)     # 0x2f908
jmp 0xb4d5
movq 0x24470(%rip), %rax     # 0x2f908
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xb4d3
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0xb4c3
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
jmp 0xb4d3
jmp 0xb4c5
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0xb49c
jmp 0xb4d5
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movb $0x1, 0x24431(%rip)     # 0x2f919
leaq 0x24491(%rip), %rax     # 0x2f980
movq (%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0xb4ff
callq 0x10ca0
jmp 0xb508
movq -0x10(%rbp), %rdi
callq 0xa630
movb $0x0, -0x1(%rbp)
jmp 0xb629
jmp 0xb513
movq -0x10(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0xb542
jmp 0xb523
movl -0x2c(%rbp), %eax
subl $0x1, %eax
je 0xb5cf
jmp 0xb531
movl -0x2c(%rbp), %eax
subl $0x2, %eax
je 0xb5f3
jmp 0xb617
movq -0x10(%rbp), %rax
movzwl 0x4e(%rax), %eax
cmpl $0x0, %eax
je 0xb5c4
jmp 0xb551
movq 0x243a8(%rip), %rax     # 0x2f900
cmpq -0x10(%rbp), %rax
jne 0xb572
movq 0x2439b(%rip), %rax     # 0x2f900
movq 0x38(%rax), %rax
movq %rax, 0x24390(%rip)     # 0x2f900
jmp 0xb5b6
movq 0x24387(%rip), %rax     # 0x2f900
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xb5b4
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0xb5a4
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
jmp 0xb5b4
jmp 0xb5a6
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0xb57d
jmp 0xb5b6
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
jmp 0xb5c4
movq -0x10(%rbp), %rdi
callq 0xa630
jmp 0xb625
movq -0x10(%rbp), %rdi
callq 0xe800
movq -0x10(%rbp), %rsi
leaq 0x24315(%rip), %rdi     # 0x2f8f8
callq 0xb9d0
movq -0x10(%rbp), %rdi
callq 0xe8d0
jmp 0xb625
jmp 0xb5f5
movq -0x10(%rbp), %rsi
leaq 0x24308(%rip), %rdi     # 0x2f908
callq 0xb9d0
movb $0x1, 0x2430d(%rip)     # 0x2f919
movq -0x10(%rbp), %rdi
callq 0xa630
jmp 0xb625
movq -0x10(%rbp), %rdi
callq 0xd400
movb %al, -0x1(%rbp)
jmp 0xb629
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)