// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: close_local_endpoint
static void close_local_endpoint(struct connection *conn) {
  struct mg_connection *c = &conn->mg_conn;
  // Must be done before free()
  int keep_alive = should_keep_alive(&conn->mg_conn) &&
    (conn->endpoint_type == EP_FILE || conn->endpoint_type == EP_USER);
  DBG(("%p %d %d %d", conn, conn->endpoint_type, keep_alive,
       conn->ns_conn->flags));

  switch (conn->endpoint_type) {
    case EP_PUT:
    case EP_FILE:
      close(conn->endpoint.fd);
      break;
    case EP_CGI:
    case EP_PROXY:
      if (conn->endpoint.nc != NULL) {
        DBG(("%p %p %p :-)", conn, conn->ns_conn, conn->endpoint.nc));
        conn->endpoint.nc->flags |= NSF_CLOSE_IMMEDIATELY;
        conn->endpoint.nc->user_data = NULL;
      }
      break;
    default: break;
  }

#ifndef MONGOOSE_NO_LOGGING
  if (c->status_code > 0 && conn->endpoint_type != EP_CLIENT &&
      c->status_code != 400) {
    log_access(conn, conn->server->config_options[ACCESS_LOG_FILE]);
  }
#endif

  // Gobble possible POST data sent to the URI handler
  iobuf_free(&conn->ns_conn->recv_iobuf);
  NS_FREE(conn->request);
  NS_FREE(conn->path_info);
  conn->endpoint.nc = NULL;
  conn->request = conn->path_info = NULL;

  conn->endpoint_type = EP_NONE;
  conn->cl = conn->num_bytes_recv = conn->request_len = 0;
  conn->ns_conn->flags &= ~(NSF_FINISHED_SENDING_DATA |
                            NSF_BUFFER_BUT_DONT_SEND | NSF_CLOSE_IMMEDIATELY |
                            MG_HEADERS_SENT | MG_USING_CHUNKED_API);

  // Do not memset() the whole structure, as some of the fields
  // (IP addresses & ports, server_param) must survive. Nullify the rest.
  c->request_method = c->uri = c->http_version = c->query_string = NULL;
  c->num_headers = c->status_code = c->is_websocket = c->content_len = 0;
  c->callback_param = NULL;

  if (keep_alive) {
    on_recv_data(conn);  // Can call us recursively if pipelining is used
  } else {
    conn->ns_conn->flags |= conn->ns_conn->send_iobuf.len == 0 ?
      NSF_CLOSE_IMMEDIATELY : NSF_FINISHED_SENDING_DATA;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0xb8f50
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x15(%rbp)
je 0xb243a
movq -0x8(%rbp), %rcx
movb $0x1, %al
cmpl $0x1, 0x2b8(%rcx)
movb %al, -0x16(%rbp)
je 0xb2434
movq -0x8(%rbp), %rax
cmpl $0x3, 0x2b8(%rax)
sete %al
movb %al, -0x16(%rbp)
movb -0x16(%rbp), %al
movb %al, -0x15(%rbp)
movb -0x15(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x2b8(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x5, %eax
ja 0xb24c2
movq -0x20(%rbp), %rax
leaq 0x14548(%rip), %rcx     # 0xc69b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movl 0x2b0(%rax), %edi
callq 0xd350
jmp 0xb24c4
movq -0x8(%rbp), %rax
cmpq $0x0, 0x2b0(%rax)
je 0xb24c0
movq -0x8(%rbp), %rax
movq 0x2b0(%rax), %rax
movl 0xa0(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0xa0(%rax)
movq -0x8(%rbp), %rax
movq 0x2b0(%rax), %rax
movq $0x0, 0x80(%rax)
jmp 0xb24c4
jmp 0xb24c4
movq -0x10(%rbp), %rax
cmpl $0x0, 0x27c(%rax)
jle 0xb2506
movq -0x8(%rbp), %rax
cmpl $0x5, 0x2b8(%rax)
je 0xb2506
movq -0x10(%rbp), %rax
cmpl $0x190, 0x27c(%rax)     # imm = 0x190
je 0xb2506
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x2a8(%rax), %rax
movq 0x40(%rax), %rsi
callq 0xb9040
movq -0x8(%rbp), %rax
movq (%rax), %rdi
addq $0x40, %rdi
callq 0xaec10
movq -0x8(%rbp), %rax
movq 0x2c8(%rax), %rdi
callq 0xd2c0
movq -0x8(%rbp), %rax
movq 0x2c0(%rax), %rdi
callq 0xd2c0
movq -0x8(%rbp), %rax
movq $0x0, 0x2b0(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x2c0(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x2c8(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x2b8(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x2e0(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x2d0(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x2d8(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0xa0(%rax), %ecx
andl $0xffcfffec, %ecx       # imm = 0xFFCFFFEC
movl %ecx, 0xa0(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x270(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x278(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x27c(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x84(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x298(%rax)
cmpl $0x0, -0x14(%rbp)
je 0xb263f
movq -0x8(%rbp), %rdi
callq 0xb9310
jmp 0xb266e
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x60(%rax), %rdx
movl $0x1, %ecx
movl $0x10, %eax
cmpq $0x0, %rdx
cmovel %eax, %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
orl 0xa0(%rax), %ecx
movl %ecx, 0xa0(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)