/*
 * WARNING: do not edit!
 * Generated by Makefile from include/openssl/ssl.h.in
 *
 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
 * Copyright 2005 Nokia. All rights reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */



#ifndef OPENSSL_SSL_H
# define OPENSSL_SSL_H
# pragma once

# include <openssl/macros.h>
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define HEADER_SSL_H
# endif

# include <openssl/e_os2.h>
# include <openssl/opensslconf.h>
# include <openssl/comp.h>
# include <openssl/bio.h>
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  include <openssl/x509.h>
#  include <openssl/crypto.h>
#  include <openssl/buffer.h>
# endif
# include <openssl/lhash.h>
# include <openssl/pem.h>
# include <openssl/hmac.h>
# include <openssl/async.h>

# include <openssl/safestack.h>
# include <openssl/symhacks.h>
# include <openssl/ct.h>
# include <openssl/sslerr.h>
# include <openssl/prov_ssl.h>

#ifdef  __cplusplus
extern "C" {
#endif

/* OpenSSL version number for ASN.1 encoding of the session information */
/*-
 * Version 0 - initial version
 * Version 1 - added the optional peer certificate
 */
# define SSL_SESSION_ASN1_VERSION 0x0001

# define SSL_MAX_SSL_SESSION_ID_LENGTH           32
# define SSL_MAX_SID_CTX_LENGTH                  32

# define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES     (512/8)
# define SSL_MAX_KEY_ARG_LENGTH                  8
/* SSL_MAX_MASTER_KEY_LENGTH is defined in prov_ssl.h */

/* The maximum number of encrypt/decrypt pipelines we can support */
# define SSL_MAX_PIPELINES  32

/* text strings for the ciphers */

/* These are used to specify which ciphers to use and not to use */

# define SSL_TXT_LOW             "LOW"
# define SSL_TXT_MEDIUM          "MEDIUM"
# define SSL_TXT_HIGH            "HIGH"
# define SSL_TXT_FIPS            "FIPS"

# define SSL_TXT_aNULL           "aNULL"
# define SSL_TXT_eNULL           "eNULL"
# define SSL_TXT_NULL            "NULL"

# define SSL_TXT_kRSA            "kRSA"
# define SSL_TXT_kDHr            "kDHr"/* this cipher class has been removed */
# define SSL_TXT_kDHd            "kDHd"/* this cipher class has been removed */
# define SSL_TXT_kDH             "kDH"/* this cipher class has been removed */
# define SSL_TXT_kEDH            "kEDH"/* alias for kDHE */
# define SSL_TXT_kDHE            "kDHE"
# define SSL_TXT_kECDHr          "kECDHr"/* this cipher class has been removed */
# define SSL_TXT_kECDHe          "kECDHe"/* this cipher class has been removed */
# define SSL_TXT_kECDH           "kECDH"/* this cipher class has been removed */
# define SSL_TXT_kEECDH          "kEECDH"/* alias for kECDHE */
# define SSL_TXT_kECDHE          "kECDHE"
# define SSL_TXT_kPSK            "kPSK"
# define SSL_TXT_kRSAPSK         "kRSAPSK"
# define SSL_TXT_kECDHEPSK       "kECDHEPSK"
# define SSL_TXT_kDHEPSK         "kDHEPSK"
# define SSL_TXT_kGOST           "kGOST"
# define SSL_TXT_kGOST18         "kGOST18"
# define SSL_TXT_kSRP            "kSRP"

# define SSL_TXT_aRSA            "aRSA"
# define SSL_TXT_aDSS            "aDSS"
# define SSL_TXT_aDH             "aDH"/* this cipher class has been removed */
# define SSL_TXT_aECDH           "aECDH"/* this cipher class has been removed */
# define SSL_TXT_aECDSA          "aECDSA"
# define SSL_TXT_aPSK            "aPSK"
# define SSL_TXT_aGOST94         "aGOST94"
# define SSL_TXT_aGOST01         "aGOST01"
# define SSL_TXT_aGOST12         "aGOST12"
# define SSL_TXT_aGOST           "aGOST"
# define SSL_TXT_aSRP            "aSRP"

# define SSL_TXT_DSS             "DSS"
# define SSL_TXT_DH              "DH"
# define SSL_TXT_DHE             "DHE"/* same as "kDHE:-ADH" */
# define SSL_TXT_EDH             "EDH"/* alias for DHE */
# define SSL_TXT_ADH             "ADH"
# define SSL_TXT_RSA             "RSA"
# define SSL_TXT_ECDH            "ECDH"
# define SSL_TXT_EECDH           "EECDH"/* alias for ECDHE" */
# define SSL_TXT_ECDHE           "ECDHE"/* same as "kECDHE:-AECDH" */
# define SSL_TXT_AECDH           "AECDH"
# define SSL_TXT_ECDSA           "ECDSA"
# define SSL_TXT_PSK             "PSK"
# define SSL_TXT_SRP             "SRP"

# define SSL_TXT_DES             "DES"
# define SSL_TXT_3DES            "3DES"
# define SSL_TXT_RC4             "RC4"
# define SSL_TXT_RC2             "RC2"
# define SSL_TXT_IDEA            "IDEA"
# define SSL_TXT_SEED            "SEED"
# define SSL_TXT_AES128          "AES128"
# define SSL_TXT_AES256          "AES256"
# define SSL_TXT_AES             "AES"
# define SSL_TXT_AES_GCM         "AESGCM"
# define SSL_TXT_AES_CCM         "AESCCM"
# define SSL_TXT_AES_CCM_8       "AESCCM8"
# define SSL_TXT_CAMELLIA128     "CAMELLIA128"
# define SSL_TXT_CAMELLIA256     "CAMELLIA256"
# define SSL_TXT_CAMELLIA        "CAMELLIA"
# define SSL_TXT_CHACHA20        "CHACHA20"
# define SSL_TXT_GOST            "GOST89"
# define SSL_TXT_ARIA            "ARIA"
# define SSL_TXT_ARIA_GCM        "ARIAGCM"
# define SSL_TXT_ARIA128         "ARIA128"
# define SSL_TXT_ARIA256         "ARIA256"
# define SSL_TXT_GOST2012_GOST8912_GOST8912 "GOST2012-GOST8912-GOST8912"
# define SSL_TXT_CBC             "CBC"

# define SSL_TXT_MD5             "MD5"
# define SSL_TXT_SHA1            "SHA1"
# define SSL_TXT_SHA             "SHA"/* same as "SHA1" */
# define SSL_TXT_GOST94          "GOST94"
# define SSL_TXT_GOST89MAC       "GOST89MAC"
# define SSL_TXT_GOST12          "GOST12"
# define SSL_TXT_GOST89MAC12     "GOST89MAC12"
# define SSL_TXT_SHA256          "SHA256"
# define SSL_TXT_SHA384          "SHA384"

# define SSL_TXT_SSLV3           "SSLv3"
# define SSL_TXT_TLSV1           "TLSv1"
# define SSL_TXT_TLSV1_1         "TLSv1.1"
# define SSL_TXT_TLSV1_2         "TLSv1.2"

# define SSL_TXT_ALL             "ALL"

/*-
 * COMPLEMENTOF* definitions. These identifiers are used to (de-select)
 * ciphers normally not being used.
 * Example: "RC4" will activate all ciphers using RC4 including ciphers
 * without authentication, which would normally disabled by DEFAULT (due
 * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT"
 * will make sure that it is also disabled in the specific selection.
 * COMPLEMENTOF* identifiers are portable between version, as adjustments
 * to the default cipher setup will also be included here.
 *
 * COMPLEMENTOFDEFAULT does not experience the same special treatment that
 * DEFAULT gets, as only selection is being done and no sorting as needed
 * for DEFAULT.
 */
# define SSL_TXT_CMPALL          "COMPLEMENTOFALL"
# define SSL_TXT_CMPDEF          "COMPLEMENTOFDEFAULT"

/*
 * The following cipher list is used by default. It also is substituted when
 * an application-defined cipher list string starts with 'DEFAULT'.
 * This applies to ciphersuites for TLSv1.2 and below.
 * DEPRECATED IN 3.0.0, in favor of OSSL_default_cipher_list()
 * Update both macro and function simultaneously
 */
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_DEFAULT_CIPHER_LIST "ALL:!COMPLEMENTOFDEFAULT:!eNULL"
/*
 * This is the default set of TLSv1.3 ciphersuites
 * DEPRECATED IN 3.0.0, in favor of OSSL_default_ciphersuites()
 * Update both macro and function simultaneously
 */
#  define TLS_DEFAULT_CIPHERSUITES "TLS_AES_256_GCM_SHA384:" \
                                   "TLS_CHACHA20_POLY1305_SHA256:" \
                                   "TLS_AES_128_GCM_SHA256"
# endif
/*
 * As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always
 * starts with a reasonable order, and all we have to do for DEFAULT is
 * throwing out anonymous and unencrypted ciphersuites! (The latter are not
 * actually enabled by ALL, but "ALL:RSA" would enable some of them.)
 */

/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
# define SSL_SENT_SHUTDOWN       1
# define SSL_RECEIVED_SHUTDOWN   2

#ifdef __cplusplus
}
#endif

#ifdef  __cplusplus
extern "C" {
#endif

# define SSL_FILETYPE_ASN1       X509_FILETYPE_ASN1
# define SSL_FILETYPE_PEM        X509_FILETYPE_PEM

/*
 * This is needed to stop compilers complaining about the 'struct ssl_st *'
 * function parameters used to prototype callbacks in SSL_CTX.
 */
typedef struct ssl_st *ssl_crock_st;
typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
typedef struct ssl_method_st SSL_METHOD;
typedef struct ssl_cipher_st SSL_CIPHER;
typedef struct ssl_session_st SSL_SESSION;
typedef struct tls_sigalgs_st TLS_SIGALGS;
typedef struct ssl_conf_ctx_st SSL_CONF_CTX;
typedef struct ssl_comp_st SSL_COMP;

STACK_OF(SSL_CIPHER);
STACK_OF(SSL_COMP);

/* SRTP protection profiles for use with the use_srtp extension (RFC 5764)*/
typedef struct srtp_protection_profile_st {
    const char *name;
    unsigned long id;
} SRTP_PROTECTION_PROFILE;
SKM_DEFINE_STACK_OF_INTERNAL(SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE)
#define sk_SRTP_PROTECTION_PROFILE_num(sk) OPENSSL_sk_num(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_value(sk, idx) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_value(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), (idx)))
#define sk_SRTP_PROTECTION_PROFILE_new(cmp) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new(ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp)))
#define sk_SRTP_PROTECTION_PROFILE_new_null() ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new_null())
#define sk_SRTP_PROTECTION_PROFILE_new_reserve(cmp, n) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new_reserve(ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp), (n)))
#define sk_SRTP_PROTECTION_PROFILE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (n))
#define sk_SRTP_PROTECTION_PROFILE_free(sk) OPENSSL_sk_free(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_zero(sk) OPENSSL_sk_zero(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_delete(sk, i) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_delete(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (i)))
#define sk_SRTP_PROTECTION_PROFILE_delete_ptr(sk, ptr) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_delete_ptr(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr)))
#define sk_SRTP_PROTECTION_PROFILE_push(sk, ptr) OPENSSL_sk_push(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_pop(sk) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_pop(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_shift(sk) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_shift(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk),ossl_check_SRTP_PROTECTION_PROFILE_freefunc_type(freefunc))
#define sk_SRTP_PROTECTION_PROFILE_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr), (idx))
#define sk_SRTP_PROTECTION_PROFILE_set(sk, idx, ptr) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_set(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (idx), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr)))
#define sk_SRTP_PROTECTION_PROFILE_find(sk, ptr) OPENSSL_sk_find(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr), pnum)
#define sk_SRTP_PROTECTION_PROFILE_sort(sk) OPENSSL_sk_sort(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_dup(sk) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_dup(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_deep_copy(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_copyfunc_type(copyfunc), ossl_check_SRTP_PROTECTION_PROFILE_freefunc_type(freefunc)))
#define sk_SRTP_PROTECTION_PROFILE_set_cmp_func(sk, cmp) ((sk_SRTP_PROTECTION_PROFILE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp)))



typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data,
                                            int len, void *arg);
typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len,
                                        STACK_OF(SSL_CIPHER) *peer_ciphers,
                                        const SSL_CIPHER **cipher, void *arg);

/* Extension context codes */
/* This extension is only allowed in TLS */
#define SSL_EXT_TLS_ONLY                        0x0001
/* This extension is only allowed in DTLS */
#define SSL_EXT_DTLS_ONLY                       0x0002
/* Some extensions may be allowed in DTLS but we don't implement them for it */
#define SSL_EXT_TLS_IMPLEMENTATION_ONLY         0x0004
/* Most extensions are not defined for SSLv3 but EXT_TYPE_renegotiate is */
#define SSL_EXT_SSL3_ALLOWED                    0x0008
/* Extension is only defined for TLS1.2 and below */
#define SSL_EXT_TLS1_2_AND_BELOW_ONLY           0x0010
/* Extension is only defined for TLS1.3 and above */
#define SSL_EXT_TLS1_3_ONLY                     0x0020
/* Ignore this extension during parsing if we are resuming */
#define SSL_EXT_IGNORE_ON_RESUMPTION            0x0040
#define SSL_EXT_CLIENT_HELLO                    0x0080
/* Really means TLS1.2 or below */
#define SSL_EXT_TLS1_2_SERVER_HELLO             0x0100
#define SSL_EXT_TLS1_3_SERVER_HELLO             0x0200
#define SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS     0x0400
#define SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST      0x0800
#define SSL_EXT_TLS1_3_CERTIFICATE              0x1000
#define SSL_EXT_TLS1_3_NEW_SESSION_TICKET       0x2000
#define SSL_EXT_TLS1_3_CERTIFICATE_REQUEST      0x4000

/* Typedefs for handling custom extensions */

typedef int (*custom_ext_add_cb)(SSL *s, unsigned int ext_type,
                                 const unsigned char **out, size_t *outlen,
                                 int *al, void *add_arg);

typedef void (*custom_ext_free_cb)(SSL *s, unsigned int ext_type,
                                   const unsigned char *out, void *add_arg);

typedef int (*custom_ext_parse_cb)(SSL *s, unsigned int ext_type,
                                   const unsigned char *in, size_t inlen,
                                   int *al, void *parse_arg);


typedef int (*SSL_custom_ext_add_cb_ex)(SSL *s, unsigned int ext_type,
                                        unsigned int context,
                                        const unsigned char **out,
                                        size_t *outlen, X509 *x,
                                        size_t chainidx,
                                        int *al, void *add_arg);

typedef void (*SSL_custom_ext_free_cb_ex)(SSL *s, unsigned int ext_type,
                                          unsigned int context,
                                          const unsigned char *out,
                                          void *add_arg);

typedef int (*SSL_custom_ext_parse_cb_ex)(SSL *s, unsigned int ext_type,
                                          unsigned int context,
                                          const unsigned char *in,
                                          size_t inlen, X509 *x,
                                          size_t chainidx,
                                          int *al, void *parse_arg);

/* Typedef for verification callback */
typedef int (*SSL_verify_cb)(int preverify_ok, X509_STORE_CTX *x509_ctx);

/* Typedef for SSL async callback */
typedef int (*SSL_async_callback_fn)(SSL *s, void *arg);

#define SSL_OP_BIT(n)  ((uint64_t)1 << (uint64_t)n)

/*
 * SSL/TLS connection options.
 */
    /* Disable Extended master secret */
# define SSL_OP_NO_EXTENDED_MASTER_SECRET                SSL_OP_BIT(0)
    /* Cleanse plaintext copies of data delivered to the application */
# define SSL_OP_CLEANSE_PLAINTEXT                        SSL_OP_BIT(1)
    /* Allow initial connection to servers that don't support RI */
# define SSL_OP_LEGACY_SERVER_CONNECT                    SSL_OP_BIT(2)
    /* Enable support for Kernel TLS */
# define SSL_OP_ENABLE_KTLS                              SSL_OP_BIT(3)
# define SSL_OP_TLSEXT_PADDING                           SSL_OP_BIT(4)
# define SSL_OP_SAFARI_ECDHE_ECDSA_BUG                   SSL_OP_BIT(6)
# define SSL_OP_IGNORE_UNEXPECTED_EOF                    SSL_OP_BIT(7)
# define SSL_OP_ALLOW_CLIENT_RENEGOTIATION               SSL_OP_BIT(8)
# define SSL_OP_DISABLE_TLSEXT_CA_NAMES                  SSL_OP_BIT(9)
    /* In TLSv1.3 allow a non-(ec)dhe based kex_mode */
# define SSL_OP_ALLOW_NO_DHE_KEX                         SSL_OP_BIT(10)
    /*
     * Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
     * in OpenSSL 0.9.6d.  Usually (depending on the application protocol)
     * the workaround is not needed.  Unfortunately some broken SSL/TLS
     * implementations cannot handle it at all, which is why we include it
     * in SSL_OP_ALL. Added in 0.9.6e
     */
# define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS              SSL_OP_BIT(11)
    /* DTLS options */
# define SSL_OP_NO_QUERY_MTU                             SSL_OP_BIT(12)
    /* Turn on Cookie Exchange (on relevant for servers) */
# define SSL_OP_COOKIE_EXCHANGE                          SSL_OP_BIT(13)
    /* Don't use RFC4507 ticket extension */
# define SSL_OP_NO_TICKET                                SSL_OP_BIT(14)
# ifndef OPENSSL_NO_DTLS1_METHOD
    /*
     * Use Cisco's version identifier of DTLS_BAD_VER
     * (only with deprecated DTLSv1_client_method())
     */
#  define SSL_OP_CISCO_ANYCONNECT                        SSL_OP_BIT(15)
# endif
    /* As server, disallow session resumption on renegotiation */
# define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION   SSL_OP_BIT(16)
    /* Don't use compression even if supported */
# define SSL_OP_NO_COMPRESSION                           SSL_OP_BIT(17)
    /* Permit unsafe legacy renegotiation */
# define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION        SSL_OP_BIT(18)
    /* Disable encrypt-then-mac */
# define SSL_OP_NO_ENCRYPT_THEN_MAC                      SSL_OP_BIT(19)
    /*
     * Enable TLSv1.3 Compatibility mode. This is on by default. A future
     * version of OpenSSL may have this disabled by default.
     */
# define SSL_OP_ENABLE_MIDDLEBOX_COMPAT                  SSL_OP_BIT(20)
    /*
     * Prioritize Chacha20Poly1305 when client does.
     * Modifies SSL_OP_CIPHER_SERVER_PREFERENCE
     */
# define SSL_OP_PRIORITIZE_CHACHA                        SSL_OP_BIT(21)
    /*
     * Set on servers to choose the cipher according to server's preferences.
     */
# define SSL_OP_CIPHER_SERVER_PREFERENCE                 SSL_OP_BIT(22)
    /*
     * If set, a server will allow a client to issue a SSLv3.0 version
     * number as latest version supported in the premaster secret, even when
     * TLSv1.0 (version 3.1) was announced in the client hello. Normally
     * this is forbidden to prevent version rollback attacks.
     */
# define SSL_OP_TLS_ROLLBACK_BUG                         SSL_OP_BIT(23)
    /*
     * Switches off automatic TLSv1.3 anti-replay protection for early data.
     * This is a server-side option only (no effect on the client).
     */
# define SSL_OP_NO_ANTI_REPLAY                           SSL_OP_BIT(24)
# define SSL_OP_NO_SSLv3                                 SSL_OP_BIT(25)
# define SSL_OP_NO_TLSv1                                 SSL_OP_BIT(26)
# define SSL_OP_NO_TLSv1_2                               SSL_OP_BIT(27)
# define SSL_OP_NO_TLSv1_1                               SSL_OP_BIT(28)
# define SSL_OP_NO_TLSv1_3                               SSL_OP_BIT(29)
# define SSL_OP_NO_DTLSv1                                SSL_OP_BIT(26)
# define SSL_OP_NO_DTLSv1_2                              SSL_OP_BIT(27)
    /* Disallow all renegotiation */
# define SSL_OP_NO_RENEGOTIATION                         SSL_OP_BIT(30)
    /*
     * Make server add server-hello extension from early version of
     * cryptopro draft, when GOST ciphersuite is negotiated. Required for
     * interoperability with CryptoPro CSP 3.x
     */
# define SSL_OP_CRYPTOPRO_TLSEXT_BUG                     SSL_OP_BIT(31)

/*
 * Option "collections."
 */
# define SSL_OP_NO_SSL_MASK \
        ( SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 \
          | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3 )
# define SSL_OP_NO_DTLS_MASK \
        ( SSL_OP_NO_DTLSv1 | SSL_OP_NO_DTLSv1_2 )

/* Various bug workarounds that should be rather harmless. */
# define SSL_OP_ALL \
        ( SSL_OP_CRYPTOPRO_TLSEXT_BUG | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS \
          | SSL_OP_TLSEXT_PADDING | SSL_OP_SAFARI_ECDHE_ECDSA_BUG )

/*
 * OBSOLETE OPTIONS retained for compatibility
 */

# define SSL_OP_MICROSOFT_SESS_ID_BUG                    0x0
# define SSL_OP_NETSCAPE_CHALLENGE_BUG                   0x0
# define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG         0x0
# define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG              0x0
# define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER               0x0
# define SSL_OP_MSIE_SSLV2_RSA_PADDING                   0x0
# define SSL_OP_SSLEAY_080_CLIENT_DH_BUG                 0x0
# define SSL_OP_TLS_D5_BUG                               0x0
# define SSL_OP_TLS_BLOCK_PADDING_BUG                    0x0
# define SSL_OP_SINGLE_ECDH_USE                          0x0
# define SSL_OP_SINGLE_DH_USE                            0x0
# define SSL_OP_EPHEMERAL_RSA                            0x0
# define SSL_OP_NO_SSLv2                                 0x0
# define SSL_OP_PKCS1_CHECK_1                            0x0
# define SSL_OP_PKCS1_CHECK_2                            0x0
# define SSL_OP_NETSCAPE_CA_DN_BUG                       0x0
# define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG          0x0

/*
 * Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
 * when just a single record has been written):
 */
# define SSL_MODE_ENABLE_PARTIAL_WRITE       0x00000001U
/*
 * Make it possible to retry SSL_write() with changed buffer location (buffer
 * contents must stay the same!); this is not the default to avoid the
 * misconception that non-blocking SSL_write() behaves like non-blocking
 * write():
 */
# define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002U
/*
 * Never bother the application with retries if the transport is blocking:
 */
# define SSL_MODE_AUTO_RETRY 0x00000004U
/* Don't attempt to automatically build certificate chain */
# define SSL_MODE_NO_AUTO_CHAIN 0x00000008U
/*
 * Save RAM by releasing read and write buffers when they're empty. (SSL3 and
 * TLS only.) Released buffers are freed.
 */
# define SSL_MODE_RELEASE_BUFFERS 0x00000010U
/*
 * Send the current time in the Random fields of the ClientHello and
 * ServerHello records for compatibility with hypothetical implementations
 * that require it.
 */
# define SSL_MODE_SEND_CLIENTHELLO_TIME 0x00000020U
# define SSL_MODE_SEND_SERVERHELLO_TIME 0x00000040U
/*
 * Send TLS_FALLBACK_SCSV in the ClientHello. To be set only by applications
 * that reconnect with a downgraded protocol version; see
 * draft-ietf-tls-downgrade-scsv-00 for details. DO NOT ENABLE THIS if your
 * application attempts a normal handshake. Only use this in explicit
 * fallback retries, following the guidance in
 * draft-ietf-tls-downgrade-scsv-00.
 */
# define SSL_MODE_SEND_FALLBACK_SCSV 0x00000080U
/*
 * Support Asynchronous operation
 */
# define SSL_MODE_ASYNC 0x00000100U

/*
 * When using DTLS/SCTP, include the terminating zero in the label
 * used for computing the endpoint-pair shared secret. Required for
 * interoperability with implementations having this bug like these
 * older version of OpenSSL:
 * - OpenSSL 1.0.0 series
 * - OpenSSL 1.0.1 series
 * - OpenSSL 1.0.2 series
 * - OpenSSL 1.1.0 series
 * - OpenSSL 1.1.1 and 1.1.1a
 */
# define SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG 0x00000400U

/* Cert related flags */
/*
 * Many implementations ignore some aspects of the TLS standards such as
 * enforcing certificate chain algorithms. When this is set we enforce them.
 */
# define SSL_CERT_FLAG_TLS_STRICT                0x00000001U

/* Suite B modes, takes same values as certificate verify flags */
# define SSL_CERT_FLAG_SUITEB_128_LOS_ONLY       0x10000
/* Suite B 192 bit only mode */
# define SSL_CERT_FLAG_SUITEB_192_LOS            0x20000
/* Suite B 128 bit mode allowing 192 bit algorithms */
# define SSL_CERT_FLAG_SUITEB_128_LOS            0x30000

/* Perform all sorts of protocol violations for testing purposes */
# define SSL_CERT_FLAG_BROKEN_PROTOCOL           0x10000000

/* Flags for building certificate chains */
/* Treat any existing certificates as untrusted CAs */
# define SSL_BUILD_CHAIN_FLAG_UNTRUSTED          0x1
/* Don't include root CA in chain */
# define SSL_BUILD_CHAIN_FLAG_NO_ROOT            0x2
/* Just check certificates already there */
# define SSL_BUILD_CHAIN_FLAG_CHECK              0x4
/* Ignore verification errors */
# define SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR       0x8
/* Clear verification errors from queue */
# define SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR        0x10

/* Flags returned by SSL_check_chain */
/* Certificate can be used with this session */
# define CERT_PKEY_VALID         0x1
/* Certificate can also be used for signing */
# define CERT_PKEY_SIGN          0x2
/* EE certificate signing algorithm OK */
# define CERT_PKEY_EE_SIGNATURE  0x10
/* CA signature algorithms OK */
# define CERT_PKEY_CA_SIGNATURE  0x20
/* EE certificate parameters OK */
# define CERT_PKEY_EE_PARAM      0x40
/* CA certificate parameters OK */
# define CERT_PKEY_CA_PARAM      0x80
/* Signing explicitly allowed as opposed to SHA1 fallback */
# define CERT_PKEY_EXPLICIT_SIGN 0x100
/* Client CA issuer names match (always set for server cert) */
# define CERT_PKEY_ISSUER_NAME   0x200
/* Cert type matches client types (always set for server cert) */
# define CERT_PKEY_CERT_TYPE     0x400
/* Cert chain suitable to Suite B */
# define CERT_PKEY_SUITEB        0x800

# define SSL_CONF_FLAG_CMDLINE           0x1
# define SSL_CONF_FLAG_FILE              0x2
# define SSL_CONF_FLAG_CLIENT            0x4
# define SSL_CONF_FLAG_SERVER            0x8
# define SSL_CONF_FLAG_SHOW_ERRORS       0x10
# define SSL_CONF_FLAG_CERTIFICATE       0x20
# define SSL_CONF_FLAG_REQUIRE_PRIVATE   0x40
/* Configuration value types */
# define SSL_CONF_TYPE_UNKNOWN           0x0
# define SSL_CONF_TYPE_STRING            0x1
# define SSL_CONF_TYPE_FILE              0x2
# define SSL_CONF_TYPE_DIR               0x3
# define SSL_CONF_TYPE_NONE              0x4
# define SSL_CONF_TYPE_STORE             0x5

/* Maximum length of the application-controlled segment of a a TLSv1.3 cookie */
# define SSL_COOKIE_LENGTH                       4096

/*
 * Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, they
 * cannot be used to clear bits.
 */

uint64_t SSL_CTX_get_options(const SSL_CTX *ctx);
uint64_t SSL_get_options(const SSL *s);
uint64_t SSL_CTX_clear_options(SSL_CTX *ctx, uint64_t op);
uint64_t SSL_clear_options(SSL *s, uint64_t op);
uint64_t SSL_CTX_set_options(SSL_CTX *ctx, uint64_t op);
uint64_t SSL_set_options(SSL *s, uint64_t op);

# define SSL_CTX_set_mode(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
# define SSL_CTX_clear_mode(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_MODE,(op),NULL)
# define SSL_CTX_get_mode(ctx) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL)
# define SSL_clear_mode(ssl,op) \
        SSL_ctrl((ssl),SSL_CTRL_CLEAR_MODE,(op),NULL)
# define SSL_set_mode(ssl,op) \
        SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL)
# define SSL_get_mode(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL)
# define SSL_set_mtu(ssl, mtu) \
        SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL)
# define DTLS_set_link_mtu(ssl, mtu) \
        SSL_ctrl((ssl),DTLS_CTRL_SET_LINK_MTU,(mtu),NULL)
# define DTLS_get_link_min_mtu(ssl) \
        SSL_ctrl((ssl),DTLS_CTRL_GET_LINK_MIN_MTU,0,NULL)

# define SSL_get_secure_renegotiation_support(ssl) \
        SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL)

# define SSL_CTX_set_cert_flags(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CERT_FLAGS,(op),NULL)
# define SSL_set_cert_flags(s,op) \
        SSL_ctrl((s),SSL_CTRL_CERT_FLAGS,(op),NULL)
# define SSL_CTX_clear_cert_flags(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL)
# define SSL_clear_cert_flags(s,op) \
        SSL_ctrl((s),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL)

void SSL_CTX_set_msg_callback(SSL_CTX *ctx,
                              void (*cb) (int write_p, int version,
                                          int content_type, const void *buf,
                                          size_t len, SSL *ssl, void *arg));
void SSL_set_msg_callback(SSL *ssl,
                          void (*cb) (int write_p, int version,
                                      int content_type, const void *buf,
                                      size_t len, SSL *ssl, void *arg));
# define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
# define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))

# define SSL_get_extms_support(s) \
        SSL_ctrl((s),SSL_CTRL_GET_EXTMS_SUPPORT,0,NULL)

# ifndef OPENSSL_NO_SRP
/* see tls_srp.c */
#  ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 __owur int SSL_SRP_CTX_init(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx);
OSSL_DEPRECATEDIN_3_0 int SSL_SRP_CTX_free(SSL *ctx);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx);
OSSL_DEPRECATEDIN_3_0 __owur int SSL_srp_server_param_with_username(SSL *s,
                                                                    int *ad);
OSSL_DEPRECATEDIN_3_0 __owur int SRP_Calc_A_param(SSL *s);
#  endif
# endif

/* 100k max cert list */
# define SSL_MAX_CERT_LIST_DEFAULT (1024*100)

# define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT      (1024*20)

/*
 * This callback type is used inside SSL_CTX, SSL, and in the functions that
 * set them. It is used to override the generation of SSL/TLS session IDs in
 * a server. Return value should be zero on an error, non-zero to proceed.
 * Also, callbacks should themselves check if the id they generate is unique
 * otherwise the SSL handshake will fail with an error - callbacks can do
 * this using the 'ssl' value they're passed by;
 * SSL_has_matching_session_id(ssl, id, *id_len) The length value passed in
 * is set at the maximum size the session ID can be. In SSLv3/TLSv1 it is 32
 * bytes. The callback can alter this length to be less if desired. It is
 * also an error for the callback to set the size to zero.
 */
typedef int (*GEN_SESSION_CB) (SSL *ssl, unsigned char *id,
                               unsigned int *id_len);

# define SSL_SESS_CACHE_OFF                      0x0000
# define SSL_SESS_CACHE_CLIENT                   0x0001
# define SSL_SESS_CACHE_SERVER                   0x0002
# define SSL_SESS_CACHE_BOTH     (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
# define SSL_SESS_CACHE_NO_AUTO_CLEAR            0x0080
/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */
# define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP       0x0100
# define SSL_SESS_CACHE_NO_INTERNAL_STORE        0x0200
# define SSL_SESS_CACHE_NO_INTERNAL \
        (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE)
# define SSL_SESS_CACHE_UPDATE_TIME              0x0400

LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx);
# define SSL_CTX_sess_number(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
# define SSL_CTX_sess_connect(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
# define SSL_CTX_sess_connect_good(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
# define SSL_CTX_sess_connect_renegotiate(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
# define SSL_CTX_sess_accept(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
# define SSL_CTX_sess_accept_renegotiate(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
# define SSL_CTX_sess_accept_good(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
# define SSL_CTX_sess_hits(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
# define SSL_CTX_sess_cb_hits(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
# define SSL_CTX_sess_misses(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
# define SSL_CTX_sess_timeouts(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
# define SSL_CTX_sess_cache_full(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)

void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
                             int (*new_session_cb) (struct ssl_st *ssl,
                                                    SSL_SESSION *sess));
int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (struct ssl_st *ssl,
                                              SSL_SESSION *sess);
void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
                                void (*remove_session_cb) (struct ssl_ctx_st
                                                           *ctx,
                                                           SSL_SESSION *sess));
void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (struct ssl_ctx_st *ctx,
                                                  SSL_SESSION *sess);
void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
                             SSL_SESSION *(*get_session_cb) (struct ssl_st
                                                             *ssl,
                                                             const unsigned char
                                                             *data, int len,
                                                             int *copy));
SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (struct ssl_st *ssl,
                                                       const unsigned char *data,
                                                       int len, int *copy);
void SSL_CTX_set_info_callback(SSL_CTX *ctx,
                               void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type,
                                                 int val);
void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
                                int (*client_cert_cb) (SSL *ssl, X509 **x509,
                                                       EVP_PKEY **pkey));
int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509,
                                                 EVP_PKEY **pkey);
# ifndef OPENSSL_NO_ENGINE
__owur int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e);
# endif
void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
                                    int (*app_gen_cookie_cb) (SSL *ssl,
                                                              unsigned char
                                                              *cookie,
                                                              unsigned int
                                                              *cookie_len));
void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
                                  int (*app_verify_cookie_cb) (SSL *ssl,
                                                               const unsigned
                                                               char *cookie,
                                                               unsigned int
                                                               cookie_len));

void SSL_CTX_set_stateless_cookie_generate_cb(
    SSL_CTX *ctx,
    int (*gen_stateless_cookie_cb) (SSL *ssl,
                                    unsigned char *cookie,
                                    size_t *cookie_len));
void SSL_CTX_set_stateless_cookie_verify_cb(
    SSL_CTX *ctx,
    int (*verify_stateless_cookie_cb) (SSL *ssl,
                                       const unsigned char *cookie,
                                       size_t cookie_len));
# ifndef OPENSSL_NO_NEXTPROTONEG

typedef int (*SSL_CTX_npn_advertised_cb_func)(SSL *ssl,
                                              const unsigned char **out,
                                              unsigned int *outlen,
                                              void *arg);
void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s,
                                           SSL_CTX_npn_advertised_cb_func cb,
                                           void *arg);
#  define SSL_CTX_set_npn_advertised_cb SSL_CTX_set_next_protos_advertised_cb

typedef int (*SSL_CTX_npn_select_cb_func)(SSL *s,
                                          unsigned char **out,
                                          unsigned char *outlen,
                                          const unsigned char *in,
                                          unsigned int inlen,
                                          void *arg);
void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s,
                                      SSL_CTX_npn_select_cb_func cb,
                                      void *arg);
#  define SSL_CTX_set_npn_select_cb SSL_CTX_set_next_proto_select_cb

void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
                                    unsigned *len);
#  define SSL_get0_npn_negotiated SSL_get0_next_proto_negotiated
# endif

__owur int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
                                 const unsigned char *in, unsigned int inlen,
                                 const unsigned char *client,
                                 unsigned int client_len);

# define OPENSSL_NPN_UNSUPPORTED 0
# define OPENSSL_NPN_NEGOTIATED  1
# define OPENSSL_NPN_NO_OVERLAP  2

__owur int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
                                   unsigned int protos_len);
__owur int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
                               unsigned int protos_len);
typedef int (*SSL_CTX_alpn_select_cb_func)(SSL *ssl,
                                           const unsigned char **out,
                                           unsigned char *outlen,
                                           const unsigned char *in,
                                           unsigned int inlen,
                                           void *arg);
void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
                                SSL_CTX_alpn_select_cb_func cb,
                                void *arg);
void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
                            unsigned int *len);

# ifndef OPENSSL_NO_PSK
/*
 * the maximum length of the buffer given to callbacks containing the
 * resulting identity/psk
 */
#  define PSK_MAX_IDENTITY_LEN 256
#  define PSK_MAX_PSK_LEN 512
typedef unsigned int (*SSL_psk_client_cb_func)(SSL *ssl,
                                               const char *hint,
                                               char *identity,
                                               unsigned int max_identity_len,
                                               unsigned char *psk,
                                               unsigned int max_psk_len);
void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, SSL_psk_client_cb_func cb);
void SSL_set_psk_client_callback(SSL *ssl, SSL_psk_client_cb_func cb);

typedef unsigned int (*SSL_psk_server_cb_func)(SSL *ssl,
                                               const char *identity,
                                               unsigned char *psk,
                                               unsigned int max_psk_len);
void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, SSL_psk_server_cb_func cb);
void SSL_set_psk_server_callback(SSL *ssl, SSL_psk_server_cb_func cb);

__owur int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint);
__owur int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint);
const char *SSL_get_psk_identity_hint(const SSL *s);
const char *SSL_get_psk_identity(const SSL *s);
# endif

typedef int (*SSL_psk_find_session_cb_func)(SSL *ssl,
                                            const unsigned char *identity,
                                            size_t identity_len,
                                            SSL_SESSION **sess);
typedef int (*SSL_psk_use_session_cb_func)(SSL *ssl, const EVP_MD *md,
                                           const unsigned char **id,
                                           size_t *idlen,
                                           SSL_SESSION **sess);

void SSL_set_psk_find_session_callback(SSL *s, SSL_psk_find_session_cb_func cb);
void SSL_CTX_set_psk_find_session_callback(SSL_CTX *ctx,
                                           SSL_psk_find_session_cb_func cb);
void SSL_set_psk_use_session_callback(SSL *s, SSL_psk_use_session_cb_func cb);
void SSL_CTX_set_psk_use_session_callback(SSL_CTX *ctx,
                                          SSL_psk_use_session_cb_func cb);

/* Register callbacks to handle custom TLS Extensions for client or server. */

__owur int SSL_CTX_has_client_custom_ext(const SSL_CTX *ctx,
                                         unsigned int ext_type);

__owur int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx,
                                         unsigned int ext_type,
                                         custom_ext_add_cb add_cb,
                                         custom_ext_free_cb free_cb,
                                         void *add_arg,
                                         custom_ext_parse_cb parse_cb,
                                         void *parse_arg);

__owur int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx,
                                         unsigned int ext_type,
                                         custom_ext_add_cb add_cb,
                                         custom_ext_free_cb free_cb,
                                         void *add_arg,
                                         custom_ext_parse_cb parse_cb,
                                         void *parse_arg);

__owur int SSL_CTX_add_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
                                  unsigned int context,
                                  SSL_custom_ext_add_cb_ex add_cb,
                                  SSL_custom_ext_free_cb_ex free_cb,
                                  void *add_arg,
                                  SSL_custom_ext_parse_cb_ex parse_cb,
                                  void *parse_arg);

__owur int SSL_extension_supported(unsigned int ext_type);

# define SSL_NOTHING            1
# define SSL_WRITING            2
# define SSL_READING            3
# define SSL_X509_LOOKUP        4
# define SSL_ASYNC_PAUSED       5
# define SSL_ASYNC_NO_JOBS      6
# define SSL_CLIENT_HELLO_CB    7
# define SSL_RETRY_VERIFY       8

/* These will only be used when doing non-blocking IO */
# define SSL_want_nothing(s)         (SSL_want(s) == SSL_NOTHING)
# define SSL_want_read(s)            (SSL_want(s) == SSL_READING)
# define SSL_want_write(s)           (SSL_want(s) == SSL_WRITING)
# define SSL_want_x509_lookup(s)     (SSL_want(s) == SSL_X509_LOOKUP)
# define SSL_want_retry_verify(s)    (SSL_want(s) == SSL_RETRY_VERIFY)
# define SSL_want_async(s)           (SSL_want(s) == SSL_ASYNC_PAUSED)
# define SSL_want_async_job(s)       (SSL_want(s) == SSL_ASYNC_NO_JOBS)
# define SSL_want_client_hello_cb(s) (SSL_want(s) == SSL_CLIENT_HELLO_CB)

# define SSL_MAC_FLAG_READ_MAC_STREAM 1
# define SSL_MAC_FLAG_WRITE_MAC_STREAM 2
# define SSL_MAC_FLAG_READ_MAC_TLSTREE 4
# define SSL_MAC_FLAG_WRITE_MAC_TLSTREE 8

/*
 * A callback for logging out TLS key material. This callback should log out
 * |line| followed by a newline.
 */
typedef void (*SSL_CTX_keylog_cb_func)(const SSL *ssl, const char *line);

/*
 * SSL_CTX_set_keylog_callback configures a callback to log key material. This
 * is intended for debugging use with tools like Wireshark. The cb function
 * should log line followed by a newline.
 */
void SSL_CTX_set_keylog_callback(SSL_CTX *ctx, SSL_CTX_keylog_cb_func cb);

/*
 * SSL_CTX_get_keylog_callback returns the callback configured by
 * SSL_CTX_set_keylog_callback.
 */
SSL_CTX_keylog_cb_func SSL_CTX_get_keylog_callback(const SSL_CTX *ctx);

int SSL_CTX_set_max_early_data(SSL_CTX *ctx, uint32_t max_early_data);
uint32_t SSL_CTX_get_max_early_data(const SSL_CTX *ctx);
int SSL_set_max_early_data(SSL *s, uint32_t max_early_data);
uint32_t SSL_get_max_early_data(const SSL *s);
int SSL_CTX_set_recv_max_early_data(SSL_CTX *ctx, uint32_t recv_max_early_data);
uint32_t SSL_CTX_get_recv_max_early_data(const SSL_CTX *ctx);
int SSL_set_recv_max_early_data(SSL *s, uint32_t recv_max_early_data);
uint32_t SSL_get_recv_max_early_data(const SSL *s);

#ifdef __cplusplus
}
#endif

# include <openssl/ssl2.h>
# include <openssl/ssl3.h>
# include <openssl/tls1.h>      /* This is mostly sslv3 with a few tweaks */
# include <openssl/dtls1.h>     /* Datagram TLS */
# include <openssl/srtp.h>      /* Support for the use_srtp extension */

#ifdef  __cplusplus
extern "C" {
#endif

/*
 * These need to be after the above set of includes due to a compiler bug
 * in VisualStudio 2015
 */
SKM_DEFINE_STACK_OF_INTERNAL(SSL_CIPHER, const SSL_CIPHER, SSL_CIPHER)
#define sk_SSL_CIPHER_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_value(sk, idx) ((const SSL_CIPHER *)OPENSSL_sk_value(ossl_check_const_SSL_CIPHER_sk_type(sk), (idx)))
#define sk_SSL_CIPHER_new(cmp) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new(ossl_check_SSL_CIPHER_compfunc_type(cmp)))
#define sk_SSL_CIPHER_new_null() ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new_null())
#define sk_SSL_CIPHER_new_reserve(cmp, n) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new_reserve(ossl_check_SSL_CIPHER_compfunc_type(cmp), (n)))
#define sk_SSL_CIPHER_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SSL_CIPHER_sk_type(sk), (n))
#define sk_SSL_CIPHER_free(sk) OPENSSL_sk_free(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_zero(sk) OPENSSL_sk_zero(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_delete(sk, i) ((const SSL_CIPHER *)OPENSSL_sk_delete(ossl_check_SSL_CIPHER_sk_type(sk), (i)))
#define sk_SSL_CIPHER_delete_ptr(sk, ptr) ((const SSL_CIPHER *)OPENSSL_sk_delete_ptr(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr)))
#define sk_SSL_CIPHER_push(sk, ptr) OPENSSL_sk_push(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_pop(sk) ((const SSL_CIPHER *)OPENSSL_sk_pop(ossl_check_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_shift(sk) ((const SSL_CIPHER *)OPENSSL_sk_shift(ossl_check_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SSL_CIPHER_sk_type(sk),ossl_check_SSL_CIPHER_freefunc_type(freefunc))
#define sk_SSL_CIPHER_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr), (idx))
#define sk_SSL_CIPHER_set(sk, idx, ptr) ((const SSL_CIPHER *)OPENSSL_sk_set(ossl_check_SSL_CIPHER_sk_type(sk), (idx), ossl_check_SSL_CIPHER_type(ptr)))
#define sk_SSL_CIPHER_find(sk, ptr) OPENSSL_sk_find(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr), pnum)
#define sk_SSL_CIPHER_sort(sk) OPENSSL_sk_sort(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_dup(sk) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_dup(ossl_check_const_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_copyfunc_type(copyfunc), ossl_check_SSL_CIPHER_freefunc_type(freefunc)))
#define sk_SSL_CIPHER_set_cmp_func(sk, cmp) ((sk_SSL_CIPHER_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_compfunc_type(cmp)))
SKM_DEFINE_STACK_OF_INTERNAL(SSL_COMP, SSL_COMP, SSL_COMP)
#define sk_SSL_COMP_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_value(sk, idx) ((SSL_COMP *)OPENSSL_sk_value(ossl_check_const_SSL_COMP_sk_type(sk), (idx)))
#define sk_SSL_COMP_new(cmp) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new(ossl_check_SSL_COMP_compfunc_type(cmp)))
#define sk_SSL_COMP_new_null() ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new_null())
#define sk_SSL_COMP_new_reserve(cmp, n) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new_reserve(ossl_check_SSL_COMP_compfunc_type(cmp), (n)))
#define sk_SSL_COMP_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SSL_COMP_sk_type(sk), (n))
#define sk_SSL_COMP_free(sk) OPENSSL_sk_free(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_zero(sk) OPENSSL_sk_zero(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_delete(sk, i) ((SSL_COMP *)OPENSSL_sk_delete(ossl_check_SSL_COMP_sk_type(sk), (i)))
#define sk_SSL_COMP_delete_ptr(sk, ptr) ((SSL_COMP *)OPENSSL_sk_delete_ptr(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr)))
#define sk_SSL_COMP_push(sk, ptr) OPENSSL_sk_push(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_pop(sk) ((SSL_COMP *)OPENSSL_sk_pop(ossl_check_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_shift(sk) ((SSL_COMP *)OPENSSL_sk_shift(ossl_check_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SSL_COMP_sk_type(sk),ossl_check_SSL_COMP_freefunc_type(freefunc))
#define sk_SSL_COMP_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr), (idx))
#define sk_SSL_COMP_set(sk, idx, ptr) ((SSL_COMP *)OPENSSL_sk_set(ossl_check_SSL_COMP_sk_type(sk), (idx), ossl_check_SSL_COMP_type(ptr)))
#define sk_SSL_COMP_find(sk, ptr) OPENSSL_sk_find(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr), pnum)
#define sk_SSL_COMP_sort(sk) OPENSSL_sk_sort(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_dup(sk) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_dup(ossl_check_const_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_copyfunc_type(copyfunc), ossl_check_SSL_COMP_freefunc_type(freefunc)))
#define sk_SSL_COMP_set_cmp_func(sk, cmp) ((sk_SSL_COMP_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_compfunc_type(cmp)))


/* compatibility */
# define SSL_set_app_data(s,arg)         (SSL_set_ex_data(s,0,(char *)(arg)))
# define SSL_get_app_data(s)             (SSL_get_ex_data(s,0))
# define SSL_SESSION_set_app_data(s,a)   (SSL_SESSION_set_ex_data(s,0, \
                                                                  (char *)(a)))
# define SSL_SESSION_get_app_data(s)     (SSL_SESSION_get_ex_data(s,0))
# define SSL_CTX_get_app_data(ctx)       (SSL_CTX_get_ex_data(ctx,0))
# define SSL_CTX_set_app_data(ctx,arg)   (SSL_CTX_set_ex_data(ctx,0, \
                                                              (char *)(arg)))
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 void SSL_set_debug(SSL *s, int debug);
# endif

/* TLSv1.3 KeyUpdate message types */
/* -1 used so that this is an invalid value for the on-the-wire protocol */
#define SSL_KEY_UPDATE_NONE             -1
/* Values as defined for the on-the-wire protocol */
#define SSL_KEY_UPDATE_NOT_REQUESTED     0
#define SSL_KEY_UPDATE_REQUESTED         1

/*
 * The valid handshake states (one for each type message sent and one for each
 * type of message received). There are also two "special" states:
 * TLS = TLS or DTLS state
 * DTLS = DTLS specific state
 * CR/SR = Client Read/Server Read
 * CW/SW = Client Write/Server Write
 *
 * The "special" states are:
 * TLS_ST_BEFORE = No handshake has been initiated yet
 * TLS_ST_OK = A handshake has been successfully completed
 */
typedef enum {
    TLS_ST_BEFORE,
    TLS_ST_OK,
    DTLS_ST_CR_HELLO_VERIFY_REQUEST,
    TLS_ST_CR_SRVR_HELLO,
    TLS_ST_CR_CERT,
    TLS_ST_CR_CERT_STATUS,
    TLS_ST_CR_KEY_EXCH,
    TLS_ST_CR_CERT_REQ,
    TLS_ST_CR_SRVR_DONE,
    TLS_ST_CR_SESSION_TICKET,
    TLS_ST_CR_CHANGE,
    TLS_ST_CR_FINISHED,
    TLS_ST_CW_CLNT_HELLO,
    TLS_ST_CW_CERT,
    TLS_ST_CW_KEY_EXCH,
    TLS_ST_CW_CERT_VRFY,
    TLS_ST_CW_CHANGE,
    TLS_ST_CW_NEXT_PROTO,
    TLS_ST_CW_FINISHED,
    TLS_ST_SW_HELLO_REQ,
    TLS_ST_SR_CLNT_HELLO,
    DTLS_ST_SW_HELLO_VERIFY_REQUEST,
    TLS_ST_SW_SRVR_HELLO,
    TLS_ST_SW_CERT,
    TLS_ST_SW_KEY_EXCH,
    TLS_ST_SW_CERT_REQ,
    TLS_ST_SW_SRVR_DONE,
    TLS_ST_SR_CERT,
    TLS_ST_SR_KEY_EXCH,
    TLS_ST_SR_CERT_VRFY,
    TLS_ST_SR_NEXT_PROTO,
    TLS_ST_SR_CHANGE,
    TLS_ST_SR_FINISHED,
    TLS_ST_SW_SESSION_TICKET,
    TLS_ST_SW_CERT_STATUS,
    TLS_ST_SW_CHANGE,
    TLS_ST_SW_FINISHED,
    TLS_ST_SW_ENCRYPTED_EXTENSIONS,
    TLS_ST_CR_ENCRYPTED_EXTENSIONS,
    TLS_ST_CR_CERT_VRFY,
    TLS_ST_SW_CERT_VRFY,
    TLS_ST_CR_HELLO_REQ,
    TLS_ST_SW_KEY_UPDATE,
    TLS_ST_CW_KEY_UPDATE,
    TLS_ST_SR_KEY_UPDATE,
    TLS_ST_CR_KEY_UPDATE,
    TLS_ST_EARLY_DATA,
    TLS_ST_PENDING_EARLY_DATA_END,
    TLS_ST_CW_END_OF_EARLY_DATA,
    TLS_ST_SR_END_OF_EARLY_DATA
} OSSL_HANDSHAKE_STATE;

/*
 * Most of the following state values are no longer used and are defined to be
 * the closest equivalent value in the current state machine code. Not all
 * defines have an equivalent and are set to a dummy value (-1). SSL_ST_CONNECT
 * and SSL_ST_ACCEPT are still in use in the definition of SSL_CB_ACCEPT_LOOP,
 * SSL_CB_ACCEPT_EXIT, SSL_CB_CONNECT_LOOP and SSL_CB_CONNECT_EXIT.
 */

# define SSL_ST_CONNECT                  0x1000
# define SSL_ST_ACCEPT                   0x2000

# define SSL_ST_MASK                     0x0FFF

# define SSL_CB_LOOP                     0x01
# define SSL_CB_EXIT                     0x02
# define SSL_CB_READ                     0x04
# define SSL_CB_WRITE                    0x08
# define SSL_CB_ALERT                    0x4000/* used in callback */
# define SSL_CB_READ_ALERT               (SSL_CB_ALERT|SSL_CB_READ)
# define SSL_CB_WRITE_ALERT              (SSL_CB_ALERT|SSL_CB_WRITE)
# define SSL_CB_ACCEPT_LOOP              (SSL_ST_ACCEPT|SSL_CB_LOOP)
# define SSL_CB_ACCEPT_EXIT              (SSL_ST_ACCEPT|SSL_CB_EXIT)
# define SSL_CB_CONNECT_LOOP             (SSL_ST_CONNECT|SSL_CB_LOOP)
# define SSL_CB_CONNECT_EXIT             (SSL_ST_CONNECT|SSL_CB_EXIT)
# define SSL_CB_HANDSHAKE_START          0x10
# define SSL_CB_HANDSHAKE_DONE           0x20

/* Is the SSL_connection established? */
# define SSL_in_connect_init(a)          (SSL_in_init(a) && !SSL_is_server(a))
# define SSL_in_accept_init(a)           (SSL_in_init(a) && SSL_is_server(a))
int SSL_in_init(const SSL *s);
int SSL_in_before(const SSL *s);
int SSL_is_init_finished(const SSL *s);

/*
 * The following 3 states are kept in ssl->rlayer.rstate when reads fail, you
 * should not need these
 */
# define SSL_ST_READ_HEADER                      0xF0
# define SSL_ST_READ_BODY                        0xF1
# define SSL_ST_READ_DONE                        0xF2

/*-
 * Obtain latest Finished message
 *   -- that we sent (SSL_get_finished)
 *   -- that we expected from peer (SSL_get_peer_finished).
 * Returns length (0 == no Finished so far), copies up to 'count' bytes.
 */
size_t SSL_get_finished(const SSL *s, void *buf, size_t count);
size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);

/*
 * use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 3 options are
 * 'ored' with SSL_VERIFY_PEER if they are desired
 */
# define SSL_VERIFY_NONE                 0x00
# define SSL_VERIFY_PEER                 0x01
# define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
# define SSL_VERIFY_CLIENT_ONCE          0x04
# define SSL_VERIFY_POST_HANDSHAKE       0x08

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define OpenSSL_add_ssl_algorithms()   SSL_library_init()
#  define SSLeay_add_ssl_algorithms()    SSL_library_init()
# endif

/* More backward compatibility */
# define SSL_get_cipher(s) \
                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
# define SSL_get_cipher_bits(s,np) \
                SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
# define SSL_get_cipher_version(s) \
                SSL_CIPHER_get_version(SSL_get_current_cipher(s))
# define SSL_get_cipher_name(s) \
                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
# define SSL_get_time(a)         SSL_SESSION_get_time(a)
# define SSL_set_time(a,b)       SSL_SESSION_set_time((a),(b))
# define SSL_get_timeout(a)      SSL_SESSION_get_timeout(a)
# define SSL_set_timeout(a,b)    SSL_SESSION_set_timeout((a),(b))

# define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id)
# define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id)

DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
# define SSL_AD_REASON_OFFSET            1000/* offset to get SSL_R_... value
                                              * from SSL_AD_... */
/* These alert types are for SSLv3 and TLSv1 */
# define SSL_AD_CLOSE_NOTIFY             SSL3_AD_CLOSE_NOTIFY
/* fatal */
# define SSL_AD_UNEXPECTED_MESSAGE       SSL3_AD_UNEXPECTED_MESSAGE
/* fatal */
# define SSL_AD_BAD_RECORD_MAC           SSL3_AD_BAD_RECORD_MAC
# define SSL_AD_DECRYPTION_FAILED        TLS1_AD_DECRYPTION_FAILED
# define SSL_AD_RECORD_OVERFLOW          TLS1_AD_RECORD_OVERFLOW
/* fatal */
# define SSL_AD_DECOMPRESSION_FAILURE    SSL3_AD_DECOMPRESSION_FAILURE
/* fatal */
# define SSL_AD_HANDSHAKE_FAILURE        SSL3_AD_HANDSHAKE_FAILURE
/* Not for TLS */
# define SSL_AD_NO_CERTIFICATE           SSL3_AD_NO_CERTIFICATE
# define SSL_AD_BAD_CERTIFICATE          SSL3_AD_BAD_CERTIFICATE
# define SSL_AD_UNSUPPORTED_CERTIFICATE  SSL3_AD_UNSUPPORTED_CERTIFICATE
# define SSL_AD_CERTIFICATE_REVOKED      SSL3_AD_CERTIFICATE_REVOKED
# define SSL_AD_CERTIFICATE_EXPIRED      SSL3_AD_CERTIFICATE_EXPIRED
# define SSL_AD_CERTIFICATE_UNKNOWN      SSL3_AD_CERTIFICATE_UNKNOWN
/* fatal */
# define SSL_AD_ILLEGAL_PARAMETER        SSL3_AD_ILLEGAL_PARAMETER
/* fatal */
# define SSL_AD_UNKNOWN_CA               TLS1_AD_UNKNOWN_CA
/* fatal */
# define SSL_AD_ACCESS_DENIED            TLS1_AD_ACCESS_DENIED
/* fatal */
# define SSL_AD_DECODE_ERROR             TLS1_AD_DECODE_ERROR
# define SSL_AD_DECRYPT_ERROR            TLS1_AD_DECRYPT_ERROR
/* fatal */
# define SSL_AD_EXPORT_RESTRICTION       TLS1_AD_EXPORT_RESTRICTION
/* fatal */
# define SSL_AD_PROTOCOL_VERSION         TLS1_AD_PROTOCOL_VERSION
/* fatal */
# define SSL_AD_INSUFFICIENT_SECURITY    TLS1_AD_INSUFFICIENT_SECURITY
/* fatal */
# define SSL_AD_INTERNAL_ERROR           TLS1_AD_INTERNAL_ERROR
# define SSL_AD_USER_CANCELLED           TLS1_AD_USER_CANCELLED
# define SSL_AD_NO_RENEGOTIATION         TLS1_AD_NO_RENEGOTIATION
# define SSL_AD_MISSING_EXTENSION        TLS13_AD_MISSING_EXTENSION
# define SSL_AD_CERTIFICATE_REQUIRED     TLS13_AD_CERTIFICATE_REQUIRED
# define SSL_AD_UNSUPPORTED_EXTENSION    TLS1_AD_UNSUPPORTED_EXTENSION
# define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE
# define SSL_AD_UNRECOGNIZED_NAME        TLS1_AD_UNRECOGNIZED_NAME
# define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE
# define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE
/* fatal */
# define SSL_AD_UNKNOWN_PSK_IDENTITY     TLS1_AD_UNKNOWN_PSK_IDENTITY
/* fatal */
# define SSL_AD_INAPPROPRIATE_FALLBACK   TLS1_AD_INAPPROPRIATE_FALLBACK
# define SSL_AD_NO_APPLICATION_PROTOCOL  TLS1_AD_NO_APPLICATION_PROTOCOL
# define SSL_ERROR_NONE                  0
# define SSL_ERROR_SSL                   1
# define SSL_ERROR_WANT_READ             2
# define SSL_ERROR_WANT_WRITE            3
# define SSL_ERROR_WANT_X509_LOOKUP      4
# define SSL_ERROR_SYSCALL               5/* look at error stack/return
                                           * value/errno */
# define SSL_ERROR_ZERO_RETURN           6
# define SSL_ERROR_WANT_CONNECT          7
# define SSL_ERROR_WANT_ACCEPT           8
# define SSL_ERROR_WANT_ASYNC            9
# define SSL_ERROR_WANT_ASYNC_JOB       10
# define SSL_ERROR_WANT_CLIENT_HELLO_CB 11
# define SSL_ERROR_WANT_RETRY_VERIFY    12

# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTRL_SET_TMP_DH                    3
#  define SSL_CTRL_SET_TMP_ECDH                  4
#  define SSL_CTRL_SET_TMP_DH_CB                 6
# endif

# define SSL_CTRL_GET_CLIENT_CERT_REQUEST        9
# define SSL_CTRL_GET_NUM_RENEGOTIATIONS         10
# define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS       11
# define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS       12
# define SSL_CTRL_GET_FLAGS                      13
# define SSL_CTRL_EXTRA_CHAIN_CERT               14
# define SSL_CTRL_SET_MSG_CALLBACK               15
# define SSL_CTRL_SET_MSG_CALLBACK_ARG           16
/* only applies to datagram connections */
# define SSL_CTRL_SET_MTU                17
/* Stats */
# define SSL_CTRL_SESS_NUMBER                    20
# define SSL_CTRL_SESS_CONNECT                   21
# define SSL_CTRL_SESS_CONNECT_GOOD              22
# define SSL_CTRL_SESS_CONNECT_RENEGOTIATE       23
# define SSL_CTRL_SESS_ACCEPT                    24
# define SSL_CTRL_SESS_ACCEPT_GOOD               25
# define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE        26
# define SSL_CTRL_SESS_HIT                       27
# define SSL_CTRL_SESS_CB_HIT                    28
# define SSL_CTRL_SESS_MISSES                    29
# define SSL_CTRL_SESS_TIMEOUTS                  30
# define SSL_CTRL_SESS_CACHE_FULL                31
# define SSL_CTRL_MODE                           33
# define SSL_CTRL_GET_READ_AHEAD                 40
# define SSL_CTRL_SET_READ_AHEAD                 41
# define SSL_CTRL_SET_SESS_CACHE_SIZE            42
# define SSL_CTRL_GET_SESS_CACHE_SIZE            43
# define SSL_CTRL_SET_SESS_CACHE_MODE            44
# define SSL_CTRL_GET_SESS_CACHE_MODE            45
# define SSL_CTRL_GET_MAX_CERT_LIST              50
# define SSL_CTRL_SET_MAX_CERT_LIST              51
# define SSL_CTRL_SET_MAX_SEND_FRAGMENT          52
/* see tls1.h for macros based on these */
# define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB       53
# define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG      54
# define SSL_CTRL_SET_TLSEXT_HOSTNAME            55
# define SSL_CTRL_SET_TLSEXT_DEBUG_CB            56
# define SSL_CTRL_SET_TLSEXT_DEBUG_ARG           57
# define SSL_CTRL_GET_TLSEXT_TICKET_KEYS         58
# define SSL_CTRL_SET_TLSEXT_TICKET_KEYS         59
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT    60 */
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB 61 */
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG 62 */
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB       63
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG   64
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE     65
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS     66
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS     67
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS      68
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS      69
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP        70
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP        71
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB      72
# endif
# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB    75
# define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB                76
# define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB             77
# define SSL_CTRL_SET_SRP_ARG            78
# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME               79
# define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH               80
# define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD               81
# define DTLS_CTRL_GET_TIMEOUT           73
# define DTLS_CTRL_HANDLE_TIMEOUT        74
# define SSL_CTRL_GET_RI_SUPPORT                 76
# define SSL_CTRL_CLEAR_MODE                     78
# define SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB      79
# define SSL_CTRL_GET_EXTRA_CHAIN_CERTS          82
# define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS        83
# define SSL_CTRL_CHAIN                          88
# define SSL_CTRL_CHAIN_CERT                     89
# define SSL_CTRL_GET_GROUPS                     90
# define SSL_CTRL_SET_GROUPS                     91
# define SSL_CTRL_SET_GROUPS_LIST                92
# define SSL_CTRL_GET_SHARED_GROUP               93
# define SSL_CTRL_SET_SIGALGS                    97
# define SSL_CTRL_SET_SIGALGS_LIST               98
# define SSL_CTRL_CERT_FLAGS                     99
# define SSL_CTRL_CLEAR_CERT_FLAGS               100
# define SSL_CTRL_SET_CLIENT_SIGALGS             101
# define SSL_CTRL_SET_CLIENT_SIGALGS_LIST        102
# define SSL_CTRL_GET_CLIENT_CERT_TYPES          103
# define SSL_CTRL_SET_CLIENT_CERT_TYPES          104
# define SSL_CTRL_BUILD_CERT_CHAIN               105
# define SSL_CTRL_SET_VERIFY_CERT_STORE          106
# define SSL_CTRL_SET_CHAIN_CERT_STORE           107
# define SSL_CTRL_GET_PEER_SIGNATURE_NID         108
# define SSL_CTRL_GET_PEER_TMP_KEY               109
# define SSL_CTRL_GET_RAW_CIPHERLIST             110
# define SSL_CTRL_GET_EC_POINT_FORMATS           111
# define SSL_CTRL_GET_CHAIN_CERTS                115
# define SSL_CTRL_SELECT_CURRENT_CERT            116
# define SSL_CTRL_SET_CURRENT_CERT               117
# define SSL_CTRL_SET_DH_AUTO                    118
# define DTLS_CTRL_SET_LINK_MTU                  120
# define DTLS_CTRL_GET_LINK_MIN_MTU              121
# define SSL_CTRL_GET_EXTMS_SUPPORT              122
# define SSL_CTRL_SET_MIN_PROTO_VERSION          123
# define SSL_CTRL_SET_MAX_PROTO_VERSION          124
# define SSL_CTRL_SET_SPLIT_SEND_FRAGMENT        125
# define SSL_CTRL_SET_MAX_PIPELINES              126
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE     127
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB       128
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG   129
# define SSL_CTRL_GET_MIN_PROTO_VERSION          130
# define SSL_CTRL_GET_MAX_PROTO_VERSION          131
# define SSL_CTRL_GET_SIGNATURE_NID              132
# define SSL_CTRL_GET_TMP_KEY                    133
# define SSL_CTRL_GET_NEGOTIATED_GROUP           134
# define SSL_CTRL_SET_RETRY_VERIFY               136
# define SSL_CTRL_GET_VERIFY_CERT_STORE          137
# define SSL_CTRL_GET_CHAIN_CERT_STORE           138
# define SSL_CERT_SET_FIRST                      1
# define SSL_CERT_SET_NEXT                       2
# define SSL_CERT_SET_SERVER                     3
# define DTLSv1_get_timeout(ssl, arg) \
        SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)(arg))
# define DTLSv1_handle_timeout(ssl) \
        SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL)
# define SSL_num_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
# define SSL_clear_num_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
# define SSL_total_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTX_set_tmp_dh(ctx,dh) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
# endif
# define SSL_CTX_set_dh_auto(ctx, onoff) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
# define SSL_set_dh_auto(s, onoff) \
        SSL_ctrl(s,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_set_tmp_dh(ssl,dh) \
        SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
# endif
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
#  define SSL_set_tmp_ecdh(ssl,ecdh) \
        SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
# endif
# define SSL_CTX_add_extra_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)(x509))
# define SSL_CTX_get_extra_chain_certs(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,0,px509)
# define SSL_CTX_get_extra_chain_certs_only(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,1,px509)
# define SSL_CTX_clear_extra_chain_certs(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS,0,NULL)
# define SSL_CTX_set0_chain(ctx,sk) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,0,(char *)(sk))
# define SSL_CTX_set1_chain(ctx,sk) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,1,(char *)(sk))
# define SSL_CTX_add0_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,0,(char *)(x509))
# define SSL_CTX_add1_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,1,(char *)(x509))
# define SSL_CTX_get0_chain_certs(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERTS,0,px509)
# define SSL_CTX_clear_chain_certs(ctx) \
        SSL_CTX_set0_chain(ctx,NULL)
# define SSL_CTX_build_cert_chain(ctx, flags) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL)
# define SSL_CTX_select_current_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509))
# define SSL_CTX_set_current_cert(ctx, op) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CURRENT_CERT, op, NULL)
# define SSL_CTX_set0_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set1_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st))
# define SSL_CTX_get0_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set0_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set1_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st))
# define SSL_CTX_get0_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_set0_chain(s,sk) \
        SSL_ctrl(s,SSL_CTRL_CHAIN,0,(char *)(sk))
# define SSL_set1_chain(s,sk) \
        SSL_ctrl(s,SSL_CTRL_CHAIN,1,(char *)(sk))
# define SSL_add0_chain_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,0,(char *)(x509))
# define SSL_add1_chain_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,1,(char *)(x509))
# define SSL_get0_chain_certs(s,px509) \
        SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERTS,0,px509)
# define SSL_clear_chain_certs(s) \
        SSL_set0_chain(s,NULL)
# define SSL_build_cert_chain(s, flags) \
        SSL_ctrl(s,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL)
# define SSL_select_current_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509))
# define SSL_set_current_cert(s,op) \
        SSL_ctrl(s,SSL_CTRL_SET_CURRENT_CERT, op, NULL)
# define SSL_set0_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_set1_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st))
#define SSL_get0_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_set0_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_set1_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st))
#define SSL_get0_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st))

# define SSL_get1_groups(s, glist) \
        SSL_ctrl(s,SSL_CTRL_GET_GROUPS,0,(int*)(glist))
# define SSL_CTX_set1_groups(ctx, glist, glistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS,glistlen,(int *)(glist))
# define SSL_CTX_set1_groups_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(s))
# define SSL_set1_groups(s, glist, glistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_GROUPS,glistlen,(char *)(glist))
# define SSL_set1_groups_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(str))
# define SSL_get_shared_group(s, n) \
        SSL_ctrl(s,SSL_CTRL_GET_SHARED_GROUP,n,NULL)
# define SSL_get_negotiated_group(s) \
        SSL_ctrl(s,SSL_CTRL_GET_NEGOTIATED_GROUP,0,NULL)
# define SSL_CTX_set1_sigalgs(ctx, slist, slistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist))
# define SSL_CTX_set1_sigalgs_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(s))
# define SSL_set1_sigalgs(s, slist, slistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist))
# define SSL_set1_sigalgs_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(str))
# define SSL_CTX_set1_client_sigalgs(ctx, slist, slistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist))
# define SSL_CTX_set1_client_sigalgs_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(s))
# define SSL_set1_client_sigalgs(s, slist, slistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist))
# define SSL_set1_client_sigalgs_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(str))
# define SSL_get0_certificate_types(s, clist) \
        SSL_ctrl(s, SSL_CTRL_GET_CLIENT_CERT_TYPES, 0, (char *)(clist))
# define SSL_CTX_set1_client_certificate_types(ctx, clist, clistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen, \
                     (char *)(clist))
# define SSL_set1_client_certificate_types(s, clist, clistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen,(char *)(clist))
# define SSL_get_signature_nid(s, pn) \
        SSL_ctrl(s,SSL_CTRL_GET_SIGNATURE_NID,0,pn)
# define SSL_get_peer_signature_nid(s, pn) \
        SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NID,0,pn)
# define SSL_get_peer_tmp_key(s, pk) \
        SSL_ctrl(s,SSL_CTRL_GET_PEER_TMP_KEY,0,pk)
# define SSL_get_tmp_key(s, pk) \
        SSL_ctrl(s,SSL_CTRL_GET_TMP_KEY,0,pk)
# define SSL_get0_raw_cipherlist(s, plst) \
        SSL_ctrl(s,SSL_CTRL_GET_RAW_CIPHERLIST,0,plst)
# define SSL_get0_ec_point_formats(s, plst) \
        SSL_ctrl(s,SSL_CTRL_GET_EC_POINT_FORMATS,0,plst)
# define SSL_CTX_set_min_proto_version(ctx, version) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
# define SSL_CTX_set_max_proto_version(ctx, version) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
# define SSL_CTX_get_min_proto_version(ctx) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL)
# define SSL_CTX_get_max_proto_version(ctx) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL)
# define SSL_set_min_proto_version(s, version) \
        SSL_ctrl(s, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
# define SSL_set_max_proto_version(s, version) \
        SSL_ctrl(s, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
# define SSL_get_min_proto_version(s) \
        SSL_ctrl(s, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL)
# define SSL_get_max_proto_version(s) \
        SSL_ctrl(s, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL)

const char *SSL_group_to_name(SSL *s, int id);

/* Backwards compatibility, original 1.1.0 names */
# define SSL_CTRL_GET_SERVER_TMP_KEY \
         SSL_CTRL_GET_PEER_TMP_KEY
# define SSL_get_server_tmp_key(s, pk) \
         SSL_get_peer_tmp_key(s, pk)

int SSL_set0_tmp_dh_pkey(SSL *s, EVP_PKEY *dhpkey);
int SSL_CTX_set0_tmp_dh_pkey(SSL_CTX *ctx, EVP_PKEY *dhpkey);

/*
 * The following symbol names are old and obsolete. They are kept
 * for compatibility reasons only and should not be used anymore.
 */
# define SSL_CTRL_GET_CURVES           SSL_CTRL_GET_GROUPS
# define SSL_CTRL_SET_CURVES           SSL_CTRL_SET_GROUPS
# define SSL_CTRL_SET_CURVES_LIST      SSL_CTRL_SET_GROUPS_LIST
# define SSL_CTRL_GET_SHARED_CURVE     SSL_CTRL_GET_SHARED_GROUP

# define SSL_get1_curves               SSL_get1_groups
# define SSL_CTX_set1_curves           SSL_CTX_set1_groups
# define SSL_CTX_set1_curves_list      SSL_CTX_set1_groups_list
# define SSL_set1_curves               SSL_set1_groups
# define SSL_set1_curves_list          SSL_set1_groups_list
# define SSL_get_shared_curve          SSL_get_shared_group


# ifndef OPENSSL_NO_DEPRECATED_1_1_0
/* Provide some compatibility macros for removed functionality. */
#  define SSL_CTX_need_tmp_RSA(ctx)                0
#  define SSL_CTX_set_tmp_rsa(ctx,rsa)             1
#  define SSL_need_tmp_RSA(ssl)                    0
#  define SSL_set_tmp_rsa(ssl,rsa)                 1
#  define SSL_CTX_set_ecdh_auto(dummy, onoff)      ((onoff) != 0)
#  define SSL_set_ecdh_auto(dummy, onoff)          ((onoff) != 0)
/*
 * We "pretend" to call the callback to avoid warnings about unused static
 * functions.
 */
#  define SSL_CTX_set_tmp_rsa_callback(ctx, cb)    while(0) (cb)(NULL, 0, 0)
#  define SSL_set_tmp_rsa_callback(ssl, cb)        while(0) (cb)(NULL, 0, 0)
# endif
__owur const BIO_METHOD *BIO_f_ssl(void);
__owur BIO *BIO_new_ssl(SSL_CTX *ctx, int client);
__owur BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
__owur BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
__owur int BIO_ssl_copy_session_id(BIO *to, BIO *from);
void BIO_ssl_shutdown(BIO *ssl_bio);

__owur int SSL_CTX_set_cipher_list(SSL_CTX *, const char *str);
__owur SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);
__owur SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq,
                               const SSL_METHOD *meth);
int SSL_CTX_up_ref(SSL_CTX *ctx);
void SSL_CTX_free(SSL_CTX *);
__owur long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
__owur long SSL_CTX_get_timeout(const SSL_CTX *ctx);
__owur X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *);
void SSL_CTX_set_cert_store(SSL_CTX *, X509_STORE *);
void SSL_CTX_set1_cert_store(SSL_CTX *, X509_STORE *);
__owur int SSL_want(const SSL *s);
__owur int SSL_clear(SSL *s);

void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm);

__owur const SSL_CIPHER *SSL_get_current_cipher(const SSL *s);
__owur const SSL_CIPHER *SSL_get_pending_cipher(const SSL *s);
__owur int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits);
__owur const char *SSL_CIPHER_get_version(const SSL_CIPHER *c);
__owur const char *SSL_CIPHER_get_name(const SSL_CIPHER *c);
__owur const char *SSL_CIPHER_standard_name(const SSL_CIPHER *c);
__owur const char *OPENSSL_cipher_name(const char *rfc_name);
__owur uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *c);
__owur uint16_t SSL_CIPHER_get_protocol_id(const SSL_CIPHER *c);
__owur int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *c);
__owur int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *c);
__owur const EVP_MD *SSL_CIPHER_get_handshake_digest(const SSL_CIPHER *c);
__owur int SSL_CIPHER_is_aead(const SSL_CIPHER *c);

__owur int SSL_get_fd(const SSL *s);
__owur int SSL_get_rfd(const SSL *s);
__owur int SSL_get_wfd(const SSL *s);
__owur const char *SSL_get_cipher_list(const SSL *s, int n);
__owur char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size);
__owur int SSL_get_read_ahead(const SSL *s);
__owur int SSL_pending(const SSL *s);
__owur int SSL_has_pending(const SSL *s);
# ifndef OPENSSL_NO_SOCK
__owur int SSL_set_fd(SSL *s, int fd);
__owur int SSL_set_rfd(SSL *s, int fd);
__owur int SSL_set_wfd(SSL *s, int fd);
# endif
void SSL_set0_rbio(SSL *s, BIO *rbio);
void SSL_set0_wbio(SSL *s, BIO *wbio);
void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio);
__owur BIO *SSL_get_rbio(const SSL *s);
__owur BIO *SSL_get_wbio(const SSL *s);
__owur int SSL_set_cipher_list(SSL *s, const char *str);
__owur int SSL_CTX_set_ciphersuites(SSL_CTX *ctx, const char *str);
__owur int SSL_set_ciphersuites(SSL *s, const char *str);
void SSL_set_read_ahead(SSL *s, int yes);
__owur int SSL_get_verify_mode(const SSL *s);
__owur int SSL_get_verify_depth(const SSL *s);
__owur SSL_verify_cb SSL_get_verify_callback(const SSL *s);
void SSL_set_verify(SSL *s, int mode, SSL_verify_cb callback);
void SSL_set_verify_depth(SSL *s, int depth);
void SSL_set_cert_cb(SSL *s, int (*cb) (SSL *ssl, void *arg), void *arg);
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 __owur int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
OSSL_DEPRECATEDIN_3_0
__owur int SSL_use_RSAPrivateKey_ASN1(SSL *ssl,
                                      const unsigned char *d, long len);
# endif
__owur int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
__owur int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d,
                                   long len);
__owur int SSL_use_certificate(SSL *ssl, X509 *x);
__owur int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
__owur int SSL_use_cert_and_key(SSL *ssl, X509 *x509, EVP_PKEY *privatekey,
                                STACK_OF(X509) *chain, int override);


/* serverinfo file format versions */
# define SSL_SERVERINFOV1   1
# define SSL_SERVERINFOV2   2

/* Set serverinfo data for the current active cert. */
__owur int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo,
                                  size_t serverinfo_length);
__owur int SSL_CTX_use_serverinfo_ex(SSL_CTX *ctx, unsigned int version,
                                     const unsigned char *serverinfo,
                                     size_t serverinfo_length);
__owur int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file);

#ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
#endif

__owur int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
__owur int SSL_use_certificate_file(SSL *ssl, const char *file, int type);

#ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file,
                                          int type);
#endif
__owur int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file,
                                       int type);
__owur int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file,
                                        int type);
/* PEM type */
__owur int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
__owur int SSL_use_certificate_chain_file(SSL *ssl, const char *file);
__owur STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
__owur STACK_OF(X509_NAME)
*SSL_load_client_CA_file_ex(const char *file, OSSL_LIB_CTX *libctx,
                            const char *propq);
__owur int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                               const char *file);
int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                       const char *dir);
int SSL_add_store_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                       const char *uri);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_load_error_strings() \
    OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS \
                     | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL)
# endif

__owur const char *SSL_state_string(const SSL *s);
__owur const char *SSL_rstate_string(const SSL *s);
__owur const char *SSL_state_string_long(const SSL *s);
__owur const char *SSL_rstate_string_long(const SSL *s);
__owur long SSL_SESSION_get_time(const SSL_SESSION *s);
__owur long SSL_SESSION_set_time(SSL_SESSION *s, long t);
__owur long SSL_SESSION_get_timeout(const SSL_SESSION *s);
__owur long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
__owur int SSL_SESSION_get_protocol_version(const SSL_SESSION *s);
__owur int SSL_SESSION_set_protocol_version(SSL_SESSION *s, int version);

__owur const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s);
__owur int SSL_SESSION_set1_hostname(SSL_SESSION *s, const char *hostname);
void SSL_SESSION_get0_alpn_selected(const SSL_SESSION *s,
                                    const unsigned char **alpn,
                                    size_t *len);
__owur int SSL_SESSION_set1_alpn_selected(SSL_SESSION *s,
                                          const unsigned char *alpn,
                                          size_t len);
__owur const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s);
__owur int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher);
__owur int SSL_SESSION_has_ticket(const SSL_SESSION *s);
__owur unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s);
void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick,
                             size_t *len);
__owur uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s);
__owur int SSL_SESSION_set_max_early_data(SSL_SESSION *s,
                                          uint32_t max_early_data);
__owur int SSL_copy_session_id(SSL *to, const SSL *from);
__owur X509 *SSL_SESSION_get0_peer(SSL_SESSION *s);
__owur int SSL_SESSION_set1_id_context(SSL_SESSION *s,
                                       const unsigned char *sid_ctx,
                                       unsigned int sid_ctx_len);
__owur int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid,
                               unsigned int sid_len);
__owur int SSL_SESSION_is_resumable(const SSL_SESSION *s);

__owur SSL_SESSION *SSL_SESSION_new(void);
__owur SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src);
const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s,
                                        unsigned int *len);
const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s,
                                                 unsigned int *len);
__owur unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s);
# ifndef OPENSSL_NO_STDIO
int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *ses);
# endif
int SSL_SESSION_print(BIO *fp, const SSL_SESSION *ses);
int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x);
int SSL_SESSION_up_ref(SSL_SESSION *ses);
void SSL_SESSION_free(SSL_SESSION *ses);
__owur int i2d_SSL_SESSION(const SSL_SESSION *in, unsigned char **pp);
__owur int SSL_set_session(SSL *to, SSL_SESSION *session);
int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *session);
int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *session);
__owur int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb);
__owur int SSL_set_generate_session_id(SSL *s, GEN_SESSION_CB cb);
__owur int SSL_has_matching_session_id(const SSL *s,
                                       const unsigned char *id,
                                       unsigned int id_len);
SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
                             long length);

# ifdef OPENSSL_X509_H
__owur X509 *SSL_get0_peer_certificate(const SSL *s);
__owur X509 *SSL_get1_peer_certificate(const SSL *s);
/* Deprecated in 3.0.0 */
#  ifndef OPENSSL_NO_DEPRECATED_3_0
#   define SSL_get_peer_certificate SSL_get1_peer_certificate
#  endif
# endif

__owur STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s);

__owur int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
__owur int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
__owur SSL_verify_cb SSL_CTX_get_verify_callback(const SSL_CTX *ctx);
void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, SSL_verify_cb callback);
void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,
                                      int (*cb) (X509_STORE_CTX *, void *),
                                      void *arg);
void SSL_CTX_set_cert_cb(SSL_CTX *c, int (*cb) (SSL *ssl, void *arg),
                         void *arg);
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d,
                                          long len);
# endif
__owur int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
__owur int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx,
                                       const unsigned char *d, long len);
__owur int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
__owur int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len,
                                        const unsigned char *d);
__owur int SSL_CTX_use_cert_and_key(SSL_CTX *ctx, X509 *x509, EVP_PKEY *privatekey,
                                    STACK_OF(X509) *chain, int override);

void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx);
void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx);
void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb);
void SSL_set_default_passwd_cb_userdata(SSL *s, void *u);
pem_password_cb *SSL_get_default_passwd_cb(SSL *s);
void *SSL_get_default_passwd_cb_userdata(SSL *s);

__owur int SSL_CTX_check_private_key(const SSL_CTX *ctx);
__owur int SSL_check_private_key(const SSL *ctx);

__owur int SSL_CTX_set_session_id_context(SSL_CTX *ctx,
                                          const unsigned char *sid_ctx,
                                          unsigned int sid_ctx_len);

SSL *SSL_new(SSL_CTX *ctx);
int SSL_up_ref(SSL *s);
int SSL_is_dtls(const SSL *s);
__owur int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx,
                                      unsigned int sid_ctx_len);

__owur int SSL_CTX_set_purpose(SSL_CTX *ctx, int purpose);
__owur int SSL_set_purpose(SSL *ssl, int purpose);
__owur int SSL_CTX_set_trust(SSL_CTX *ctx, int trust);
__owur int SSL_set_trust(SSL *ssl, int trust);

__owur int SSL_set1_host(SSL *s, const char *hostname);
__owur int SSL_add1_host(SSL *s, const char *hostname);
__owur const char *SSL_get0_peername(SSL *s);
void SSL_set_hostflags(SSL *s, unsigned int flags);

__owur int SSL_CTX_dane_enable(SSL_CTX *ctx);
__owur int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md,
                                  uint8_t mtype, uint8_t ord);
__owur int SSL_dane_enable(SSL *s, const char *basedomain);
__owur int SSL_dane_tlsa_add(SSL *s, uint8_t usage, uint8_t selector,
                             uint8_t mtype, const unsigned char *data, size_t dlen);
__owur int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki);
__owur int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector,
                              uint8_t *mtype, const unsigned char **data,
                              size_t *dlen);
/*
 * Bridge opacity barrier between libcrypt and libssl, also needed to support
 * offline testing in test/danetest.c
 */
SSL_DANE *SSL_get0_dane(SSL *ssl);
/*
 * DANE flags
 */
unsigned long SSL_CTX_dane_set_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_CTX_dane_clear_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_dane_set_flags(SSL *ssl, unsigned long flags);
unsigned long SSL_dane_clear_flags(SSL *ssl, unsigned long flags);

__owur int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
__owur int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm);

__owur X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx);
__owur X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl);

# ifndef OPENSSL_NO_SRP
#  ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength);
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx,
                                        char *(*cb) (SSL *, void *));
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx,
                                          int (*cb) (SSL *, void *));
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx,
                                      int (*cb) (SSL *, int *, void *));
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg);

OSSL_DEPRECATEDIN_3_0
int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g,
                             BIGNUM *sa, BIGNUM *v, char *info);
OSSL_DEPRECATEDIN_3_0
int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass,
                                const char *grp);

OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_g(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_N(SSL *s);

OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_username(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_userinfo(SSL *s);
#  endif
# endif

/*
 * ClientHello callback and helpers.
 */

# define SSL_CLIENT_HELLO_SUCCESS 1
# define SSL_CLIENT_HELLO_ERROR   0
# define SSL_CLIENT_HELLO_RETRY   (-1)

typedef int (*SSL_client_hello_cb_fn) (SSL *s, int *al, void *arg);
void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_fn cb,
                                 void *arg);
int SSL_client_hello_isv2(SSL *s);
unsigned int SSL_client_hello_get0_legacy_version(SSL *s);
size_t SSL_client_hello_get0_random(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_session_id(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_compression_methods(SSL *s,
                                                 const unsigned char **out);
int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen);
int SSL_client_hello_get0_ext(SSL *s, unsigned int type,
                              const unsigned char **out, size_t *outlen);

void SSL_certs_clear(SSL *s);
void SSL_free(SSL *ssl);
# ifdef OSSL_ASYNC_FD
/*
 * Windows application developer has to include windows.h to use these.
 */
__owur int SSL_waiting_for_async(SSL *s);
__owur int SSL_get_all_async_fds(SSL *s, OSSL_ASYNC_FD *fds, size_t *numfds);
__owur int SSL_get_changed_async_fds(SSL *s, OSSL_ASYNC_FD *addfd,
                                     size_t *numaddfds, OSSL_ASYNC_FD *delfd,
                                     size_t *numdelfds);
__owur int SSL_CTX_set_async_callback(SSL_CTX *ctx, SSL_async_callback_fn callback);
__owur int SSL_CTX_set_async_callback_arg(SSL_CTX *ctx, void *arg);
__owur int SSL_set_async_callback(SSL *s, SSL_async_callback_fn callback);
__owur int SSL_set_async_callback_arg(SSL *s, void *arg);
__owur int SSL_get_async_status(SSL *s, int *status);

# endif
__owur int SSL_accept(SSL *ssl);
__owur int SSL_stateless(SSL *s);
__owur int SSL_connect(SSL *ssl);
__owur int SSL_read(SSL *ssl, void *buf, int num);
__owur int SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);

# define SSL_READ_EARLY_DATA_ERROR   0
# define SSL_READ_EARLY_DATA_SUCCESS 1
# define SSL_READ_EARLY_DATA_FINISH  2

__owur int SSL_read_early_data(SSL *s, void *buf, size_t num,
                               size_t *readbytes);
__owur int SSL_peek(SSL *ssl, void *buf, int num);
__owur int SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);
__owur ossl_ssize_t SSL_sendfile(SSL *s, int fd, off_t offset, size_t size,
                                 int flags);
__owur int SSL_write(SSL *ssl, const void *buf, int num);
__owur int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
__owur int SSL_write_early_data(SSL *s, const void *buf, size_t num,
                                size_t *written);
long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg);
long SSL_callback_ctrl(SSL *, int, void (*)(void));
long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void));

# define SSL_EARLY_DATA_NOT_SENT    0
# define SSL_EARLY_DATA_REJECTED    1
# define SSL_EARLY_DATA_ACCEPTED    2

__owur int SSL_get_early_data_status(const SSL *s);

__owur int SSL_get_error(const SSL *s, int ret_code);
__owur const char *SSL_get_version(const SSL *s);

/* This sets the 'default' SSL version that SSL_new() will create */
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
# endif

# ifndef OPENSSL_NO_SSL3_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_method(void); /* SSLv3 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_client_method(void);
#  endif
# endif

#define SSLv23_method           TLS_method
#define SSLv23_server_method    TLS_server_method
#define SSLv23_client_method    TLS_client_method

/* Negotiate highest available SSL/TLS version */
__owur const SSL_METHOD *TLS_method(void);
__owur const SSL_METHOD *TLS_server_method(void);
__owur const SSL_METHOD *TLS_client_method(void);

# ifndef OPENSSL_NO_TLS1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_TLS1_1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_method(void); /* TLSv1.1 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_TLS1_2_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_method(void); /* TLSv1.2 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_DTLS1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_method(void); /* DTLSv1.0 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_DTLS1_2_METHOD
/* DTLSv1.2 */
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_client_method(void);
#  endif
# endif

__owur const SSL_METHOD *DTLS_method(void); /* DTLS 1.0 and 1.2 */
__owur const SSL_METHOD *DTLS_server_method(void); /* DTLS 1.0 and 1.2 */
__owur const SSL_METHOD *DTLS_client_method(void); /* DTLS 1.0 and 1.2 */

__owur size_t DTLS_get_data_mtu(const SSL *s);

__owur STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s);
__owur STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx);
__owur STACK_OF(SSL_CIPHER) *SSL_get_client_ciphers(const SSL *s);
__owur STACK_OF(SSL_CIPHER) *SSL_get1_supported_ciphers(SSL *s);

__owur int SSL_do_handshake(SSL *s);
int SSL_key_update(SSL *s, int updatetype);
int SSL_get_key_update_type(const SSL *s);
int SSL_renegotiate(SSL *s);
int SSL_renegotiate_abbreviated(SSL *s);
__owur int SSL_renegotiate_pending(const SSL *s);
int SSL_new_session_ticket(SSL *s);
int SSL_shutdown(SSL *s);
__owur int SSL_verify_client_post_handshake(SSL *s);
void SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val);
void SSL_set_post_handshake_auth(SSL *s, int val);

__owur const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx);
__owur const SSL_METHOD *SSL_get_ssl_method(const SSL *s);
__owur int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method);
__owur const char *SSL_alert_type_string_long(int value);
__owur const char *SSL_alert_type_string(int value);
__owur const char *SSL_alert_desc_string_long(int value);
__owur const char *SSL_alert_desc_string(int value);

void SSL_set0_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
void SSL_CTX_set0_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
__owur const STACK_OF(X509_NAME) *SSL_get0_CA_list(const SSL *s);
__owur const STACK_OF(X509_NAME) *SSL_CTX_get0_CA_list(const SSL_CTX *ctx);
__owur int SSL_add1_to_CA_list(SSL *ssl, const X509 *x);
__owur int SSL_CTX_add1_to_CA_list(SSL_CTX *ctx, const X509 *x);
__owur const STACK_OF(X509_NAME) *SSL_get0_peer_CA_list(const SSL *s);

void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
__owur STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s);
__owur STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s);
__owur int SSL_add_client_CA(SSL *ssl, X509 *x);
__owur int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);

void SSL_set_connect_state(SSL *s);
void SSL_set_accept_state(SSL *s);

__owur long SSL_get_default_timeout(const SSL *s);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_library_init() OPENSSL_init_ssl(0, NULL)
# endif

__owur char *SSL_CIPHER_description(const SSL_CIPHER *, char *buf, int size);
__owur STACK_OF(X509_NAME) *SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk);

__owur SSL *SSL_dup(SSL *ssl);

__owur X509 *SSL_get_certificate(const SSL *ssl);
/*
 * EVP_PKEY
 */
struct evp_pkey_st *SSL_get_privatekey(const SSL *ssl);

__owur X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx);
__owur EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx);

void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode);
__owur int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
void SSL_set_quiet_shutdown(SSL *ssl, int mode);
__owur int SSL_get_quiet_shutdown(const SSL *ssl);
void SSL_set_shutdown(SSL *ssl, int mode);
__owur int SSL_get_shutdown(const SSL *ssl);
__owur int SSL_version(const SSL *ssl);
__owur int SSL_client_version(const SSL *s);
__owur int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_store(SSL_CTX *ctx);
__owur int SSL_CTX_load_verify_file(SSL_CTX *ctx, const char *CAfile);
__owur int SSL_CTX_load_verify_dir(SSL_CTX *ctx, const char *CApath);
__owur int SSL_CTX_load_verify_store(SSL_CTX *ctx, const char *CAstore);
__owur int SSL_CTX_load_verify_locations(SSL_CTX *ctx,
                                                        const char *CAfile,
                                                        const char *CApath);
# define SSL_get0_session SSL_get_session/* just peek at pointer */
__owur SSL_SESSION *SSL_get_session(const SSL *ssl);
__owur SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
__owur SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx);
void SSL_set_info_callback(SSL *ssl,
                           void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type,
                                               int val);
__owur OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl);

void SSL_set_verify_result(SSL *ssl, long v);
__owur long SSL_get_verify_result(const SSL *ssl);
__owur STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s);

__owur size_t SSL_get_client_random(const SSL *ssl, unsigned char *out,
                                    size_t outlen);
__owur size_t SSL_get_server_random(const SSL *ssl, unsigned char *out,
                                    size_t outlen);
__owur size_t SSL_SESSION_get_master_key(const SSL_SESSION *sess,
                                         unsigned char *out, size_t outlen);
__owur int SSL_SESSION_set1_master_key(SSL_SESSION *sess,
                                       const unsigned char *in, size_t len);
uint8_t SSL_SESSION_get_max_fragment_length(const SSL_SESSION *sess);

#define SSL_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, l, p, newf, dupf, freef)
__owur int SSL_set_ex_data(SSL *ssl, int idx, void *data);
void *SSL_get_ex_data(const SSL *ssl, int idx);
#define SSL_SESSION_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, l, p, newf, dupf, freef)
__owur int SSL_SESSION_set_ex_data(SSL_SESSION *ss, int idx, void *data);
void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss, int idx);
#define SSL_CTX_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, l, p, newf, dupf, freef)
__owur int SSL_CTX_set_ex_data(SSL_CTX *ssl, int idx, void *data);
void *SSL_CTX_get_ex_data(const SSL_CTX *ssl, int idx);

__owur int SSL_get_ex_data_X509_STORE_CTX_idx(void);

# define SSL_CTX_sess_set_cache_size(ctx,t) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
# define SSL_CTX_sess_get_cache_size(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
# define SSL_CTX_set_session_cache_mode(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
# define SSL_CTX_get_session_cache_mode(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)

# define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
# define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
# define SSL_CTX_get_read_ahead(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
# define SSL_CTX_set_read_ahead(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL)
# define SSL_CTX_get_max_cert_list(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
# define SSL_CTX_set_max_cert_list(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
# define SSL_get_max_cert_list(ssl) \
        SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
# define SSL_set_max_cert_list(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)

# define SSL_CTX_set_max_send_fragment(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
# define SSL_set_max_send_fragment(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
# define SSL_CTX_set_split_send_fragment(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL)
# define SSL_set_split_send_fragment(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL)
# define SSL_CTX_set_max_pipelines(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
# define SSL_set_max_pipelines(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
# define SSL_set_retry_verify(ssl) \
        (SSL_ctrl(ssl,SSL_CTRL_SET_RETRY_VERIFY,0,NULL) > 0)

void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len);
void SSL_set_default_read_buffer_len(SSL *s, size_t len);

# ifndef OPENSSL_NO_DH
#  ifndef OPENSSL_NO_DEPRECATED_3_0
/* NB: the |keylength| is only applicable when is_export is true */
OSSL_DEPRECATEDIN_3_0
void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
                                 DH *(*dh) (SSL *ssl, int is_export,
                                            int keylength));
OSSL_DEPRECATEDIN_3_0
void SSL_set_tmp_dh_callback(SSL *ssl,
                             DH *(*dh) (SSL *ssl, int is_export,
                                        int keylength));
#  endif
# endif

__owur const COMP_METHOD *SSL_get_current_compression(const SSL *s);
__owur const COMP_METHOD *SSL_get_current_expansion(const SSL *s);
__owur const char *SSL_COMP_get_name(const COMP_METHOD *comp);
__owur const char *SSL_COMP_get0_name(const SSL_COMP *comp);
__owur int SSL_COMP_get_id(const SSL_COMP *comp);
STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
__owur STACK_OF(SSL_COMP) *SSL_COMP_set0_compression_methods(STACK_OF(SSL_COMP)
                                                             *meths);
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_COMP_free_compression_methods() while(0) continue
# endif
__owur int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm);

const SSL_CIPHER *SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr);
int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c);
int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c);
int SSL_bytes_to_cipher_list(SSL *s, const unsigned char *bytes, size_t len,
                             int isv2format, STACK_OF(SSL_CIPHER) **sk,
                             STACK_OF(SSL_CIPHER) **scsvs);

/* TLS extensions functions */
__owur int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);

__owur int SSL_set_session_ticket_ext_cb(SSL *s,
                                         tls_session_ticket_ext_cb_fn cb,
                                         void *arg);

/* Pre-shared secret session resumption functions */
__owur int SSL_set_session_secret_cb(SSL *s,
                                     tls_session_secret_cb_fn session_secret_cb,
                                     void *arg);

void SSL_CTX_set_not_resumable_session_callback(SSL_CTX *ctx,
                                                int (*cb) (SSL *ssl,
                                                           int
                                                           is_forward_secure));

void SSL_set_not_resumable_session_callback(SSL *ssl,
                                            int (*cb) (SSL *ssl,
                                                       int is_forward_secure));

void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx,
                                         size_t (*cb) (SSL *ssl, int type,
                                                       size_t len, void *arg));
void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg);
void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx);
int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size);

int SSL_set_record_padding_callback(SSL *ssl,
                                    size_t (*cb) (SSL *ssl, int type,
                                                  size_t len, void *arg));
void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg);
void *SSL_get_record_padding_callback_arg(const SSL *ssl);
int SSL_set_block_padding(SSL *ssl, size_t block_size);

int SSL_set_num_tickets(SSL *s, size_t num_tickets);
size_t SSL_get_num_tickets(const SSL *s);
int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets);
size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_cache_hit(s) SSL_session_reused(s)
# endif

__owur int SSL_session_reused(const SSL *s);
__owur int SSL_is_server(const SSL *s);

__owur __owur SSL_CONF_CTX *SSL_CONF_CTX_new(void);
int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx);
void SSL_CONF_CTX_free(SSL_CONF_CTX *cctx);
unsigned int SSL_CONF_CTX_set_flags(SSL_CONF_CTX *cctx, unsigned int flags);
__owur unsigned int SSL_CONF_CTX_clear_flags(SSL_CONF_CTX *cctx,
                                             unsigned int flags);
__owur int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre);

void SSL_CONF_CTX_set_ssl(SSL_CONF_CTX *cctx, SSL *ssl);
void SSL_CONF_CTX_set_ssl_ctx(SSL_CONF_CTX *cctx, SSL_CTX *ctx);

__owur int SSL_CONF_cmd(SSL_CONF_CTX *cctx, const char *cmd, const char *value);
__owur int SSL_CONF_cmd_argv(SSL_CONF_CTX *cctx, int *pargc, char ***pargv);
__owur int SSL_CONF_cmd_value_type(SSL_CONF_CTX *cctx, const char *cmd);

void SSL_add_ssl_module(void);
int SSL_config(SSL *s, const char *name);
int SSL_CTX_config(SSL_CTX *ctx, const char *name);

# ifndef OPENSSL_NO_SSL_TRACE
void SSL_trace(int write_p, int version, int content_type,
               const void *buf, size_t len, SSL *ssl, void *arg);
# endif

# ifndef OPENSSL_NO_SOCK
int DTLSv1_listen(SSL *s, BIO_ADDR *client);
# endif

# ifndef OPENSSL_NO_CT

/*
 * A callback for verifying that the received SCTs are sufficient.
 * Expected to return 1 if they are sufficient, otherwise 0.
 * May return a negative integer if an error occurs.
 * A connection should be aborted if the SCTs are deemed insufficient.
 */
typedef int (*ssl_ct_validation_cb)(const CT_POLICY_EVAL_CTX *ctx,
                                    const STACK_OF(SCT) *scts, void *arg);

/*
 * Sets a |callback| that is invoked upon receipt of ServerHelloDone to validate
 * the received SCTs.
 * If the callback returns a non-positive result, the connection is terminated.
 * Call this function before beginning a handshake.
 * If a NULL |callback| is provided, SCT validation is disabled.
 * |arg| is arbitrary userdata that will be passed to the callback whenever it
 * is invoked. Ownership of |arg| remains with the caller.
 *
 * NOTE: A side-effect of setting a CT callback is that an OCSP stapled response
 *       will be requested.
 */
int SSL_set_ct_validation_callback(SSL *s, ssl_ct_validation_cb callback,
                                   void *arg);
int SSL_CTX_set_ct_validation_callback(SSL_CTX *ctx,
                                       ssl_ct_validation_cb callback,
                                       void *arg);
#define SSL_disable_ct(s) \
        ((void) SSL_set_validation_callback((s), NULL, NULL))
#define SSL_CTX_disable_ct(ctx) \
        ((void) SSL_CTX_set_validation_callback((ctx), NULL, NULL))

/*
 * The validation type enumerates the available behaviours of the built-in SSL
 * CT validation callback selected via SSL_enable_ct() and SSL_CTX_enable_ct().
 * The underlying callback is a static function in libssl.
 */
enum {
    SSL_CT_VALIDATION_PERMISSIVE = 0,
    SSL_CT_VALIDATION_STRICT
};

/*
 * Enable CT by setting up a callback that implements one of the built-in
 * validation variants.  The SSL_CT_VALIDATION_PERMISSIVE variant always
 * continues the handshake, the application can make appropriate decisions at
 * handshake completion.  The SSL_CT_VALIDATION_STRICT variant requires at
 * least one valid SCT, or else handshake termination will be requested.  The
 * handshake may continue anyway if SSL_VERIFY_NONE is in effect.
 */
int SSL_enable_ct(SSL *s, int validation_mode);
int SSL_CTX_enable_ct(SSL_CTX *ctx, int validation_mode);

/*
 * Report whether a non-NULL callback is enabled.
 */
int SSL_ct_is_enabled(const SSL *s);
int SSL_CTX_ct_is_enabled(const SSL_CTX *ctx);

/* Gets the SCTs received from a connection */
const STACK_OF(SCT) *SSL_get0_peer_scts(SSL *s);

/*
 * Loads the CT log list from the default location.
 * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store,
 * the log information loaded from this file will be appended to the
 * CTLOG_STORE.
 * Returns 1 on success, 0 otherwise.
 */
int SSL_CTX_set_default_ctlog_list_file(SSL_CTX *ctx);

/*
 * Loads the CT log list from the specified file path.
 * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store,
 * the log information loaded from this file will be appended to the
 * CTLOG_STORE.
 * Returns 1 on success, 0 otherwise.
 */
int SSL_CTX_set_ctlog_list_file(SSL_CTX *ctx, const char *path);

/*
 * Sets the CT log list used by all SSL connections created from this SSL_CTX.
 * Ownership of the CTLOG_STORE is transferred to the SSL_CTX.
 */
void SSL_CTX_set0_ctlog_store(SSL_CTX *ctx, CTLOG_STORE *logs);

/*
 * Gets the CT log list used by all SSL connections created from this SSL_CTX.
 * This will be NULL unless one of the following functions has been called:
 * - SSL_CTX_set_default_ctlog_list_file
 * - SSL_CTX_set_ctlog_list_file
 * - SSL_CTX_set_ctlog_store
 */
const CTLOG_STORE *SSL_CTX_get0_ctlog_store(const SSL_CTX *ctx);

# endif /* OPENSSL_NO_CT */

/* What the "other" parameter contains in security callback */
/* Mask for type */
# define SSL_SECOP_OTHER_TYPE    0xffff0000
# define SSL_SECOP_OTHER_NONE    0
# define SSL_SECOP_OTHER_CIPHER  (1 << 16)
# define SSL_SECOP_OTHER_CURVE   (2 << 16)
# define SSL_SECOP_OTHER_DH      (3 << 16)
# define SSL_SECOP_OTHER_PKEY    (4 << 16)
# define SSL_SECOP_OTHER_SIGALG  (5 << 16)
# define SSL_SECOP_OTHER_CERT    (6 << 16)

/* Indicated operation refers to peer key or certificate */
# define SSL_SECOP_PEER          0x1000

/* Values for "op" parameter in security callback */

/* Called to filter ciphers */
/* Ciphers client supports */
# define SSL_SECOP_CIPHER_SUPPORTED      (1 | SSL_SECOP_OTHER_CIPHER)
/* Cipher shared by client/server */
# define SSL_SECOP_CIPHER_SHARED         (2 | SSL_SECOP_OTHER_CIPHER)
/* Sanity check of cipher server selects */
# define SSL_SECOP_CIPHER_CHECK          (3 | SSL_SECOP_OTHER_CIPHER)
/* Curves supported by client */
# define SSL_SECOP_CURVE_SUPPORTED       (4 | SSL_SECOP_OTHER_CURVE)
/* Curves shared by client/server */
# define SSL_SECOP_CURVE_SHARED          (5 | SSL_SECOP_OTHER_CURVE)
/* Sanity check of curve server selects */
# define SSL_SECOP_CURVE_CHECK           (6 | SSL_SECOP_OTHER_CURVE)
/* Temporary DH key */
# define SSL_SECOP_TMP_DH                (7 | SSL_SECOP_OTHER_PKEY)
/* SSL/TLS version */
# define SSL_SECOP_VERSION               (9 | SSL_SECOP_OTHER_NONE)
/* Session tickets */
# define SSL_SECOP_TICKET                (10 | SSL_SECOP_OTHER_NONE)
/* Supported signature algorithms sent to peer */
# define SSL_SECOP_SIGALG_SUPPORTED      (11 | SSL_SECOP_OTHER_SIGALG)
/* Shared signature algorithm */
# define SSL_SECOP_SIGALG_SHARED         (12 | SSL_SECOP_OTHER_SIGALG)
/* Sanity check signature algorithm allowed */
# define SSL_SECOP_SIGALG_CHECK          (13 | SSL_SECOP_OTHER_SIGALG)
/* Used to get mask of supported public key signature algorithms */
# define SSL_SECOP_SIGALG_MASK           (14 | SSL_SECOP_OTHER_SIGALG)
/* Use to see if compression is allowed */
# define SSL_SECOP_COMPRESSION           (15 | SSL_SECOP_OTHER_NONE)
/* EE key in certificate */
# define SSL_SECOP_EE_KEY                (16 | SSL_SECOP_OTHER_CERT)
/* CA key in certificate */
# define SSL_SECOP_CA_KEY                (17 | SSL_SECOP_OTHER_CERT)
/* CA digest algorithm in certificate */
# define SSL_SECOP_CA_MD                 (18 | SSL_SECOP_OTHER_CERT)
/* Peer EE key in certificate */
# define SSL_SECOP_PEER_EE_KEY           (SSL_SECOP_EE_KEY | SSL_SECOP_PEER)
/* Peer CA key in certificate */
# define SSL_SECOP_PEER_CA_KEY           (SSL_SECOP_CA_KEY | SSL_SECOP_PEER)
/* Peer CA digest algorithm in certificate */
# define SSL_SECOP_PEER_CA_MD            (SSL_SECOP_CA_MD | SSL_SECOP_PEER)

void SSL_set_security_level(SSL *s, int level);
__owur int SSL_get_security_level(const SSL *s);
void SSL_set_security_callback(SSL *s,
                               int (*cb) (const SSL *s, const SSL_CTX *ctx,
                                          int op, int bits, int nid,
                                          void *other, void *ex));
int (*SSL_get_security_callback(const SSL *s)) (const SSL *s,
                                                const SSL_CTX *ctx, int op,
                                                int bits, int nid, void *other,
                                                void *ex);
void SSL_set0_security_ex_data(SSL *s, void *ex);
__owur void *SSL_get0_security_ex_data(const SSL *s);

void SSL_CTX_set_security_level(SSL_CTX *ctx, int level);
__owur int SSL_CTX_get_security_level(const SSL_CTX *ctx);
void SSL_CTX_set_security_callback(SSL_CTX *ctx,
                                   int (*cb) (const SSL *s, const SSL_CTX *ctx,
                                              int op, int bits, int nid,
                                              void *other, void *ex));
int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx)) (const SSL *s,
                                                          const SSL_CTX *ctx,
                                                          int op, int bits,
                                                          int nid,
                                                          void *other,
                                                          void *ex);
void SSL_CTX_set0_security_ex_data(SSL_CTX *ctx, void *ex);
__owur void *SSL_CTX_get0_security_ex_data(const SSL_CTX *ctx);

/* OPENSSL_INIT flag 0x010000 reserved for internal use */
# define OPENSSL_INIT_NO_LOAD_SSL_STRINGS    0x00100000L
# define OPENSSL_INIT_LOAD_SSL_STRINGS       0x00200000L

# define OPENSSL_INIT_SSL_DEFAULT \
        (OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS)

int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);

# ifndef OPENSSL_NO_UNIT_TEST
__owur const struct openssl_ssl_test_functions *SSL_test_functions(void);
# endif

__owur int SSL_free_buffers(SSL *ssl);
__owur int SSL_alloc_buffers(SSL *ssl);

/* Status codes passed to the decrypt session ticket callback. Some of these
 * are for internal use only and are never passed to the callback. */
typedef int SSL_TICKET_STATUS;

/* Support for ticket appdata */
/* fatal error, malloc failure */
# define SSL_TICKET_FATAL_ERR_MALLOC 0
/* fatal error, either from parsing or decrypting the ticket */
# define SSL_TICKET_FATAL_ERR_OTHER  1
/* No ticket present */
# define SSL_TICKET_NONE             2
/* Empty ticket present */
# define SSL_TICKET_EMPTY            3
/* the ticket couldn't be decrypted */
# define SSL_TICKET_NO_DECRYPT       4
/* a ticket was successfully decrypted */
# define SSL_TICKET_SUCCESS          5
/* same as above but the ticket needs to be renewed */
# define SSL_TICKET_SUCCESS_RENEW    6

/* Return codes for the decrypt session ticket callback */
typedef int SSL_TICKET_RETURN;

/* An error occurred */
#define SSL_TICKET_RETURN_ABORT             0
/* Do not use the ticket, do not send a renewed ticket to the client */
#define SSL_TICKET_RETURN_IGNORE            1
/* Do not use the ticket, send a renewed ticket to the client */
#define SSL_TICKET_RETURN_IGNORE_RENEW      2
/* Use the ticket, do not send a renewed ticket to the client */
#define SSL_TICKET_RETURN_USE               3
/* Use the ticket, send a renewed ticket to the client */
#define SSL_TICKET_RETURN_USE_RENEW         4

typedef int (*SSL_CTX_generate_session_ticket_fn)(SSL *s, void *arg);
typedef SSL_TICKET_RETURN (*SSL_CTX_decrypt_session_ticket_fn)(SSL *s, SSL_SESSION *ss,
                                                               const unsigned char *keyname,
                                                               size_t keyname_length,
                                                               SSL_TICKET_STATUS status,
                                                               void *arg);
int SSL_CTX_set_session_ticket_cb(SSL_CTX *ctx,
                                  SSL_CTX_generate_session_ticket_fn gen_cb,
                                  SSL_CTX_decrypt_session_ticket_fn dec_cb,
                                  void *arg);
int SSL_SESSION_set1_ticket_appdata(SSL_SESSION *ss, const void *data, size_t len);
int SSL_SESSION_get0_ticket_appdata(SSL_SESSION *ss, void **data, size_t *len);

typedef unsigned int (*DTLS_timer_cb)(SSL *s, unsigned int timer_us);

void DTLS_set_timer_cb(SSL *s, DTLS_timer_cb cb);


typedef int (*SSL_allow_early_data_cb_fn)(SSL *s, void *arg);
void SSL_CTX_set_allow_early_data_cb(SSL_CTX *ctx,
                                     SSL_allow_early_data_cb_fn cb,
                                     void *arg);
void SSL_set_allow_early_data_cb(SSL *s,
                                 SSL_allow_early_data_cb_fn cb,
                                 void *arg);

/* store the default cipher strings inside the library */
const char *OSSL_default_cipher_list(void);
const char *OSSL_default_ciphersuites(void);

#  ifndef OPENSSL_NO_QUIC
/*
 * QUIC integration - The QUIC interface matches BoringSSL
 *
 * ssl_encryption_level_t represents a specific QUIC encryption level used to
 * transmit handshake messages. BoringSSL has this as an 'enum'.
 */
#include <openssl/quic.h>

/* Used by Chromium/QUIC - moved from evp.h to avoid breaking FIPS checksums */
# define X25519_PRIVATE_KEY_LEN          32
# define X25519_PUBLIC_VALUE_LEN         32

/* moved from types.h to avoid breaking FIPS checksums */
typedef struct ssl_quic_method_st SSL_QUIC_METHOD;

typedef enum ssl_encryption_level_t {
    ssl_encryption_initial = 0,
    ssl_encryption_early_data,
    ssl_encryption_handshake,
    ssl_encryption_application
} OSSL_ENCRYPTION_LEVEL;

struct ssl_quic_method_st {
    int (*set_encryption_secrets)(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                                  const uint8_t *read_secret,
                                  const uint8_t *write_secret, size_t secret_len);
    int (*add_handshake_data)(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                              const uint8_t *data, size_t len);
    int (*flush_flight)(SSL *ssl);
    int (*send_alert)(SSL *ssl, enum ssl_encryption_level_t level, uint8_t alert);
};

__owur int SSL_CTX_set_quic_method(SSL_CTX *ctx, const SSL_QUIC_METHOD *quic_method);
__owur int SSL_set_quic_method(SSL *ssl, const SSL_QUIC_METHOD *quic_method);
__owur int SSL_set_quic_transport_params(SSL *ssl,
                                         const uint8_t *params,
                                         size_t params_len);
void SSL_get_peer_quic_transport_params(const SSL *ssl,
                                        const uint8_t **out_params,
                                        size_t *out_params_len);
__owur size_t SSL_quic_max_handshake_flight_len(const SSL *ssl, OSSL_ENCRYPTION_LEVEL level);
__owur OSSL_ENCRYPTION_LEVEL SSL_quic_read_level(const SSL *ssl);
__owur OSSL_ENCRYPTION_LEVEL SSL_quic_write_level(const SSL *ssl);
__owur int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                                 const uint8_t *data, size_t len);
__owur int SSL_process_quic_post_handshake(SSL *ssl);

__owur int SSL_is_quic(SSL *ssl);

/* BoringSSL API */
void SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy);

/*
 * Set an explicit value that you want to use
 * If 0 (default) the server will use the highest extenstion the client sent
 * If 0 (default) the client will send both extensions
 */
void SSL_set_quic_transport_version(SSL *ssl, int version);
__owur int SSL_get_quic_transport_version(const SSL *ssl);
/* Returns the negotiated version, or -1 on error */
__owur int SSL_get_peer_quic_transport_version(const SSL *ssl);

int SSL_CIPHER_get_prf_nid(const SSL_CIPHER *c);

void SSL_set_quic_early_data_enabled(SSL *ssl, int enabled);

#  endif

# ifdef  __cplusplus
}
# endif
#endif
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     /*
 * WARNING: do not edit!
 * Generated by Makefile from include/openssl/ssl.h.in
 *
 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
 * Copyright 2005 Nokia. All rights reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */



#ifndef OPENSSL_SSL_H
# define OPENSSL_SSL_H
# pragma once

# include <openssl/macros.h>
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define HEADER_SSL_H
# endif

# include <openssl/e_os2.h>
# include <openssl/opensslconf.h>
# include <openssl/comp.h>
# include <openssl/bio.h>
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  include <openssl/x509.h>
#  include <openssl/crypto.h>
#  include <openssl/buffer.h>
# endif
# include <openssl/lhash.h>
# include <openssl/pem.h>
# include <openssl/hmac.h>
# include <openssl/async.h>

# include <openssl/safestack.h>
# include <openssl/symhacks.h>
# include <openssl/ct.h>
# include <openssl/sslerr.h>
# include <openssl/prov_ssl.h>

#ifdef  __cplusplus
extern "C" {
#endif

/* OpenSSL version number for ASN.1 encoding of the session information */
/*-
 * Version 0 - initial version
 * Version 1 - added the optional peer certificate
 */
# define SSL_SESSION_ASN1_VERSION 0x0001

# define SSL_MAX_SSL_SESSION_ID_LENGTH           32
# define SSL_MAX_SID_CTX_LENGTH                  32

# define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES     (512/8)
# define SSL_MAX_KEY_ARG_LENGTH                  8
/* SSL_MAX_MASTER_KEY_LENGTH is defined in prov_ssl.h */

/* The maximum number of encrypt/decrypt pipelines we can support */
# define SSL_MAX_PIPELINES  32

/* text strings for the ciphers */

/* These are used to specify which ciphers to use and not to use */

# define SSL_TXT_LOW             "LOW"
# define SSL_TXT_MEDIUM          "MEDIUM"
# define SSL_TXT_HIGH            "HIGH"
# define SSL_TXT_FIPS            "FIPS"

# define SSL_TXT_aNULL           "aNULL"
# define SSL_TXT_eNULL           "eNULL"
# define SSL_TXT_NULL            "NULL"

# define SSL_TXT_kRSA            "kRSA"
# define SSL_TXT_kDHr            "kDHr"/* this cipher class has been removed */
# define SSL_TXT_kDHd            "kDHd"/* this cipher class has been removed */
# define SSL_TXT_kDH             "kDH"/* this cipher class has been removed */
# define SSL_TXT_kEDH            "kEDH"/* alias for kDHE */
# define SSL_TXT_kDHE            "kDHE"
# define SSL_TXT_kECDHr          "kECDHr"/* this cipher class has been removed */
# define SSL_TXT_kECDHe          "kECDHe"/* this cipher class has been removed */
# define SSL_TXT_kECDH           "kECDH"/* this cipher class has been removed */
# define SSL_TXT_kEECDH          "kEECDH"/* alias for kECDHE */
# define SSL_TXT_kECDHE          "kECDHE"
# define SSL_TXT_kPSK            "kPSK"
# define SSL_TXT_kRSAPSK         "kRSAPSK"
# define SSL_TXT_kECDHEPSK       "kECDHEPSK"
# define SSL_TXT_kDHEPSK         "kDHEPSK"
# define SSL_TXT_kGOST           "kGOST"
# define SSL_TXT_kGOST18         "kGOST18"
# define SSL_TXT_kSRP            "kSRP"

# define SSL_TXT_aRSA            "aRSA"
# define SSL_TXT_aDSS            "aDSS"
# define SSL_TXT_aDH             "aDH"/* this cipher class has been removed */
# define SSL_TXT_aECDH           "aECDH"/* this cipher class has been removed */
# define SSL_TXT_aECDSA          "aECDSA"
# define SSL_TXT_aPSK            "aPSK"
# define SSL_TXT_aGOST94         "aGOST94"
# define SSL_TXT_aGOST01         "aGOST01"
# define SSL_TXT_aGOST12         "aGOST12"
# define SSL_TXT_aGOST           "aGOST"
# define SSL_TXT_aSRP            "aSRP"

# define SSL_TXT_DSS             "DSS"
# define SSL_TXT_DH              "DH"
# define SSL_TXT_DHE             "DHE"/* same as "kDHE:-ADH" */
# define SSL_TXT_EDH             "EDH"/* alias for DHE */
# define SSL_TXT_ADH             "ADH"
# define SSL_TXT_RSA             "RSA"
# define SSL_TXT_ECDH            "ECDH"
# define SSL_TXT_EECDH           "EECDH"/* alias for ECDHE" */
# define SSL_TXT_ECDHE           "ECDHE"/* same as "kECDHE:-AECDH" */
# define SSL_TXT_AECDH           "AECDH"
# define SSL_TXT_ECDSA           "ECDSA"
# define SSL_TXT_PSK             "PSK"
# define SSL_TXT_SRP             "SRP"

# define SSL_TXT_DES             "DES"
# define SSL_TXT_3DES            "3DES"
# define SSL_TXT_RC4             "RC4"
# define SSL_TXT_RC2             "RC2"
# define SSL_TXT_IDEA            "IDEA"
# define SSL_TXT_SEED            "SEED"
# define SSL_TXT_AES128          "AES128"
# define SSL_TXT_AES256          "AES256"
# define SSL_TXT_AES             "AES"
# define SSL_TXT_AES_GCM         "AESGCM"
# define SSL_TXT_AES_CCM         "AESCCM"
# define SSL_TXT_AES_CCM_8       "AESCCM8"
# define SSL_TXT_CAMELLIA128     "CAMELLIA128"
# define SSL_TXT_CAMELLIA256     "CAMELLIA256"
# define SSL_TXT_CAMELLIA        "CAMELLIA"
# define SSL_TXT_CHACHA20        "CHACHA20"
# define SSL_TXT_GOST            "GOST89"
# define SSL_TXT_ARIA            "ARIA"
# define SSL_TXT_ARIA_GCM        "ARIAGCM"
# define SSL_TXT_ARIA128         "ARIA128"
# define SSL_TXT_ARIA256         "ARIA256"
# define SSL_TXT_GOST2012_GOST8912_GOST8912 "GOST2012-GOST8912-GOST8912"
# define SSL_TXT_CBC             "CBC"

# define SSL_TXT_MD5             "MD5"
# define SSL_TXT_SHA1            "SHA1"
# define SSL_TXT_SHA             "SHA"/* same as "SHA1" */
# define SSL_TXT_GOST94          "GOST94"
# define SSL_TXT_GOST89MAC       "GOST89MAC"
# define SSL_TXT_GOST12          "GOST12"
# define SSL_TXT_GOST89MAC12     "GOST89MAC12"
# define SSL_TXT_SHA256          "SHA256"
# define SSL_TXT_SHA384          "SHA384"

# define SSL_TXT_SSLV3           "SSLv3"
# define SSL_TXT_TLSV1           "TLSv1"
# define SSL_TXT_TLSV1_1         "TLSv1.1"
# define SSL_TXT_TLSV1_2         "TLSv1.2"

# define SSL_TXT_ALL             "ALL"

/*-
 * COMPLEMENTOF* definitions. These identifiers are used to (de-select)
 * ciphers normally not being used.
 * Example: "RC4" will activate all ciphers using RC4 including ciphers
 * without authentication, which would normally disabled by DEFAULT (due
 * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT"
 * will make sure that it is also disabled in the specific selection.
 * COMPLEMENTOF* identifiers are portable between version, as adjustments
 * to the default cipher setup will also be included here.
 *
 * COMPLEMENTOFDEFAULT does not experience the same special treatment that
 * DEFAULT gets, as only selection is being done and no sorting as needed
 * for DEFAULT.
 */
# define SSL_TXT_CMPALL          "COMPLEMENTOFALL"
# define SSL_TXT_CMPDEF          "COMPLEMENTOFDEFAULT"

/*
 * The following cipher list is used by default. It also is substituted when
 * an application-defined cipher list string starts with 'DEFAULT'.
 * This applies to ciphersuites for TLSv1.2 and below.
 * DEPRECATED IN 3.0.0, in favor of OSSL_default_cipher_list()
 * Update both macro and function simultaneously
 */
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_DEFAULT_CIPHER_LIST "ALL:!COMPLEMENTOFDEFAULT:!eNULL"
/*
 * This is the default set of TLSv1.3 ciphersuites
 * DEPRECATED IN 3.0.0, in favor of OSSL_default_ciphersuites()
 * Update both macro and function simultaneously
 */
#  define TLS_DEFAULT_CIPHERSUITES "TLS_AES_256_GCM_SHA384:" \
                                   "TLS_CHACHA20_POLY1305_SHA256:" \
                                   "TLS_AES_128_GCM_SHA256"
# endif
/*
 * As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always
 * starts with a reasonable order, and all we have to do for DEFAULT is
 * throwing out anonymous and unencrypted ciphersuites! (The latter are not
 * actually enabled by ALL, but "ALL:RSA" would enable some of them.)
 */

/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
# define SSL_SENT_SHUTDOWN       1
# define SSL_RECEIVED_SHUTDOWN   2

#ifdef __cplusplus
}
#endif

#ifdef  __cplusplus
extern "C" {
#endif

# define SSL_FILETYPE_ASN1       X509_FILETYPE_ASN1
# define SSL_FILETYPE_PEM        X509_FILETYPE_PEM

/*
 * This is needed to stop compilers complaining about the 'struct ssl_st *'
 * function parameters used to prototype callbacks in SSL_CTX.
 */
typedef struct ssl_st *ssl_crock_st;
typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
typedef struct ssl_method_st SSL_METHOD;
typedef struct ssl_cipher_st SSL_CIPHER;
typedef struct ssl_session_st SSL_SESSION;
typedef struct tls_sigalgs_st TLS_SIGALGS;
typedef struct ssl_conf_ctx_st SSL_CONF_CTX;
typedef struct ssl_comp_st SSL_COMP;

STACK_OF(SSL_CIPHER);
STACK_OF(SSL_COMP);

/* SRTP protection profiles for use with the use_srtp extension (RFC 5764)*/
typedef struct srtp_protection_profile_st {
    const char *name;
    unsigned long id;
} SRTP_PROTECTION_PROFILE;
SKM_DEFINE_STACK_OF_INTERNAL(SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE)
#define sk_SRTP_PROTECTION_PROFILE_num(sk) OPENSSL_sk_num(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_value(sk, idx) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_value(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), (idx)))
#define sk_SRTP_PROTECTION_PROFILE_new(cmp) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new(ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp)))
#define sk_SRTP_PROTECTION_PROFILE_new_null() ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new_null())
#define sk_SRTP_PROTECTION_PROFILE_new_reserve(cmp, n) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new_reserve(ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp), (n)))
#define sk_SRTP_PROTECTION_PROFILE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (n))
#define sk_SRTP_PROTECTION_PROFILE_free(sk) OPENSSL_sk_free(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_zero(sk) OPENSSL_sk_zero(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_delete(sk, i) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_delete(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (i)))
#define sk_SRTP_PROTECTION_PROFILE_delete_ptr(sk, ptr) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_delete_ptr(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr)))
#define sk_SRTP_PROTECTION_PROFILE_push(sk, ptr) OPENSSL_sk_push(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_pop(sk) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_pop(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_shift(sk) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_shift(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk),ossl_check_SRTP_PROTECTION_PROFILE_freefunc_type(freefunc))
#define sk_SRTP_PROTECTION_PROFILE_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr), (idx))
#define sk_SRTP_PROTECTION_PROFILE_set(sk, idx, ptr) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_set(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (idx), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr)))
#define sk_SRTP_PROTECTION_PROFILE_find(sk, ptr) OPENSSL_sk_find(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr), pnum)
#define sk_SRTP_PROTECTION_PROFILE_sort(sk) OPENSSL_sk_sort(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_dup(sk) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_dup(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_deep_copy(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_copyfunc_type(copyfunc), ossl_check_SRTP_PROTECTION_PROFILE_freefunc_type(freefunc)))
#define sk_SRTP_PROTECTION_PROFILE_set_cmp_func(sk, cmp) ((sk_SRTP_PROTECTION_PROFILE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp)))



typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data,
                                            int len, void *arg);
typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len,
                                        STACK_OF(SSL_CIPHER) *peer_ciphers,
                                        const SSL_CIPHER **cipher, void *arg);

/* Extension context codes */
/* This extension is only allowed in TLS */
#define SSL_EXT_TLS_ONLY                        0x0001
/* This extension is only allowed in DTLS */
#define SSL_EXT_DTLS_ONLY                       0x0002
/* Some extensions may be allowed in DTLS but we don't implement them for it */
#define SSL_EXT_TLS_IMPLEMENTATION_ONLY         0x0004
/* Most extensions are not defined for SSLv3 but EXT_TYPE_renegotiate is */
#define SSL_EXT_SSL3_ALLOWED                    0x0008
/* Extension is only defined for TLS1.2 and below */
#define SSL_EXT_TLS1_2_AND_BELOW_ONLY           0x0010
/* Extension is only defined for TLS1.3 and above */
#define SSL_EXT_TLS1_3_ONLY                     0x0020
/* Ignore this extension during parsing if we are resuming */
#define SSL_EXT_IGNORE_ON_RESUMPTION            0x0040
#define SSL_EXT_CLIENT_HELLO                    0x0080
/* Really means TLS1.2 or below */
#define SSL_EXT_TLS1_2_SERVER_HELLO             0x0100
#define SSL_EXT_TLS1_3_SERVER_HELLO             0x0200
#define SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS     0x0400
#define SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST      0x0800
#define SSL_EXT_TLS1_3_CERTIFICATE              0x1000
#define SSL_EXT_TLS1_3_NEW_SESSION_TICKET       0x2000
#define SSL_EXT_TLS1_3_CERTIFICATE_REQUEST      0x4000

/* Typedefs for handling custom extensions */

typedef int (*custom_ext_add_cb)(SSL *s, unsigned int ext_type,
                                 const unsigned char **out, size_t *outlen,
                                 int *al, void *add_arg);

typedef void (*custom_ext_free_cb)(SSL *s, unsigned int ext_type,
                                   const unsigned char *out, void *add_arg);

typedef int (*custom_ext_parse_cb)(SSL *s, unsigned int ext_type,
                                   const unsigned char *in, size_t inlen,
                                   int *al, void *parse_arg);


typedef int (*SSL_custom_ext_add_cb_ex)(SSL *s, unsigned int ext_type,
                                        unsigned int context,
                                        const unsigned char **out,
                                        size_t *outlen, X509 *x,
                                        size_t chainidx,
                                        int *al, void *add_arg);

typedef void (*SSL_custom_ext_free_cb_ex)(SSL *s, unsigned int ext_type,
                                          unsigned int context,
                                          const unsigned char *out,
                                          void *add_arg);

typedef int (*SSL_custom_ext_parse_cb_ex)(SSL *s, unsigned int ext_type,
                                          unsigned int context,
                                          const unsigned char *in,
                                          size_t inlen, X509 *x,
                                          size_t chainidx,
                                          int *al, void *parse_arg);

/* Typedef for verification callback */
typedef int (*SSL_verify_cb)(int preverify_ok, X509_STORE_CTX *x509_ctx);

/* Typedef for SSL async callback */
typedef int (*SSL_async_callback_fn)(SSL *s, void *arg);

#define SSL_OP_BIT(n)  ((uint64_t)1 << (uint64_t)n)

/*
 * SSL/TLS connection options.
 */
    /* Disable Extended master secret */
# define SSL_OP_NO_EXTENDED_MASTER_SECRET                SSL_OP_BIT(0)
    /* Cleanse plaintext copies of data delivered to the application */
# define SSL_OP_CLEANSE_PLAINTEXT                        SSL_OP_BIT(1)
    /* Allow initial connection to servers that don't support RI */
# define SSL_OP_LEGACY_SERVER_CONNECT                    SSL_OP_BIT(2)
    /* Enable support for Kernel TLS */
# define SSL_OP_ENABLE_KTLS                              SSL_OP_BIT(3)
# define SSL_OP_TLSEXT_PADDING                           SSL_OP_BIT(4)
# define SSL_OP_SAFARI_ECDHE_ECDSA_BUG                   SSL_OP_BIT(6)
# define SSL_OP_IGNORE_UNEXPECTED_EOF                    SSL_OP_BIT(7)
# define SSL_OP_ALLOW_CLIENT_RENEGOTIATION               SSL_OP_BIT(8)
# define SSL_OP_DISABLE_TLSEXT_CA_NAMES                  SSL_OP_BIT(9)
    /* In TLSv1.3 allow a non-(ec)dhe based kex_mode */
# define SSL_OP_ALLOW_NO_DHE_KEX                         SSL_OP_BIT(10)
    /*
     * Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
     * in OpenSSL 0.9.6d.  Usually (depending on the application protocol)
     * the workaround is not needed.  Unfortunately some broken SSL/TLS
     * implementations cannot handle it at all, which is why we include it
     * in SSL_OP_ALL. Added in 0.9.6e
     */
# define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS              SSL_OP_BIT(11)
    /* DTLS options */
# define SSL_OP_NO_QUERY_MTU                             SSL_OP_BIT(12)
    /* Turn on Cookie Exchange (on relevant for servers) */
# define SSL_OP_COOKIE_EXCHANGE                          SSL_OP_BIT(13)
    /* Don't use RFC4507 ticket extension */
# define SSL_OP_NO_TICKET                                SSL_OP_BIT(14)
# ifndef OPENSSL_NO_DTLS1_METHOD
    /*
     * Use Cisco's version identifier of DTLS_BAD_VER
     * (only with deprecated DTLSv1_client_method())
     */
#  define SSL_OP_CISCO_ANYCONNECT                        SSL_OP_BIT(15)
# endif
    /* As server, disallow session resumption on renegotiation */
# define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION   SSL_OP_BIT(16)
    /* Don't use compression even if supported */
# define SSL_OP_NO_COMPRESSION                           SSL_OP_BIT(17)
    /* Permit unsafe legacy renegotiation */
# define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION        SSL_OP_BIT(18)
    /* Disable encrypt-then-mac */
# define SSL_OP_NO_ENCRYPT_THEN_MAC                      SSL_OP_BIT(19)
    /*
     * Enable TLSv1.3 Compatibility mode. This is on by default. A future
     * version of OpenSSL may have this disabled by default.
     */
# define SSL_OP_ENABLE_MIDDLEBOX_COMPAT                  SSL_OP_BIT(20)
    /*
     * Prioritize Chacha20Poly1305 when client does.
     * Modifies SSL_OP_CIPHER_SERVER_PREFERENCE
     */
# define SSL_OP_PRIORITIZE_CHACHA                        SSL_OP_BIT(21)
    /*
     * Set on servers to choose the cipher according to server's preferences.
     */
# define SSL_OP_CIPHER_SERVER_PREFERENCE                 SSL_OP_BIT(22)
    /*
     * If set, a server will allow a client to issue a SSLv3.0 version
     * number as latest version supported in the premaster secret, even when
     * TLSv1.0 (version 3.1) was announced in the client hello. Normally
     * this is forbidden to prevent version rollback attacks.
     */
# define SSL_OP_TLS_ROLLBACK_BUG                         SSL_OP_BIT(23)
    /*
     * Switches off automatic TLSv1.3 anti-replay protection for early data.
     * This is a server-side option only (no effect on the client).
     */
# define SSL_OP_NO_ANTI_REPLAY                           SSL_OP_BIT(24)
# define SSL_OP_NO_SSLv3                                 SSL_OP_BIT(25)
# define SSL_OP_NO_TLSv1                                 SSL_OP_BIT(26)
# define SSL_OP_NO_TLSv1_2                               SSL_OP_BIT(27)
# define SSL_OP_NO_TLSv1_1                               SSL_OP_BIT(28)
# define SSL_OP_NO_TLSv1_3                               SSL_OP_BIT(29)
# define SSL_OP_NO_DTLSv1                                SSL_OP_BIT(26)
# define SSL_OP_NO_DTLSv1_2                              SSL_OP_BIT(27)
    /* Disallow all renegotiation */
# define SSL_OP_NO_RENEGOTIATION                         SSL_OP_BIT(30)
    /*
     * Make server add server-hello extension from early version of
     * cryptopro draft, when GOST ciphersuite is negotiated. Required for
     * interoperability with CryptoPro CSP 3.x
     */
# define SSL_OP_CRYPTOPRO_TLSEXT_BUG                     SSL_OP_BIT(31)

/*
 * Option "collections."
 */
# define SSL_OP_NO_SSL_MASK \
        ( SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 \
          | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3 )
# define SSL_OP_NO_DTLS_MASK \
        ( SSL_OP_NO_DTLSv1 | SSL_OP_NO_DTLSv1_2 )

/* Various bug workarounds that should be rather harmless. */
# define SSL_OP_ALL \
        ( SSL_OP_CRYPTOPRO_TLSEXT_BUG | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS \
          | SSL_OP_TLSEXT_PADDING | SSL_OP_SAFARI_ECDHE_ECDSA_BUG )

/*
 * OBSOLETE OPTIONS retained for compatibility
 */

# define SSL_OP_MICROSOFT_SESS_ID_BUG                    0x0
# define SSL_OP_NETSCAPE_CHALLENGE_BUG                   0x0
# define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG         0x0
# define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG              0x0
# define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER               0x0
# define SSL_OP_MSIE_SSLV2_RSA_PADDING                   0x0
# define SSL_OP_SSLEAY_080_CLIENT_DH_BUG                 0x0
# define SSL_OP_TLS_D5_BUG                               0x0
# define SSL_OP_TLS_BLOCK_PADDING_BUG                    0x0
# define SSL_OP_SINGLE_ECDH_USE                          0x0
# define SSL_OP_SINGLE_DH_USE                            0x0
# define SSL_OP_EPHEMERAL_RSA                            0x0
# define SSL_OP_NO_SSLv2                                 0x0
# define SSL_OP_PKCS1_CHECK_1                            0x0
# define SSL_OP_PKCS1_CHECK_2                            0x0
# define SSL_OP_NETSCAPE_CA_DN_BUG                       0x0
# define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG          0x0

/*
 * Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
 * when just a single record has been written):
 */
# define SSL_MODE_ENABLE_PARTIAL_WRITE       0x00000001U
/*
 * Make it possible to retry SSL_write() with changed buffer location (buffer
 * contents must stay the same!); this is not the default to avoid the
 * misconception that non-blocking SSL_write() behaves like non-blocking
 * write():
 */
# define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002U
/*
 * Never bother the application with retries if the transport is blocking:
 */
# define SSL_MODE_AUTO_RETRY 0x00000004U
/* Don't attempt to automatically build certificate chain */
# define SSL_MODE_NO_AUTO_CHAIN 0x00000008U
/*
 * Save RAM by releasing read and write buffers when they're empty. (SSL3 and
 * TLS only.) Released buffers are freed.
 */
# define SSL_MODE_RELEASE_BUFFERS 0x00000010U
/*
 * Send the current time in the Random fields of the ClientHello and
 * ServerHello records for compatibility with hypothetical implementations
 * that require it.
 */
# define SSL_MODE_SEND_CLIENTHELLO_TIME 0x00000020U
# define SSL_MODE_SEND_SERVERHELLO_TIME 0x00000040U
/*
 * Send TLS_FALLBACK_SCSV in the ClientHello. To be set only by applications
 * that reconnect with a downgraded protocol version; see
 * draft-ietf-tls-downgrade-scsv-00 for details. DO NOT ENABLE THIS if your
 * application attempts a normal handshake. Only use this in explicit
 * fallback retries, following the guidance in
 * draft-ietf-tls-downgrade-scsv-00.
 */
# define SSL_MODE_SEND_FALLBACK_SCSV 0x00000080U
/*
 * Support Asynchronous operation
 */
# define SSL_MODE_ASYNC 0x00000100U

/*
 * When using DTLS/SCTP, include the terminating zero in the label
 * used for computing the endpoint-pair shared secret. Required for
 * interoperability with implementations having this bug like these
 * older version of OpenSSL:
 * - OpenSSL 1.0.0 series
 * - OpenSSL 1.0.1 series
 * - OpenSSL 1.0.2 series
 * - OpenSSL 1.1.0 series
 * - OpenSSL 1.1.1 and 1.1.1a
 */
# define SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG 0x00000400U

/* Cert related flags */
/*
 * Many implementations ignore some aspects of the TLS standards such as
 * enforcing certificate chain algorithms. When this is set we enforce them.
 */
# define SSL_CERT_FLAG_TLS_STRICT                0x00000001U

/* Suite B modes, takes same values as certificate verify flags */
# define SSL_CERT_FLAG_SUITEB_128_LOS_ONLY       0x10000
/* Suite B 192 bit only mode */
# define SSL_CERT_FLAG_SUITEB_192_LOS            0x20000
/* Suite B 128 bit mode allowing 192 bit algorithms */
# define SSL_CERT_FLAG_SUITEB_128_LOS            0x30000

/* Perform all sorts of protocol violations for testing purposes */
# define SSL_CERT_FLAG_BROKEN_PROTOCOL           0x10000000

/* Flags for building certificate chains */
/* Treat any existing certificates as untrusted CAs */
# define SSL_BUILD_CHAIN_FLAG_UNTRUSTED          0x1
/* Don't include root CA in chain */
# define SSL_BUILD_CHAIN_FLAG_NO_ROOT            0x2
/* Just check certificates already there */
# define SSL_BUILD_CHAIN_FLAG_CHECK              0x4
/* Ignore verification errors */
# define SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR       0x8
/* Clear verification errors from queue */
# define SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR        0x10

/* Flags returned by SSL_check_chain */
/* Certificate can be used with this session */
# define CERT_PKEY_VALID         0x1
/* Certificate can also be used for signing */
# define CERT_PKEY_SIGN          0x2
/* EE certificate signing algorithm OK */
# define CERT_PKEY_EE_SIGNATURE  0x10
/* CA signature algorithms OK */
# define CERT_PKEY_CA_SIGNATURE  0x20
/* EE certificate parameters OK */
# define CERT_PKEY_EE_PARAM      0x40
/* CA certificate parameters OK */
# define CERT_PKEY_CA_PARAM      0x80
/* Signing explicitly allowed as opposed to SHA1 fallback */
# define CERT_PKEY_EXPLICIT_SIGN 0x100
/* Client CA issuer names match (always set for server cert) */
# define CERT_PKEY_ISSUER_NAME   0x200
/* Cert type matches client types (always set for server cert) */
# define CERT_PKEY_CERT_TYPE     0x400
/* Cert chain suitable to Suite B */
# define CERT_PKEY_SUITEB        0x800

# define SSL_CONF_FLAG_CMDLINE           0x1
# define SSL_CONF_FLAG_FILE              0x2
# define SSL_CONF_FLAG_CLIENT            0x4
# define SSL_CONF_FLAG_SERVER            0x8
# define SSL_CONF_FLAG_SHOW_ERRORS       0x10
# define SSL_CONF_FLAG_CERTIFICATE       0x20
# define SSL_CONF_FLAG_REQUIRE_PRIVATE   0x40
/* Configuration value types */
# define SSL_CONF_TYPE_UNKNOWN           0x0
# define SSL_CONF_TYPE_STRING            0x1
# define SSL_CONF_TYPE_FILE              0x2
# define SSL_CONF_TYPE_DIR               0x3
# define SSL_CONF_TYPE_NONE              0x4
# define SSL_CONF_TYPE_STORE             0x5

/* Maximum length of the application-controlled segment of a a TLSv1.3 cookie */
# define SSL_COOKIE_LENGTH                       4096

/*
 * Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, they
 * cannot be used to clear bits.
 */

uint64_t SSL_CTX_get_options(const SSL_CTX *ctx);
uint64_t SSL_get_options(const SSL *s);
uint64_t SSL_CTX_clear_options(SSL_CTX *ctx, uint64_t op);
uint64_t SSL_clear_options(SSL *s, uint64_t op);
uint64_t SSL_CTX_set_options(SSL_CTX *ctx, uint64_t op);
uint64_t SSL_set_options(SSL *s, uint64_t op);

# define SSL_CTX_set_mode(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
# define SSL_CTX_clear_mode(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_MODE,(op),NULL)
# define SSL_CTX_get_mode(ctx) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL)
# define SSL_clear_mode(ssl,op) \
        SSL_ctrl((ssl),SSL_CTRL_CLEAR_MODE,(op),NULL)
# define SSL_set_mode(ssl,op) \
        SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL)
# define SSL_get_mode(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL)
# define SSL_set_mtu(ssl, mtu) \
        SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL)
# define DTLS_set_link_mtu(ssl, mtu) \
        SSL_ctrl((ssl),DTLS_CTRL_SET_LINK_MTU,(mtu),NULL)
# define DTLS_get_link_min_mtu(ssl) \
        SSL_ctrl((ssl),DTLS_CTRL_GET_LINK_MIN_MTU,0,NULL)

# define SSL_get_secure_renegotiation_support(ssl) \
        SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL)

# define SSL_CTX_set_cert_flags(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CERT_FLAGS,(op),NULL)
# define SSL_set_cert_flags(s,op) \
        SSL_ctrl((s),SSL_CTRL_CERT_FLAGS,(op),NULL)
# define SSL_CTX_clear_cert_flags(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL)
# define SSL_clear_cert_flags(s,op) \
        SSL_ctrl((s),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL)

void SSL_CTX_set_msg_callback(SSL_CTX *ctx,
                              void (*cb) (int write_p, int version,
                                          int content_type, const void *buf,
                                          size_t len, SSL *ssl, void *arg));
void SSL_set_msg_callback(SSL *ssl,
                          void (*cb) (int write_p, int version,
                                      int content_type, const void *buf,
                                      size_t len, SSL *ssl, void *arg));
# define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
# define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))

# define SSL_get_extms_support(s) \
        SSL_ctrl((s),SSL_CTRL_GET_EXTMS_SUPPORT,0,NULL)

# ifndef OPENSSL_NO_SRP
/* see tls_srp.c */
#  ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 __owur int SSL_SRP_CTX_init(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx);
OSSL_DEPRECATEDIN_3_0 int SSL_SRP_CTX_free(SSL *ctx);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx);
OSSL_DEPRECATEDIN_3_0 __owur int SSL_srp_server_param_with_username(SSL *s,
                                                                    int *ad);
OSSL_DEPRECATEDIN_3_0 __owur int SRP_Calc_A_param(SSL *s);
#  endif
# endif

/* 100k max cert list */
# define SSL_MAX_CERT_LIST_DEFAULT (1024*100)

# define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT      (1024*20)

/*
 * This callback type is used inside SSL_CTX, SSL, and in the functions that
 * set them. It is used to override the generation of SSL/TLS session IDs in
 * a server. Return value should be zero on an error, non-zero to proceed.
 * Also, callbacks should themselves check if the id they generate is unique
 * otherwise the SSL handshake will fail with an error - callbacks can do
 * this using the 'ssl' value they're passed by;
 * SSL_has_matching_session_id(ssl, id, *id_len) The length value passed in
 * is set at the maximum size the session ID can be. In SSLv3/TLSv1 it is 32
 * bytes. The callback can alter this length to be less if desired. It is
 * also an error for the callback to set the size to zero.
 */
typedef int (*GEN_SESSION_CB) (SSL *ssl, unsigned char *id,
                               unsigned int *id_len);

# define SSL_SESS_CACHE_OFF                      0x0000
# define SSL_SESS_CACHE_CLIENT                   0x0001
# define SSL_SESS_CACHE_SERVER                   0x0002
# define SSL_SESS_CACHE_BOTH     (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
# define SSL_SESS_CACHE_NO_AUTO_CLEAR            0x0080
/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */
# define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP       0x0100
# define SSL_SESS_CACHE_NO_INTERNAL_STORE        0x0200
# define SSL_SESS_CACHE_NO_INTERNAL \
        (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE)
# define SSL_SESS_CACHE_UPDATE_TIME              0x0400

LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx);
# define SSL_CTX_sess_number(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
# define SSL_CTX_sess_connect(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
# define SSL_CTX_sess_connect_good(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
# define SSL_CTX_sess_connect_renegotiate(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
# define SSL_CTX_sess_accept(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
# define SSL_CTX_sess_accept_renegotiate(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
# define SSL_CTX_sess_accept_good(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
# define SSL_CTX_sess_hits(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
# define SSL_CTX_sess_cb_hits(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
# define SSL_CTX_sess_misses(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
# define SSL_CTX_sess_timeouts(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
# define SSL_CTX_sess_cache_full(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)

void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
                             int (*new_session_cb) (struct ssl_st *ssl,
                                                    SSL_SESSION *sess));
int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (struct ssl_st *ssl,
                                              SSL_SESSION *sess);
void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
                                void (*remove_session_cb) (struct ssl_ctx_st
                                                           *ctx,
                                                           SSL_SESSION *sess));
void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (struct ssl_ctx_st *ctx,
                                                  SSL_SESSION *sess);
void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
                             SSL_SESSION *(*get_session_cb) (struct ssl_st
                                                             *ssl,
                                                             const unsigned char
                                                             *data, int len,
                                                             int *copy));
SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (struct ssl_st *ssl,
                                                       const unsigned char *data,
                                                       int len, int *copy);
void SSL_CTX_set_info_callback(SSL_CTX *ctx,
                               void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type,
                                                 int val);
void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
                                int (*client_cert_cb) (SSL *ssl, X509 **x509,
                                                       EVP_PKEY **pkey));
int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509,
                                                 EVP_PKEY **pkey);
# ifndef OPENSSL_NO_ENGINE
__owur int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e);
# endif
void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
                                    int (*app_gen_cookie_cb) (SSL *ssl,
                                                              unsigned char
                                                              *cookie,
                                                              unsigned int
                                                              *cookie_len));
void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
                                  int (*app_verify_cookie_cb) (SSL *ssl,
                                                               const unsigned
                                                               char *cookie,
                                                               unsigned int
                                                               cookie_len));

void SSL_CTX_set_stateless_cookie_generate_cb(
    SSL_CTX *ctx,
    int (*gen_stateless_cookie_cb) (SSL *ssl,
                                    unsigned char *cookie,
                                    size_t *cookie_len));
void SSL_CTX_set_stateless_cookie_verify_cb(
    SSL_CTX *ctx,
    int (*verify_stateless_cookie_cb) (SSL *ssl,
                                       const unsigned char *cookie,
                                       size_t cookie_len));
# ifndef OPENSSL_NO_NEXTPROTONEG

typedef int (*SSL_CTX_npn_advertised_cb_func)(SSL *ssl,
                                              const unsigned char **out,
                                              unsigned int *outlen,
                                              void *arg);
void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s,
                                           SSL_CTX_npn_advertised_cb_func cb,
                                           void *arg);
#  define SSL_CTX_set_npn_advertised_cb SSL_CTX_set_next_protos_advertised_cb

typedef int (*SSL_CTX_npn_select_cb_func)(SSL *s,
                                          unsigned char **out,
                                          unsigned char *outlen,
                                          const unsigned char *in,
                                          unsigned int inlen,
                                          void *arg);
void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s,
                                      SSL_CTX_npn_select_cb_func cb,
                                      void *arg);
#  define SSL_CTX_set_npn_select_cb SSL_CTX_set_next_proto_select_cb

void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
                                    unsigned *len);
#  define SSL_get0_npn_negotiated SSL_get0_next_proto_negotiated
# endif

__owur int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
                                 const unsigned char *in, unsigned int inlen,
                                 const unsigned char *client,
                                 unsigned int client_len);

# define OPENSSL_NPN_UNSUPPORTED 0
# define OPENSSL_NPN_NEGOTIATED  1
# define OPENSSL_NPN_NO_OVERLAP  2

__owur int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
                                   unsigned int protos_len);
__owur int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
                               unsigned int protos_len);
typedef int (*SSL_CTX_alpn_select_cb_func)(SSL *ssl,
                                           const unsigned char **out,
                                           unsigned char *outlen,
                                           const unsigned char *in,
                                           unsigned int inlen,
                                           void *arg);
void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
                                SSL_CTX_alpn_select_cb_func cb,
                                void *arg);
void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
                            unsigned int *len);

# ifndef OPENSSL_NO_PSK
/*
 * the maximum length of the buffer given to callbacks containing the
 * resulting identity/psk
 */
#  define PSK_MAX_IDENTITY_LEN 256
#  define PSK_MAX_PSK_LEN 512
typedef unsigned int (*SSL_psk_client_cb_func)(SSL *ssl,
                                               const char *hint,
                                               char *identity,
                                               unsigned int max_identity_len,
                                               unsigned char *psk,
                                               unsigned int max_psk_len);
void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, SSL_psk_client_cb_func cb);
void SSL_set_psk_client_callback(SSL *ssl, SSL_psk_client_cb_func cb);

typedef unsigned int (*SSL_psk_server_cb_func)(SSL *ssl,
                                               const char *identity,
                                               unsigned char *psk,
                                               unsigned int max_psk_len);
void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, SSL_psk_server_cb_func cb);
void SSL_set_psk_server_callback(SSL *ssl, SSL_psk_server_cb_func cb);

__owur int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint);
__owur int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint);
const char *SSL_get_psk_identity_hint(const SSL *s);
const char *SSL_get_psk_identity(const SSL *s);
# endif

typedef int (*SSL_psk_find_session_cb_func)(SSL *ssl,
                                            const unsigned char *identity,
                                            size_t identity_len,
                                            SSL_SESSION **sess);
typedef int (*SSL_psk_use_session_cb_func)(SSL *ssl, const EVP_MD *md,
                                           const unsigned char **id,
                                           size_t *idlen,
                                           SSL_SESSION **sess);

void SSL_set_psk_find_session_callback(SSL *s, SSL_psk_find_session_cb_func cb);
void SSL_CTX_set_psk_find_session_callback(SSL_CTX *ctx,
                                           SSL_psk_find_session_cb_func cb);
void SSL_set_psk_use_session_callback(SSL *s, SSL_psk_use_session_cb_func cb);
void SSL_CTX_set_psk_use_session_callback(SSL_CTX *ctx,
                                          SSL_psk_use_session_cb_func cb);

/* Register callbacks to handle custom TLS Extensions for client or server. */

__owur int SSL_CTX_has_client_custom_ext(const SSL_CTX *ctx,
                                         unsigned int ext_type);

__owur int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx,
                                         unsigned int ext_type,
                                         custom_ext_add_cb add_cb,
                                         custom_ext_free_cb free_cb,
                                         void *add_arg,
                                         custom_ext_parse_cb parse_cb,
                                         void *parse_arg);

__owur int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx,
                                         unsigned int ext_type,
                                         custom_ext_add_cb add_cb,
                                         custom_ext_free_cb free_cb,
                                         void *add_arg,
                                         custom_ext_parse_cb parse_cb,
                                         void *parse_arg);

__owur int SSL_CTX_add_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
                                  unsigned int context,
                                  SSL_custom_ext_add_cb_ex add_cb,
                                  SSL_custom_ext_free_cb_ex free_cb,
                                  void *add_arg,
                                  SSL_custom_ext_parse_cb_ex parse_cb,
                                  void *parse_arg);

__owur int SSL_extension_supported(unsigned int ext_type);

# define SSL_NOTHING            1
# define SSL_WRITING            2
# define SSL_READING            3
# define SSL_X509_LOOKUP        4
# define SSL_ASYNC_PAUSED       5
# define SSL_ASYNC_NO_JOBS      6
# define SSL_CLIENT_HELLO_CB    7
# define SSL_RETRY_VERIFY       8

/* These will only be used when doing non-blocking IO */
# define SSL_want_nothing(s)         (SSL_want(s) == SSL_NOTHING)
# define SSL_want_read(s)            (SSL_want(s) == SSL_READING)
# define SSL_want_write(s)           (SSL_want(s) == SSL_WRITING)
# define SSL_want_x509_lookup(s)     (SSL_want(s) == SSL_X509_LOOKUP)
# define SSL_want_retry_verify(s)    (SSL_want(s) == SSL_RETRY_VERIFY)
# define SSL_want_async(s)           (SSL_want(s) == SSL_ASYNC_PAUSED)
# define SSL_want_async_job(s)       (SSL_want(s) == SSL_ASYNC_NO_JOBS)
# define SSL_want_client_hello_cb(s) (SSL_want(s) == SSL_CLIENT_HELLO_CB)

# define SSL_MAC_FLAG_READ_MAC_STREAM 1
# define SSL_MAC_FLAG_WRITE_MAC_STREAM 2
# define SSL_MAC_FLAG_READ_MAC_TLSTREE 4
# define SSL_MAC_FLAG_WRITE_MAC_TLSTREE 8

/*
 * A callback for logging out TLS key material. This callback should log out
 * |line| followed by a newline.
 */
typedef void (*SSL_CTX_keylog_cb_func)(const SSL *ssl, const char *line);

/*
 * SSL_CTX_set_keylog_callback configures a callback to log key material. This
 * is intended for debugging use with tools like Wireshark. The cb function
 * should log line followed by a newline.
 */
void SSL_CTX_set_keylog_callback(SSL_CTX *ctx, SSL_CTX_keylog_cb_func cb);

/*
 * SSL_CTX_get_keylog_callback returns the callback configured by
 * SSL_CTX_set_keylog_callback.
 */
SSL_CTX_keylog_cb_func SSL_CTX_get_keylog_callback(const SSL_CTX *ctx);

int SSL_CTX_set_max_early_data(SSL_CTX *ctx, uint32_t max_early_data);
uint32_t SSL_CTX_get_max_early_data(const SSL_CTX *ctx);
int SSL_set_max_early_data(SSL *s, uint32_t max_early_data);
uint32_t SSL_get_max_early_data(const SSL *s);
int SSL_CTX_set_recv_max_early_data(SSL_CTX *ctx, uint32_t recv_max_early_data);
uint32_t SSL_CTX_get_recv_max_early_data(const SSL_CTX *ctx);
int SSL_set_recv_max_early_data(SSL *s, uint32_t recv_max_early_data);
uint32_t SSL_get_recv_max_early_data(const SSL *s);

#ifdef __cplusplus
}
#endif

# include <openssl/ssl2.h>
# include <openssl/ssl3.h>
# include <openssl/tls1.h>      /* This is mostly sslv3 with a few tweaks */
# include <openssl/dtls1.h>     /* Datagram TLS */
# include <openssl/srtp.h>      /* Support for the use_srtp extension */

#ifdef  __cplusplus
extern "C" {
#endif

/*
 * These need to be after the above set of includes due to a compiler bug
 * in VisualStudio 2015
 */
SKM_DEFINE_STACK_OF_INTERNAL(SSL_CIPHER, const SSL_CIPHER, SSL_CIPHER)
#define sk_SSL_CIPHER_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_value(sk, idx) ((const SSL_CIPHER *)OPENSSL_sk_value(ossl_check_const_SSL_CIPHER_sk_type(sk), (idx)))
#define sk_SSL_CIPHER_new(cmp) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new(ossl_check_SSL_CIPHER_compfunc_type(cmp)))
#define sk_SSL_CIPHER_new_null() ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new_null())
#define sk_SSL_CIPHER_new_reserve(cmp, n) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new_reserve(ossl_check_SSL_CIPHER_compfunc_type(cmp), (n)))
#define sk_SSL_CIPHER_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SSL_CIPHER_sk_type(sk), (n))
#define sk_SSL_CIPHER_free(sk) OPENSSL_sk_free(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_zero(sk) OPENSSL_sk_zero(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_delete(sk, i) ((const SSL_CIPHER *)OPENSSL_sk_delete(ossl_check_SSL_CIPHER_sk_type(sk), (i)))
#define sk_SSL_CIPHER_delete_ptr(sk, ptr) ((const SSL_CIPHER *)OPENSSL_sk_delete_ptr(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr)))
#define sk_SSL_CIPHER_push(sk, ptr) OPENSSL_sk_push(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_pop(sk) ((const SSL_CIPHER *)OPENSSL_sk_pop(ossl_check_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_shift(sk) ((const SSL_CIPHER *)OPENSSL_sk_shift(ossl_check_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SSL_CIPHER_sk_type(sk),ossl_check_SSL_CIPHER_freefunc_type(freefunc))
#define sk_SSL_CIPHER_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr), (idx))
#define sk_SSL_CIPHER_set(sk, idx, ptr) ((const SSL_CIPHER *)OPENSSL_sk_set(ossl_check_SSL_CIPHER_sk_type(sk), (idx), ossl_check_SSL_CIPHER_type(ptr)))
#define sk_SSL_CIPHER_find(sk, ptr) OPENSSL_sk_find(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr), pnum)
#define sk_SSL_CIPHER_sort(sk) OPENSSL_sk_sort(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_dup(sk) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_dup(ossl_check_const_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_copyfunc_type(copyfunc), ossl_check_SSL_CIPHER_freefunc_type(freefunc)))
#define sk_SSL_CIPHER_set_cmp_func(sk, cmp) ((sk_SSL_CIPHER_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_compfunc_type(cmp)))
SKM_DEFINE_STACK_OF_INTERNAL(SSL_COMP, SSL_COMP, SSL_COMP)
#define sk_SSL_COMP_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_value(sk, idx) ((SSL_COMP *)OPENSSL_sk_value(ossl_check_const_SSL_COMP_sk_type(sk), (idx)))
#define sk_SSL_COMP_new(cmp) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new(ossl_check_SSL_COMP_compfunc_type(cmp)))
#define sk_SSL_COMP_new_null() ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new_null())
#define sk_SSL_COMP_new_reserve(cmp, n) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new_reserve(ossl_check_SSL_COMP_compfunc_type(cmp), (n)))
#define sk_SSL_COMP_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SSL_COMP_sk_type(sk), (n))
#define sk_SSL_COMP_free(sk) OPENSSL_sk_free(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_zero(sk) OPENSSL_sk_zero(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_delete(sk, i) ((SSL_COMP *)OPENSSL_sk_delete(ossl_check_SSL_COMP_sk_type(sk), (i)))
#define sk_SSL_COMP_delete_ptr(sk, ptr) ((SSL_COMP *)OPENSSL_sk_delete_ptr(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr)))
#define sk_SSL_COMP_push(sk, ptr) OPENSSL_sk_push(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_pop(sk) ((SSL_COMP *)OPENSSL_sk_pop(ossl_check_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_shift(sk) ((SSL_COMP *)OPENSSL_sk_shift(ossl_check_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SSL_COMP_sk_type(sk),ossl_check_SSL_COMP_freefunc_type(freefunc))
#define sk_SSL_COMP_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr), (idx))
#define sk_SSL_COMP_set(sk, idx, ptr) ((SSL_COMP *)OPENSSL_sk_set(ossl_check_SSL_COMP_sk_type(sk), (idx), ossl_check_SSL_COMP_type(ptr)))
#define sk_SSL_COMP_find(sk, ptr) OPENSSL_sk_find(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr), pnum)
#define sk_SSL_COMP_sort(sk) OPENSSL_sk_sort(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_dup(sk) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_dup(ossl_check_const_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_copyfunc_type(copyfunc), ossl_check_SSL_COMP_freefunc_type(freefunc)))
#define sk_SSL_COMP_set_cmp_func(sk, cmp) ((sk_SSL_COMP_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_compfunc_type(cmp)))


/* compatibility */
# define SSL_set_app_data(s,arg)         (SSL_set_ex_data(s,0,(char *)(arg)))
# define SSL_get_app_data(s)             (SSL_get_ex_data(s,0))
# define SSL_SESSION_set_app_data(s,a)   (SSL_SESSION_set_ex_data(s,0, \
                                                                  (char *)(a)))
# define SSL_SESSION_get_app_data(s)     (SSL_SESSION_get_ex_data(s,0))
# define SSL_CTX_get_app_data(ctx)       (SSL_CTX_get_ex_data(ctx,0))
# define SSL_CTX_set_app_data(ctx,arg)   (SSL_CTX_set_ex_data(ctx,0, \
                                                              (char *)(arg)))
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 void SSL_set_debug(SSL *s, int debug);
# endif

/* TLSv1.3 KeyUpdate message types */
/* -1 used so that this is an invalid value for the on-the-wire protocol */
#define SSL_KEY_UPDATE_NONE             -1
/* Values as defined for the on-the-wire protocol */
#define SSL_KEY_UPDATE_NOT_REQUESTED     0
#define SSL_KEY_UPDATE_REQUESTED         1

/*
 * The valid handshake states (one for each type message sent and one for each
 * type of message received). There are also two "special" states:
 * TLS = TLS or DTLS state
 * DTLS = DTLS specific state
 * CR/SR = Client Read/Server Read
 * CW/SW = Client Write/Server Write
 *
 * The "special" states are:
 * TLS_ST_BEFORE = No handshake has been initiated yet
 * TLS_ST_OK = A handshake has been successfully completed
 */
typedef enum {
    TLS_ST_BEFORE,
    TLS_ST_OK,
    DTLS_ST_CR_HELLO_VERIFY_REQUEST,
    TLS_ST_CR_SRVR_HELLO,
    TLS_ST_CR_CERT,
    TLS_ST_CR_CERT_STATUS,
    TLS_ST_CR_KEY_EXCH,
    TLS_ST_CR_CERT_REQ,
    TLS_ST_CR_SRVR_DONE,
    TLS_ST_CR_SESSION_TICKET,
    TLS_ST_CR_CHANGE,
    TLS_ST_CR_FINISHED,
    TLS_ST_CW_CLNT_HELLO,
    TLS_ST_CW_CERT,
    TLS_ST_CW_KEY_EXCH,
    TLS_ST_CW_CERT_VRFY,
    TLS_ST_CW_CHANGE,
    TLS_ST_CW_NEXT_PROTO,
    TLS_ST_CW_FINISHED,
    TLS_ST_SW_HELLO_REQ,
    TLS_ST_SR_CLNT_HELLO,
    DTLS_ST_SW_HELLO_VERIFY_REQUEST,
    TLS_ST_SW_SRVR_HELLO,
    TLS_ST_SW_CERT,
    TLS_ST_SW_KEY_EXCH,
    TLS_ST_SW_CERT_REQ,
    TLS_ST_SW_SRVR_DONE,
    TLS_ST_SR_CERT,
    TLS_ST_SR_KEY_EXCH,
    TLS_ST_SR_CERT_VRFY,
    TLS_ST_SR_NEXT_PROTO,
    TLS_ST_SR_CHANGE,
    TLS_ST_SR_FINISHED,
    TLS_ST_SW_SESSION_TICKET,
    TLS_ST_SW_CERT_STATUS,
    TLS_ST_SW_CHANGE,
    TLS_ST_SW_FINISHED,
    TLS_ST_SW_ENCRYPTED_EXTENSIONS,
    TLS_ST_CR_ENCRYPTED_EXTENSIONS,
    TLS_ST_CR_CERT_VRFY,
    TLS_ST_SW_CERT_VRFY,
    TLS_ST_CR_HELLO_REQ,
    TLS_ST_SW_KEY_UPDATE,
    TLS_ST_CW_KEY_UPDATE,
    TLS_ST_SR_KEY_UPDATE,
    TLS_ST_CR_KEY_UPDATE,
    TLS_ST_EARLY_DATA,
    TLS_ST_PENDING_EARLY_DATA_END,
    TLS_ST_CW_END_OF_EARLY_DATA,
    TLS_ST_SR_END_OF_EARLY_DATA
} OSSL_HANDSHAKE_STATE;

/*
 * Most of the following state values are no longer used and are defined to be
 * the closest equivalent value in the current state machine code. Not all
 * defines have an equivalent and are set to a dummy value (-1). SSL_ST_CONNECT
 * and SSL_ST_ACCEPT are still in use in the definition of SSL_CB_ACCEPT_LOOP,
 * SSL_CB_ACCEPT_EXIT, SSL_CB_CONNECT_LOOP and SSL_CB_CONNECT_EXIT.
 */

# define SSL_ST_CONNECT                  0x1000
# define SSL_ST_ACCEPT                   0x2000

# define SSL_ST_MASK                     0x0FFF

# define SSL_CB_LOOP                     0x01
# define SSL_CB_EXIT                     0x02
# define SSL_CB_READ                     0x04
# define SSL_CB_WRITE                    0x08
# define SSL_CB_ALERT                    0x4000/* used in callback */
# define SSL_CB_READ_ALERT               (SSL_CB_ALERT|SSL_CB_READ)
# define SSL_CB_WRITE_ALERT              (SSL_CB_ALERT|SSL_CB_WRITE)
# define SSL_CB_ACCEPT_LOOP              (SSL_ST_ACCEPT|SSL_CB_LOOP)
# define SSL_CB_ACCEPT_EXIT              (SSL_ST_ACCEPT|SSL_CB_EXIT)
# define SSL_CB_CONNECT_LOOP             (SSL_ST_CONNECT|SSL_CB_LOOP)
# define SSL_CB_CONNECT_EXIT             (SSL_ST_CONNECT|SSL_CB_EXIT)
# define SSL_CB_HANDSHAKE_START          0x10
# define SSL_CB_HANDSHAKE_DONE           0x20

/* Is the SSL_connection established? */
# define SSL_in_connect_init(a)          (SSL_in_init(a) && !SSL_is_server(a))
# define SSL_in_accept_init(a)           (SSL_in_init(a) && SSL_is_server(a))
int SSL_in_init(const SSL *s);
int SSL_in_before(const SSL *s);
int SSL_is_init_finished(const SSL *s);

/*
 * The following 3 states are kept in ssl->rlayer.rstate when reads fail, you
 * should not need these
 */
# define SSL_ST_READ_HEADER                      0xF0
# define SSL_ST_READ_BODY                        0xF1
# define SSL_ST_READ_DONE                        0xF2

/*-
 * Obtain latest Finished message
 *   -- that we sent (SSL_get_finished)
 *   -- that we expected from peer (SSL_get_peer_finished).
 * Returns length (0 == no Finished so far), copies up to 'count' bytes.
 */
size_t SSL_get_finished(const SSL *s, void *buf, size_t count);
size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);

/*
 * use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 3 options are
 * 'ored' with SSL_VERIFY_PEER if they are desired
 */
# define SSL_VERIFY_NONE                 0x00
# define SSL_VERIFY_PEER                 0x01
# define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
# define SSL_VERIFY_CLIENT_ONCE          0x04
# define SSL_VERIFY_POST_HANDSHAKE       0x08

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define OpenSSL_add_ssl_algorithms()   SSL_library_init()
#  define SSLeay_add_ssl_algorithms()    SSL_library_init()
# endif

/* More backward compatibility */
# define SSL_get_cipher(s) \
                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
# define SSL_get_cipher_bits(s,np) \
                SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
# define SSL_get_cipher_version(s) \
                SSL_CIPHER_get_version(SSL_get_current_cipher(s))
# define SSL_get_cipher_name(s) \
                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
# define SSL_get_time(a)         SSL_SESSION_get_time(a)
# define SSL_set_time(a,b)       SSL_SESSION_set_time((a),(b))
# define SSL_get_timeout(a)      SSL_SESSION_get_timeout(a)
# define SSL_set_timeout(a,b)    SSL_SESSION_set_timeout((a),(b))

# define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id)
# define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id)

DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
# define SSL_AD_REASON_OFFSET            1000/* offset to get SSL_R_... value
                                              * from SSL_AD_... */
/* These alert types are for SSLv3 and TLSv1 */
# define SSL_AD_CLOSE_NOTIFY             SSL3_AD_CLOSE_NOTIFY
/* fatal */
# define SSL_AD_UNEXPECTED_MESSAGE       SSL3_AD_UNEXPECTED_MESSAGE
/* fatal */
# define SSL_AD_BAD_RECORD_MAC           SSL3_AD_BAD_RECORD_MAC
# define SSL_AD_DECRYPTION_FAILED        TLS1_AD_DECRYPTION_FAILED
# define SSL_AD_RECORD_OVERFLOW          TLS1_AD_RECORD_OVERFLOW
/* fatal */
# define SSL_AD_DECOMPRESSION_FAILURE    SSL3_AD_DECOMPRESSION_FAILURE
/* fatal */
# define SSL_AD_HANDSHAKE_FAILURE        SSL3_AD_HANDSHAKE_FAILURE
/* Not for TLS */
# define SSL_AD_NO_CERTIFICATE           SSL3_AD_NO_CERTIFICATE
# define SSL_AD_BAD_CERTIFICATE          SSL3_AD_BAD_CERTIFICATE
# define SSL_AD_UNSUPPORTED_CERTIFICATE  SSL3_AD_UNSUPPORTED_CERTIFICATE
# define SSL_AD_CERTIFICATE_REVOKED      SSL3_AD_CERTIFICATE_REVOKED
# define SSL_AD_CERTIFICATE_EXPIRED      SSL3_AD_CERTIFICATE_EXPIRED
# define SSL_AD_CERTIFICATE_UNKNOWN      SSL3_AD_CERTIFICATE_UNKNOWN
/* fatal */
# define SSL_AD_ILLEGAL_PARAMETER        SSL3_AD_ILLEGAL_PARAMETER
/* fatal */
# define SSL_AD_UNKNOWN_CA               TLS1_AD_UNKNOWN_CA
/* fatal */
# define SSL_AD_ACCESS_DENIED            TLS1_AD_ACCESS_DENIED
/* fatal */
# define SSL_AD_DECODE_ERROR             TLS1_AD_DECODE_ERROR
# define SSL_AD_DECRYPT_ERROR            TLS1_AD_DECRYPT_ERROR
/* fatal */
# define SSL_AD_EXPORT_RESTRICTION       TLS1_AD_EXPORT_RESTRICTION
/* fatal */
# define SSL_AD_PROTOCOL_VERSION         TLS1_AD_PROTOCOL_VERSION
/* fatal */
# define SSL_AD_INSUFFICIENT_SECURITY    TLS1_AD_INSUFFICIENT_SECURITY
/* fatal */
# define SSL_AD_INTERNAL_ERROR           TLS1_AD_INTERNAL_ERROR
# define SSL_AD_USER_CANCELLED           TLS1_AD_USER_CANCELLED
# define SSL_AD_NO_RENEGOTIATION         TLS1_AD_NO_RENEGOTIATION
# define SSL_AD_MISSING_EXTENSION        TLS13_AD_MISSING_EXTENSION
# define SSL_AD_CERTIFICATE_REQUIRED     TLS13_AD_CERTIFICATE_REQUIRED
# define SSL_AD_UNSUPPORTED_EXTENSION    TLS1_AD_UNSUPPORTED_EXTENSION
# define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE
# define SSL_AD_UNRECOGNIZED_NAME        TLS1_AD_UNRECOGNIZED_NAME
# define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE
# define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE
/* fatal */
# define SSL_AD_UNKNOWN_PSK_IDENTITY     TLS1_AD_UNKNOWN_PSK_IDENTITY
/* fatal */
# define SSL_AD_INAPPROPRIATE_FALLBACK   TLS1_AD_INAPPROPRIATE_FALLBACK
# define SSL_AD_NO_APPLICATION_PROTOCOL  TLS1_AD_NO_APPLICATION_PROTOCOL
# define SSL_ERROR_NONE                  0
# define SSL_ERROR_SSL                   1
# define SSL_ERROR_WANT_READ             2
# define SSL_ERROR_WANT_WRITE            3
# define SSL_ERROR_WANT_X509_LOOKUP      4
# define SSL_ERROR_SYSCALL               5/* look at error stack/return
                                           * value/errno */
# define SSL_ERROR_ZERO_RETURN           6
# define SSL_ERROR_WANT_CONNECT          7
# define SSL_ERROR_WANT_ACCEPT           8
# define SSL_ERROR_WANT_ASYNC            9
# define SSL_ERROR_WANT_ASYNC_JOB       10
# define SSL_ERROR_WANT_CLIENT_HELLO_CB 11
# define SSL_ERROR_WANT_RETRY_VERIFY    12

# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTRL_SET_TMP_DH                    3
#  define SSL_CTRL_SET_TMP_ECDH                  4
#  define SSL_CTRL_SET_TMP_DH_CB                 6
# endif

# define SSL_CTRL_GET_CLIENT_CERT_REQUEST        9
# define SSL_CTRL_GET_NUM_RENEGOTIATIONS         10
# define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS       11
# define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS       12
# define SSL_CTRL_GET_FLAGS                      13
# define SSL_CTRL_EXTRA_CHAIN_CERT               14
# define SSL_CTRL_SET_MSG_CALLBACK               15
# define SSL_CTRL_SET_MSG_CALLBACK_ARG           16
/* only applies to datagram connections */
# define SSL_CTRL_SET_MTU                17
/* Stats */
# define SSL_CTRL_SESS_NUMBER                    20
# define SSL_CTRL_SESS_CONNECT                   21
# define SSL_CTRL_SESS_CONNECT_GOOD              22
# define SSL_CTRL_SESS_CONNECT_RENEGOTIATE       23
# define SSL_CTRL_SESS_ACCEPT                    24
# define SSL_CTRL_SESS_ACCEPT_GOOD               25
# define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE        26
# define SSL_CTRL_SESS_HIT                       27
# define SSL_CTRL_SESS_CB_HIT                    28
# define SSL_CTRL_SESS_MISSES                    29
# define SSL_CTRL_SESS_TIMEOUTS                  30
# define SSL_CTRL_SESS_CACHE_FULL                31
# define SSL_CTRL_MODE                           33
# define SSL_CTRL_GET_READ_AHEAD                 40
# define SSL_CTRL_SET_READ_AHEAD                 41
# define SSL_CTRL_SET_SESS_CACHE_SIZE            42
# define SSL_CTRL_GET_SESS_CACHE_SIZE            43
# define SSL_CTRL_SET_SESS_CACHE_MODE            44
# define SSL_CTRL_GET_SESS_CACHE_MODE            45
# define SSL_CTRL_GET_MAX_CERT_LIST              50
# define SSL_CTRL_SET_MAX_CERT_LIST              51
# define SSL_CTRL_SET_MAX_SEND_FRAGMENT          52
/* see tls1.h for macros based on these */
# define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB       53
# define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG      54
# define SSL_CTRL_SET_TLSEXT_HOSTNAME            55
# define SSL_CTRL_SET_TLSEXT_DEBUG_CB            56
# define SSL_CTRL_SET_TLSEXT_DEBUG_ARG           57
# define SSL_CTRL_GET_TLSEXT_TICKET_KEYS         58
# define SSL_CTRL_SET_TLSEXT_TICKET_KEYS         59
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT    60 */
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB 61 */
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG 62 */
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB       63
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG   64
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE     65
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS     66
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS     67
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS      68
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS      69
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP        70
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP        71
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB      72
# endif
# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB    75
# define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB                76
# define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB             77
# define SSL_CTRL_SET_SRP_ARG            78
# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME               79
# define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH               80
# define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD               81
# define DTLS_CTRL_GET_TIMEOUT           73
# define DTLS_CTRL_HANDLE_TIMEOUT        74
# define SSL_CTRL_GET_RI_SUPPORT                 76
# define SSL_CTRL_CLEAR_MODE                     78
# define SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB      79
# define SSL_CTRL_GET_EXTRA_CHAIN_CERTS          82
# define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS        83
# define SSL_CTRL_CHAIN                          88
# define SSL_CTRL_CHAIN_CERT                     89
# define SSL_CTRL_GET_GROUPS                     90
# define SSL_CTRL_SET_GROUPS                     91
# define SSL_CTRL_SET_GROUPS_LIST                92
# define SSL_CTRL_GET_SHARED_GROUP               93
# define SSL_CTRL_SET_SIGALGS                    97
# define SSL_CTRL_SET_SIGALGS_LIST               98
# define SSL_CTRL_CERT_FLAGS                     99
# define SSL_CTRL_CLEAR_CERT_FLAGS               100
# define SSL_CTRL_SET_CLIENT_SIGALGS             101
# define SSL_CTRL_SET_CLIENT_SIGALGS_LIST        102
# define SSL_CTRL_GET_CLIENT_CERT_TYPES          103
# define SSL_CTRL_SET_CLIENT_CERT_TYPES          104
# define SSL_CTRL_BUILD_CERT_CHAIN               105
# define SSL_CTRL_SET_VERIFY_CERT_STORE          106
# define SSL_CTRL_SET_CHAIN_CERT_STORE           107
# define SSL_CTRL_GET_PEER_SIGNATURE_NID         108
# define SSL_CTRL_GET_PEER_TMP_KEY               109
# define SSL_CTRL_GET_RAW_CIPHERLIST             110
# define SSL_CTRL_GET_EC_POINT_FORMATS           111
# define SSL_CTRL_GET_CHAIN_CERTS                115
# define SSL_CTRL_SELECT_CURRENT_CERT            116
# define SSL_CTRL_SET_CURRENT_CERT               117
# define SSL_CTRL_SET_DH_AUTO                    118
# define DTLS_CTRL_SET_LINK_MTU                  120
# define DTLS_CTRL_GET_LINK_MIN_MTU              121
# define SSL_CTRL_GET_EXTMS_SUPPORT              122
# define SSL_CTRL_SET_MIN_PROTO_VERSION          123
# define SSL_CTRL_SET_MAX_PROTO_VERSION          124
# define SSL_CTRL_SET_SPLIT_SEND_FRAGMENT        125
# define SSL_CTRL_SET_MAX_PIPELINES              126
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE     127
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB       128
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG   129
# define SSL_CTRL_GET_MIN_PROTO_VERSION          130
# define SSL_CTRL_GET_MAX_PROTO_VERSION          131
# define SSL_CTRL_GET_SIGNATURE_NID              132
# define SSL_CTRL_GET_TMP_KEY                    133
# define SSL_CTRL_GET_NEGOTIATED_GROUP           134
# define SSL_CTRL_SET_RETRY_VERIFY               136
# define SSL_CTRL_GET_VERIFY_CERT_STORE          137
# define SSL_CTRL_GET_CHAIN_CERT_STORE           138
# define SSL_CERT_SET_FIRST                      1
# define SSL_CERT_SET_NEXT                       2
# define SSL_CERT_SET_SERVER                     3
# define DTLSv1_get_timeout(ssl, arg) \
        SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)(arg))
# define DTLSv1_handle_timeout(ssl) \
        SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL)
# define SSL_num_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
# define SSL_clear_num_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
# define SSL_total_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTX_set_tmp_dh(ctx,dh) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
# endif
# define SSL_CTX_set_dh_auto(ctx, onoff) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
# define SSL_set_dh_auto(s, onoff) \
        SSL_ctrl(s,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_set_tmp_dh(ssl,dh) \
        SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
# endif
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
#  define SSL_set_tmp_ecdh(ssl,ecdh) \
        SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
# endif
# define SSL_CTX_add_extra_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)(x509))
# define SSL_CTX_get_extra_chain_certs(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,0,px509)
# define SSL_CTX_get_extra_chain_certs_only(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,1,px509)
# define SSL_CTX_clear_extra_chain_certs(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS,0,NULL)
# define SSL_CTX_set0_chain(ctx,sk) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,0,(char *)(sk))
# define SSL_CTX_set1_chain(ctx,sk) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,1,(char *)(sk))
# define SSL_CTX_add0_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,0,(char *)(x509))
# define SSL_CTX_add1_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,1,(char *)(x509))
# define SSL_CTX_get0_chain_certs(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERTS,0,px509)
# define SSL_CTX_clear_chain_certs(ctx) \
        SSL_CTX_set0_chain(ctx,NULL)
# define SSL_CTX_build_cert_chain(ctx, flags) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL)
# define SSL_CTX_select_current_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509))
# define SSL_CTX_set_current_cert(ctx, op) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CURRENT_CERT, op, NULL)
# define SSL_CTX_set0_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set1_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st))
# define SSL_CTX_get0_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set0_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set1_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st))
# define SSL_CTX_get0_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_set0_chain(s,sk) \
        SSL_ctrl(s,SSL_CTRL_CHAIN,0,(char *)(sk))
# define SSL_set1_chain(s,sk) \
        SSL_ctrl(s,SSL_CTRL_CHAIN,1,(char *)(sk))
# define SSL_add0_chain_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,0,(char *)(x509))
# define SSL_add1_chain_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,1,(char *)(x509))
# define SSL_get0_chain_certs(s,px509) \
        SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERTS,0,px509)
# define SSL_clear_chain_certs(s) \
        SSL_set0_chain(s,NULL)
# define SSL_build_cert_chain(s, flags) \
        SSL_ctrl(s,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL)
# define SSL_select_current_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509))
# define SSL_set_current_cert(s,op) \
        SSL_ctrl(s,SSL_CTRL_SET_CURRENT_CERT, op, NULL)
# define SSL_set0_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_set1_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st))
#define SSL_get0_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_set0_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_set1_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st))
#define SSL_get0_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st))

# define SSL_get1_groups(s, glist) \
        SSL_ctrl(s,SSL_CTRL_GET_GROUPS,0,(int*)(glist))
# define SSL_CTX_set1_groups(ctx, glist, glistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS,glistlen,(int *)(glist))
# define SSL_CTX_set1_groups_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(s))
# define SSL_set1_groups(s, glist, glistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_GROUPS,glistlen,(char *)(glist))
# define SSL_set1_groups_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(str))
# define SSL_get_shared_group(s, n) \
        SSL_ctrl(s,SSL_CTRL_GET_SHARED_GROUP,n,NULL)
# define SSL_get_negotiated_group(s) \
        SSL_ctrl(s,SSL_CTRL_GET_NEGOTIATED_GROUP,0,NULL)
# define SSL_CTX_set1_sigalgs(ctx, slist, slistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist))
# define SSL_CTX_set1_sigalgs_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(s))
# define SSL_set1_sigalgs(s, slist, slistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist))
# define SSL_set1_sigalgs_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(str))
# define SSL_CTX_set1_client_sigalgs(ctx, slist, slistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist))
# define SSL_CTX_set1_client_sigalgs_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(s))
# define SSL_set1_client_sigalgs(s, slist, slistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist))
# define SSL_set1_client_sigalgs_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(str))
# define SSL_get0_certificate_types(s, clist) \
        SSL_ctrl(s, SSL_CTRL_GET_CLIENT_CERT_TYPES, 0, (char *)(clist))
# define SSL_CTX_set1_client_certificate_types(ctx, clist, clistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen, \
                     (char *)(clist))
# define SSL_set1_client_certificate_types(s, clist, clistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen,(char *)(clist))
# define SSL_get_signature_nid(s, pn) \
        SSL_ctrl(s,SSL_CTRL_GET_SIGNATURE_NID,0,pn)
# define SSL_get_peer_signature_nid(s, pn) \
        SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NID,0,pn)
# define SSL_get_peer_tmp_key(s, pk) \
        SSL_ctrl(s,SSL_CTRL_GET_PEER_TMP_KEY,0,pk)
# define SSL_get_tmp_key(s, pk) \
        SSL_ctrl(s,SSL_CTRL_GET_TMP_KEY,0,pk)
# define SSL_get0_raw_cipherlist(s, plst) \
        SSL_ctrl(s,SSL_CTRL_GET_RAW_CIPHERLIST,0,plst)
# define SSL_get0_ec_point_formats(s, plst) \
        SSL_ctrl(s,SSL_CTRL_GET_EC_POINT_FORMATS,0,plst)
# define SSL_CTX_set_min_proto_version(ctx, version) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
# define SSL_CTX_set_max_proto_version(ctx, version) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
# define SSL_CTX_get_min_proto_version(ctx) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL)
# define SSL_CTX_get_max_proto_version(ctx) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL)
# define SSL_set_min_proto_version(s, version) \
        SSL_ctrl(s, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
# define SSL_set_max_proto_version(s, version) \
        SSL_ctrl(s, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
# define SSL_get_min_proto_version(s) \
        SSL_ctrl(s, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL)
# define SSL_get_max_proto_version(s) \
        SSL_ctrl(s, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL)

const char *SSL_group_to_name(SSL *s, int id);

/* Backwards compatibility, original 1.1.0 names */
# define SSL_CTRL_GET_SERVER_TMP_KEY \
         SSL_CTRL_GET_PEER_TMP_KEY
# define SSL_get_server_tmp_key(s, pk) \
         SSL_get_peer_tmp_key(s, pk)

int SSL_set0_tmp_dh_pkey(SSL *s, EVP_PKEY *dhpkey);
int SSL_CTX_set0_tmp_dh_pkey(SSL_CTX *ctx, EVP_PKEY *dhpkey);

/*
 * The following symbol names are old and obsolete. They are kept
 * for compatibility reasons only and should not be used anymore.
 */
# define SSL_CTRL_GET_CURVES           SSL_CTRL_GET_GROUPS
# define SSL_CTRL_SET_CURVES           SSL_CTRL_SET_GROUPS
# define SSL_CTRL_SET_CURVES_LIST      SSL_CTRL_SET_GROUPS_LIST
# define SSL_CTRL_GET_SHARED_CURVE     SSL_CTRL_GET_SHARED_GROUP

# define SSL_get1_curves               SSL_get1_groups
# define SSL_CTX_set1_curves           SSL_CTX_set1_groups
# define SSL_CTX_set1_curves_list      SSL_CTX_set1_groups_list
# define SSL_set1_curves               SSL_set1_groups
# define SSL_set1_curves_list          SSL_set1_groups_list
# define SSL_get_shared_curve          SSL_get_shared_group


# ifndef OPENSSL_NO_DEPRECATED_1_1_0
/* Provide some compatibility macros for removed functionality. */
#  define SSL_CTX_need_tmp_RSA(ctx)                0
#  define SSL_CTX_set_tmp_rsa(ctx,rsa)             1
#  define SSL_need_tmp_RSA(ssl)                    0
#  define SSL_set_tmp_rsa(ssl,rsa)                 1
#  define SSL_CTX_set_ecdh_auto(dummy, onoff)      ((onoff) != 0)
#  define SSL_set_ecdh_auto(dummy, onoff)          ((onoff) != 0)
/*
 * We "pretend" to call the callback to avoid warnings about unused static
 * functions.
 */
#  define SSL_CTX_set_tmp_rsa_callback(ctx, cb)    while(0) (cb)(NULL, 0, 0)
#  define SSL_set_tmp_rsa_callback(ssl, cb)        while(0) (cb)(NULL, 0, 0)
# endif
__owur const BIO_METHOD *BIO_f_ssl(void);
__owur BIO *BIO_new_ssl(SSL_CTX *ctx, int client);
__owur BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
__owur BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
__owur int BIO_ssl_copy_session_id(BIO *to, BIO *from);
void BIO_ssl_shutdown(BIO *ssl_bio);

__owur int SSL_CTX_set_cipher_list(SSL_CTX *, const char *str);
__owur SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);
__owur SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq,
                               const SSL_METHOD *meth);
int SSL_CTX_up_ref(SSL_CTX *ctx);
void SSL_CTX_free(SSL_CTX *);
__owur long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
__owur long SSL_CTX_get_timeout(const SSL_CTX *ctx);
__owur X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *);
void SSL_CTX_set_cert_store(SSL_CTX *, X509_STORE *);
void SSL_CTX_set1_cert_store(SSL_CTX *, X509_STORE *);
__owur int SSL_want(const SSL *s);
__owur int SSL_clear(SSL *s);

void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm);

__owur const SSL_CIPHER *SSL_get_current_cipher(const SSL *s);
__owur const SSL_CIPHER *SSL_get_pending_cipher(const SSL *s);
__owur int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits);
__owur const char *SSL_CIPHER_get_version(const SSL_CIPHER *c);
__owur const char *SSL_CIPHER_get_name(const SSL_CIPHER *c);
__owur const char *SSL_CIPHER_standard_name(const SSL_CIPHER *c);
__owur const char *OPENSSL_cipher_name(const char *rfc_name);
__owur uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *c);
__owur uint16_t SSL_CIPHER_get_protocol_id(const SSL_CIPHER *c);
__owur int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *c);
__owur int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *c);
__owur const EVP_MD *SSL_CIPHER_get_handshake_digest(const SSL_CIPHER *c);
__owur int SSL_CIPHER_is_aead(const SSL_CIPHER *c);

__owur int SSL_get_fd(const SSL *s);
__owur int SSL_get_rfd(const SSL *s);
__owur int SSL_get_wfd(const SSL *s);
__owur const char *SSL_get_cipher_list(const SSL *s, int n);
__owur char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size);
__owur int SSL_get_read_ahead(const SSL *s);
__owur int SSL_pending(const SSL *s);
__owur int SSL_has_pending(const SSL *s);
# ifndef OPENSSL_NO_SOCK
__owur int SSL_set_fd(SSL *s, int fd);
__owur int SSL_set_rfd(SSL *s, int fd);
__owur int SSL_set_wfd(SSL *s, int fd);
# endif
void SSL_set0_rbio(SSL *s, BIO *rbio);
void SSL_set0_wbio(SSL *s, BIO *wbio);
void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio);
__owur BIO *SSL_get_rbio(const SSL *s);
__owur BIO *SSL_get_wbio(const SSL *s);
__owur int SSL_set_cipher_list(SSL *s, const char *str);
__owur int SSL_CTX_set_ciphersuites(SSL_CTX *ctx, const char *str);
__owur int SSL_set_ciphersuites(SSL *s, const char *str);
void SSL_set_read_ahead(SSL *s, int yes);
__owur int SSL_get_verify_mode(const SSL *s);
__owur int SSL_get_verify_depth(const SSL *s);
__owur SSL_verify_cb SSL_get_verify_callback(const SSL *s);
void SSL_set_verify(SSL *s, int mode, SSL_verify_cb callback);
void SSL_set_verify_depth(SSL *s, int depth);
void SSL_set_cert_cb(SSL *s, int (*cb) (SSL *ssl, void *arg), void *arg);
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 __owur int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
OSSL_DEPRECATEDIN_3_0
__owur int SSL_use_RSAPrivateKey_ASN1(SSL *ssl,
                                      const unsigned char *d, long len);
# endif
__owur int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
__owur int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d,
                                   long len);
__owur int SSL_use_certificate(SSL *ssl, X509 *x);
__owur int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
__owur int SSL_use_cert_and_key(SSL *ssl, X509 *x509, EVP_PKEY *privatekey,
                                STACK_OF(X509) *chain, int override);


/* serverinfo file format versions */
# define SSL_SERVERINFOV1   1
# define SSL_SERVERINFOV2   2

/* Set serverinfo data for the current active cert. */
__owur int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo,
                                  size_t serverinfo_length);
__owur int SSL_CTX_use_serverinfo_ex(SSL_CTX *ctx, unsigned int version,
                                     const unsigned char *serverinfo,
                                     size_t serverinfo_length);
__owur int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file);

#ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
#endif

__owur int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
__owur int SSL_use_certificate_file(SSL *ssl, const char *file, int type);

#ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file,
                                          int type);
#endif
__owur int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file,
                                       int type);
__owur int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file,
                                        int type);
/* PEM type */
__owur int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
__owur int SSL_use_certificate_chain_file(SSL *ssl, const char *file);
__owur STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
__owur STACK_OF(X509_NAME)
*SSL_load_client_CA_file_ex(const char *file, OSSL_LIB_CTX *libctx,
                            const char *propq);
__owur int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                               const char *file);
int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                       const char *dir);
int SSL_add_store_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                       const char *uri);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_load_error_strings() \
    OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS \
                     | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL)
# endif

__owur const char *SSL_state_string(const SSL *s);
__owur const char *SSL_rstate_string(const SSL *s);
__owur const char *SSL_state_string_long(const SSL *s);
__owur const char *SSL_rstate_string_long(const SSL *s);
__owur long SSL_SESSION_get_time(const SSL_SESSION *s);
__owur long SSL_SESSION_set_time(SSL_SESSION *s, long t);
__owur long SSL_SESSION_get_timeout(const SSL_SESSION *s);
__owur long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
__owur int SSL_SESSION_get_protocol_version(const SSL_SESSION *s);
__owur int SSL_SESSION_set_protocol_version(SSL_SESSION *s, int version);

__owur const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s);
__owur int SSL_SESSION_set1_hostname(SSL_SESSION *s, const char *hostname);
void SSL_SESSION_get0_alpn_selected(const SSL_SESSION *s,
                                    const unsigned char **alpn,
                                    size_t *len);
__owur int SSL_SESSION_set1_alpn_selected(SSL_SESSION *s,
                                          const unsigned char *alpn,
                                          size_t len);
__owur const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s);
__owur int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher);
__owur int SSL_SESSION_has_ticket(const SSL_SESSION *s);
__owur unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s);
void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick,
                             size_t *len);
__owur uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s);
__owur int SSL_SESSION_set_max_early_data(SSL_SESSION *s,
                                          uint32_t max_early_data);
__owur int SSL_copy_session_id(SSL *to, const SSL *from);
__owur X509 *SSL_SESSION_get0_peer(SSL_SESSION *s);
__owur int SSL_SESSION_set1_id_context(SSL_SESSION *s,
                                       const unsigned char *sid_ctx,
                                       unsigned int sid_ctx_len);
__owur int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid,
                               unsigned int sid_len);
__owur int SSL_SESSION_is_resumable(const SSL_SESSION *s);

__owur SSL_SESSION *SSL_SESSION_new(void);
__owur SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src);
const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s,
                                        unsigned int *len);
const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s,
                                                 unsigned int *len);
__owur unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s);
# ifndef OPENSSL_NO_STDIO
int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *ses);
# endif
int SSL_SESSION_print(BIO *fp, const SSL_SESSION *ses);
int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x);
int SSL_SESSION_up_ref(SSL_SESSION *ses);
void SSL_SESSION_free(SSL_SESSION *ses);
__owur int i2d_SSL_SESSION(const SSL_SESSION *in, unsigned char **pp);
__owur int SSL_set_session(SSL *to, SSL_SESSION *session);
int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *session);
int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *session);
__owur int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb);
__owur int SSL_set_generate_session_id(SSL *s, GEN_SESSION_CB cb);
__owur int SSL_has_matching_session_id(const SSL *s,
                                       const unsigned char *id,
                                       unsigned int id_len);
SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
                             long length);

# ifdef OPENSSL_X509_H
__owur X509 *SSL_get0_peer_certificate(const SSL *s);
__owur X509 *SSL_get1_peer_certificate(const SSL *s);
/* Deprecated in 3.0.0 */
#  ifndef OPENSSL_NO_DEPRECATED_3_0
#   define SSL_get_peer_certificate SSL_get1_peer_certificate
#  endif
# endif

__owur STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s);

__owur int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
__owur int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
__owur SSL_verify_cb SSL_CTX_get_verify_callback(const SSL_CTX *ctx);
void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, SSL_verify_cb callback);
void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,
                                      int (*cb) (X509_STORE_CTX *, void *),
                                      void *arg);
void SSL_CTX_set_cert_cb(SSL_CTX *c, int (*cb) (SSL *ssl, void *arg),
                         void *arg);
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d,
                                          long len);
# endif
__owur int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
__owur int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx,
                                       const unsigned char *d, long len);
__owur int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
__owur int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len,
                                        const unsigned char *d);
__owur int SSL_CTX_use_cert_and_key(SSL_CTX *ctx, X509 *x509, EVP_PKEY *privatekey,
                                    STACK_OF(X509) *chain, int override);

void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx);
void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx);
void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb);
void SSL_set_default_passwd_cb_userdata(SSL *s, void *u);
pem_password_cb *SSL_get_default_passwd_cb(SSL *s);
void *SSL_get_default_passwd_cb_userdata(SSL *s);

__owur int SSL_CTX_check_private_key(const SSL_CTX *ctx);
__owur int SSL_check_private_key(const SSL *ctx);

__owur int SSL_CTX_set_session_id_context(SSL_CTX *ctx,
                                          const unsigned char *sid_ctx,
                                          unsigned int sid_ctx_len);

SSL *SSL_new(SSL_CTX *ctx);
int SSL_up_ref(SSL *s);
int SSL_is_dtls(const SSL *s);
__owur int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx,
                                      unsigned int sid_ctx_len);

__owur int SSL_CTX_set_purpose(SSL_CTX *ctx, int purpose);
__owur int SSL_set_purpose(SSL *ssl, int purpose);
__owur int SSL_CTX_set_trust(SSL_CTX *ctx, int trust);
__owur int SSL_set_trust(SSL *ssl, int trust);

__owur int SSL_set1_host(SSL *s, const char *hostname);
__owur int SSL_add1_host(SSL *s, const char *hostname);
__owur const char *SSL_get0_peername(SSL *s);
void SSL_set_hostflags(SSL *s, unsigned int flags);

__owur int SSL_CTX_dane_enable(SSL_CTX *ctx);
__owur int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md,
                                  uint8_t mtype, uint8_t ord);
__owur int SSL_dane_enable(SSL *s, const char *basedomain);
__owur int SSL_dane_tlsa_add(SSL *s, uint8_t usage, uint8_t selector,
                             uint8_t mtype, const unsigned char *data, size_t dlen);
__owur int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki);
__owur int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector,
                              uint8_t *mtype, const unsigned char **data,
                              size_t *dlen);
/*
 * Bridge opacity barrier between libcrypt and libssl, also needed to support
 * offline testing in test/danetest.c
 */
SSL_DANE *SSL_get0_dane(SSL *ssl);
/*
 * DANE flags
 */
unsigned long SSL_CTX_dane_set_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_CTX_dane_clear_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_dane_set_flags(SSL *ssl, unsigned long flags);
unsigned long SSL_dane_clear_flags(SSL *ssl, unsigned long flags);

__owur int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
__owur int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm);

__owur X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx);
__owur X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl);

# ifndef OPENSSL_NO_SRP
#  ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength);
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx,
                                        char *(*cb) (SSL *, void *));
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx,
                                          int (*cb) (SSL *, void *));
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx,
                                      int (*cb) (SSL *, int *, void *));
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg);

OSSL_DEPRECATEDIN_3_0
int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g,
                             BIGNUM *sa, BIGNUM *v, char *info);
OSSL_DEPRECATEDIN_3_0
int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass,
                                const char *grp);

OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_g(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_N(SSL *s);

OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_username(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_userinfo(SSL *s);
#  endif
# endif

/*
 * ClientHello callback and helpers.
 */

# define SSL_CLIENT_HELLO_SUCCESS 1
# define SSL_CLIENT_HELLO_ERROR   0
# define SSL_CLIENT_HELLO_RETRY   (-1)

typedef int (*SSL_client_hello_cb_fn) (SSL *s, int *al, void *arg);
void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_fn cb,
                                 void *arg);
int SSL_client_hello_isv2(SSL *s);
unsigned int SSL_client_hello_get0_legacy_version(SSL *s);
size_t SSL_client_hello_get0_random(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_session_id(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_compression_methods(SSL *s,
                                                 const unsigned char **out);
int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen);
int SSL_client_hello_get0_ext(SSL *s, unsigned int type,
                              const unsigned char **out, size_t *outlen);

void SSL_certs_clear(SSL *s);
void SSL_free(SSL *ssl);
# ifdef OSSL_ASYNC_FD
/*
 * Windows application developer has to include windows.h to use these.
 */
__owur int SSL_waiting_for_async(SSL *s);
__owur int SSL_get_all_async_fds(SSL *s, OSSL_ASYNC_FD *fds, size_t *numfds);
__owur int SSL_get_changed_async_fds(SSL *s, OSSL_ASYNC_FD *addfd,
                                     size_t *numaddfds, OSSL_ASYNC_FD *delfd,
                                     size_t *numdelfds);
__owur int SSL_CTX_set_async_callback(SSL_CTX *ctx, SSL_async_callback_fn callback);
__owur int SSL_CTX_set_async_callback_arg(SSL_CTX *ctx, void *arg);
__owur int SSL_set_async_callback(SSL *s, SSL_async_callback_fn callback);
__owur int SSL_set_async_callback_arg(SSL *s, void *arg);
__owur int SSL_get_async_status(SSL *s, int *status);

# endif
__owur int SSL_accept(SSL *ssl);
__owur int SSL_stateless(SSL *s);
__owur int SSL_connect(SSL *ssl);
__owur int SSL_read(SSL *ssl, void *buf, int num);
__owur int SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);

# define SSL_READ_EARLY_DATA_ERROR   0
# define SSL_READ_EARLY_DATA_SUCCESS 1
# define SSL_READ_EARLY_DATA_FINISH  2

__owur int SSL_read_early_data(SSL *s, void *buf, size_t num,
                               size_t *readbytes);
__owur int SSL_peek(SSL *ssl, void *buf, int num);
__owur int SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);
__owur ossl_ssize_t SSL_sendfile(SSL *s, int fd, off_t offset, size_t size,
                                 int flags);
__owur int SSL_write(SSL *ssl, const void *buf, int num);
__owur int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
__owur int SSL_write_early_data(SSL *s, const void *buf, size_t num,
                                size_t *written);
long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg);
long SSL_callback_ctrl(SSL *, int, void (*)(void));
long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void));

# define SSL_EARLY_DATA_NOT_SENT    0
# define SSL_EARLY_DATA_REJECTED    1
# define SSL_EARLY_DATA_ACCEPTED    2

__owur int SSL_get_early_data_status(const SSL *s);

__owur int SSL_get_error(const SSL *s, int ret_code);
__owur const char *SSL_get_version(const SSL *s);

/* This sets the 'default' SSL version that SSL_new() will create */
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
# endif

# ifndef OPENSSL_NO_SSL3_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_method(void); /* SSLv3 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_client_method(void);
#  endif
# endif

#define SSLv23_method           TLS_method
#define SSLv23_server_method    TLS_server_method
#define SSLv23_client_method    TLS_client_method

/* Negotiate highest available SSL/TLS version */
__owur const SSL_METHOD *TLS_method(void);
__owur const SSL_METHOD *TLS_server_method(void);
__owur const SSL_METHOD *TLS_client_method(void);

# ifndef OPENSSL_NO_TLS1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_TLS1_1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_method(void); /* TLSv1.1 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_TLS1_2_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_method(void); /* TLSv1.2 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_DTLS1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_method(void); /* DTLSv1.0 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_DTLS1_2_METHOD
/* DTLSv1.2 */
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_client_method(void);
#  endif
# endif

__owur const SSL_METHOD *DTLS_method(void); /* DTLS 1.0 and 1.2 */
__owur const SSL_METHOD *DTLS_server_method(void); /* DTLS 1.0 and 1.2 */
__owur const SSL_METHOD *DTLS_client_method(void); /* DTLS 1.0 and 1.2 */

__owur size_t DTLS_get_data_mtu(const SSL *s);

__owur STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s);
__owur STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx);
__owur STACK_OF(SSL_CIPHER) *SSL_get_client_ciphers(const SSL *s);
__owur STACK_OF(SSL_CIPHER) *SSL_get1_supported_ciphers(SSL *s);

__owur int SSL_do_handshake(SSL *s);
int SSL_key_update(SSL *s, int updatetype);
int SSL_get_key_update_type(const SSL *s);
int SSL_renegotiate(SSL *s);
int SSL_renegotiate_abbreviated(SSL *s);
__owur int SSL_renegotiate_pending(const SSL *s);
int SSL_new_session_ticket(SSL *s);
int SSL_shutdown(SSL *s);
__owur int SSL_verify_client_post_handshake(SSL *s);
void SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val);
void SSL_set_post_handshake_auth(SSL *s, int val);

__owur const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx);
__owur const SSL_METHOD *SSL_get_ssl_method(const SSL *s);
__owur int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method);
__owur const char *SSL_alert_type_string_long(int value);
__owur const char *SSL_alert_type_string(int value);
__owur const char *SSL_alert_desc_string_long(int value);
__owur const char *SSL_alert_desc_string(int value);

void SSL_set0_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
void SSL_CTX_set0_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
__owur const STACK_OF(X509_NAME) *SSL_get0_CA_list(const SSL *s);
__owur const STACK_OF(X509_NAME) *SSL_CTX_get0_CA_list(const SSL_CTX *ctx);
__owur int SSL_add1_to_CA_list(SSL *ssl, const X509 *x);
__owur int SSL_CTX_add1_to_CA_list(SSL_CTX *ctx, const X509 *x);
__owur const STACK_OF(X509_NAME) *SSL_get0_peer_CA_list(const SSL *s);

void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
__owur STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s);
__owur STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s);
__owur int SSL_add_client_CA(SSL *ssl, X509 *x);
__owur int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);

void SSL_set_connect_state(SSL *s);
void SSL_set_accept_state(SSL *s);

__owur long SSL_get_default_timeout(const SSL *s);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_library_init() OPENSSL_init_ssl(0, NULL)
# endif

__owur char *SSL_CIPHER_description(const SSL_CIPHER *, char *buf, int size);
__owur STACK_OF(X509_NAME) *SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk);

__owur SSL *SSL_dup(SSL *ssl);

__owur X509 *SSL_get_certificate(const SSL *ssl);
/*
 * EVP_PKEY
 */
struct evp_pkey_st *SSL_get_privatekey(const SSL *ssl);

__owur X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx);
__owur EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx);

void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode);
__owur int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
void SSL_set_quiet_shutdown(SSL *ssl, int mode);
__owur int SSL_get_quiet_shutdown(const SSL *ssl);
void SSL_set_shutdown(SSL *ssl, int mode);
__owur int SSL_get_shutdown(const SSL *ssl);
__owur int SSL_version(const SSL *ssl);
__owur int SSL_client_version(const SSL *s);
__owur int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_store(SSL_CTX *ctx);
__owur int SSL_CTX_load_verify_file(SSL_CTX *ctx, const char *CAfile);
__owur int SSL_CTX_load_verify_dir(SSL_CTX *ctx, const char *CApath);
__owur int SSL_CTX_load_verify_store(SSL_CTX *ctx, const char *CAstore);
__owur int SSL_CTX_load_verify_locations(SSL_CTX *ctx,
                                                        const char *CAfile,
                                                        const char *CApath);
# define SSL_get0_session SSL_get_session/* just peek at pointer */
__owur SSL_SESSION *SSL_get_session(const SSL *ssl);
__owur SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
__owur SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx);
void SSL_set_info_callback(SSL *ssl,
                           void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type,
                                               int val);
__owur OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl);

void SSL_set_verify_result(SSL *ssl, long v);
__owur long SSL_get_verify_result(const SSL *ssl);
__owur STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s);

__owur size_t SSL_get_client_random(const SSL *ssl, unsigned char *out,
                                    size_t outlen);
__owur size_t SSL_get_server_random(const SSL *ssl, unsigned char *out,
                                    size_t outlen);
__owur size_t SSL_SESSION_get_master_key(const SSL_SESSION *sess,
                                         unsigned char *out, size_t outlen);
__owur int SSL_SESSION_set1_master_key(SSL_SESSION *sess,
                                       const unsigned char *in, size_t len);
uint8_t SSL_SESSION_get_max_fragment_length(const SSL_SESSION *sess);

#define SSL_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, l, p, newf, dupf, freef)
__owur int SSL_set_ex_data(SSL *ssl, int idx, void *data);
void *SSL_get_ex_data(const SSL *ssl, int idx);
#define SSL_SESSION_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, l, p, newf, dupf, freef)
__owur int SSL_SESSION_set_ex_data(SSL_SESSION *ss, int idx, void *data);
void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss, int idx);
#define SSL_CTX_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, l, p, newf, dupf, freef)
__owur int SSL_CTX_set_ex_data(SSL_CTX *ssl, int idx, void *data);
void *SSL_CTX_get_ex_data(const SSL_CTX *ssl, int idx);

__owur int SSL_get_ex_data_X509_STORE_CTX_idx(void);

# define SSL_CTX_sess_set_cache_size(ctx,t) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
# define SSL_CTX_sess_get_cache_size(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
# define SSL_CTX_set_session_cache_mode(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
# define SSL_CTX_get_session_cache_mode(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)

# define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
# define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
# define SSL_CTX_get_read_ahead(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
# define SSL_CTX_set_read_ahead(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL)
# define SSL_CTX_get_max_cert_list(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
# define SSL_CTX_set_max_cert_list(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
# define SSL_get_max_cert_list(ssl) \
        SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
# define SSL_set_max_cert_list(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)

# define SSL_CTX_set_max_send_fragment(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
# define SSL_set_max_send_fragment(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
# define SSL_CTX_set_split_send_fragment(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL)
# define SSL_set_split_send_fragment(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL)
# define SSL_CTX_set_max_pipelines(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
# define SSL_set_max_pipelines(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
# define SSL_set_retry_verify(ssl) \
        (SSL_ctrl(ssl,SSL_CTRL_SET_RETRY_VERIFY,0,NULL) > 0)

void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len);
void SSL_set_default_read_buffer_len(SSL *s, size_t len);

# ifndef OPENSSL_NO_DH
#  ifndef OPENSSL_NO_DEPRECATED_3_0
/* NB: the |keylength| is only applicable when is_export is true */
OSSL_DEPRECATEDIN_3_0
void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
                                 DH *(*dh) (SSL *ssl, int is_export,
                                            int keylength));
OSSL_DEPRECATEDIN_3_0
void SSL_set_tmp_dh_callback(SSL *ssl,
                             DH *(*dh) (SSL *ssl, int is_export,
                                        int keylength));
#  endif
# endif

__owur const COMP_METHOD *SSL_get_current_compression(const SSL *s);
__owur const COMP_METHOD *SSL_get_current_expansion(const SSL *s);
__owur const char *SSL_COMP_get_name(const COMP_METHOD *comp);
__owur const char *SSL_COMP_get0_name(const SSL_COMP *comp);
__owur int SSL_COMP_get_id(const SSL_COMP *comp);
STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
__owur STACK_OF(SSL_COMP) *SSL_COMP_set0_compression_methods(STACK_OF(SSL_COMP)
                                                             *meths);
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_COMP_free_compression_methods() while(0) continue
# endif
__owur int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm);

const SSL_CIPHER *SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr);
int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c);
int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c);
int SSL_bytes_to_cipher_list(SSL *s, const unsigned char *bytes, size_t len,
                             int isv2format, STACK_OF(SSL_CIPHER) **sk,
                             STACK_OF(SSL_CIPHER) **scsvs);

/* TLS extensions functions */
__owur int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);

__owur int SSL_set_session_ticket_ext_cb(SSL *s,
                                         tls_session_ticket_ext_cb_fn cb,
                                         void *arg);

/* Pre-shared secret session resumption functions */
__owur int SSL_set_session_secret_cb(SSL *s,
                                     tls_session_secret_cb_fn session_secret_cb,
                                     void *arg);

void SSL_CTX_set_not_resumable_session_callback(SSL_CTX *ctx,
                                                int (*cb) (SSL *ssl,
                                                           int
                                                           is_forward_secure));

void SSL_set_not_resumable_session_callback(SSL *ssl,
                                            int (*cb) (SSL *ssl,
                                                       int is_forward_secure));

void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx,
                                         size_t (*cb) (SSL *ssl, int type,
                                                       size_t len, void *arg));
void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg);
void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx);
int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size);

int SSL_set_record_padding_callback(SSL *ssl,
                                    size_t (*cb) (SSL *ssl, int type,
                                                  size_t len, void *arg));
void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg);
void *SSL_get_record_padding_callback_arg(const SSL *ssl);
int SSL_set_block_padding(SSL *ssl, size_t block_size);

int SSL_set_num_tickets(SSL *s, size_t num_tickets);
size_t SSL_get_num_tickets(const SSL *s);
int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets);
size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_cache_hit(s) SSL_session_reused(s)
# endif

__owur int SSL_session_reused(const SSL *s);
__owur int SSL_is_server(const SSL *s);

__owur __owur SSL_CONF_CTX *SSL_CONF_CTX_new(void);
int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx);
void SSL_CONF_CTX_free(SSL_CONF_CTX *cctx);
unsigned int SSL_CONF_CTX_set_flags(SSL_CONF_CTX *cctx, unsigned int flags);
__owur unsigned int SSL_CONF_CTX_clear_flags(SSL_CONF_CTX *cctx,
                                             unsigned int flags);
__owur int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre);

void SSL_CONF_CTX_set_ssl(SSL_CONF_CTX *cctx, SSL *ssl);
void SSL_CONF_CTX_set_ssl_ctx(SSL_CONF_CTX *cctx, SSL_CTX *ctx);

__owur int SSL_CONF_cmd(SSL_CONF_CTX *cctx, const char *cmd, const char *value);
__owur int SSL_CONF_cmd_argv(SSL_CONF_CTX *cctx, int *pargc, char ***pargv);
__owur int SSL_CONF_cmd_value_type(SSL_CONF_CTX *cctx, const char *cmd);

void SSL_add_ssl_module(void);
int SSL_config(SSL *s, const char *name);
int SSL_CTX_config(SSL_CTX *ctx, const char *name);

# ifndef OPENSSL_NO_SSL_TRACE
void SSL_trace(int write_p, int version, int content_type,
               const void *buf, size_t len, SSL *ssl, void *arg);
# endif

# ifndef OPENSSL_NO_SOCK
int DTLSv1_listen(SSL *s, BIO_ADDR *client);
# endif

# ifndef OPENSSL_NO_CT

/*
 * A callback for verifying that the received SCTs are sufficient.
 * Expected to return 1 if they are sufficient, otherwise 0.
 * May return a negative integer if an error occurs.
 * A connection should be aborted if the SCTs are deemed insufficient.
 */
typedef int (*ssl_ct_validation_cb)(const CT_POLICY_EVAL_CTX *ctx,
                                    const STACK_OF(SCT) *scts, void *arg);

/*
 * Sets a |callback| that is invoked upon receipt of ServerHelloDone to validate
 * the received SCTs.
 * If the callback returns a non-positive result, the connection is terminated.
 * Call this function before beginning a handshake.
 * If a NULL |callback| is provided, SCT validation is disabled.
 * |arg| is arbitrary userdata that will be passed to the callback whenever it
 * is invoked. Ownership of |arg| remains with the caller.
 *
 * NOTE: A side-effect of setting a CT callback is that an OCSP stapled response
 *       will be requested.
 */
int SSL_set_ct_validation_callback(SSL *s, ssl_ct_validation_cb callback,
                                   void *arg);
int SSL_CTX_set_ct_validation_callback(SSL_CTX *ctx,
                                       ssl_ct_validation_cb callback,
                                       void *arg);
#define SSL_disable_ct(s) \
        ((void) SSL_set_validation_callback((s), NULL, NULL))
#define SSL_CTX_disable_ct(ctx) \
        ((void) SSL_CTX_set_validation_callback((ctx), NULL, NULL))

/*
 * The validation type enumerates the available behaviours of the built-in SSL
 * CT validation callback selected via SSL_enable_ct() and SSL_CTX_enable_ct().
 * The underlying callback is a static function in libssl.
 */
enum {
    SSL_CT_VALIDATION_PERMISSIVE = 0,
    SSL_CT_VALIDATION_STRICT
};

/*
 * Enable CT by setting up a callback that implements one of the built-in
 * validation variants.  The SSL_CT_VALIDATION_PERMISSIVE variant always
 * continues the handshake, the application can make appropriate decisions at
 * handshake completion.  The SSL_CT_VALIDATION_STRICT variant requires at
 * least one valid SCT, or else handshake termination will be requested.  The
 * handshake may continue anyway if SSL_VERIFY_NONE is in effect.
 */
int SSL_enable_ct(SSL *s, int validation_mode);
int SSL_CTX_enable_ct(SSL_CTX *ctx, int validation_mode);

/*
 * Report whether a non-NULL callback is enabled.
 */
int SSL_ct_is_enabled(const SSL *s);
int SSL_CTX_ct_is_enabled(const SSL_CTX *ctx);

/* Gets the SCTs received from a connection */
const STACK_OF(SCT) *SSL_get0_peer_scts(SSL *s);

/*
 * Loads the CT log list from the default location.
 * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store,
 * the log information loaded from this file will be appended to the
 * CTLOG_STORE.
 * Returns 1 on success, 0 otherwise.
 */
int SSL_CTX_set_default_ctlog_list_file(SSL_CTX *ctx);

/*
 * Loads the CT log list from the specified file path.
 * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store,
 * the log information loaded from this file will be appended to the
 * CTLOG_STORE.
 * Returns 1 on success, 0 otherwise.
 */
int SSL_CTX_set_ctlog_list_file(SSL_CTX *ctx, const char *path);

/*
 * Sets the CT log list used by all SSL connections created from this SSL_CTX.
 * Ownership of the CTLOG_STORE is transferred to the SSL_CTX.
 */
void SSL_CTX_set0_ctlog_store(SSL_CTX *ctx, CTLOG_STORE *logs);

/*
 * Gets the CT log list used by all SSL connections created from this SSL_CTX.
 * This will be NULL unless one of the following functions has been called:
 * - SSL_CTX_set_default_ctlog_list_file
 * - SSL_CTX_set_ctlog_list_file
 * - SSL_CTX_set_ctlog_store
 */
const CTLOG_STORE *SSL_CTX_get0_ctlog_store(const SSL_CTX *ctx);

# endif /* OPENSSL_NO_CT */

/* What the "other" parameter contains in security callback */
/* Mask for type */
# define SSL_SECOP_OTHER_TYPE    0xffff0000
# define SSL_SECOP_OTHER_NONE    0
# define SSL_SECOP_OTHER_CIPHER  (1 << 16)
# define SSL_SECOP_OTHER_CURVE   (2 << 16)
# define SSL_SECOP_OTHER_DH      (3 << 16)
# define SSL_SECOP_OTHER_PKEY    (4 << 16)
# define SSL_SECOP_OTHER_SIGALG  (5 << 16)
# define SSL_SECOP_OTHER_CERT    (6 << 16)

/* Indicated operation refers to peer key or certificate */
# define SSL_SECOP_PEER          0x1000

/* Values for "op" parameter in security callback */

/* Called to filter ciphers */
/* Ciphers client supports */
# define SSL_SECOP_CIPHER_SUPPORTED      (1 | SSL_SECOP_OTHER_CIPHER)
/* Cipher shared by client/server */
# define SSL_SECOP_CIPHER_SHARED         (2 | SSL_SECOP_OTHER_CIPHER)
/* Sanity check of cipher server selects */
# define SSL_SECOP_CIPHER_CHECK          (3 | SSL_SECOP_OTHER_CIPHER)
/* Curves supported by client */
# define SSL_SECOP_CURVE_SUPPORTED       (4 | SSL_SECOP_OTHER_CURVE)
/* Curves shared by client/server */
# define SSL_SECOP_CURVE_SHARED          (5 | SSL_SECOP_OTHER_CURVE)
/* Sanity check of curve server selects */
# define SSL_SECOP_CURVE_CHECK           (6 | SSL_SECOP_OTHER_CURVE)
/* Temporary DH key */
# define SSL_SECOP_TMP_DH                (7 | SSL_SECOP_OTHER_PKEY)
/* SSL/TLS version */
# define SSL_SECOP_VERSION               (9 | SSL_SECOP_OTHER_NONE)
/* Session tickets */
# define SSL_SECOP_TICKET                (10 | SSL_SECOP_OTHER_NONE)
/* Supported signature algorithms sent to peer */
# define SSL_SECOP_SIGALG_SUPPORTED      (11 | SSL_SECOP_OTHER_SIGALG)
/* Shared signature algorithm */
# define SSL_SECOP_SIGALG_SHARED         (12 | SSL_SECOP_OTHER_SIGALG)
/* Sanity check signature algorithm allowed */
# define SSL_SECOP_SIGALG_CHECK          (13 | SSL_SECOP_OTHER_SIGALG)
/* Used to get mask of supported public key signature algorithms */
# define SSL_SECOP_SIGALG_MASK           (14 | SSL_SECOP_OTHER_SIGALG)
/* Use to see if compression is allowed */
# define SSL_SECOP_COMPRESSION           (15 | SSL_SECOP_OTHER_NONE)
/* EE key in certificate */
# define SSL_SECOP_EE_KEY                (16 | SSL_SECOP_OTHER_CERT)
/* CA key in certificate */
# define SSL_SECOP_CA_KEY                (17 | SSL_SECOP_OTHER_CERT)
/* CA digest algorithm in certificate */
# define SSL_SECOP_CA_MD                 (18 | SSL_SECOP_OTHER_CERT)
/* Peer EE key in certificate */
# define SSL_SECOP_PEER_EE_KEY           (SSL_SECOP_EE_KEY | SSL_SECOP_PEER)
/* Peer CA key in certificate */
# define SSL_SECOP_PEER_CA_KEY           (SSL_SECOP_CA_KEY | SSL_SECOP_PEER)
/* Peer CA digest algorithm in certificate */
# define SSL_SECOP_PEER_CA_MD            (SSL_SECOP_CA_MD | SSL_SECOP_PEER)

void SSL_set_security_level(SSL *s, int level);
__owur int SSL_get_security_level(const SSL *s);
void SSL_set_security_callback(SSL *s,
                               int (*cb) (const SSL *s, const SSL_CTX *ctx,
                                          int op, int bits, int nid,
                                          void *other, void *ex));
int (*SSL_get_security_callback(const SSL *s)) (const SSL *s,
                                                const SSL_CTX *ctx, int op,
                                                int bits, int nid, void *other,
                                                void *ex);
void SSL_set0_security_ex_data(SSL *s, void *ex);
__owur void *SSL_get0_security_ex_data(const SSL *s);

void SSL_CTX_set_security_level(SSL_CTX *ctx, int level);
__owur int SSL_CTX_get_security_level(const SSL_CTX *ctx);
void SSL_CTX_set_security_callback(SSL_CTX *ctx,
                                   int (*cb) (const SSL *s, const SSL_CTX *ctx,
                                              int op, int bits, int nid,
                                              void *other, void *ex));
int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx)) (const SSL *s,
                                                          const SSL_CTX *ctx,
                                                          int op, int bits,
                                                          int nid,
                                                          void *other,
                                                          void *ex);
void SSL_CTX_set0_security_ex_data(SSL_CTX *ctx, void *ex);
__owur void *SSL_CTX_get0_security_ex_data(const SSL_CTX *ctx);

/* OPENSSL_INIT flag 0x010000 reserved for internal use */
# define OPENSSL_INIT_NO_LOAD_SSL_STRINGS    0x00100000L
# define OPENSSL_INIT_LOAD_SSL_STRINGS       0x00200000L

# define OPENSSL_INIT_SSL_DEFAULT \
        (OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS)

int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);

# ifndef OPENSSL_NO_UNIT_TEST
__owur const struct openssl_ssl_test_functions *SSL_test_functions(void);
# endif

__owur int SSL_free_buffers(SSL *ssl);
__owur int SSL_alloc_buffers(SSL *ssl);

/* Status codes passed to the decrypt session ticket callback. Some of these
 * are for internal use only and are never passed to the callback. */
typedef int SSL_TICKET_STATUS;

/* Support for ticket appdata */
/* fatal error, malloc failure */
# define SSL_TICKET_FATAL_ERR_MALLOC 0
/* fatal error, either from parsing or decrypting the ticket */
# define SSL_TICKET_FATAL_ERR_OTHER  1
/* No ticket present */
# define SSL_TICKET_NONE             2
/* Empty ticket present */
# define SSL_TICKET_EMPTY            3
/* the ticket couldn't be decrypted */
# define SSL_TICKET_NO_DECRYPT       4
/* a ticket was successfully decrypted */
# define SSL_TICKET_SUCCESS          5
/* same as above but the ticket needs to be renewed */
# define SSL_TICKET_SUCCESS_RENEW    6

/* Return codes for the decrypt session ticket callback */
typedef int SSL_TICKET_RETURN;

/* An error occurred */
#define SSL_TICKET_RETURN_ABORT             0
/* Do not use the ticket, do not send a renewed ticket to the client */
#define SSL_TICKET_RETURN_IGNORE            1
/* Do not use the ticket, send a renewed ticket to the client */
#define SSL_TICKET_RETURN_IGNORE_RENEW      2
/* Use the ticket, do not send a renewed ticket to the client */
#define SSL_TICKET_RETURN_USE               3
/* Use the ticket, send a renewed ticket to the client */
#define SSL_TICKET_RETURN_USE_RENEW         4

typedef int (*SSL_CTX_generate_session_ticket_fn)(SSL *s, void *arg);
typedef SSL_TICKET_RETURN (*SSL_CTX_decrypt_session_ticket_fn)(SSL *s, SSL_SESSION *ss,
                                                               const unsigned char *keyname,
                                                               size_t keyname_length,
                                                               SSL_TICKET_STATUS status,
                                                               void *arg);
int SSL_CTX_set_session_ticket_cb(SSL_CTX *ctx,
                                  SSL_CTX_generate_session_ticket_fn gen_cb,
                                  SSL_CTX_decrypt_session_ticket_fn dec_cb,
                                  void *arg);
int SSL_SESSION_set1_ticket_appdata(SSL_SESSION *ss, const void *data, size_t len);
int SSL_SESSION_get0_ticket_appdata(SSL_SESSION *ss, void **data, size_t *len);

typedef unsigned int (*DTLS_timer_cb)(SSL *s, unsigned int timer_us);

void DTLS_set_timer_cb(SSL *s, DTLS_timer_cb cb);


typedef int (*SSL_allow_early_data_cb_fn)(SSL *s, void *arg);
void SSL_CTX_set_allow_early_data_cb(SSL_CTX *ctx,
                                     SSL_allow_early_data_cb_fn cb,
                                     void *arg);
void SSL_set_allow_early_data_cb(SSL *s,
                                 SSL_allow_early_data_cb_fn cb,
                                 void *arg);

/* store the default cipher strings inside the library */
const char *OSSL_default_cipher_list(void);
const char *OSSL_default_ciphersuites(void);

#  ifndef OPENSSL_NO_QUIC
/*
 * QUIC integration - The QUIC interface matches BoringSSL
 *
 * ssl_encryption_level_t represents a specific QUIC encryption level used to
 * transmit handshake messages. BoringSSL has this as an 'enum'.
 */
#include <openssl/quic.h>

/* Used by Chromium/QUIC - moved from evp.h to avoid breaking FIPS checksums */
# define X25519_PRIVATE_KEY_LEN          32
# define X25519_PUBLIC_VALUE_LEN         32

/* moved from types.h to avoid breaking FIPS checksums */
typedef struct ssl_quic_method_st SSL_QUIC_METHOD;

typedef enum ssl_encryption_level_t {
    ssl_encryption_initial = 0,
    ssl_encryption_early_data,
    ssl_encryption_handshake,
    ssl_encryption_application
} OSSL_ENCRYPTION_LEVEL;

struct ssl_quic_method_st {
    int (*set_encryption_secrets)(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                                  const uint8_t *read_secret,
                                  const uint8_t *write_secret, size_t secret_len);
    int (*add_handshake_data)(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                              const uint8_t *data, size_t len);
    int (*flush_flight)(SSL *ssl);
    int (*send_alert)(SSL *ssl, enum ssl_encryption_level_t level, uint8_t alert);
};

__owur int SSL_CTX_set_quic_method(SSL_CTX *ctx, const SSL_QUIC_METHOD *quic_method);
__owur int SSL_set_quic_method(SSL *ssl, const SSL_QUIC_METHOD *quic_method);
__owur int SSL_set_quic_transport_params(SSL *ssl,
                                         const uint8_t *params,
                                         size_t params_len);
void SSL_get_peer_quic_transport_params(const SSL *ssl,
                                        const uint8_t **out_params,
                                        size_t *out_params_len);
__owur size_t SSL_quic_max_handshake_flight_len(const SSL *ssl, OSSL_ENCRYPTION_LEVEL level);
__owur OSSL_ENCRYPTION_LEVEL SSL_quic_read_level(const SSL *ssl);
__owur OSSL_ENCRYPTION_LEVEL SSL_quic_write_level(const SSL *ssl);
__owur int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                                 const uint8_t *data, size_t len);
__owur int SSL_process_quic_post_handshake(SSL *ssl);

__owur int SSL_is_quic(SSL *ssl);

/* BoringSSL API */
void SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy);

/*
 * Set an explicit value that you want to use
 * If 0 (default) the server will use the highest extenstion the client sent
 * If 0 (default) the client will send both extensions
 */
void SSL_set_quic_transport_version(SSL *ssl, int version);
__owur int SSL_get_quic_transport_version(const SSL *ssl);
/* Returns the negotiated version, or -1 on error */
__owur int SSL_get_peer_quic_transport_version(const SSL *ssl);

int SSL_CIPHER_get_prf_nid(const SSL_CIPHER *c);

void SSL_set_quic_early_data_enabled(SSL *ssl, int enabled);

#  endif

# ifdef  __cplusplus
}
# endif
#endif
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     /*
 * WARNING: do not edit!
 * Generated by Makefile from include/openssl/ssl.h.in
 *
 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
 * Copyright 2005 Nokia. All rights reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */



#ifndef OPENSSL_SSL_H
# define OPENSSL_SSL_H
# pragma once

# include <openssl/macros.h>
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define HEADER_SSL_H
# endif

# include <openssl/e_os2.h>
# include <openssl/opensslconf.h>
# include <openssl/comp.h>
# include <openssl/bio.h>
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  include <openssl/x509.h>
#  include <openssl/crypto.h>
#  include <openssl/buffer.h>
# endif
# include <openssl/lhash.h>
# include <openssl/pem.h>
# include <openssl/hmac.h>
# include <openssl/async.h>

# include <openssl/safestack.h>
# include <openssl/symhacks.h>
# include <openssl/ct.h>
# include <openssl/sslerr.h>
# include <openssl/prov_ssl.h>

#ifdef  __cplusplus
extern "C" {
#endif

/* OpenSSL version number for ASN.1 encoding of the session information */
/*-
 * Version 0 - initial version
 * Version 1 - added the optional peer certificate
 */
# define SSL_SESSION_ASN1_VERSION 0x0001

# define SSL_MAX_SSL_SESSION_ID_LENGTH           32
# define SSL_MAX_SID_CTX_LENGTH                  32

# define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES     (512/8)
# define SSL_MAX_KEY_ARG_LENGTH                  8
/* SSL_MAX_MASTER_KEY_LENGTH is defined in prov_ssl.h */

/* The maximum number of encrypt/decrypt pipelines we can support */
# define SSL_MAX_PIPELINES  32

/* text strings for the ciphers */

/* These are used to specify which ciphers to use and not to use */

# define SSL_TXT_LOW             "LOW"
# define SSL_TXT_MEDIUM          "MEDIUM"
# define SSL_TXT_HIGH            "HIGH"
# define SSL_TXT_FIPS            "FIPS"

# define SSL_TXT_aNULL           "aNULL"
# define SSL_TXT_eNULL           "eNULL"
# define SSL_TXT_NULL            "NULL"

# define SSL_TXT_kRSA            "kRSA"
# define SSL_TXT_kDHr            "kDHr"/* this cipher class has been removed */
# define SSL_TXT_kDHd            "kDHd"/* this cipher class has been removed */
# define SSL_TXT_kDH             "kDH"/* this cipher class has been removed */
# define SSL_TXT_kEDH            "kEDH"/* alias for kDHE */
# define SSL_TXT_kDHE            "kDHE"
# define SSL_TXT_kECDHr          "kECDHr"/* this cipher class has been removed */
# define SSL_TXT_kECDHe          "kECDHe"/* this cipher class has been removed */
# define SSL_TXT_kECDH           "kECDH"/* this cipher class has been removed */
# define SSL_TXT_kEECDH          "kEECDH"/* alias for kECDHE */
# define SSL_TXT_kECDHE          "kECDHE"
# define SSL_TXT_kPSK            "kPSK"
# define SSL_TXT_kRSAPSK         "kRSAPSK"
# define SSL_TXT_kECDHEPSK       "kECDHEPSK"
# define SSL_TXT_kDHEPSK         "kDHEPSK"
# define SSL_TXT_kGOST           "kGOST"
# define SSL_TXT_kGOST18         "kGOST18"
# define SSL_TXT_kSRP            "kSRP"

# define SSL_TXT_aRSA            "aRSA"
# define SSL_TXT_aDSS            "aDSS"
# define SSL_TXT_aDH             "aDH"/* this cipher class has been removed */
# define SSL_TXT_aECDH           "aECDH"/* this cipher class has been removed */
# define SSL_TXT_aECDSA          "aECDSA"
# define SSL_TXT_aPSK            "aPSK"
# define SSL_TXT_aGOST94         "aGOST94"
# define SSL_TXT_aGOST01         "aGOST01"
# define SSL_TXT_aGOST12         "aGOST12"
# define SSL_TXT_aGOST           "aGOST"
# define SSL_TXT_aSRP            "aSRP"

# define SSL_TXT_DSS             "DSS"
# define SSL_TXT_DH              "DH"
# define SSL_TXT_DHE             "DHE"/* same as "kDHE:-ADH" */
# define SSL_TXT_EDH             "EDH"/* alias for DHE */
# define SSL_TXT_ADH             "ADH"
# define SSL_TXT_RSA             "RSA"
# define SSL_TXT_ECDH            "ECDH"
# define SSL_TXT_EECDH           "EECDH"/* alias for ECDHE" */
# define SSL_TXT_ECDHE           "ECDHE"/* same as "kECDHE:-AECDH" */
# define SSL_TXT_AECDH           "AECDH"
# define SSL_TXT_ECDSA           "ECDSA"
# define SSL_TXT_PSK             "PSK"
# define SSL_TXT_SRP             "SRP"

# define SSL_TXT_DES             "DES"
# define SSL_TXT_3DES            "3DES"
# define SSL_TXT_RC4             "RC4"
# define SSL_TXT_RC2             "RC2"
# define SSL_TXT_IDEA            "IDEA"
# define SSL_TXT_SEED            "SEED"
# define SSL_TXT_AES128          "AES128"
# define SSL_TXT_AES256          "AES256"
# define SSL_TXT_AES             "AES"
# define SSL_TXT_AES_GCM         "AESGCM"
# define SSL_TXT_AES_CCM         "AESCCM"
# define SSL_TXT_AES_CCM_8       "AESCCM8"
# define SSL_TXT_CAMELLIA128     "CAMELLIA128"
# define SSL_TXT_CAMELLIA256     "CAMELLIA256"
# define SSL_TXT_CAMELLIA        "CAMELLIA"
# define SSL_TXT_CHACHA20        "CHACHA20"
# define SSL_TXT_GOST            "GOST89"
# define SSL_TXT_ARIA            "ARIA"
# define SSL_TXT_ARIA_GCM        "ARIAGCM"
# define SSL_TXT_ARIA128         "ARIA128"
# define SSL_TXT_ARIA256         "ARIA256"
# define SSL_TXT_GOST2012_GOST8912_GOST8912 "GOST2012-GOST8912-GOST8912"
# define SSL_TXT_CBC             "CBC"

# define SSL_TXT_MD5             "MD5"
# define SSL_TXT_SHA1            "SHA1"
# define SSL_TXT_SHA             "SHA"/* same as "SHA1" */
# define SSL_TXT_GOST94          "GOST94"
# define SSL_TXT_GOST89MAC       "GOST89MAC"
# define SSL_TXT_GOST12          "GOST12"
# define SSL_TXT_GOST89MAC12     "GOST89MAC12"
# define SSL_TXT_SHA256          "SHA256"
# define SSL_TXT_SHA384          "SHA384"

# define SSL_TXT_SSLV3           "SSLv3"
# define SSL_TXT_TLSV1           "TLSv1"
# define SSL_TXT_TLSV1_1         "TLSv1.1"
# define SSL_TXT_TLSV1_2         "TLSv1.2"

# define SSL_TXT_ALL             "ALL"

/*-
 * COMPLEMENTOF* definitions. These identifiers are used to (de-select)
 * ciphers normally not being used.
 * Example: "RC4" will activate all ciphers using RC4 including ciphers
 * without authentication, which would normally disabled by DEFAULT (due
 * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT"
 * will make sure that it is also disabled in the specific selection.
 * COMPLEMENTOF* identifiers are portable between version, as adjustments
 * to the default cipher setup will also be included here.
 *
 * COMPLEMENTOFDEFAULT does not experience the same special treatment that
 * DEFAULT gets, as only selection is being done and no sorting as needed
 * for DEFAULT.
 */
# define SSL_TXT_CMPALL          "COMPLEMENTOFALL"
# define SSL_TXT_CMPDEF          "COMPLEMENTOFDEFAULT"

/*
 * The following cipher list is used by default. It also is substituted when
 * an application-defined cipher list string starts with 'DEFAULT'.
 * This applies to ciphersuites for TLSv1.2 and below.
 * DEPRECATED IN 3.0.0, in favor of OSSL_default_cipher_list()
 * Update both macro and function simultaneously
 */
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_DEFAULT_CIPHER_LIST "ALL:!COMPLEMENTOFDEFAULT:!eNULL"
/*
 * This is the default set of TLSv1.3 ciphersuites
 * DEPRECATED IN 3.0.0, in favor of OSSL_default_ciphersuites()
 * Update both macro and function simultaneously
 */
#  define TLS_DEFAULT_CIPHERSUITES "TLS_AES_256_GCM_SHA384:" \
                                   "TLS_CHACHA20_POLY1305_SHA256:" \
                                   "TLS_AES_128_GCM_SHA256"
# endif
/*
 * As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always
 * starts with a reasonable order, and all we have to do for DEFAULT is
 * throwing out anonymous and unencrypted ciphersuites! (The latter are not
 * actually enabled by ALL, but "ALL:RSA" would enable some of them.)
 */

/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
# define SSL_SENT_SHUTDOWN       1
# define SSL_RECEIVED_SHUTDOWN   2

#ifdef __cplusplus
}
#endif

#ifdef  __cplusplus
extern "C" {
#endif

# define SSL_FILETYPE_ASN1       X509_FILETYPE_ASN1
# define SSL_FILETYPE_PEM        X509_FILETYPE_PEM

/*
 * This is needed to stop compilers complaining about the 'struct ssl_st *'
 * function parameters used to prototype callbacks in SSL_CTX.
 */
typedef struct ssl_st *ssl_crock_st;
typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
typedef struct ssl_method_st SSL_METHOD;
typedef struct ssl_cipher_st SSL_CIPHER;
typedef struct ssl_session_st SSL_SESSION;
typedef struct tls_sigalgs_st TLS_SIGALGS;
typedef struct ssl_conf_ctx_st SSL_CONF_CTX;
typedef struct ssl_comp_st SSL_COMP;

STACK_OF(SSL_CIPHER);
STACK_OF(SSL_COMP);

/* SRTP protection profiles for use with the use_srtp extension (RFC 5764)*/
typedef struct srtp_protection_profile_st {
    const char *name;
    unsigned long id;
} SRTP_PROTECTION_PROFILE;
SKM_DEFINE_STACK_OF_INTERNAL(SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE)
#define sk_SRTP_PROTECTION_PROFILE_num(sk) OPENSSL_sk_num(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_value(sk, idx) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_value(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), (idx)))
#define sk_SRTP_PROTECTION_PROFILE_new(cmp) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new(ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp)))
#define sk_SRTP_PROTECTION_PROFILE_new_null() ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new_null())
#define sk_SRTP_PROTECTION_PROFILE_new_reserve(cmp, n) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new_reserve(ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp), (n)))
#define sk_SRTP_PROTECTION_PROFILE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (n))
#define sk_SRTP_PROTECTION_PROFILE_free(sk) OPENSSL_sk_free(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_zero(sk) OPENSSL_sk_zero(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_delete(sk, i) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_delete(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (i)))
#define sk_SRTP_PROTECTION_PROFILE_delete_ptr(sk, ptr) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_delete_ptr(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr)))
#define sk_SRTP_PROTECTION_PROFILE_push(sk, ptr) OPENSSL_sk_push(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_pop(sk) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_pop(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_shift(sk) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_shift(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk),ossl_check_SRTP_PROTECTION_PROFILE_freefunc_type(freefunc))
#define sk_SRTP_PROTECTION_PROFILE_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr), (idx))
#define sk_SRTP_PROTECTION_PROFILE_set(sk, idx, ptr) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_set(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (idx), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr)))
#define sk_SRTP_PROTECTION_PROFILE_find(sk, ptr) OPENSSL_sk_find(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr), pnum)
#define sk_SRTP_PROTECTION_PROFILE_sort(sk) OPENSSL_sk_sort(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_dup(sk) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_dup(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_deep_copy(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_copyfunc_type(copyfunc), ossl_check_SRTP_PROTECTION_PROFILE_freefunc_type(freefunc)))
#define sk_SRTP_PROTECTION_PROFILE_set_cmp_func(sk, cmp) ((sk_SRTP_PROTECTION_PROFILE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp)))



typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data,
                                            int len, void *arg);
typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len,
                                        STACK_OF(SSL_CIPHER) *peer_ciphers,
                                        const SSL_CIPHER **cipher, void *arg);

/* Extension context codes */
/* This extension is only allowed in TLS */
#define SSL_EXT_TLS_ONLY                        0x0001
/* This extension is only allowed in DTLS */
#define SSL_EXT_DTLS_ONLY                       0x0002
/* Some extensions may be allowed in DTLS but we don't implement them for it */
#define SSL_EXT_TLS_IMPLEMENTATION_ONLY         0x0004
/* Most extensions are not defined for SSLv3 but EXT_TYPE_renegotiate is */
#define SSL_EXT_SSL3_ALLOWED                    0x0008
/* Extension is only defined for TLS1.2 and below */
#define SSL_EXT_TLS1_2_AND_BELOW_ONLY           0x0010
/* Extension is only defined for TLS1.3 and above */
#define SSL_EXT_TLS1_3_ONLY                     0x0020
/* Ignore this extension during parsing if we are resuming */
#define SSL_EXT_IGNORE_ON_RESUMPTION            0x0040
#define SSL_EXT_CLIENT_HELLO                    0x0080
/* Really means TLS1.2 or below */
#define SSL_EXT_TLS1_2_SERVER_HELLO             0x0100
#define SSL_EXT_TLS1_3_SERVER_HELLO             0x0200
#define SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS     0x0400
#define SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST      0x0800
#define SSL_EXT_TLS1_3_CERTIFICATE              0x1000
#define SSL_EXT_TLS1_3_NEW_SESSION_TICKET       0x2000
#define SSL_EXT_TLS1_3_CERTIFICATE_REQUEST      0x4000

/* Typedefs for handling custom extensions */

typedef int (*custom_ext_add_cb)(SSL *s, unsigned int ext_type,
                                 const unsigned char **out, size_t *outlen,
                                 int *al, void *add_arg);

typedef void (*custom_ext_free_cb)(SSL *s, unsigned int ext_type,
                                   const unsigned char *out, void *add_arg);

typedef int (*custom_ext_parse_cb)(SSL *s, unsigned int ext_type,
                                   const unsigned char *in, size_t inlen,
                                   int *al, void *parse_arg);


typedef int (*SSL_custom_ext_add_cb_ex)(SSL *s, unsigned int ext_type,
                                        unsigned int context,
                                        const unsigned char **out,
                                        size_t *outlen, X509 *x,
                                        size_t chainidx,
                                        int *al, void *add_arg);

typedef void (*SSL_custom_ext_free_cb_ex)(SSL *s, unsigned int ext_type,
                                          unsigned int context,
                                          const unsigned char *out,
                                          void *add_arg);

typedef int (*SSL_custom_ext_parse_cb_ex)(SSL *s, unsigned int ext_type,
                                          unsigned int context,
                                          const unsigned char *in,
                                          size_t inlen, X509 *x,
                                          size_t chainidx,
                                          int *al, void *parse_arg);

/* Typedef for verification callback */
typedef int (*SSL_verify_cb)(int preverify_ok, X509_STORE_CTX *x509_ctx);

/* Typedef for SSL async callback */
typedef int (*SSL_async_callback_fn)(SSL *s, void *arg);

#define SSL_OP_BIT(n)  ((uint64_t)1 << (uint64_t)n)

/*
 * SSL/TLS connection options.
 */
    /* Disable Extended master secret */
# define SSL_OP_NO_EXTENDED_MASTER_SECRET                SSL_OP_BIT(0)
    /* Cleanse plaintext copies of data delivered to the application */
# define SSL_OP_CLEANSE_PLAINTEXT                        SSL_OP_BIT(1)
    /* Allow initial connection to servers that don't support RI */
# define SSL_OP_LEGACY_SERVER_CONNECT                    SSL_OP_BIT(2)
    /* Enable support for Kernel TLS */
# define SSL_OP_ENABLE_KTLS                              SSL_OP_BIT(3)
# define SSL_OP_TLSEXT_PADDING                           SSL_OP_BIT(4)
# define SSL_OP_SAFARI_ECDHE_ECDSA_BUG                   SSL_OP_BIT(6)
# define SSL_OP_IGNORE_UNEXPECTED_EOF                    SSL_OP_BIT(7)
# define SSL_OP_ALLOW_CLIENT_RENEGOTIATION               SSL_OP_BIT(8)
# define SSL_OP_DISABLE_TLSEXT_CA_NAMES                  SSL_OP_BIT(9)
    /* In TLSv1.3 allow a non-(ec)dhe based kex_mode */
# define SSL_OP_ALLOW_NO_DHE_KEX                         SSL_OP_BIT(10)
    /*
     * Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
     * in OpenSSL 0.9.6d.  Usually (depending on the application protocol)
     * the workaround is not needed.  Unfortunately some broken SSL/TLS
     * implementations cannot handle it at all, which is why we include it
     * in SSL_OP_ALL. Added in 0.9.6e
     */
# define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS              SSL_OP_BIT(11)
    /* DTLS options */
# define SSL_OP_NO_QUERY_MTU                             SSL_OP_BIT(12)
    /* Turn on Cookie Exchange (on relevant for servers) */
# define SSL_OP_COOKIE_EXCHANGE                          SSL_OP_BIT(13)
    /* Don't use RFC4507 ticket extension */
# define SSL_OP_NO_TICKET                                SSL_OP_BIT(14)
# ifndef OPENSSL_NO_DTLS1_METHOD
    /*
     * Use Cisco's version identifier of DTLS_BAD_VER
     * (only with deprecated DTLSv1_client_method())
     */
#  define SSL_OP_CISCO_ANYCONNECT                        SSL_OP_BIT(15)
# endif
    /* As server, disallow session resumption on renegotiation */
# define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION   SSL_OP_BIT(16)
    /* Don't use compression even if supported */
# define SSL_OP_NO_COMPRESSION                           SSL_OP_BIT(17)
    /* Permit unsafe legacy renegotiation */
# define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION        SSL_OP_BIT(18)
    /* Disable encrypt-then-mac */
# define SSL_OP_NO_ENCRYPT_THEN_MAC                      SSL_OP_BIT(19)
    /*
     * Enable TLSv1.3 Compatibility mode. This is on by default. A future
     * version of OpenSSL may have this disabled by default.
     */
# define SSL_OP_ENABLE_MIDDLEBOX_COMPAT                  SSL_OP_BIT(20)
    /*
     * Prioritize Chacha20Poly1305 when client does.
     * Modifies SSL_OP_CIPHER_SERVER_PREFERENCE
     */
# define SSL_OP_PRIORITIZE_CHACHA                        SSL_OP_BIT(21)
    /*
     * Set on servers to choose the cipher according to server's preferences.
     */
# define SSL_OP_CIPHER_SERVER_PREFERENCE                 SSL_OP_BIT(22)
    /*
     * If set, a server will allow a client to issue a SSLv3.0 version
     * number as latest version supported in the premaster secret, even when
     * TLSv1.0 (version 3.1) was announced in the client hello. Normally
     * this is forbidden to prevent version rollback attacks.
     */
# define SSL_OP_TLS_ROLLBACK_BUG                         SSL_OP_BIT(23)
    /*
     * Switches off automatic TLSv1.3 anti-replay protection for early data.
     * This is a server-side option only (no effect on the client).
     */
# define SSL_OP_NO_ANTI_REPLAY                           SSL_OP_BIT(24)
# define SSL_OP_NO_SSLv3                                 SSL_OP_BIT(25)
# define SSL_OP_NO_TLSv1                                 SSL_OP_BIT(26)
# define SSL_OP_NO_TLSv1_2                               SSL_OP_BIT(27)
# define SSL_OP_NO_TLSv1_1                               SSL_OP_BIT(28)
# define SSL_OP_NO_TLSv1_3                               SSL_OP_BIT(29)
# define SSL_OP_NO_DTLSv1                                SSL_OP_BIT(26)
# define SSL_OP_NO_DTLSv1_2                              SSL_OP_BIT(27)
    /* Disallow all renegotiation */
# define SSL_OP_NO_RENEGOTIATION                         SSL_OP_BIT(30)
    /*
     * Make server add server-hello extension from early version of
     * cryptopro draft, when GOST ciphersuite is negotiated. Required for
     * interoperability with CryptoPro CSP 3.x
     */
# define SSL_OP_CRYPTOPRO_TLSEXT_BUG                     SSL_OP_BIT(31)

/*
 * Option "collections."
 */
# define SSL_OP_NO_SSL_MASK \
        ( SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 \
          | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3 )
# define SSL_OP_NO_DTLS_MASK \
        ( SSL_OP_NO_DTLSv1 | SSL_OP_NO_DTLSv1_2 )

/* Various bug workarounds that should be rather harmless. */
# define SSL_OP_ALL \
        ( SSL_OP_CRYPTOPRO_TLSEXT_BUG | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS \
          | SSL_OP_TLSEXT_PADDING | SSL_OP_SAFARI_ECDHE_ECDSA_BUG )

/*
 * OBSOLETE OPTIONS retained for compatibility
 */

# define SSL_OP_MICROSOFT_SESS_ID_BUG                    0x0
# define SSL_OP_NETSCAPE_CHALLENGE_BUG                   0x0
# define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG         0x0
# define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG              0x0
# define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER               0x0
# define SSL_OP_MSIE_SSLV2_RSA_PADDING                   0x0
# define SSL_OP_SSLEAY_080_CLIENT_DH_BUG                 0x0
# define SSL_OP_TLS_D5_BUG                               0x0
# define SSL_OP_TLS_BLOCK_PADDING_BUG                    0x0
# define SSL_OP_SINGLE_ECDH_USE                          0x0
# define SSL_OP_SINGLE_DH_USE                            0x0
# define SSL_OP_EPHEMERAL_RSA                            0x0
# define SSL_OP_NO_SSLv2                                 0x0
# define SSL_OP_PKCS1_CHECK_1                            0x0
# define SSL_OP_PKCS1_CHECK_2                            0x0
# define SSL_OP_NETSCAPE_CA_DN_BUG                       0x0
# define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG          0x0

/*
 * Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
 * when just a single record has been written):
 */
# define SSL_MODE_ENABLE_PARTIAL_WRITE       0x00000001U
/*
 * Make it possible to retry SSL_write() with changed buffer location (buffer
 * contents must stay the same!); this is not the default to avoid the
 * misconception that non-blocking SSL_write() behaves like non-blocking
 * write():
 */
# define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002U
/*
 * Never bother the application with retries if the transport is blocking:
 */
# define SSL_MODE_AUTO_RETRY 0x00000004U
/* Don't attempt to automatically build certificate chain */
# define SSL_MODE_NO_AUTO_CHAIN 0x00000008U
/*
 * Save RAM by releasing read and write buffers when they're empty. (SSL3 and
 * TLS only.) Released buffers are freed.
 */
# define SSL_MODE_RELEASE_BUFFERS 0x00000010U
/*
 * Send the current time in the Random fields of the ClientHello and
 * ServerHello records for compatibility with hypothetical implementations
 * that require it.
 */
# define SSL_MODE_SEND_CLIENTHELLO_TIME 0x00000020U
# define SSL_MODE_SEND_SERVERHELLO_TIME 0x00000040U
/*
 * Send TLS_FALLBACK_SCSV in the ClientHello. To be set only by applications
 * that reconnect with a downgraded protocol version; see
 * draft-ietf-tls-downgrade-scsv-00 for details. DO NOT ENABLE THIS if your
 * application attempts a normal handshake. Only use this in explicit
 * fallback retries, following the guidance in
 * draft-ietf-tls-downgrade-scsv-00.
 */
# define SSL_MODE_SEND_FALLBACK_SCSV 0x00000080U
/*
 * Support Asynchronous operation
 */
# define SSL_MODE_ASYNC 0x00000100U

/*
 * When using DTLS/SCTP, include the terminating zero in the label
 * used for computing the endpoint-pair shared secret. Required for
 * interoperability with implementations having this bug like these
 * older version of OpenSSL:
 * - OpenSSL 1.0.0 series
 * - OpenSSL 1.0.1 series
 * - OpenSSL 1.0.2 series
 * - OpenSSL 1.1.0 series
 * - OpenSSL 1.1.1 and 1.1.1a
 */
# define SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG 0x00000400U

/* Cert related flags */
/*
 * Many implementations ignore some aspects of the TLS standards such as
 * enforcing certificate chain algorithms. When this is set we enforce them.
 */
# define SSL_CERT_FLAG_TLS_STRICT                0x00000001U

/* Suite B modes, takes same values as certificate verify flags */
# define SSL_CERT_FLAG_SUITEB_128_LOS_ONLY       0x10000
/* Suite B 192 bit only mode */
# define SSL_CERT_FLAG_SUITEB_192_LOS            0x20000
/* Suite B 128 bit mode allowing 192 bit algorithms */
# define SSL_CERT_FLAG_SUITEB_128_LOS            0x30000

/* Perform all sorts of protocol violations for testing purposes */
# define SSL_CERT_FLAG_BROKEN_PROTOCOL           0x10000000

/* Flags for building certificate chains */
/* Treat any existing certificates as untrusted CAs */
# define SSL_BUILD_CHAIN_FLAG_UNTRUSTED          0x1
/* Don't include root CA in chain */
# define SSL_BUILD_CHAIN_FLAG_NO_ROOT            0x2
/* Just check certificates already there */
# define SSL_BUILD_CHAIN_FLAG_CHECK              0x4
/* Ignore verification errors */
# define SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR       0x8
/* Clear verification errors from queue */
# define SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR        0x10

/* Flags returned by SSL_check_chain */
/* Certificate can be used with this session */
# define CERT_PKEY_VALID         0x1
/* Certificate can also be used for signing */
# define CERT_PKEY_SIGN          0x2
/* EE certificate signing algorithm OK */
# define CERT_PKEY_EE_SIGNATURE  0x10
/* CA signature algorithms OK */
# define CERT_PKEY_CA_SIGNATURE  0x20
/* EE certificate parameters OK */
# define CERT_PKEY_EE_PARAM      0x40
/* CA certificate parameters OK */
# define CERT_PKEY_CA_PARAM      0x80
/* Signing explicitly allowed as opposed to SHA1 fallback */
# define CERT_PKEY_EXPLICIT_SIGN 0x100
/* Client CA issuer names match (always set for server cert) */
# define CERT_PKEY_ISSUER_NAME   0x200
/* Cert type matches client types (always set for server cert) */
# define CERT_PKEY_CERT_TYPE     0x400
/* Cert chain suitable to Suite B */
# define CERT_PKEY_SUITEB        0x800

# define SSL_CONF_FLAG_CMDLINE           0x1
# define SSL_CONF_FLAG_FILE              0x2
# define SSL_CONF_FLAG_CLIENT            0x4
# define SSL_CONF_FLAG_SERVER            0x8
# define SSL_CONF_FLAG_SHOW_ERRORS       0x10
# define SSL_CONF_FLAG_CERTIFICATE       0x20
# define SSL_CONF_FLAG_REQUIRE_PRIVATE   0x40
/* Configuration value types */
# define SSL_CONF_TYPE_UNKNOWN           0x0
# define SSL_CONF_TYPE_STRING            0x1
# define SSL_CONF_TYPE_FILE              0x2
# define SSL_CONF_TYPE_DIR               0x3
# define SSL_CONF_TYPE_NONE              0x4
# define SSL_CONF_TYPE_STORE             0x5

/* Maximum length of the application-controlled segment of a a TLSv1.3 cookie */
# define SSL_COOKIE_LENGTH                       4096

/*
 * Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, they
 * cannot be used to clear bits.
 */

uint64_t SSL_CTX_get_options(const SSL_CTX *ctx);
uint64_t SSL_get_options(const SSL *s);
uint64_t SSL_CTX_clear_options(SSL_CTX *ctx, uint64_t op);
uint64_t SSL_clear_options(SSL *s, uint64_t op);
uint64_t SSL_CTX_set_options(SSL_CTX *ctx, uint64_t op);
uint64_t SSL_set_options(SSL *s, uint64_t op);

# define SSL_CTX_set_mode(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
# define SSL_CTX_clear_mode(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_MODE,(op),NULL)
# define SSL_CTX_get_mode(ctx) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL)
# define SSL_clear_mode(ssl,op) \
        SSL_ctrl((ssl),SSL_CTRL_CLEAR_MODE,(op),NULL)
# define SSL_set_mode(ssl,op) \
        SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL)
# define SSL_get_mode(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL)
# define SSL_set_mtu(ssl, mtu) \
        SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL)
# define DTLS_set_link_mtu(ssl, mtu) \
        SSL_ctrl((ssl),DTLS_CTRL_SET_LINK_MTU,(mtu),NULL)
# define DTLS_get_link_min_mtu(ssl) \
        SSL_ctrl((ssl),DTLS_CTRL_GET_LINK_MIN_MTU,0,NULL)

# define SSL_get_secure_renegotiation_support(ssl) \
        SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL)

# define SSL_CTX_set_cert_flags(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CERT_FLAGS,(op),NULL)
# define SSL_set_cert_flags(s,op) \
        SSL_ctrl((s),SSL_CTRL_CERT_FLAGS,(op),NULL)
# define SSL_CTX_clear_cert_flags(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL)
# define SSL_clear_cert_flags(s,op) \
        SSL_ctrl((s),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL)

void SSL_CTX_set_msg_callback(SSL_CTX *ctx,
                              void (*cb) (int write_p, int version,
                                          int content_type, const void *buf,
                                          size_t len, SSL *ssl, void *arg));
void SSL_set_msg_callback(SSL *ssl,
                          void (*cb) (int write_p, int version,
                                      int content_type, const void *buf,
                                      size_t len, SSL *ssl, void *arg));
# define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
# define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))

# define SSL_get_extms_support(s) \
        SSL_ctrl((s),SSL_CTRL_GET_EXTMS_SUPPORT,0,NULL)

# ifndef OPENSSL_NO_SRP
/* see tls_srp.c */
#  ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 __owur int SSL_SRP_CTX_init(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx);
OSSL_DEPRECATEDIN_3_0 int SSL_SRP_CTX_free(SSL *ctx);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx);
OSSL_DEPRECATEDIN_3_0 __owur int SSL_srp_server_param_with_username(SSL *s,
                                                                    int *ad);
OSSL_DEPRECATEDIN_3_0 __owur int SRP_Calc_A_param(SSL *s);
#  endif
# endif

/* 100k max cert list */
# define SSL_MAX_CERT_LIST_DEFAULT (1024*100)

# define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT      (1024*20)

/*
 * This callback type is used inside SSL_CTX, SSL, and in the functions that
 * set them. It is used to override the generation of SSL/TLS session IDs in
 * a server. Return value should be zero on an error, non-zero to proceed.
 * Also, callbacks should themselves check if the id they generate is unique
 * otherwise the SSL handshake will fail with an error - callbacks can do
 * this using the 'ssl' value they're passed by;
 * SSL_has_matching_session_id(ssl, id, *id_len) The length value passed in
 * is set at the maximum size the session ID can be. In SSLv3/TLSv1 it is 32
 * bytes. The callback can alter this length to be less if desired. It is
 * also an error for the callback to set the size to zero.
 */
typedef int (*GEN_SESSION_CB) (SSL *ssl, unsigned char *id,
                               unsigned int *id_len);

# define SSL_SESS_CACHE_OFF                      0x0000
# define SSL_SESS_CACHE_CLIENT                   0x0001
# define SSL_SESS_CACHE_SERVER                   0x0002
# define SSL_SESS_CACHE_BOTH     (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
# define SSL_SESS_CACHE_NO_AUTO_CLEAR            0x0080
/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */
# define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP       0x0100
# define SSL_SESS_CACHE_NO_INTERNAL_STORE        0x0200
# define SSL_SESS_CACHE_NO_INTERNAL \
        (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE)
# define SSL_SESS_CACHE_UPDATE_TIME              0x0400

LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx);
# define SSL_CTX_sess_number(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
# define SSL_CTX_sess_connect(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
# define SSL_CTX_sess_connect_good(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
# define SSL_CTX_sess_connect_renegotiate(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
# define SSL_CTX_sess_accept(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
# define SSL_CTX_sess_accept_renegotiate(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
# define SSL_CTX_sess_accept_good(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
# define SSL_CTX_sess_hits(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
# define SSL_CTX_sess_cb_hits(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
# define SSL_CTX_sess_misses(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
# define SSL_CTX_sess_timeouts(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
# define SSL_CTX_sess_cache_full(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)

void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
                             int (*new_session_cb) (struct ssl_st *ssl,
                                                    SSL_SESSION *sess));
int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (struct ssl_st *ssl,
                                              SSL_SESSION *sess);
void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
                                void (*remove_session_cb) (struct ssl_ctx_st
                                                           *ctx,
                                                           SSL_SESSION *sess));
void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (struct ssl_ctx_st *ctx,
                                                  SSL_SESSION *sess);
void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
                             SSL_SESSION *(*get_session_cb) (struct ssl_st
                                                             *ssl,
                                                             const unsigned char
                                                             *data, int len,
                                                             int *copy));
SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (struct ssl_st *ssl,
                                                       const unsigned char *data,
                                                       int len, int *copy);
void SSL_CTX_set_info_callback(SSL_CTX *ctx,
                               void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type,
                                                 int val);
void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
                                int (*client_cert_cb) (SSL *ssl, X509 **x509,
                                                       EVP_PKEY **pkey));
int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509,
                                                 EVP_PKEY **pkey);
# ifndef OPENSSL_NO_ENGINE
__owur int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e);
# endif
void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
                                    int (*app_gen_cookie_cb) (SSL *ssl,
                                                              unsigned char
                                                              *cookie,
                                                              unsigned int
                                                              *cookie_len));
void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
                                  int (*app_verify_cookie_cb) (SSL *ssl,
                                                               const unsigned
                                                               char *cookie,
                                                               unsigned int
                                                               cookie_len));

void SSL_CTX_set_stateless_cookie_generate_cb(
    SSL_CTX *ctx,
    int (*gen_stateless_cookie_cb) (SSL *ssl,
                                    unsigned char *cookie,
                                    size_t *cookie_len));
void SSL_CTX_set_stateless_cookie_verify_cb(
    SSL_CTX *ctx,
    int (*verify_stateless_cookie_cb) (SSL *ssl,
                                       const unsigned char *cookie,
                                       size_t cookie_len));
# ifndef OPENSSL_NO_NEXTPROTONEG

typedef int (*SSL_CTX_npn_advertised_cb_func)(SSL *ssl,
                                              const unsigned char **out,
                                              unsigned int *outlen,
                                              void *arg);
void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s,
                                           SSL_CTX_npn_advertised_cb_func cb,
                                           void *arg);
#  define SSL_CTX_set_npn_advertised_cb SSL_CTX_set_next_protos_advertised_cb

typedef int (*SSL_CTX_npn_select_cb_func)(SSL *s,
                                          unsigned char **out,
                                          unsigned char *outlen,
                                          const unsigned char *in,
                                          unsigned int inlen,
                                          void *arg);
void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s,
                                      SSL_CTX_npn_select_cb_func cb,
                                      void *arg);
#  define SSL_CTX_set_npn_select_cb SSL_CTX_set_next_proto_select_cb

void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
                                    unsigned *len);
#  define SSL_get0_npn_negotiated SSL_get0_next_proto_negotiated
# endif

__owur int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
                                 const unsigned char *in, unsigned int inlen,
                                 const unsigned char *client,
                                 unsigned int client_len);

# define OPENSSL_NPN_UNSUPPORTED 0
# define OPENSSL_NPN_NEGOTIATED  1
# define OPENSSL_NPN_NO_OVERLAP  2

__owur int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
                                   unsigned int protos_len);
__owur int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
                               unsigned int protos_len);
typedef int (*SSL_CTX_alpn_select_cb_func)(SSL *ssl,
                                           const unsigned char **out,
                                           unsigned char *outlen,
                                           const unsigned char *in,
                                           unsigned int inlen,
                                           void *arg);
void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
                                SSL_CTX_alpn_select_cb_func cb,
                                void *arg);
void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
                            unsigned int *len);

# ifndef OPENSSL_NO_PSK
/*
 * the maximum length of the buffer given to callbacks containing the
 * resulting identity/psk
 */
#  define PSK_MAX_IDENTITY_LEN 256
#  define PSK_MAX_PSK_LEN 512
typedef unsigned int (*SSL_psk_client_cb_func)(SSL *ssl,
                                               const char *hint,
                                               char *identity,
                                               unsigned int max_identity_len,
                                               unsigned char *psk,
                                               unsigned int max_psk_len);
void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, SSL_psk_client_cb_func cb);
void SSL_set_psk_client_callback(SSL *ssl, SSL_psk_client_cb_func cb);

typedef unsigned int (*SSL_psk_server_cb_func)(SSL *ssl,
                                               const char *identity,
                                               unsigned char *psk,
                                               unsigned int max_psk_len);
void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, SSL_psk_server_cb_func cb);
void SSL_set_psk_server_callback(SSL *ssl, SSL_psk_server_cb_func cb);

__owur int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint);
__owur int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint);
const char *SSL_get_psk_identity_hint(const SSL *s);
const char *SSL_get_psk_identity(const SSL *s);
# endif

typedef int (*SSL_psk_find_session_cb_func)(SSL *ssl,
                                            const unsigned char *identity,
                                            size_t identity_len,
                                            SSL_SESSION **sess);
typedef int (*SSL_psk_use_session_cb_func)(SSL *ssl, const EVP_MD *md,
                                           const unsigned char **id,
                                           size_t *idlen,
                                           SSL_SESSION **sess);

void SSL_set_psk_find_session_callback(SSL *s, SSL_psk_find_session_cb_func cb);
void SSL_CTX_set_psk_find_session_callback(SSL_CTX *ctx,
                                           SSL_psk_find_session_cb_func cb);
void SSL_set_psk_use_session_callback(SSL *s, SSL_psk_use_session_cb_func cb);
void SSL_CTX_set_psk_use_session_callback(SSL_CTX *ctx,
                                          SSL_psk_use_session_cb_func cb);

/* Register callbacks to handle custom TLS Extensions for client or server. */

__owur int SSL_CTX_has_client_custom_ext(const SSL_CTX *ctx,
                                         unsigned int ext_type);

__owur int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx,
                                         unsigned int ext_type,
                                         custom_ext_add_cb add_cb,
                                         custom_ext_free_cb free_cb,
                                         void *add_arg,
                                         custom_ext_parse_cb parse_cb,
                                         void *parse_arg);

__owur int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx,
                                         unsigned int ext_type,
                                         custom_ext_add_cb add_cb,
                                         custom_ext_free_cb free_cb,
                                         void *add_arg,
                                         custom_ext_parse_cb parse_cb,
                                         void *parse_arg);

__owur int SSL_CTX_add_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
                                  unsigned int context,
                                  SSL_custom_ext_add_cb_ex add_cb,
                                  SSL_custom_ext_free_cb_ex free_cb,
                                  void *add_arg,
                                  SSL_custom_ext_parse_cb_ex parse_cb,
                                  void *parse_arg);

__owur int SSL_extension_supported(unsigned int ext_type);

# define SSL_NOTHING            1
# define SSL_WRITING            2
# define SSL_READING            3
# define SSL_X509_LOOKUP        4
# define SSL_ASYNC_PAUSED       5
# define SSL_ASYNC_NO_JOBS      6
# define SSL_CLIENT_HELLO_CB    7
# define SSL_RETRY_VERIFY       8

/* These will only be used when doing non-blocking IO */
# define SSL_want_nothing(s)         (SSL_want(s) == SSL_NOTHING)
# define SSL_want_read(s)            (SSL_want(s) == SSL_READING)
# define SSL_want_write(s)           (SSL_want(s) == SSL_WRITING)
# define SSL_want_x509_lookup(s)     (SSL_want(s) == SSL_X509_LOOKUP)
# define SSL_want_retry_verify(s)    (SSL_want(s) == SSL_RETRY_VERIFY)
# define SSL_want_async(s)           (SSL_want(s) == SSL_ASYNC_PAUSED)
# define SSL_want_async_job(s)       (SSL_want(s) == SSL_ASYNC_NO_JOBS)
# define SSL_want_client_hello_cb(s) (SSL_want(s) == SSL_CLIENT_HELLO_CB)

# define SSL_MAC_FLAG_READ_MAC_STREAM 1
# define SSL_MAC_FLAG_WRITE_MAC_STREAM 2
# define SSL_MAC_FLAG_READ_MAC_TLSTREE 4
# define SSL_MAC_FLAG_WRITE_MAC_TLSTREE 8

/*
 * A callback for logging out TLS key material. This callback should log out
 * |line| followed by a newline.
 */
typedef void (*SSL_CTX_keylog_cb_func)(const SSL *ssl, const char *line);

/*
 * SSL_CTX_set_keylog_callback configures a callback to log key material. This
 * is intended for debugging use with tools like Wireshark. The cb function
 * should log line followed by a newline.
 */
void SSL_CTX_set_keylog_callback(SSL_CTX *ctx, SSL_CTX_keylog_cb_func cb);

/*
 * SSL_CTX_get_keylog_callback returns the callback configured by
 * SSL_CTX_set_keylog_callback.
 */
SSL_CTX_keylog_cb_func SSL_CTX_get_keylog_callback(const SSL_CTX *ctx);

int SSL_CTX_set_max_early_data(SSL_CTX *ctx, uint32_t max_early_data);
uint32_t SSL_CTX_get_max_early_data(const SSL_CTX *ctx);
int SSL_set_max_early_data(SSL *s, uint32_t max_early_data);
uint32_t SSL_get_max_early_data(const SSL *s);
int SSL_CTX_set_recv_max_early_data(SSL_CTX *ctx, uint32_t recv_max_early_data);
uint32_t SSL_CTX_get_recv_max_early_data(const SSL_CTX *ctx);
int SSL_set_recv_max_early_data(SSL *s, uint32_t recv_max_early_data);
uint32_t SSL_get_recv_max_early_data(const SSL *s);

#ifdef __cplusplus
}
#endif

# include <openssl/ssl2.h>
# include <openssl/ssl3.h>
# include <openssl/tls1.h>      /* This is mostly sslv3 with a few tweaks */
# include <openssl/dtls1.h>     /* Datagram TLS */
# include <openssl/srtp.h>      /* Support for the use_srtp extension */

#ifdef  __cplusplus
extern "C" {
#endif

/*
 * These need to be after the above set of includes due to a compiler bug
 * in VisualStudio 2015
 */
SKM_DEFINE_STACK_OF_INTERNAL(SSL_CIPHER, const SSL_CIPHER, SSL_CIPHER)
#define sk_SSL_CIPHER_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_value(sk, idx) ((const SSL_CIPHER *)OPENSSL_sk_value(ossl_check_const_SSL_CIPHER_sk_type(sk), (idx)))
#define sk_SSL_CIPHER_new(cmp) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new(ossl_check_SSL_CIPHER_compfunc_type(cmp)))
#define sk_SSL_CIPHER_new_null() ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new_null())
#define sk_SSL_CIPHER_new_reserve(cmp, n) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new_reserve(ossl_check_SSL_CIPHER_compfunc_type(cmp), (n)))
#define sk_SSL_CIPHER_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SSL_CIPHER_sk_type(sk), (n))
#define sk_SSL_CIPHER_free(sk) OPENSSL_sk_free(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_zero(sk) OPENSSL_sk_zero(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_delete(sk, i) ((const SSL_CIPHER *)OPENSSL_sk_delete(ossl_check_SSL_CIPHER_sk_type(sk), (i)))
#define sk_SSL_CIPHER_delete_ptr(sk, ptr) ((const SSL_CIPHER *)OPENSSL_sk_delete_ptr(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr)))
#define sk_SSL_CIPHER_push(sk, ptr) OPENSSL_sk_push(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_pop(sk) ((const SSL_CIPHER *)OPENSSL_sk_pop(ossl_check_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_shift(sk) ((const SSL_CIPHER *)OPENSSL_sk_shift(ossl_check_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SSL_CIPHER_sk_type(sk),ossl_check_SSL_CIPHER_freefunc_type(freefunc))
#define sk_SSL_CIPHER_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr), (idx))
#define sk_SSL_CIPHER_set(sk, idx, ptr) ((const SSL_CIPHER *)OPENSSL_sk_set(ossl_check_SSL_CIPHER_sk_type(sk), (idx), ossl_check_SSL_CIPHER_type(ptr)))
#define sk_SSL_CIPHER_find(sk, ptr) OPENSSL_sk_find(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr), pnum)
#define sk_SSL_CIPHER_sort(sk) OPENSSL_sk_sort(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_dup(sk) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_dup(ossl_check_const_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_copyfunc_type(copyfunc), ossl_check_SSL_CIPHER_freefunc_type(freefunc)))
#define sk_SSL_CIPHER_set_cmp_func(sk, cmp) ((sk_SSL_CIPHER_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_compfunc_type(cmp)))
SKM_DEFINE_STACK_OF_INTERNAL(SSL_COMP, SSL_COMP, SSL_COMP)
#define sk_SSL_COMP_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_value(sk, idx) ((SSL_COMP *)OPENSSL_sk_value(ossl_check_const_SSL_COMP_sk_type(sk), (idx)))
#define sk_SSL_COMP_new(cmp) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new(ossl_check_SSL_COMP_compfunc_type(cmp)))
#define sk_SSL_COMP_new_null() ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new_null())
#define sk_SSL_COMP_new_reserve(cmp, n) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new_reserve(ossl_check_SSL_COMP_compfunc_type(cmp), (n)))
#define sk_SSL_COMP_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SSL_COMP_sk_type(sk), (n))
#define sk_SSL_COMP_free(sk) OPENSSL_sk_free(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_zero(sk) OPENSSL_sk_zero(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_delete(sk, i) ((SSL_COMP *)OPENSSL_sk_delete(ossl_check_SSL_COMP_sk_type(sk), (i)))
#define sk_SSL_COMP_delete_ptr(sk, ptr) ((SSL_COMP *)OPENSSL_sk_delete_ptr(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr)))
#define sk_SSL_COMP_push(sk, ptr) OPENSSL_sk_push(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_pop(sk) ((SSL_COMP *)OPENSSL_sk_pop(ossl_check_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_shift(sk) ((SSL_COMP *)OPENSSL_sk_shift(ossl_check_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SSL_COMP_sk_type(sk),ossl_check_SSL_COMP_freefunc_type(freefunc))
#define sk_SSL_COMP_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr), (idx))
#define sk_SSL_COMP_set(sk, idx, ptr) ((SSL_COMP *)OPENSSL_sk_set(ossl_check_SSL_COMP_sk_type(sk), (idx), ossl_check_SSL_COMP_type(ptr)))
#define sk_SSL_COMP_find(sk, ptr) OPENSSL_sk_find(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr), pnum)
#define sk_SSL_COMP_sort(sk) OPENSSL_sk_sort(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_dup(sk) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_dup(ossl_check_const_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_copyfunc_type(copyfunc), ossl_check_SSL_COMP_freefunc_type(freefunc)))
#define sk_SSL_COMP_set_cmp_func(sk, cmp) ((sk_SSL_COMP_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_compfunc_type(cmp)))


/* compatibility */
# define SSL_set_app_data(s,arg)         (SSL_set_ex_data(s,0,(char *)(arg)))
# define SSL_get_app_data(s)             (SSL_get_ex_data(s,0))
# define SSL_SESSION_set_app_data(s,a)   (SSL_SESSION_set_ex_data(s,0, \
                                                                  (char *)(a)))
# define SSL_SESSION_get_app_data(s)     (SSL_SESSION_get_ex_data(s,0))
# define SSL_CTX_get_app_data(ctx)       (SSL_CTX_get_ex_data(ctx,0))
# define SSL_CTX_set_app_data(ctx,arg)   (SSL_CTX_set_ex_data(ctx,0, \
                                                              (char *)(arg)))
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 void SSL_set_debug(SSL *s, int debug);
# endif

/* TLSv1.3 KeyUpdate message types */
/* -1 used so that this is an invalid value for the on-the-wire protocol */
#define SSL_KEY_UPDATE_NONE             -1
/* Values as defined for the on-the-wire protocol */
#define SSL_KEY_UPDATE_NOT_REQUESTED     0
#define SSL_KEY_UPDATE_REQUESTED         1

/*
 * The valid handshake states (one for each type message sent and one for each
 * type of message received). There are also two "special" states:
 * TLS = TLS or DTLS state
 * DTLS = DTLS specific state
 * CR/SR = Client Read/Server Read
 * CW/SW = Client Write/Server Write
 *
 * The "special" states are:
 * TLS_ST_BEFORE = No handshake has been initiated yet
 * TLS_ST_OK = A handshake has been successfully completed
 */
typedef enum {
    TLS_ST_BEFORE,
    TLS_ST_OK,
    DTLS_ST_CR_HELLO_VERIFY_REQUEST,
    TLS_ST_CR_SRVR_HELLO,
    TLS_ST_CR_CERT,
    TLS_ST_CR_CERT_STATUS,
    TLS_ST_CR_KEY_EXCH,
    TLS_ST_CR_CERT_REQ,
    TLS_ST_CR_SRVR_DONE,
    TLS_ST_CR_SESSION_TICKET,
    TLS_ST_CR_CHANGE,
    TLS_ST_CR_FINISHED,
    TLS_ST_CW_CLNT_HELLO,
    TLS_ST_CW_CERT,
    TLS_ST_CW_KEY_EXCH,
    TLS_ST_CW_CERT_VRFY,
    TLS_ST_CW_CHANGE,
    TLS_ST_CW_NEXT_PROTO,
    TLS_ST_CW_FINISHED,
    TLS_ST_SW_HELLO_REQ,
    TLS_ST_SR_CLNT_HELLO,
    DTLS_ST_SW_HELLO_VERIFY_REQUEST,
    TLS_ST_SW_SRVR_HELLO,
    TLS_ST_SW_CERT,
    TLS_ST_SW_KEY_EXCH,
    TLS_ST_SW_CERT_REQ,
    TLS_ST_SW_SRVR_DONE,
    TLS_ST_SR_CERT,
    TLS_ST_SR_KEY_EXCH,
    TLS_ST_SR_CERT_VRFY,
    TLS_ST_SR_NEXT_PROTO,
    TLS_ST_SR_CHANGE,
    TLS_ST_SR_FINISHED,
    TLS_ST_SW_SESSION_TICKET,
    TLS_ST_SW_CERT_STATUS,
    TLS_ST_SW_CHANGE,
    TLS_ST_SW_FINISHED,
    TLS_ST_SW_ENCRYPTED_EXTENSIONS,
    TLS_ST_CR_ENCRYPTED_EXTENSIONS,
    TLS_ST_CR_CERT_VRFY,
    TLS_ST_SW_CERT_VRFY,
    TLS_ST_CR_HELLO_REQ,
    TLS_ST_SW_KEY_UPDATE,
    TLS_ST_CW_KEY_UPDATE,
    TLS_ST_SR_KEY_UPDATE,
    TLS_ST_CR_KEY_UPDATE,
    TLS_ST_EARLY_DATA,
    TLS_ST_PENDING_EARLY_DATA_END,
    TLS_ST_CW_END_OF_EARLY_DATA,
    TLS_ST_SR_END_OF_EARLY_DATA
} OSSL_HANDSHAKE_STATE;

/*
 * Most of the following state values are no longer used and are defined to be
 * the closest equivalent value in the current state machine code. Not all
 * defines have an equivalent and are set to a dummy value (-1). SSL_ST_CONNECT
 * and SSL_ST_ACCEPT are still in use in the definition of SSL_CB_ACCEPT_LOOP,
 * SSL_CB_ACCEPT_EXIT, SSL_CB_CONNECT_LOOP and SSL_CB_CONNECT_EXIT.
 */

# define SSL_ST_CONNECT                  0x1000
# define SSL_ST_ACCEPT                   0x2000

# define SSL_ST_MASK                     0x0FFF

# define SSL_CB_LOOP                     0x01
# define SSL_CB_EXIT                     0x02
# define SSL_CB_READ                     0x04
# define SSL_CB_WRITE                    0x08
# define SSL_CB_ALERT                    0x4000/* used in callback */
# define SSL_CB_READ_ALERT               (SSL_CB_ALERT|SSL_CB_READ)
# define SSL_CB_WRITE_ALERT              (SSL_CB_ALERT|SSL_CB_WRITE)
# define SSL_CB_ACCEPT_LOOP              (SSL_ST_ACCEPT|SSL_CB_LOOP)
# define SSL_CB_ACCEPT_EXIT              (SSL_ST_ACCEPT|SSL_CB_EXIT)
# define SSL_CB_CONNECT_LOOP             (SSL_ST_CONNECT|SSL_CB_LOOP)
# define SSL_CB_CONNECT_EXIT             (SSL_ST_CONNECT|SSL_CB_EXIT)
# define SSL_CB_HANDSHAKE_START          0x10
# define SSL_CB_HANDSHAKE_DONE           0x20

/* Is the SSL_connection established? */
# define SSL_in_connect_init(a)          (SSL_in_init(a) && !SSL_is_server(a))
# define SSL_in_accept_init(a)           (SSL_in_init(a) && SSL_is_server(a))
int SSL_in_init(const SSL *s);
int SSL_in_before(const SSL *s);
int SSL_is_init_finished(const SSL *s);

/*
 * The following 3 states are kept in ssl->rlayer.rstate when reads fail, you
 * should not need these
 */
# define SSL_ST_READ_HEADER                      0xF0
# define SSL_ST_READ_BODY                        0xF1
# define SSL_ST_READ_DONE                        0xF2

/*-
 * Obtain latest Finished message
 *   -- that we sent (SSL_get_finished)
 *   -- that we expected from peer (SSL_get_peer_finished).
 * Returns length (0 == no Finished so far), copies up to 'count' bytes.
 */
size_t SSL_get_finished(const SSL *s, void *buf, size_t count);
size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);

/*
 * use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 3 options are
 * 'ored' with SSL_VERIFY_PEER if they are desired
 */
# define SSL_VERIFY_NONE                 0x00
# define SSL_VERIFY_PEER                 0x01
# define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
# define SSL_VERIFY_CLIENT_ONCE          0x04
# define SSL_VERIFY_POST_HANDSHAKE       0x08

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define OpenSSL_add_ssl_algorithms()   SSL_library_init()
#  define SSLeay_add_ssl_algorithms()    SSL_library_init()
# endif

/* More backward compatibility */
# define SSL_get_cipher(s) \
                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
# define SSL_get_cipher_bits(s,np) \
                SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
# define SSL_get_cipher_version(s) \
                SSL_CIPHER_get_version(SSL_get_current_cipher(s))
# define SSL_get_cipher_name(s) \
                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
# define SSL_get_time(a)         SSL_SESSION_get_time(a)
# define SSL_set_time(a,b)       SSL_SESSION_set_time((a),(b))
# define SSL_get_timeout(a)      SSL_SESSION_get_timeout(a)
# define SSL_set_timeout(a,b)    SSL_SESSION_set_timeout((a),(b))

# define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id)
# define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id)

DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
# define SSL_AD_REASON_OFFSET            1000/* offset to get SSL_R_... value
                                              * from SSL_AD_... */
/* These alert types are for SSLv3 and TLSv1 */
# define SSL_AD_CLOSE_NOTIFY             SSL3_AD_CLOSE_NOTIFY
/* fatal */
# define SSL_AD_UNEXPECTED_MESSAGE       SSL3_AD_UNEXPECTED_MESSAGE
/* fatal */
# define SSL_AD_BAD_RECORD_MAC           SSL3_AD_BAD_RECORD_MAC
# define SSL_AD_DECRYPTION_FAILED        TLS1_AD_DECRYPTION_FAILED
# define SSL_AD_RECORD_OVERFLOW          TLS1_AD_RECORD_OVERFLOW
/* fatal */
# define SSL_AD_DECOMPRESSION_FAILURE    SSL3_AD_DECOMPRESSION_FAILURE
/* fatal */
# define SSL_AD_HANDSHAKE_FAILURE        SSL3_AD_HANDSHAKE_FAILURE
/* Not for TLS */
# define SSL_AD_NO_CERTIFICATE           SSL3_AD_NO_CERTIFICATE
# define SSL_AD_BAD_CERTIFICATE          SSL3_AD_BAD_CERTIFICATE
# define SSL_AD_UNSUPPORTED_CERTIFICATE  SSL3_AD_UNSUPPORTED_CERTIFICATE
# define SSL_AD_CERTIFICATE_REVOKED      SSL3_AD_CERTIFICATE_REVOKED
# define SSL_AD_CERTIFICATE_EXPIRED      SSL3_AD_CERTIFICATE_EXPIRED
# define SSL_AD_CERTIFICATE_UNKNOWN      SSL3_AD_CERTIFICATE_UNKNOWN
/* fatal */
# define SSL_AD_ILLEGAL_PARAMETER        SSL3_AD_ILLEGAL_PARAMETER
/* fatal */
# define SSL_AD_UNKNOWN_CA               TLS1_AD_UNKNOWN_CA
/* fatal */
# define SSL_AD_ACCESS_DENIED            TLS1_AD_ACCESS_DENIED
/* fatal */
# define SSL_AD_DECODE_ERROR             TLS1_AD_DECODE_ERROR
# define SSL_AD_DECRYPT_ERROR            TLS1_AD_DECRYPT_ERROR
/* fatal */
# define SSL_AD_EXPORT_RESTRICTION       TLS1_AD_EXPORT_RESTRICTION
/* fatal */
# define SSL_AD_PROTOCOL_VERSION         TLS1_AD_PROTOCOL_VERSION
/* fatal */
# define SSL_AD_INSUFFICIENT_SECURITY    TLS1_AD_INSUFFICIENT_SECURITY
/* fatal */
# define SSL_AD_INTERNAL_ERROR           TLS1_AD_INTERNAL_ERROR
# define SSL_AD_USER_CANCELLED           TLS1_AD_USER_CANCELLED
# define SSL_AD_NO_RENEGOTIATION         TLS1_AD_NO_RENEGOTIATION
# define SSL_AD_MISSING_EXTENSION        TLS13_AD_MISSING_EXTENSION
# define SSL_AD_CERTIFICATE_REQUIRED     TLS13_AD_CERTIFICATE_REQUIRED
# define SSL_AD_UNSUPPORTED_EXTENSION    TLS1_AD_UNSUPPORTED_EXTENSION
# define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE
# define SSL_AD_UNRECOGNIZED_NAME        TLS1_AD_UNRECOGNIZED_NAME
# define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE
# define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE
/* fatal */
# define SSL_AD_UNKNOWN_PSK_IDENTITY     TLS1_AD_UNKNOWN_PSK_IDENTITY
/* fatal */
# define SSL_AD_INAPPROPRIATE_FALLBACK   TLS1_AD_INAPPROPRIATE_FALLBACK
# define SSL_AD_NO_APPLICATION_PROTOCOL  TLS1_AD_NO_APPLICATION_PROTOCOL
# define SSL_ERROR_NONE                  0
# define SSL_ERROR_SSL                   1
# define SSL_ERROR_WANT_READ             2
# define SSL_ERROR_WANT_WRITE            3
# define SSL_ERROR_WANT_X509_LOOKUP      4
# define SSL_ERROR_SYSCALL               5/* look at error stack/return
                                           * value/errno */
# define SSL_ERROR_ZERO_RETURN           6
# define SSL_ERROR_WANT_CONNECT          7
# define SSL_ERROR_WANT_ACCEPT           8
# define SSL_ERROR_WANT_ASYNC            9
# define SSL_ERROR_WANT_ASYNC_JOB       10
# define SSL_ERROR_WANT_CLIENT_HELLO_CB 11
# define SSL_ERROR_WANT_RETRY_VERIFY    12

# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTRL_SET_TMP_DH                    3
#  define SSL_CTRL_SET_TMP_ECDH                  4
#  define SSL_CTRL_SET_TMP_DH_CB                 6
# endif

# define SSL_CTRL_GET_CLIENT_CERT_REQUEST        9
# define SSL_CTRL_GET_NUM_RENEGOTIATIONS         10
# define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS       11
# define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS       12
# define SSL_CTRL_GET_FLAGS                      13
# define SSL_CTRL_EXTRA_CHAIN_CERT               14
# define SSL_CTRL_SET_MSG_CALLBACK               15
# define SSL_CTRL_SET_MSG_CALLBACK_ARG           16
/* only applies to datagram connections */
# define SSL_CTRL_SET_MTU                17
/* Stats */
# define SSL_CTRL_SESS_NUMBER                    20
# define SSL_CTRL_SESS_CONNECT                   21
# define SSL_CTRL_SESS_CONNECT_GOOD              22
# define SSL_CTRL_SESS_CONNECT_RENEGOTIATE       23
# define SSL_CTRL_SESS_ACCEPT                    24
# define SSL_CTRL_SESS_ACCEPT_GOOD               25
# define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE        26
# define SSL_CTRL_SESS_HIT                       27
# define SSL_CTRL_SESS_CB_HIT                    28
# define SSL_CTRL_SESS_MISSES                    29
# define SSL_CTRL_SESS_TIMEOUTS                  30
# define SSL_CTRL_SESS_CACHE_FULL                31
# define SSL_CTRL_MODE                           33
# define SSL_CTRL_GET_READ_AHEAD                 40
# define SSL_CTRL_SET_READ_AHEAD                 41
# define SSL_CTRL_SET_SESS_CACHE_SIZE            42
# define SSL_CTRL_GET_SESS_CACHE_SIZE            43
# define SSL_CTRL_SET_SESS_CACHE_MODE            44
# define SSL_CTRL_GET_SESS_CACHE_MODE            45
# define SSL_CTRL_GET_MAX_CERT_LIST              50
# define SSL_CTRL_SET_MAX_CERT_LIST              51
# define SSL_CTRL_SET_MAX_SEND_FRAGMENT          52
/* see tls1.h for macros based on these */
# define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB       53
# define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG      54
# define SSL_CTRL_SET_TLSEXT_HOSTNAME            55
# define SSL_CTRL_SET_TLSEXT_DEBUG_CB            56
# define SSL_CTRL_SET_TLSEXT_DEBUG_ARG           57
# define SSL_CTRL_GET_TLSEXT_TICKET_KEYS         58
# define SSL_CTRL_SET_TLSEXT_TICKET_KEYS         59
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT    60 */
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB 61 */
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG 62 */
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB       63
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG   64
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE     65
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS     66
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS     67
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS      68
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS      69
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP        70
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP        71
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB      72
# endif
# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB    75
# define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB                76
# define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB             77
# define SSL_CTRL_SET_SRP_ARG            78
# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME               79
# define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH               80
# define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD               81
# define DTLS_CTRL_GET_TIMEOUT           73
# define DTLS_CTRL_HANDLE_TIMEOUT        74
# define SSL_CTRL_GET_RI_SUPPORT                 76
# define SSL_CTRL_CLEAR_MODE                     78
# define SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB      79
# define SSL_CTRL_GET_EXTRA_CHAIN_CERTS          82
# define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS        83
# define SSL_CTRL_CHAIN                          88
# define SSL_CTRL_CHAIN_CERT                     89
# define SSL_CTRL_GET_GROUPS                     90
# define SSL_CTRL_SET_GROUPS                     91
# define SSL_CTRL_SET_GROUPS_LIST                92
# define SSL_CTRL_GET_SHARED_GROUP               93
# define SSL_CTRL_SET_SIGALGS                    97
# define SSL_CTRL_SET_SIGALGS_LIST               98
# define SSL_CTRL_CERT_FLAGS                     99
# define SSL_CTRL_CLEAR_CERT_FLAGS               100
# define SSL_CTRL_SET_CLIENT_SIGALGS             101
# define SSL_CTRL_SET_CLIENT_SIGALGS_LIST        102
# define SSL_CTRL_GET_CLIENT_CERT_TYPES          103
# define SSL_CTRL_SET_CLIENT_CERT_TYPES          104
# define SSL_CTRL_BUILD_CERT_CHAIN               105
# define SSL_CTRL_SET_VERIFY_CERT_STORE          106
# define SSL_CTRL_SET_CHAIN_CERT_STORE           107
# define SSL_CTRL_GET_PEER_SIGNATURE_NID         108
# define SSL_CTRL_GET_PEER_TMP_KEY               109
# define SSL_CTRL_GET_RAW_CIPHERLIST             110
# define SSL_CTRL_GET_EC_POINT_FORMATS           111
# define SSL_CTRL_GET_CHAIN_CERTS                115
# define SSL_CTRL_SELECT_CURRENT_CERT            116
# define SSL_CTRL_SET_CURRENT_CERT               117
# define SSL_CTRL_SET_DH_AUTO                    118
# define DTLS_CTRL_SET_LINK_MTU                  120
# define DTLS_CTRL_GET_LINK_MIN_MTU              121
# define SSL_CTRL_GET_EXTMS_SUPPORT              122
# define SSL_CTRL_SET_MIN_PROTO_VERSION          123
# define SSL_CTRL_SET_MAX_PROTO_VERSION          124
# define SSL_CTRL_SET_SPLIT_SEND_FRAGMENT        125
# define SSL_CTRL_SET_MAX_PIPELINES              126
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE     127
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB       128
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG   129
# define SSL_CTRL_GET_MIN_PROTO_VERSION          130
# define SSL_CTRL_GET_MAX_PROTO_VERSION          131
# define SSL_CTRL_GET_SIGNATURE_NID              132
# define SSL_CTRL_GET_TMP_KEY                    133
# define SSL_CTRL_GET_NEGOTIATED_GROUP           134
# define SSL_CTRL_SET_RETRY_VERIFY               136
# define SSL_CTRL_GET_VERIFY_CERT_STORE          137
# define SSL_CTRL_GET_CHAIN_CERT_STORE           138
# define SSL_CERT_SET_FIRST                      1
# define SSL_CERT_SET_NEXT                       2
# define SSL_CERT_SET_SERVER                     3
# define DTLSv1_get_timeout(ssl, arg) \
        SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)(arg))
# define DTLSv1_handle_timeout(ssl) \
        SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL)
# define SSL_num_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
# define SSL_clear_num_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
# define SSL_total_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTX_set_tmp_dh(ctx,dh) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
# endif
# define SSL_CTX_set_dh_auto(ctx, onoff) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
# define SSL_set_dh_auto(s, onoff) \
        SSL_ctrl(s,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_set_tmp_dh(ssl,dh) \
        SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
# endif
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
#  define SSL_set_tmp_ecdh(ssl,ecdh) \
        SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
# endif
# define SSL_CTX_add_extra_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)(x509))
# define SSL_CTX_get_extra_chain_certs(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,0,px509)
# define SSL_CTX_get_extra_chain_certs_only(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,1,px509)
# define SSL_CTX_clear_extra_chain_certs(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS,0,NULL)
# define SSL_CTX_set0_chain(ctx,sk) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,0,(char *)(sk))
# define SSL_CTX_set1_chain(ctx,sk) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,1,(char *)(sk))
# define SSL_CTX_add0_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,0,(char *)(x509))
# define SSL_CTX_add1_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,1,(char *)(x509))
# define SSL_CTX_get0_chain_certs(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERTS,0,px509)
# define SSL_CTX_clear_chain_certs(ctx) \
        SSL_CTX_set0_chain(ctx,NULL)
# define SSL_CTX_build_cert_chain(ctx, flags) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL)
# define SSL_CTX_select_current_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509))
# define SSL_CTX_set_current_cert(ctx, op) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CURRENT_CERT, op, NULL)
# define SSL_CTX_set0_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set1_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st))
# define SSL_CTX_get0_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set0_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set1_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st))
# define SSL_CTX_get0_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_set0_chain(s,sk) \
        SSL_ctrl(s,SSL_CTRL_CHAIN,0,(char *)(sk))
# define SSL_set1_chain(s,sk) \
        SSL_ctrl(s,SSL_CTRL_CHAIN,1,(char *)(sk))
# define SSL_add0_chain_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,0,(char *)(x509))
# define SSL_add1_chain_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,1,(char *)(x509))
# define SSL_get0_chain_certs(s,px509) \
        SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERTS,0,px509)
# define SSL_clear_chain_certs(s) \
        SSL_set0_chain(s,NULL)
# define SSL_build_cert_chain(s, flags) \
        SSL_ctrl(s,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL)
# define SSL_select_current_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509))
# define SSL_set_current_cert(s,op) \
        SSL_ctrl(s,SSL_CTRL_SET_CURRENT_CERT, op, NULL)
# define SSL_set0_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_set1_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st))
#define SSL_get0_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_set0_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_set1_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st))
#define SSL_get0_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st))

# define SSL_get1_groups(s, glist) \
        SSL_ctrl(s,SSL_CTRL_GET_GROUPS,0,(int*)(glist))
# define SSL_CTX_set1_groups(ctx, glist, glistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS,glistlen,(int *)(glist))
# define SSL_CTX_set1_groups_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(s))
# define SSL_set1_groups(s, glist, glistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_GROUPS,glistlen,(char *)(glist))
# define SSL_set1_groups_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(str))
# define SSL_get_shared_group(s, n) \
        SSL_ctrl(s,SSL_CTRL_GET_SHARED_GROUP,n,NULL)
# define SSL_get_negotiated_group(s) \
        SSL_ctrl(s,SSL_CTRL_GET_NEGOTIATED_GROUP,0,NULL)
# define SSL_CTX_set1_sigalgs(ctx, slist, slistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist))
# define SSL_CTX_set1_sigalgs_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(s))
# define SSL_set1_sigalgs(s, slist, slistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist))
# define SSL_set1_sigalgs_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(str))
# define SSL_CTX_set1_client_sigalgs(ctx, slist, slistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist))
# define SSL_CTX_set1_client_sigalgs_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(s))
# define SSL_set1_client_sigalgs(s, slist, slistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist))
# define SSL_set1_client_sigalgs_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(str))
# define SSL_get0_certificate_types(s, clist) \
        SSL_ctrl(s, SSL_CTRL_GET_CLIENT_CERT_TYPES, 0, (char *)(clist))
# define SSL_CTX_set1_client_certificate_types(ctx, clist, clistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen, \
                     (char *)(clist))
# define SSL_set1_client_certificate_types(s, clist, clistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen,(char *)(clist))
# define SSL_get_signature_nid(s, pn) \
        SSL_ctrl(s,SSL_CTRL_GET_SIGNATURE_NID,0,pn)
# define SSL_get_peer_signature_nid(s, pn) \
        SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NID,0,pn)
# define SSL_get_peer_tmp_key(s, pk) \
        SSL_ctrl(s,SSL_CTRL_GET_PEER_TMP_KEY,0,pk)
# define SSL_get_tmp_key(s, pk) \
        SSL_ctrl(s,SSL_CTRL_GET_TMP_KEY,0,pk)
# define SSL_get0_raw_cipherlist(s, plst) \
        SSL_ctrl(s,SSL_CTRL_GET_RAW_CIPHERLIST,0,plst)
# define SSL_get0_ec_point_formats(s, plst) \
        SSL_ctrl(s,SSL_CTRL_GET_EC_POINT_FORMATS,0,plst)
# define SSL_CTX_set_min_proto_version(ctx, version) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
# define SSL_CTX_set_max_proto_version(ctx, version) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
# define SSL_CTX_get_min_proto_version(ctx) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL)
# define SSL_CTX_get_max_proto_version(ctx) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL)
# define SSL_set_min_proto_version(s, version) \
        SSL_ctrl(s, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
# define SSL_set_max_proto_version(s, version) \
        SSL_ctrl(s, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
# define SSL_get_min_proto_version(s) \
        SSL_ctrl(s, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL)
# define SSL_get_max_proto_version(s) \
        SSL_ctrl(s, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL)

const char *SSL_group_to_name(SSL *s, int id);

/* Backwards compatibility, original 1.1.0 names */
# define SSL_CTRL_GET_SERVER_TMP_KEY \
         SSL_CTRL_GET_PEER_TMP_KEY
# define SSL_get_server_tmp_key(s, pk) \
         SSL_get_peer_tmp_key(s, pk)

int SSL_set0_tmp_dh_pkey(SSL *s, EVP_PKEY *dhpkey);
int SSL_CTX_set0_tmp_dh_pkey(SSL_CTX *ctx, EVP_PKEY *dhpkey);

/*
 * The following symbol names are old and obsolete. They are kept
 * for compatibility reasons only and should not be used anymore.
 */
# define SSL_CTRL_GET_CURVES           SSL_CTRL_GET_GROUPS
# define SSL_CTRL_SET_CURVES           SSL_CTRL_SET_GROUPS
# define SSL_CTRL_SET_CURVES_LIST      SSL_CTRL_SET_GROUPS_LIST
# define SSL_CTRL_GET_SHARED_CURVE     SSL_CTRL_GET_SHARED_GROUP

# define SSL_get1_curves               SSL_get1_groups
# define SSL_CTX_set1_curves           SSL_CTX_set1_groups
# define SSL_CTX_set1_curves_list      SSL_CTX_set1_groups_list
# define SSL_set1_curves               SSL_set1_groups
# define SSL_set1_curves_list          SSL_set1_groups_list
# define SSL_get_shared_curve          SSL_get_shared_group


# ifndef OPENSSL_NO_DEPRECATED_1_1_0
/* Provide some compatibility macros for removed functionality. */
#  define SSL_CTX_need_tmp_RSA(ctx)                0
#  define SSL_CTX_set_tmp_rsa(ctx,rsa)             1
#  define SSL_need_tmp_RSA(ssl)                    0
#  define SSL_set_tmp_rsa(ssl,rsa)                 1
#  define SSL_CTX_set_ecdh_auto(dummy, onoff)      ((onoff) != 0)
#  define SSL_set_ecdh_auto(dummy, onoff)          ((onoff) != 0)
/*
 * We "pretend" to call the callback to avoid warnings about unused static
 * functions.
 */
#  define SSL_CTX_set_tmp_rsa_callback(ctx, cb)    while(0) (cb)(NULL, 0, 0)
#  define SSL_set_tmp_rsa_callback(ssl, cb)        while(0) (cb)(NULL, 0, 0)
# endif
__owur const BIO_METHOD *BIO_f_ssl(void);
__owur BIO *BIO_new_ssl(SSL_CTX *ctx, int client);
__owur BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
__owur BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
__owur int BIO_ssl_copy_session_id(BIO *to, BIO *from);
void BIO_ssl_shutdown(BIO *ssl_bio);

__owur int SSL_CTX_set_cipher_list(SSL_CTX *, const char *str);
__owur SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);
__owur SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq,
                               const SSL_METHOD *meth);
int SSL_CTX_up_ref(SSL_CTX *ctx);
void SSL_CTX_free(SSL_CTX *);
__owur long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
__owur long SSL_CTX_get_timeout(const SSL_CTX *ctx);
__owur X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *);
void SSL_CTX_set_cert_store(SSL_CTX *, X509_STORE *);
void SSL_CTX_set1_cert_store(SSL_CTX *, X509_STORE *);
__owur int SSL_want(const SSL *s);
__owur int SSL_clear(SSL *s);

void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm);

__owur const SSL_CIPHER *SSL_get_current_cipher(const SSL *s);
__owur const SSL_CIPHER *SSL_get_pending_cipher(const SSL *s);
__owur int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits);
__owur const char *SSL_CIPHER_get_version(const SSL_CIPHER *c);
__owur const char *SSL_CIPHER_get_name(const SSL_CIPHER *c);
__owur const char *SSL_CIPHER_standard_name(const SSL_CIPHER *c);
__owur const char *OPENSSL_cipher_name(const char *rfc_name);
__owur uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *c);
__owur uint16_t SSL_CIPHER_get_protocol_id(const SSL_CIPHER *c);
__owur int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *c);
__owur int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *c);
__owur const EVP_MD *SSL_CIPHER_get_handshake_digest(const SSL_CIPHER *c);
__owur int SSL_CIPHER_is_aead(const SSL_CIPHER *c);

__owur int SSL_get_fd(const SSL *s);
__owur int SSL_get_rfd(const SSL *s);
__owur int SSL_get_wfd(const SSL *s);
__owur const char *SSL_get_cipher_list(const SSL *s, int n);
__owur char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size);
__owur int SSL_get_read_ahead(const SSL *s);
__owur int SSL_pending(const SSL *s);
__owur int SSL_has_pending(const SSL *s);
# ifndef OPENSSL_NO_SOCK
__owur int SSL_set_fd(SSL *s, int fd);
__owur int SSL_set_rfd(SSL *s, int fd);
__owur int SSL_set_wfd(SSL *s, int fd);
# endif
void SSL_set0_rbio(SSL *s, BIO *rbio);
void SSL_set0_wbio(SSL *s, BIO *wbio);
void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio);
__owur BIO *SSL_get_rbio(const SSL *s);
__owur BIO *SSL_get_wbio(const SSL *s);
__owur int SSL_set_cipher_list(SSL *s, const char *str);
__owur int SSL_CTX_set_ciphersuites(SSL_CTX *ctx, const char *str);
__owur int SSL_set_ciphersuites(SSL *s, const char *str);
void SSL_set_read_ahead(SSL *s, int yes);
__owur int SSL_get_verify_mode(const SSL *s);
__owur int SSL_get_verify_depth(const SSL *s);
__owur SSL_verify_cb SSL_get_verify_callback(const SSL *s);
void SSL_set_verify(SSL *s, int mode, SSL_verify_cb callback);
void SSL_set_verify_depth(SSL *s, int depth);
void SSL_set_cert_cb(SSL *s, int (*cb) (SSL *ssl, void *arg), void *arg);
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 __owur int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
OSSL_DEPRECATEDIN_3_0
__owur int SSL_use_RSAPrivateKey_ASN1(SSL *ssl,
                                      const unsigned char *d, long len);
# endif
__owur int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
__owur int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d,
                                   long len);
__owur int SSL_use_certificate(SSL *ssl, X509 *x);
__owur int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
__owur int SSL_use_cert_and_key(SSL *ssl, X509 *x509, EVP_PKEY *privatekey,
                                STACK_OF(X509) *chain, int override);


/* serverinfo file format versions */
# define SSL_SERVERINFOV1   1
# define SSL_SERVERINFOV2   2

/* Set serverinfo data for the current active cert. */
__owur int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo,
                                  size_t serverinfo_length);
__owur int SSL_CTX_use_serverinfo_ex(SSL_CTX *ctx, unsigned int version,
                                     const unsigned char *serverinfo,
                                     size_t serverinfo_length);
__owur int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file);

#ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
#endif

__owur int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
__owur int SSL_use_certificate_file(SSL *ssl, const char *file, int type);

#ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file,
                                          int type);
#endif
__owur int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file,
                                       int type);
__owur int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file,
                                        int type);
/* PEM type */
__owur int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
__owur int SSL_use_certificate_chain_file(SSL *ssl, const char *file);
__owur STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
__owur STACK_OF(X509_NAME)
*SSL_load_client_CA_file_ex(const char *file, OSSL_LIB_CTX *libctx,
                            const char *propq);
__owur int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                               const char *file);
int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                       const char *dir);
int SSL_add_store_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                       const char *uri);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_load_error_strings() \
    OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS \
                     | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL)
# endif

__owur const char *SSL_state_string(const SSL *s);
__owur const char *SSL_rstate_string(const SSL *s);
__owur const char *SSL_state_string_long(const SSL *s);
__owur const char *SSL_rstate_string_long(const SSL *s);
__owur long SSL_SESSION_get_time(const SSL_SESSION *s);
__owur long SSL_SESSION_set_time(SSL_SESSION *s, long t);
__owur long SSL_SESSION_get_timeout(const SSL_SESSION *s);
__owur long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
__owur int SSL_SESSION_get_protocol_version(const SSL_SESSION *s);
__owur int SSL_SESSION_set_protocol_version(SSL_SESSION *s, int version);

__owur const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s);
__owur int SSL_SESSION_set1_hostname(SSL_SESSION *s, const char *hostname);
void SSL_SESSION_get0_alpn_selected(const SSL_SESSION *s,
                                    const unsigned char **alpn,
                                    size_t *len);
__owur int SSL_SESSION_set1_alpn_selected(SSL_SESSION *s,
                                          const unsigned char *alpn,
                                          size_t len);
__owur const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s);
__owur int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher);
__owur int SSL_SESSION_has_ticket(const SSL_SESSION *s);
__owur unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s);
void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick,
                             size_t *len);
__owur uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s);
__owur int SSL_SESSION_set_max_early_data(SSL_SESSION *s,
                                          uint32_t max_early_data);
__owur int SSL_copy_session_id(SSL *to, const SSL *from);
__owur X509 *SSL_SESSION_get0_peer(SSL_SESSION *s);
__owur int SSL_SESSION_set1_id_context(SSL_SESSION *s,
                                       const unsigned char *sid_ctx,
                                       unsigned int sid_ctx_len);
__owur int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid,
                               unsigned int sid_len);
__owur int SSL_SESSION_is_resumable(const SSL_SESSION *s);

__owur SSL_SESSION *SSL_SESSION_new(void);
__owur SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src);
const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s,
                                        unsigned int *len);
const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s,
                                                 unsigned int *len);
__owur unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s);
# ifndef OPENSSL_NO_STDIO
int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *ses);
# endif
int SSL_SESSION_print(BIO *fp, const SSL_SESSION *ses);
int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x);
int SSL_SESSION_up_ref(SSL_SESSION *ses);
void SSL_SESSION_free(SSL_SESSION *ses);
__owur int i2d_SSL_SESSION(const SSL_SESSION *in, unsigned char **pp);
__owur int SSL_set_session(SSL *to, SSL_SESSION *session);
int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *session);
int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *session);
__owur int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb);
__owur int SSL_set_generate_session_id(SSL *s, GEN_SESSION_CB cb);
__owur int SSL_has_matching_session_id(const SSL *s,
                                       const unsigned char *id,
                                       unsigned int id_len);
SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
                             long length);

# ifdef OPENSSL_X509_H
__owur X509 *SSL_get0_peer_certificate(const SSL *s);
__owur X509 *SSL_get1_peer_certificate(const SSL *s);
/* Deprecated in 3.0.0 */
#  ifndef OPENSSL_NO_DEPRECATED_3_0
#   define SSL_get_peer_certificate SSL_get1_peer_certificate
#  endif
# endif

__owur STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s);

__owur int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
__owur int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
__owur SSL_verify_cb SSL_CTX_get_verify_callback(const SSL_CTX *ctx);
void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, SSL_verify_cb callback);
void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,
                                      int (*cb) (X509_STORE_CTX *, void *),
                                      void *arg);
void SSL_CTX_set_cert_cb(SSL_CTX *c, int (*cb) (SSL *ssl, void *arg),
                         void *arg);
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d,
                                          long len);
# endif
__owur int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
__owur int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx,
                                       const unsigned char *d, long len);
__owur int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
__owur int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len,
                                        const unsigned char *d);
__owur int SSL_CTX_use_cert_and_key(SSL_CTX *ctx, X509 *x509, EVP_PKEY *privatekey,
                                    STACK_OF(X509) *chain, int override);

void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx);
void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx);
void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb);
void SSL_set_default_passwd_cb_userdata(SSL *s, void *u);
pem_password_cb *SSL_get_default_passwd_cb(SSL *s);
void *SSL_get_default_passwd_cb_userdata(SSL *s);

__owur int SSL_CTX_check_private_key(const SSL_CTX *ctx);
__owur int SSL_check_private_key(const SSL *ctx);

__owur int SSL_CTX_set_session_id_context(SSL_CTX *ctx,
                                          const unsigned char *sid_ctx,
                                          unsigned int sid_ctx_len);

SSL *SSL_new(SSL_CTX *ctx);
int SSL_up_ref(SSL *s);
int SSL_is_dtls(const SSL *s);
__owur int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx,
                                      unsigned int sid_ctx_len);

__owur int SSL_CTX_set_purpose(SSL_CTX *ctx, int purpose);
__owur int SSL_set_purpose(SSL *ssl, int purpose);
__owur int SSL_CTX_set_trust(SSL_CTX *ctx, int trust);
__owur int SSL_set_trust(SSL *ssl, int trust);

__owur int SSL_set1_host(SSL *s, const char *hostname);
__owur int SSL_add1_host(SSL *s, const char *hostname);
__owur const char *SSL_get0_peername(SSL *s);
void SSL_set_hostflags(SSL *s, unsigned int flags);

__owur int SSL_CTX_dane_enable(SSL_CTX *ctx);
__owur int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md,
                                  uint8_t mtype, uint8_t ord);
__owur int SSL_dane_enable(SSL *s, const char *basedomain);
__owur int SSL_dane_tlsa_add(SSL *s, uint8_t usage, uint8_t selector,
                             uint8_t mtype, const unsigned char *data, size_t dlen);
__owur int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki);
__owur int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector,
                              uint8_t *mtype, const unsigned char **data,
                              size_t *dlen);
/*
 * Bridge opacity barrier between libcrypt and libssl, also needed to support
 * offline testing in test/danetest.c
 */
SSL_DANE *SSL_get0_dane(SSL *ssl);
/*
 * DANE flags
 */
unsigned long SSL_CTX_dane_set_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_CTX_dane_clear_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_dane_set_flags(SSL *ssl, unsigned long flags);
unsigned long SSL_dane_clear_flags(SSL *ssl, unsigned long flags);

__owur int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
__owur int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm);

__owur X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx);
__owur X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl);

# ifndef OPENSSL_NO_SRP
#  ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength);
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx,
                                        char *(*cb) (SSL *, void *));
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx,
                                          int (*cb) (SSL *, void *));
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx,
                                      int (*cb) (SSL *, int *, void *));
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg);

OSSL_DEPRECATEDIN_3_0
int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g,
                             BIGNUM *sa, BIGNUM *v, char *info);
OSSL_DEPRECATEDIN_3_0
int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass,
                                const char *grp);

OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_g(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_N(SSL *s);

OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_username(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_userinfo(SSL *s);
#  endif
# endif

/*
 * ClientHello callback and helpers.
 */

# define SSL_CLIENT_HELLO_SUCCESS 1
# define SSL_CLIENT_HELLO_ERROR   0
# define SSL_CLIENT_HELLO_RETRY   (-1)

typedef int (*SSL_client_hello_cb_fn) (SSL *s, int *al, void *arg);
void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_fn cb,
                                 void *arg);
int SSL_client_hello_isv2(SSL *s);
unsigned int SSL_client_hello_get0_legacy_version(SSL *s);
size_t SSL_client_hello_get0_random(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_session_id(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_compression_methods(SSL *s,
                                                 const unsigned char **out);
int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen);
int SSL_client_hello_get0_ext(SSL *s, unsigned int type,
                              const unsigned char **out, size_t *outlen);

void SSL_certs_clear(SSL *s);
void SSL_free(SSL *ssl);
# ifdef OSSL_ASYNC_FD
/*
 * Windows application developer has to include windows.h to use these.
 */
__owur int SSL_waiting_for_async(SSL *s);
__owur int SSL_get_all_async_fds(SSL *s, OSSL_ASYNC_FD *fds, size_t *numfds);
__owur int SSL_get_changed_async_fds(SSL *s, OSSL_ASYNC_FD *addfd,
                                     size_t *numaddfds, OSSL_ASYNC_FD *delfd,
                                     size_t *numdelfds);
__owur int SSL_CTX_set_async_callback(SSL_CTX *ctx, SSL_async_callback_fn callback);
__owur int SSL_CTX_set_async_callback_arg(SSL_CTX *ctx, void *arg);
__owur int SSL_set_async_callback(SSL *s, SSL_async_callback_fn callback);
__owur int SSL_set_async_callback_arg(SSL *s, void *arg);
__owur int SSL_get_async_status(SSL *s, int *status);

# endif
__owur int SSL_accept(SSL *ssl);
__owur int SSL_stateless(SSL *s);
__owur int SSL_connect(SSL *ssl);
__owur int SSL_read(SSL *ssl, void *buf, int num);
__owur int SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);

# define SSL_READ_EARLY_DATA_ERROR   0
# define SSL_READ_EARLY_DATA_SUCCESS 1
# define SSL_READ_EARLY_DATA_FINISH  2

__owur int SSL_read_early_data(SSL *s, void *buf, size_t num,
                               size_t *readbytes);
__owur int SSL_peek(SSL *ssl, void *buf, int num);
__owur int SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);
__owur ossl_ssize_t SSL_sendfile(SSL *s, int fd, off_t offset, size_t size,
                                 int flags);
__owur int SSL_write(SSL *ssl, const void *buf, int num);
__owur int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
__owur int SSL_write_early_data(SSL *s, const void *buf, size_t num,
                                size_t *written);
long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg);
long SSL_callback_ctrl(SSL *, int, void (*)(void));
long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void));

# define SSL_EARLY_DATA_NOT_SENT    0
# define SSL_EARLY_DATA_REJECTED    1
# define SSL_EARLY_DATA_ACCEPTED    2

__owur int SSL_get_early_data_status(const SSL *s);

__owur int SSL_get_error(const SSL *s, int ret_code);
__owur const char *SSL_get_version(const SSL *s);

/* This sets the 'default' SSL version that SSL_new() will create */
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
# endif

# ifndef OPENSSL_NO_SSL3_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_method(void); /* SSLv3 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_client_method(void);
#  endif
# endif

#define SSLv23_method           TLS_method
#define SSLv23_server_method    TLS_server_method
#define SSLv23_client_method    TLS_client_method

/* Negotiate highest available SSL/TLS version */
__owur const SSL_METHOD *TLS_method(void);
__owur const SSL_METHOD *TLS_server_method(void);
__owur const SSL_METHOD *TLS_client_method(void);

# ifndef OPENSSL_NO_TLS1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_TLS1_1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_method(void); /* TLSv1.1 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_TLS1_2_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_method(void); /* TLSv1.2 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_DTLS1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_method(void); /* DTLSv1.0 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_DTLS1_2_METHOD
/* DTLSv1.2 */
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_client_method(void);
#  endif
# endif

__owur const SSL_METHOD *DTLS_method(void); /* DTLS 1.0 and 1.2 */
__owur const SSL_METHOD *DTLS_server_method(void); /* DTLS 1.0 and 1.2 */
__owur const SSL_METHOD *DTLS_client_method(void); /* DTLS 1.0 and 1.2 */

__owur size_t DTLS_get_data_mtu(const SSL *s);

__owur STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s);
__owur STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx);
__owur STACK_OF(SSL_CIPHER) *SSL_get_client_ciphers(const SSL *s);
__owur STACK_OF(SSL_CIPHER) *SSL_get1_supported_ciphers(SSL *s);

__owur int SSL_do_handshake(SSL *s);
int SSL_key_update(SSL *s, int updatetype);
int SSL_get_key_update_type(const SSL *s);
int SSL_renegotiate(SSL *s);
int SSL_renegotiate_abbreviated(SSL *s);
__owur int SSL_renegotiate_pending(const SSL *s);
int SSL_new_session_ticket(SSL *s);
int SSL_shutdown(SSL *s);
__owur int SSL_verify_client_post_handshake(SSL *s);
void SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val);
void SSL_set_post_handshake_auth(SSL *s, int val);

__owur const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx);
__owur const SSL_METHOD *SSL_get_ssl_method(const SSL *s);
__owur int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method);
__owur const char *SSL_alert_type_string_long(int value);
__owur const char *SSL_alert_type_string(int value);
__owur const char *SSL_alert_desc_string_long(int value);
__owur const char *SSL_alert_desc_string(int value);

void SSL_set0_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
void SSL_CTX_set0_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
__owur const STACK_OF(X509_NAME) *SSL_get0_CA_list(const SSL *s);
__owur const STACK_OF(X509_NAME) *SSL_CTX_get0_CA_list(const SSL_CTX *ctx);
__owur int SSL_add1_to_CA_list(SSL *ssl, const X509 *x);
__owur int SSL_CTX_add1_to_CA_list(SSL_CTX *ctx, const X509 *x);
__owur const STACK_OF(X509_NAME) *SSL_get0_peer_CA_list(const SSL *s);

void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
__owur STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s);
__owur STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s);
__owur int SSL_add_client_CA(SSL *ssl, X509 *x);
__owur int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);

void SSL_set_connect_state(SSL *s);
void SSL_set_accept_state(SSL *s);

__owur long SSL_get_default_timeout(const SSL *s);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_library_init() OPENSSL_init_ssl(0, NULL)
# endif

__owur char *SSL_CIPHER_description(const SSL_CIPHER *, char *buf, int size);
__owur STACK_OF(X509_NAME) *SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk);

__owur SSL *SSL_dup(SSL *ssl);

__owur X509 *SSL_get_certificate(const SSL *ssl);
/*
 * EVP_PKEY
 */
struct evp_pkey_st *SSL_get_privatekey(const SSL *ssl);

__owur X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx);
__owur EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx);

void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode);
__owur int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
void SSL_set_quiet_shutdown(SSL *ssl, int mode);
__owur int SSL_get_quiet_shutdown(const SSL *ssl);
void SSL_set_shutdown(SSL *ssl, int mode);
__owur int SSL_get_shutdown(const SSL *ssl);
__owur int SSL_version(const SSL *ssl);
__owur int SSL_client_version(const SSL *s);
__owur int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_store(SSL_CTX *ctx);
__owur int SSL_CTX_load_verify_file(SSL_CTX *ctx, const char *CAfile);
__owur int SSL_CTX_load_verify_dir(SSL_CTX *ctx, const char *CApath);
__owur int SSL_CTX_load_verify_store(SSL_CTX *ctx, const char *CAstore);
__owur int SSL_CTX_load_verify_locations(SSL_CTX *ctx,
                                                        const char *CAfile,
                                                        const char *CApath);
# define SSL_get0_session SSL_get_session/* just peek at pointer */
__owur SSL_SESSION *SSL_get_session(const SSL *ssl);
__owur SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
__owur SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx);
void SSL_set_info_callback(SSL *ssl,
                           void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type,
                                               int val);
__owur OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl);

void SSL_set_verify_result(SSL *ssl, long v);
__owur long SSL_get_verify_result(const SSL *ssl);
__owur STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s);

__owur size_t SSL_get_client_random(const SSL *ssl, unsigned char *out,
                                    size_t outlen);
__owur size_t SSL_get_server_random(const SSL *ssl, unsigned char *out,
                                    size_t outlen);
__owur size_t SSL_SESSION_get_master_key(const SSL_SESSION *sess,
                                         unsigned char *out, size_t outlen);
__owur int SSL_SESSION_set1_master_key(SSL_SESSION *sess,
                                       const unsigned char *in, size_t len);
uint8_t SSL_SESSION_get_max_fragment_length(const SSL_SESSION *sess);

#define SSL_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, l, p, newf, dupf, freef)
__owur int SSL_set_ex_data(SSL *ssl, int idx, void *data);
void *SSL_get_ex_data(const SSL *ssl, int idx);
#define SSL_SESSION_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, l, p, newf, dupf, freef)
__owur int SSL_SESSION_set_ex_data(SSL_SESSION *ss, int idx, void *data);
void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss, int idx);
#define SSL_CTX_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, l, p, newf, dupf, freef)
__owur int SSL_CTX_set_ex_data(SSL_CTX *ssl, int idx, void *data);
void *SSL_CTX_get_ex_data(const SSL_CTX *ssl, int idx);

__owur int SSL_get_ex_data_X509_STORE_CTX_idx(void);

# define SSL_CTX_sess_set_cache_size(ctx,t) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
# define SSL_CTX_sess_get_cache_size(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
# define SSL_CTX_set_session_cache_mode(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
# define SSL_CTX_get_session_cache_mode(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)

# define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
# define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
# define SSL_CTX_get_read_ahead(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
# define SSL_CTX_set_read_ahead(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL)
# define SSL_CTX_get_max_cert_list(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
# define SSL_CTX_set_max_cert_list(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
# define SSL_get_max_cert_list(ssl) \
        SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
# define SSL_set_max_cert_list(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)

# define SSL_CTX_set_max_send_fragment(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
# define SSL_set_max_send_fragment(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
# define SSL_CTX_set_split_send_fragment(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL)
# define SSL_set_split_send_fragment(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL)
# define SSL_CTX_set_max_pipelines(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
# define SSL_set_max_pipelines(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
# define SSL_set_retry_verify(ssl) \
        (SSL_ctrl(ssl,SSL_CTRL_SET_RETRY_VERIFY,0,NULL) > 0)

void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len);
void SSL_set_default_read_buffer_len(SSL *s, size_t len);

# ifndef OPENSSL_NO_DH
#  ifndef OPENSSL_NO_DEPRECATED_3_0
/* NB: the |keylength| is only applicable when is_export is true */
OSSL_DEPRECATEDIN_3_0
void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
                                 DH *(*dh) (SSL *ssl, int is_export,
                                            int keylength));
OSSL_DEPRECATEDIN_3_0
void SSL_set_tmp_dh_callback(SSL *ssl,
                             DH *(*dh) (SSL *ssl, int is_export,
                                        int keylength));
#  endif
# endif

__owur const COMP_METHOD *SSL_get_current_compression(const SSL *s);
__owur const COMP_METHOD *SSL_get_current_expansion(const SSL *s);
__owur const char *SSL_COMP_get_name(const COMP_METHOD *comp);
__owur const char *SSL_COMP_get0_name(const SSL_COMP *comp);
__owur int SSL_COMP_get_id(const SSL_COMP *comp);
STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
__owur STACK_OF(SSL_COMP) *SSL_COMP_set0_compression_methods(STACK_OF(SSL_COMP)
                                                             *meths);
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_COMP_free_compression_methods() while(0) continue
# endif
__owur int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm);

const SSL_CIPHER *SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr);
int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c);
int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c);
int SSL_bytes_to_cipher_list(SSL *s, const unsigned char *bytes, size_t len,
                             int isv2format, STACK_OF(SSL_CIPHER) **sk,
                             STACK_OF(SSL_CIPHER) **scsvs);

/* TLS extensions functions */
__owur int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);

__owur int SSL_set_session_ticket_ext_cb(SSL *s,
                                         tls_session_ticket_ext_cb_fn cb,
                                         void *arg);

/* Pre-shared secret session resumption functions */
__owur int SSL_set_session_secret_cb(SSL *s,
                                     tls_session_secret_cb_fn session_secret_cb,
                                     void *arg);

void SSL_CTX_set_not_resumable_session_callback(SSL_CTX *ctx,
                                                int (*cb) (SSL *ssl,
                                                           int
                                                           is_forward_secure));

void SSL_set_not_resumable_session_callback(SSL *ssl,
                                            int (*cb) (SSL *ssl,
                                                       int is_forward_secure));

void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx,
                                         size_t (*cb) (SSL *ssl, int type,
                                                       size_t len, void *arg));
void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg);
void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx);
int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size);

int SSL_set_record_padding_callback(SSL *ssl,
                                    size_t (*cb) (SSL *ssl, int type,
                                                  size_t len, void *arg));
void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg);
void *SSL_get_record_padding_callback_arg(const SSL *ssl);
int SSL_set_block_padding(SSL *ssl, size_t block_size);

int SSL_set_num_tickets(SSL *s, size_t num_tickets);
size_t SSL_get_num_tickets(const SSL *s);
int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets);
size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_cache_hit(s) SSL_session_reused(s)
# endif

__owur int SSL_session_reused(const SSL *s);
__owur int SSL_is_server(const SSL *s);

__owur __owur SSL_CONF_CTX *SSL_CONF_CTX_new(void);
int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx);
void SSL_CONF_CTX_free(SSL_CONF_CTX *cctx);
unsigned int SSL_CONF_CTX_set_flags(SSL_CONF_CTX *cctx, unsigned int flags);
__owur unsigned int SSL_CONF_CTX_clear_flags(SSL_CONF_CTX *cctx,
                                             unsigned int flags);
__owur int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre);

void SSL_CONF_CTX_set_ssl(SSL_CONF_CTX *cctx, SSL *ssl);
void SSL_CONF_CTX_set_ssl_ctx(SSL_CONF_CTX *cctx, SSL_CTX *ctx);

__owur int SSL_CONF_cmd(SSL_CONF_CTX *cctx, const char *cmd, const char *value);
__owur int SSL_CONF_cmd_argv(SSL_CONF_CTX *cctx, int *pargc, char ***pargv);
__owur int SSL_CONF_cmd_value_type(SSL_CONF_CTX *cctx, const char *cmd);

void SSL_add_ssl_module(void);
int SSL_config(SSL *s, const char *name);
int SSL_CTX_config(SSL_CTX *ctx, const char *name);

# ifndef OPENSSL_NO_SSL_TRACE
void SSL_trace(int write_p, int version, int content_type,
               const void *buf, size_t len, SSL *ssl, void *arg);
# endif

# ifndef OPENSSL_NO_SOCK
int DTLSv1_listen(SSL *s, BIO_ADDR *client);
# endif

# ifndef OPENSSL_NO_CT

/*
 * A callback for verifying that the received SCTs are sufficient.
 * Expected to return 1 if they are sufficient, otherwise 0.
 * May return a negative integer if an error occurs.
 * A connection should be aborted if the SCTs are deemed insufficient.
 */
typedef int (*ssl_ct_validation_cb)(const CT_POLICY_EVAL_CTX *ctx,
                                    const STACK_OF(SCT) *scts, void *arg);

/*
 * Sets a |callback| that is invoked upon receipt of ServerHelloDone to validate
 * the received SCTs.
 * If the callback returns a non-positive result, the connection is terminated.
 * Call this function before beginning a handshake.
 * If a NULL |callback| is provided, SCT validation is disabled.
 * |arg| is arbitrary userdata that will be passed to the callback whenever it
 * is invoked. Ownership of |arg| remains with the caller.
 *
 * NOTE: A side-effect of setting a CT callback is that an OCSP stapled response
 *       will be requested.
 */
int SSL_set_ct_validation_callback(SSL *s, ssl_ct_validation_cb callback,
                                   void *arg);
int SSL_CTX_set_ct_validation_callback(SSL_CTX *ctx,
                                       ssl_ct_validation_cb callback,
                                       void *arg);
#define SSL_disable_ct(s) \
        ((void) SSL_set_validation_callback((s), NULL, NULL))
#define SSL_CTX_disable_ct(ctx) \
        ((void) SSL_CTX_set_validation_callback((ctx), NULL, NULL))

/*
 * The validation type enumerates the available behaviours of the built-in SSL
 * CT validation callback selected via SSL_enable_ct() and SSL_CTX_enable_ct().
 * The underlying callback is a static function in libssl.
 */
enum {
    SSL_CT_VALIDATION_PERMISSIVE = 0,
    SSL_CT_VALIDATION_STRICT
};

/*
 * Enable CT by setting up a callback that implements one of the built-in
 * validation variants.  The SSL_CT_VALIDATION_PERMISSIVE variant always
 * continues the handshake, the application can make appropriate decisions at
 * handshake completion.  The SSL_CT_VALIDATION_STRICT variant requires at
 * least one valid SCT, or else handshake termination will be requested.  The
 * handshake may continue anyway if SSL_VERIFY_NONE is in effect.
 */
int SSL_enable_ct(SSL *s, int validation_mode);
int SSL_CTX_enable_ct(SSL_CTX *ctx, int validation_mode);

/*
 * Report whether a non-NULL callback is enabled.
 */
int SSL_ct_is_enabled(const SSL *s);
int SSL_CTX_ct_is_enabled(const SSL_CTX *ctx);

/* Gets the SCTs received from a connection */
const STACK_OF(SCT) *SSL_get0_peer_scts(SSL *s);

/*
 * Loads the CT log list from the default location.
 * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store,
 * the log information loaded from this file will be appended to the
 * CTLOG_STORE.
 * Returns 1 on success, 0 otherwise.
 */
int SSL_CTX_set_default_ctlog_list_file(SSL_CTX *ctx);

/*
 * Loads the CT log list from the specified file path.
 * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store,
 * the log information loaded from this file will be appended to the
 * CTLOG_STORE.
 * Returns 1 on success, 0 otherwise.
 */
int SSL_CTX_set_ctlog_list_file(SSL_CTX *ctx, const char *path);

/*
 * Sets the CT log list used by all SSL connections created from this SSL_CTX.
 * Ownership of the CTLOG_STORE is transferred to the SSL_CTX.
 */
void SSL_CTX_set0_ctlog_store(SSL_CTX *ctx, CTLOG_STORE *logs);

/*
 * Gets the CT log list used by all SSL connections created from this SSL_CTX.
 * This will be NULL unless one of the following functions has been called:
 * - SSL_CTX_set_default_ctlog_list_file
 * - SSL_CTX_set_ctlog_list_file
 * - SSL_CTX_set_ctlog_store
 */
const CTLOG_STORE *SSL_CTX_get0_ctlog_store(const SSL_CTX *ctx);

# endif /* OPENSSL_NO_CT */

/* What the "other" parameter contains in security callback */
/* Mask for type */
# define SSL_SECOP_OTHER_TYPE    0xffff0000
# define SSL_SECOP_OTHER_NONE    0
# define SSL_SECOP_OTHER_CIPHER  (1 << 16)
# define SSL_SECOP_OTHER_CURVE   (2 << 16)
# define SSL_SECOP_OTHER_DH      (3 << 16)
# define SSL_SECOP_OTHER_PKEY    (4 << 16)
# define SSL_SECOP_OTHER_SIGALG  (5 << 16)
# define SSL_SECOP_OTHER_CERT    (6 << 16)

/* Indicated operation refers to peer key or certificate */
# define SSL_SECOP_PEER          0x1000

/* Values for "op" parameter in security callback */

/* Called to filter ciphers */
/* Ciphers client supports */
# define SSL_SECOP_CIPHER_SUPPORTED      (1 | SSL_SECOP_OTHER_CIPHER)
/* Cipher shared by client/server */
# define SSL_SECOP_CIPHER_SHARED         (2 | SSL_SECOP_OTHER_CIPHER)
/* Sanity check of cipher server selects */
# define SSL_SECOP_CIPHER_CHECK          (3 | SSL_SECOP_OTHER_CIPHER)
/* Curves supported by client */
# define SSL_SECOP_CURVE_SUPPORTED       (4 | SSL_SECOP_OTHER_CURVE)
/* Curves shared by client/server */
# define SSL_SECOP_CURVE_SHARED          (5 | SSL_SECOP_OTHER_CURVE)
/* Sanity check of curve server selects */
# define SSL_SECOP_CURVE_CHECK           (6 | SSL_SECOP_OTHER_CURVE)
/* Temporary DH key */
# define SSL_SECOP_TMP_DH                (7 | SSL_SECOP_OTHER_PKEY)
/* SSL/TLS version */
# define SSL_SECOP_VERSION               (9 | SSL_SECOP_OTHER_NONE)
/* Session tickets */
# define SSL_SECOP_TICKET                (10 | SSL_SECOP_OTHER_NONE)
/* Supported signature algorithms sent to peer */
# define SSL_SECOP_SIGALG_SUPPORTED      (11 | SSL_SECOP_OTHER_SIGALG)
/* Shared signature algorithm */
# define SSL_SECOP_SIGALG_SHARED         (12 | SSL_SECOP_OTHER_SIGALG)
/* Sanity check signature algorithm allowed */
# define SSL_SECOP_SIGALG_CHECK          (13 | SSL_SECOP_OTHER_SIGALG)
/* Used to get mask of supported public key signature algorithms */
# define SSL_SECOP_SIGALG_MASK           (14 | SSL_SECOP_OTHER_SIGALG)
/* Use to see if compression is allowed */
# define SSL_SECOP_COMPRESSION           (15 | SSL_SECOP_OTHER_NONE)
/* EE key in certificate */
# define SSL_SECOP_EE_KEY                (16 | SSL_SECOP_OTHER_CERT)
/* CA key in certificate */
# define SSL_SECOP_CA_KEY                (17 | SSL_SECOP_OTHER_CERT)
/* CA digest algorithm in certificate */
# define SSL_SECOP_CA_MD                 (18 | SSL_SECOP_OTHER_CERT)
/* Peer EE key in certificate */
# define SSL_SECOP_PEER_EE_KEY           (SSL_SECOP_EE_KEY | SSL_SECOP_PEER)
/* Peer CA key in certificate */
# define SSL_SECOP_PEER_CA_KEY           (SSL_SECOP_CA_KEY | SSL_SECOP_PEER)
/* Peer CA digest algorithm in certificate */
# define SSL_SECOP_PEER_CA_MD            (SSL_SECOP_CA_MD | SSL_SECOP_PEER)

void SSL_set_security_level(SSL *s, int level);
__owur int SSL_get_security_level(const SSL *s);
void SSL_set_security_callback(SSL *s,
                               int (*cb) (const SSL *s, const SSL_CTX *ctx,
                                          int op, int bits, int nid,
                                          void *other, void *ex));
int (*SSL_get_security_callback(const SSL *s)) (const SSL *s,
                                                const SSL_CTX *ctx, int op,
                                                int bits, int nid, void *other,
                                                void *ex);
void SSL_set0_security_ex_data(SSL *s, void *ex);
__owur void *SSL_get0_security_ex_data(const SSL *s);

void SSL_CTX_set_security_level(SSL_CTX *ctx, int level);
__owur int SSL_CTX_get_security_level(const SSL_CTX *ctx);
void SSL_CTX_set_security_callback(SSL_CTX *ctx,
                                   int (*cb) (const SSL *s, const SSL_CTX *ctx,
                                              int op, int bits, int nid,
                                              void *other, void *ex));
int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx)) (const SSL *s,
                                                          const SSL_CTX *ctx,
                                                          int op, int bits,
                                                          int nid,
                                                          void *other,
                                                          void *ex);
void SSL_CTX_set0_security_ex_data(SSL_CTX *ctx, void *ex);
__owur void *SSL_CTX_get0_security_ex_data(const SSL_CTX *ctx);

/* OPENSSL_INIT flag 0x010000 reserved for internal use */
# define OPENSSL_INIT_NO_LOAD_SSL_STRINGS    0x00100000L
# define OPENSSL_INIT_LOAD_SSL_STRINGS       0x00200000L

# define OPENSSL_INIT_SSL_DEFAULT \
        (OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS)

int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);

# ifndef OPENSSL_NO_UNIT_TEST
__owur const struct openssl_ssl_test_functions *SSL_test_functions(void);
# endif

__owur int SSL_free_buffers(SSL *ssl);
__owur int SSL_alloc_buffers(SSL *ssl);

/* Status codes passed to the decrypt session ticket callback. Some of these
 * are for internal use only and are never passed to the callback. */
typedef int SSL_TICKET_STATUS;

/* Support for ticket appdata */
/* fatal error, malloc failure */
# define SSL_TICKET_FATAL_ERR_MALLOC 0
/* fatal error, either from parsing or decrypting the ticket */
# define SSL_TICKET_FATAL_ERR_OTHER  1
/* No ticket present */
# define SSL_TICKET_NONE             2
/* Empty ticket present */
# define SSL_TICKET_EMPTY            3
/* the ticket couldn't be decrypted */
# define SSL_TICKET_NO_DECRYPT       4
/* a ticket was successfully decrypted */
# define SSL_TICKET_SUCCESS          5
/* same as above but the ticket needs to be renewed */
# define SSL_TICKET_SUCCESS_RENEW    6

/* Return codes for the decrypt session ticket callback */
typedef int SSL_TICKET_RETURN;

/* An error occurred */
#define SSL_TICKET_RETURN_ABORT             0
/* Do not use the ticket, do not send a renewed ticket to the client */
#define SSL_TICKET_RETURN_IGNORE            1
/* Do not use the ticket, send a renewed ticket to the client */
#define SSL_TICKET_RETURN_IGNORE_RENEW      2
/* Use the ticket, do not send a renewed ticket to the client */
#define SSL_TICKET_RETURN_USE               3
/* Use the ticket, send a renewed ticket to the client */
#define SSL_TICKET_RETURN_USE_RENEW         4

typedef int (*SSL_CTX_generate_session_ticket_fn)(SSL *s, void *arg);
typedef SSL_TICKET_RETURN (*SSL_CTX_decrypt_session_ticket_fn)(SSL *s, SSL_SESSION *ss,
                                                               const unsigned char *keyname,
                                                               size_t keyname_length,
                                                               SSL_TICKET_STATUS status,
                                                               void *arg);
int SSL_CTX_set_session_ticket_cb(SSL_CTX *ctx,
                                  SSL_CTX_generate_session_ticket_fn gen_cb,
                                  SSL_CTX_decrypt_session_ticket_fn dec_cb,
                                  void *arg);
int SSL_SESSION_set1_ticket_appdata(SSL_SESSION *ss, const void *data, size_t len);
int SSL_SESSION_get0_ticket_appdata(SSL_SESSION *ss, void **data, size_t *len);

typedef unsigned int (*DTLS_timer_cb)(SSL *s, unsigned int timer_us);

void DTLS_set_timer_cb(SSL *s, DTLS_timer_cb cb);


typedef int (*SSL_allow_early_data_cb_fn)(SSL *s, void *arg);
void SSL_CTX_set_allow_early_data_cb(SSL_CTX *ctx,
                                     SSL_allow_early_data_cb_fn cb,
                                     void *arg);
void SSL_set_allow_early_data_cb(SSL *s,
                                 SSL_allow_early_data_cb_fn cb,
                                 void *arg);

/* store the default cipher strings inside the library */
const char *OSSL_default_cipher_list(void);
const char *OSSL_default_ciphersuites(void);

#  ifndef OPENSSL_NO_QUIC
/*
 * QUIC integration - The QUIC interface matches BoringSSL
 *
 * ssl_encryption_level_t represents a specific QUIC encryption level used to
 * transmit handshake messages. BoringSSL has this as an 'enum'.
 */
#include <openssl/quic.h>

/* Used by Chromium/QUIC - moved from evp.h to avoid breaking FIPS checksums */
# define X25519_PRIVATE_KEY_LEN          32
# define X25519_PUBLIC_VALUE_LEN         32

/* moved from types.h to avoid breaking FIPS checksums */
typedef struct ssl_quic_method_st SSL_QUIC_METHOD;

typedef enum ssl_encryption_level_t {
    ssl_encryption_initial = 0,
    ssl_encryption_early_data,
    ssl_encryption_handshake,
    ssl_encryption_application
} OSSL_ENCRYPTION_LEVEL;

struct ssl_quic_method_st {
    int (*set_encryption_secrets)(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                                  const uint8_t *read_secret,
                                  const uint8_t *write_secret, size_t secret_len);
    int (*add_handshake_data)(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                              const uint8_t *data, size_t len);
    int (*flush_flight)(SSL *ssl);
    int (*send_alert)(SSL *ssl, enum ssl_encryption_level_t level, uint8_t alert);
};

__owur int SSL_CTX_set_quic_method(SSL_CTX *ctx, const SSL_QUIC_METHOD *quic_method);
__owur int SSL_set_quic_method(SSL *ssl, const SSL_QUIC_METHOD *quic_method);
__owur int SSL_set_quic_transport_params(SSL *ssl,
                                         const uint8_t *params,
                                         size_t params_len);
void SSL_get_peer_quic_transport_params(const SSL *ssl,
                                        const uint8_t **out_params,
                                        size_t *out_params_len);
__owur size_t SSL_quic_max_handshake_flight_len(const SSL *ssl, OSSL_ENCRYPTION_LEVEL level);
__owur OSSL_ENCRYPTION_LEVEL SSL_quic_read_level(const SSL *ssl);
__owur OSSL_ENCRYPTION_LEVEL SSL_quic_write_level(const SSL *ssl);
__owur int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                                 const uint8_t *data, size_t len);
__owur int SSL_process_quic_post_handshake(SSL *ssl);

__owur int SSL_is_quic(SSL *ssl);

/* BoringSSL API */
void SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy);

/*
 * Set an explicit value that you want to use
 * If 0 (default) the server will use the highest extenstion the client sent
 * If 0 (default) the client will send both extensions
 */
void SSL_set_quic_transport_version(SSL *ssl, int version);
__owur int SSL_get_quic_transport_version(const SSL *ssl);
/* Returns the negotiated version, or -1 on error */
__owur int SSL_get_peer_quic_transport_version(const SSL *ssl);

int SSL_CIPHER_get_prf_nid(const SSL_CIPHER *c);

void SSL_set_quic_early_data_enabled(SSL *ssl, int enabled);

#  endif

# ifdef  __cplusplus
}
# endif
#endif
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     /*
 * WARNING: do not edit!
 * Generated by Makefile from include/openssl/ssl.h.in
 *
 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
 * Copyright 2005 Nokia. All rights reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */



#ifndef OPENSSL_SSL_H
# define OPENSSL_SSL_H
# pragma once

# include <openssl/macros.h>
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define HEADER_SSL_H
# endif

# include <openssl/e_os2.h>
# include <openssl/opensslconf.h>
# include <openssl/comp.h>
# include <openssl/bio.h>
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  include <openssl/x509.h>
#  include <openssl/crypto.h>
#  include <openssl/buffer.h>
# endif
# include <openssl/lhash.h>
# include <openssl/pem.h>
# include <openssl/hmac.h>
# include <openssl/async.h>

# include <openssl/safestack.h>
# include <openssl/symhacks.h>
# include <openssl/ct.h>
# include <openssl/sslerr.h>
# include <openssl/prov_ssl.h>

#ifdef  __cplusplus
extern "C" {
#endif

/* OpenSSL version number for ASN.1 encoding of the session information */
/*-
 * Version 0 - initial version
 * Version 1 - added the optional peer certificate
 */
# define SSL_SESSION_ASN1_VERSION 0x0001

# define SSL_MAX_SSL_SESSION_ID_LENGTH           32
# define SSL_MAX_SID_CTX_LENGTH                  32

# define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES     (512/8)
# define SSL_MAX_KEY_ARG_LENGTH                  8
/* SSL_MAX_MASTER_KEY_LENGTH is defined in prov_ssl.h */

/* The maximum number of encrypt/decrypt pipelines we can support */
# define SSL_MAX_PIPELINES  32

/* text strings for the ciphers */

/* These are used to specify which ciphers to use and not to use */

# define SSL_TXT_LOW             "LOW"
# define SSL_TXT_MEDIUM          "MEDIUM"
# define SSL_TXT_HIGH            "HIGH"
# define SSL_TXT_FIPS            "FIPS"

# define SSL_TXT_aNULL           "aNULL"
# define SSL_TXT_eNULL           "eNULL"
# define SSL_TXT_NULL            "NULL"

# define SSL_TXT_kRSA            "kRSA"
# define SSL_TXT_kDHr            "kDHr"/* this cipher class has been removed */
# define SSL_TXT_kDHd            "kDHd"/* this cipher class has been removed */
# define SSL_TXT_kDH             "kDH"/* this cipher class has been removed */
# define SSL_TXT_kEDH            "kEDH"/* alias for kDHE */
# define SSL_TXT_kDHE            "kDHE"
# define SSL_TXT_kECDHr          "kECDHr"/* this cipher class has been removed */
# define SSL_TXT_kECDHe          "kECDHe"/* this cipher class has been removed */
# define SSL_TXT_kECDH           "kECDH"/* this cipher class has been removed */
# define SSL_TXT_kEECDH          "kEECDH"/* alias for kECDHE */
# define SSL_TXT_kECDHE          "kECDHE"
# define SSL_TXT_kPSK            "kPSK"
# define SSL_TXT_kRSAPSK         "kRSAPSK"
# define SSL_TXT_kECDHEPSK       "kECDHEPSK"
# define SSL_TXT_kDHEPSK         "kDHEPSK"
# define SSL_TXT_kGOST           "kGOST"
# define SSL_TXT_kGOST18         "kGOST18"
# define SSL_TXT_kSRP            "kSRP"

# define SSL_TXT_aRSA            "aRSA"
# define SSL_TXT_aDSS            "aDSS"
# define SSL_TXT_aDH             "aDH"/* this cipher class has been removed */
# define SSL_TXT_aECDH           "aECDH"/* this cipher class has been removed */
# define SSL_TXT_aECDSA          "aECDSA"
# define SSL_TXT_aPSK            "aPSK"
# define SSL_TXT_aGOST94         "aGOST94"
# define SSL_TXT_aGOST01         "aGOST01"
# define SSL_TXT_aGOST12         "aGOST12"
# define SSL_TXT_aGOST           "aGOST"
# define SSL_TXT_aSRP            "aSRP"

# define SSL_TXT_DSS             "DSS"
# define SSL_TXT_DH              "DH"
# define SSL_TXT_DHE             "DHE"/* same as "kDHE:-ADH" */
# define SSL_TXT_EDH             "EDH"/* alias for DHE */
# define SSL_TXT_ADH             "ADH"
# define SSL_TXT_RSA             "RSA"
# define SSL_TXT_ECDH            "ECDH"
# define SSL_TXT_EECDH           "EECDH"/* alias for ECDHE" */
# define SSL_TXT_ECDHE           "ECDHE"/* same as "kECDHE:-AECDH" */
# define SSL_TXT_AECDH           "AECDH"
# define SSL_TXT_ECDSA           "ECDSA"
# define SSL_TXT_PSK             "PSK"
# define SSL_TXT_SRP             "SRP"

# define SSL_TXT_DES             "DES"
# define SSL_TXT_3DES            "3DES"
# define SSL_TXT_RC4             "RC4"
# define SSL_TXT_RC2             "RC2"
# define SSL_TXT_IDEA            "IDEA"
# define SSL_TXT_SEED            "SEED"
# define SSL_TXT_AES128          "AES128"
# define SSL_TXT_AES256          "AES256"
# define SSL_TXT_AES             "AES"
# define SSL_TXT_AES_GCM         "AESGCM"
# define SSL_TXT_AES_CCM         "AESCCM"
# define SSL_TXT_AES_CCM_8       "AESCCM8"
# define SSL_TXT_CAMELLIA128     "CAMELLIA128"
# define SSL_TXT_CAMELLIA256     "CAMELLIA256"
# define SSL_TXT_CAMELLIA        "CAMELLIA"
# define SSL_TXT_CHACHA20        "CHACHA20"
# define SSL_TXT_GOST            "GOST89"
# define SSL_TXT_ARIA            "ARIA"
# define SSL_TXT_ARIA_GCM        "ARIAGCM"
# define SSL_TXT_ARIA128         "ARIA128"
# define SSL_TXT_ARIA256         "ARIA256"
# define SSL_TXT_GOST2012_GOST8912_GOST8912 "GOST2012-GOST8912-GOST8912"
# define SSL_TXT_CBC             "CBC"

# define SSL_TXT_MD5             "MD5"
# define SSL_TXT_SHA1            "SHA1"
# define SSL_TXT_SHA             "SHA"/* same as "SHA1" */
# define SSL_TXT_GOST94          "GOST94"
# define SSL_TXT_GOST89MAC       "GOST89MAC"
# define SSL_TXT_GOST12          "GOST12"
# define SSL_TXT_GOST89MAC12     "GOST89MAC12"
# define SSL_TXT_SHA256          "SHA256"
# define SSL_TXT_SHA384          "SHA384"

# define SSL_TXT_SSLV3           "SSLv3"
# define SSL_TXT_TLSV1           "TLSv1"
# define SSL_TXT_TLSV1_1         "TLSv1.1"
# define SSL_TXT_TLSV1_2         "TLSv1.2"

# define SSL_TXT_ALL             "ALL"

/*-
 * COMPLEMENTOF* definitions. These identifiers are used to (de-select)
 * ciphers normally not being used.
 * Example: "RC4" will activate all ciphers using RC4 including ciphers
 * without authentication, which would normally disabled by DEFAULT (due
 * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT"
 * will make sure that it is also disabled in the specific selection.
 * COMPLEMENTOF* identifiers are portable between version, as adjustments
 * to the default cipher setup will also be included here.
 *
 * COMPLEMENTOFDEFAULT does not experience the same special treatment that
 * DEFAULT gets, as only selection is being done and no sorting as needed
 * for DEFAULT.
 */
# define SSL_TXT_CMPALL          "COMPLEMENTOFALL"
# define SSL_TXT_CMPDEF          "COMPLEMENTOFDEFAULT"

/*
 * The following cipher list is used by default. It also is substituted when
 * an application-defined cipher list string starts with 'DEFAULT'.
 * This applies to ciphersuites for TLSv1.2 and below.
 * DEPRECATED IN 3.0.0, in favor of OSSL_default_cipher_list()
 * Update both macro and function simultaneously
 */
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_DEFAULT_CIPHER_LIST "ALL:!COMPLEMENTOFDEFAULT:!eNULL"
/*
 * This is the default set of TLSv1.3 ciphersuites
 * DEPRECATED IN 3.0.0, in favor of OSSL_default_ciphersuites()
 * Update both macro and function simultaneously
 */
#  define TLS_DEFAULT_CIPHERSUITES "TLS_AES_256_GCM_SHA384:" \
                                   "TLS_CHACHA20_POLY1305_SHA256:" \
                                   "TLS_AES_128_GCM_SHA256"
# endif
/*
 * As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always
 * starts with a reasonable order, and all we have to do for DEFAULT is
 * throwing out anonymous and unencrypted ciphersuites! (The latter are not
 * actually enabled by ALL, but "ALL:RSA" would enable some of them.)
 */

/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
# define SSL_SENT_SHUTDOWN       1
# define SSL_RECEIVED_SHUTDOWN   2

#ifdef __cplusplus
}
#endif

#ifdef  __cplusplus
extern "C" {
#endif

# define SSL_FILETYPE_ASN1       X509_FILETYPE_ASN1
# define SSL_FILETYPE_PEM        X509_FILETYPE_PEM

/*
 * This is needed to stop compilers complaining about the 'struct ssl_st *'
 * function parameters used to prototype callbacks in SSL_CTX.
 */
typedef struct ssl_st *ssl_crock_st;
typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
typedef struct ssl_method_st SSL_METHOD;
typedef struct ssl_cipher_st SSL_CIPHER;
typedef struct ssl_session_st SSL_SESSION;
typedef struct tls_sigalgs_st TLS_SIGALGS;
typedef struct ssl_conf_ctx_st SSL_CONF_CTX;
typedef struct ssl_comp_st SSL_COMP;

STACK_OF(SSL_CIPHER);
STACK_OF(SSL_COMP);

/* SRTP protection profiles for use with the use_srtp extension (RFC 5764)*/
typedef struct srtp_protection_profile_st {
    const char *name;
    unsigned long id;
} SRTP_PROTECTION_PROFILE;
SKM_DEFINE_STACK_OF_INTERNAL(SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE, SRTP_PROTECTION_PROFILE)
#define sk_SRTP_PROTECTION_PROFILE_num(sk) OPENSSL_sk_num(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_value(sk, idx) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_value(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), (idx)))
#define sk_SRTP_PROTECTION_PROFILE_new(cmp) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new(ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp)))
#define sk_SRTP_PROTECTION_PROFILE_new_null() ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new_null())
#define sk_SRTP_PROTECTION_PROFILE_new_reserve(cmp, n) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_new_reserve(ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp), (n)))
#define sk_SRTP_PROTECTION_PROFILE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (n))
#define sk_SRTP_PROTECTION_PROFILE_free(sk) OPENSSL_sk_free(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_zero(sk) OPENSSL_sk_zero(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_delete(sk, i) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_delete(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (i)))
#define sk_SRTP_PROTECTION_PROFILE_delete_ptr(sk, ptr) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_delete_ptr(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr)))
#define sk_SRTP_PROTECTION_PROFILE_push(sk, ptr) OPENSSL_sk_push(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_pop(sk) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_pop(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_shift(sk) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_shift(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk),ossl_check_SRTP_PROTECTION_PROFILE_freefunc_type(freefunc))
#define sk_SRTP_PROTECTION_PROFILE_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr), (idx))
#define sk_SRTP_PROTECTION_PROFILE_set(sk, idx, ptr) ((SRTP_PROTECTION_PROFILE *)OPENSSL_sk_set(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), (idx), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr)))
#define sk_SRTP_PROTECTION_PROFILE_find(sk, ptr) OPENSSL_sk_find(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr))
#define sk_SRTP_PROTECTION_PROFILE_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_type(ptr), pnum)
#define sk_SRTP_PROTECTION_PROFILE_sort(sk) OPENSSL_sk_sort(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk))
#define sk_SRTP_PROTECTION_PROFILE_dup(sk) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_dup(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk)))
#define sk_SRTP_PROTECTION_PROFILE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRTP_PROTECTION_PROFILE) *)OPENSSL_sk_deep_copy(ossl_check_const_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_copyfunc_type(copyfunc), ossl_check_SRTP_PROTECTION_PROFILE_freefunc_type(freefunc)))
#define sk_SRTP_PROTECTION_PROFILE_set_cmp_func(sk, cmp) ((sk_SRTP_PROTECTION_PROFILE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRTP_PROTECTION_PROFILE_sk_type(sk), ossl_check_SRTP_PROTECTION_PROFILE_compfunc_type(cmp)))



typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data,
                                            int len, void *arg);
typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len,
                                        STACK_OF(SSL_CIPHER) *peer_ciphers,
                                        const SSL_CIPHER **cipher, void *arg);

/* Extension context codes */
/* This extension is only allowed in TLS */
#define SSL_EXT_TLS_ONLY                        0x0001
/* This extension is only allowed in DTLS */
#define SSL_EXT_DTLS_ONLY                       0x0002
/* Some extensions may be allowed in DTLS but we don't implement them for it */
#define SSL_EXT_TLS_IMPLEMENTATION_ONLY         0x0004
/* Most extensions are not defined for SSLv3 but EXT_TYPE_renegotiate is */
#define SSL_EXT_SSL3_ALLOWED                    0x0008
/* Extension is only defined for TLS1.2 and below */
#define SSL_EXT_TLS1_2_AND_BELOW_ONLY           0x0010
/* Extension is only defined for TLS1.3 and above */
#define SSL_EXT_TLS1_3_ONLY                     0x0020
/* Ignore this extension during parsing if we are resuming */
#define SSL_EXT_IGNORE_ON_RESUMPTION            0x0040
#define SSL_EXT_CLIENT_HELLO                    0x0080
/* Really means TLS1.2 or below */
#define SSL_EXT_TLS1_2_SERVER_HELLO             0x0100
#define SSL_EXT_TLS1_3_SERVER_HELLO             0x0200
#define SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS     0x0400
#define SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST      0x0800
#define SSL_EXT_TLS1_3_CERTIFICATE              0x1000
#define SSL_EXT_TLS1_3_NEW_SESSION_TICKET       0x2000
#define SSL_EXT_TLS1_3_CERTIFICATE_REQUEST      0x4000

/* Typedefs for handling custom extensions */

typedef int (*custom_ext_add_cb)(SSL *s, unsigned int ext_type,
                                 const unsigned char **out, size_t *outlen,
                                 int *al, void *add_arg);

typedef void (*custom_ext_free_cb)(SSL *s, unsigned int ext_type,
                                   const unsigned char *out, void *add_arg);

typedef int (*custom_ext_parse_cb)(SSL *s, unsigned int ext_type,
                                   const unsigned char *in, size_t inlen,
                                   int *al, void *parse_arg);


typedef int (*SSL_custom_ext_add_cb_ex)(SSL *s, unsigned int ext_type,
                                        unsigned int context,
                                        const unsigned char **out,
                                        size_t *outlen, X509 *x,
                                        size_t chainidx,
                                        int *al, void *add_arg);

typedef void (*SSL_custom_ext_free_cb_ex)(SSL *s, unsigned int ext_type,
                                          unsigned int context,
                                          const unsigned char *out,
                                          void *add_arg);

typedef int (*SSL_custom_ext_parse_cb_ex)(SSL *s, unsigned int ext_type,
                                          unsigned int context,
                                          const unsigned char *in,
                                          size_t inlen, X509 *x,
                                          size_t chainidx,
                                          int *al, void *parse_arg);

/* Typedef for verification callback */
typedef int (*SSL_verify_cb)(int preverify_ok, X509_STORE_CTX *x509_ctx);

/* Typedef for SSL async callback */
typedef int (*SSL_async_callback_fn)(SSL *s, void *arg);

#define SSL_OP_BIT(n)  ((uint64_t)1 << (uint64_t)n)

/*
 * SSL/TLS connection options.
 */
    /* Disable Extended master secret */
# define SSL_OP_NO_EXTENDED_MASTER_SECRET                SSL_OP_BIT(0)
    /* Cleanse plaintext copies of data delivered to the application */
# define SSL_OP_CLEANSE_PLAINTEXT                        SSL_OP_BIT(1)
    /* Allow initial connection to servers that don't support RI */
# define SSL_OP_LEGACY_SERVER_CONNECT                    SSL_OP_BIT(2)
    /* Enable support for Kernel TLS */
# define SSL_OP_ENABLE_KTLS                              SSL_OP_BIT(3)
# define SSL_OP_TLSEXT_PADDING                           SSL_OP_BIT(4)
# define SSL_OP_SAFARI_ECDHE_ECDSA_BUG                   SSL_OP_BIT(6)
# define SSL_OP_IGNORE_UNEXPECTED_EOF                    SSL_OP_BIT(7)
# define SSL_OP_ALLOW_CLIENT_RENEGOTIATION               SSL_OP_BIT(8)
# define SSL_OP_DISABLE_TLSEXT_CA_NAMES                  SSL_OP_BIT(9)
    /* In TLSv1.3 allow a non-(ec)dhe based kex_mode */
# define SSL_OP_ALLOW_NO_DHE_KEX                         SSL_OP_BIT(10)
    /*
     * Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
     * in OpenSSL 0.9.6d.  Usually (depending on the application protocol)
     * the workaround is not needed.  Unfortunately some broken SSL/TLS
     * implementations cannot handle it at all, which is why we include it
     * in SSL_OP_ALL. Added in 0.9.6e
     */
# define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS              SSL_OP_BIT(11)
    /* DTLS options */
# define SSL_OP_NO_QUERY_MTU                             SSL_OP_BIT(12)
    /* Turn on Cookie Exchange (on relevant for servers) */
# define SSL_OP_COOKIE_EXCHANGE                          SSL_OP_BIT(13)
    /* Don't use RFC4507 ticket extension */
# define SSL_OP_NO_TICKET                                SSL_OP_BIT(14)
# ifndef OPENSSL_NO_DTLS1_METHOD
    /*
     * Use Cisco's version identifier of DTLS_BAD_VER
     * (only with deprecated DTLSv1_client_method())
     */
#  define SSL_OP_CISCO_ANYCONNECT                        SSL_OP_BIT(15)
# endif
    /* As server, disallow session resumption on renegotiation */
# define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION   SSL_OP_BIT(16)
    /* Don't use compression even if supported */
# define SSL_OP_NO_COMPRESSION                           SSL_OP_BIT(17)
    /* Permit unsafe legacy renegotiation */
# define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION        SSL_OP_BIT(18)
    /* Disable encrypt-then-mac */
# define SSL_OP_NO_ENCRYPT_THEN_MAC                      SSL_OP_BIT(19)
    /*
     * Enable TLSv1.3 Compatibility mode. This is on by default. A future
     * version of OpenSSL may have this disabled by default.
     */
# define SSL_OP_ENABLE_MIDDLEBOX_COMPAT                  SSL_OP_BIT(20)
    /*
     * Prioritize Chacha20Poly1305 when client does.
     * Modifies SSL_OP_CIPHER_SERVER_PREFERENCE
     */
# define SSL_OP_PRIORITIZE_CHACHA                        SSL_OP_BIT(21)
    /*
     * Set on servers to choose the cipher according to server's preferences.
     */
# define SSL_OP_CIPHER_SERVER_PREFERENCE                 SSL_OP_BIT(22)
    /*
     * If set, a server will allow a client to issue a SSLv3.0 version
     * number as latest version supported in the premaster secret, even when
     * TLSv1.0 (version 3.1) was announced in the client hello. Normally
     * this is forbidden to prevent version rollback attacks.
     */
# define SSL_OP_TLS_ROLLBACK_BUG                         SSL_OP_BIT(23)
    /*
     * Switches off automatic TLSv1.3 anti-replay protection for early data.
     * This is a server-side option only (no effect on the client).
     */
# define SSL_OP_NO_ANTI_REPLAY                           SSL_OP_BIT(24)
# define SSL_OP_NO_SSLv3                                 SSL_OP_BIT(25)
# define SSL_OP_NO_TLSv1                                 SSL_OP_BIT(26)
# define SSL_OP_NO_TLSv1_2                               SSL_OP_BIT(27)
# define SSL_OP_NO_TLSv1_1                               SSL_OP_BIT(28)
# define SSL_OP_NO_TLSv1_3                               SSL_OP_BIT(29)
# define SSL_OP_NO_DTLSv1                                SSL_OP_BIT(26)
# define SSL_OP_NO_DTLSv1_2                              SSL_OP_BIT(27)
    /* Disallow all renegotiation */
# define SSL_OP_NO_RENEGOTIATION                         SSL_OP_BIT(30)
    /*
     * Make server add server-hello extension from early version of
     * cryptopro draft, when GOST ciphersuite is negotiated. Required for
     * interoperability with CryptoPro CSP 3.x
     */
# define SSL_OP_CRYPTOPRO_TLSEXT_BUG                     SSL_OP_BIT(31)

/*
 * Option "collections."
 */
# define SSL_OP_NO_SSL_MASK \
        ( SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 \
          | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3 )
# define SSL_OP_NO_DTLS_MASK \
        ( SSL_OP_NO_DTLSv1 | SSL_OP_NO_DTLSv1_2 )

/* Various bug workarounds that should be rather harmless. */
# define SSL_OP_ALL \
        ( SSL_OP_CRYPTOPRO_TLSEXT_BUG | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS \
          | SSL_OP_TLSEXT_PADDING | SSL_OP_SAFARI_ECDHE_ECDSA_BUG )

/*
 * OBSOLETE OPTIONS retained for compatibility
 */

# define SSL_OP_MICROSOFT_SESS_ID_BUG                    0x0
# define SSL_OP_NETSCAPE_CHALLENGE_BUG                   0x0
# define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG         0x0
# define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG              0x0
# define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER               0x0
# define SSL_OP_MSIE_SSLV2_RSA_PADDING                   0x0
# define SSL_OP_SSLEAY_080_CLIENT_DH_BUG                 0x0
# define SSL_OP_TLS_D5_BUG                               0x0
# define SSL_OP_TLS_BLOCK_PADDING_BUG                    0x0
# define SSL_OP_SINGLE_ECDH_USE                          0x0
# define SSL_OP_SINGLE_DH_USE                            0x0
# define SSL_OP_EPHEMERAL_RSA                            0x0
# define SSL_OP_NO_SSLv2                                 0x0
# define SSL_OP_PKCS1_CHECK_1                            0x0
# define SSL_OP_PKCS1_CHECK_2                            0x0
# define SSL_OP_NETSCAPE_CA_DN_BUG                       0x0
# define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG          0x0

/*
 * Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
 * when just a single record has been written):
 */
# define SSL_MODE_ENABLE_PARTIAL_WRITE       0x00000001U
/*
 * Make it possible to retry SSL_write() with changed buffer location (buffer
 * contents must stay the same!); this is not the default to avoid the
 * misconception that non-blocking SSL_write() behaves like non-blocking
 * write():
 */
# define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002U
/*
 * Never bother the application with retries if the transport is blocking:
 */
# define SSL_MODE_AUTO_RETRY 0x00000004U
/* Don't attempt to automatically build certificate chain */
# define SSL_MODE_NO_AUTO_CHAIN 0x00000008U
/*
 * Save RAM by releasing read and write buffers when they're empty. (SSL3 and
 * TLS only.) Released buffers are freed.
 */
# define SSL_MODE_RELEASE_BUFFERS 0x00000010U
/*
 * Send the current time in the Random fields of the ClientHello and
 * ServerHello records for compatibility with hypothetical implementations
 * that require it.
 */
# define SSL_MODE_SEND_CLIENTHELLO_TIME 0x00000020U
# define SSL_MODE_SEND_SERVERHELLO_TIME 0x00000040U
/*
 * Send TLS_FALLBACK_SCSV in the ClientHello. To be set only by applications
 * that reconnect with a downgraded protocol version; see
 * draft-ietf-tls-downgrade-scsv-00 for details. DO NOT ENABLE THIS if your
 * application attempts a normal handshake. Only use this in explicit
 * fallback retries, following the guidance in
 * draft-ietf-tls-downgrade-scsv-00.
 */
# define SSL_MODE_SEND_FALLBACK_SCSV 0x00000080U
/*
 * Support Asynchronous operation
 */
# define SSL_MODE_ASYNC 0x00000100U

/*
 * When using DTLS/SCTP, include the terminating zero in the label
 * used for computing the endpoint-pair shared secret. Required for
 * interoperability with implementations having this bug like these
 * older version of OpenSSL:
 * - OpenSSL 1.0.0 series
 * - OpenSSL 1.0.1 series
 * - OpenSSL 1.0.2 series
 * - OpenSSL 1.1.0 series
 * - OpenSSL 1.1.1 and 1.1.1a
 */
# define SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG 0x00000400U

/* Cert related flags */
/*
 * Many implementations ignore some aspects of the TLS standards such as
 * enforcing certificate chain algorithms. When this is set we enforce them.
 */
# define SSL_CERT_FLAG_TLS_STRICT                0x00000001U

/* Suite B modes, takes same values as certificate verify flags */
# define SSL_CERT_FLAG_SUITEB_128_LOS_ONLY       0x10000
/* Suite B 192 bit only mode */
# define SSL_CERT_FLAG_SUITEB_192_LOS            0x20000
/* Suite B 128 bit mode allowing 192 bit algorithms */
# define SSL_CERT_FLAG_SUITEB_128_LOS            0x30000

/* Perform all sorts of protocol violations for testing purposes */
# define SSL_CERT_FLAG_BROKEN_PROTOCOL           0x10000000

/* Flags for building certificate chains */
/* Treat any existing certificates as untrusted CAs */
# define SSL_BUILD_CHAIN_FLAG_UNTRUSTED          0x1
/* Don't include root CA in chain */
# define SSL_BUILD_CHAIN_FLAG_NO_ROOT            0x2
/* Just check certificates already there */
# define SSL_BUILD_CHAIN_FLAG_CHECK              0x4
/* Ignore verification errors */
# define SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR       0x8
/* Clear verification errors from queue */
# define SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR        0x10

/* Flags returned by SSL_check_chain */
/* Certificate can be used with this session */
# define CERT_PKEY_VALID         0x1
/* Certificate can also be used for signing */
# define CERT_PKEY_SIGN          0x2
/* EE certificate signing algorithm OK */
# define CERT_PKEY_EE_SIGNATURE  0x10
/* CA signature algorithms OK */
# define CERT_PKEY_CA_SIGNATURE  0x20
/* EE certificate parameters OK */
# define CERT_PKEY_EE_PARAM      0x40
/* CA certificate parameters OK */
# define CERT_PKEY_CA_PARAM      0x80
/* Signing explicitly allowed as opposed to SHA1 fallback */
# define CERT_PKEY_EXPLICIT_SIGN 0x100
/* Client CA issuer names match (always set for server cert) */
# define CERT_PKEY_ISSUER_NAME   0x200
/* Cert type matches client types (always set for server cert) */
# define CERT_PKEY_CERT_TYPE     0x400
/* Cert chain suitable to Suite B */
# define CERT_PKEY_SUITEB        0x800

# define SSL_CONF_FLAG_CMDLINE           0x1
# define SSL_CONF_FLAG_FILE              0x2
# define SSL_CONF_FLAG_CLIENT            0x4
# define SSL_CONF_FLAG_SERVER            0x8
# define SSL_CONF_FLAG_SHOW_ERRORS       0x10
# define SSL_CONF_FLAG_CERTIFICATE       0x20
# define SSL_CONF_FLAG_REQUIRE_PRIVATE   0x40
/* Configuration value types */
# define SSL_CONF_TYPE_UNKNOWN           0x0
# define SSL_CONF_TYPE_STRING            0x1
# define SSL_CONF_TYPE_FILE              0x2
# define SSL_CONF_TYPE_DIR               0x3
# define SSL_CONF_TYPE_NONE              0x4
# define SSL_CONF_TYPE_STORE             0x5

/* Maximum length of the application-controlled segment of a a TLSv1.3 cookie */
# define SSL_COOKIE_LENGTH                       4096

/*
 * Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, they
 * cannot be used to clear bits.
 */

uint64_t SSL_CTX_get_options(const SSL_CTX *ctx);
uint64_t SSL_get_options(const SSL *s);
uint64_t SSL_CTX_clear_options(SSL_CTX *ctx, uint64_t op);
uint64_t SSL_clear_options(SSL *s, uint64_t op);
uint64_t SSL_CTX_set_options(SSL_CTX *ctx, uint64_t op);
uint64_t SSL_set_options(SSL *s, uint64_t op);

# define SSL_CTX_set_mode(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
# define SSL_CTX_clear_mode(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_MODE,(op),NULL)
# define SSL_CTX_get_mode(ctx) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL)
# define SSL_clear_mode(ssl,op) \
        SSL_ctrl((ssl),SSL_CTRL_CLEAR_MODE,(op),NULL)
# define SSL_set_mode(ssl,op) \
        SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL)
# define SSL_get_mode(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL)
# define SSL_set_mtu(ssl, mtu) \
        SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL)
# define DTLS_set_link_mtu(ssl, mtu) \
        SSL_ctrl((ssl),DTLS_CTRL_SET_LINK_MTU,(mtu),NULL)
# define DTLS_get_link_min_mtu(ssl) \
        SSL_ctrl((ssl),DTLS_CTRL_GET_LINK_MIN_MTU,0,NULL)

# define SSL_get_secure_renegotiation_support(ssl) \
        SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL)

# define SSL_CTX_set_cert_flags(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CERT_FLAGS,(op),NULL)
# define SSL_set_cert_flags(s,op) \
        SSL_ctrl((s),SSL_CTRL_CERT_FLAGS,(op),NULL)
# define SSL_CTX_clear_cert_flags(ctx,op) \
        SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL)
# define SSL_clear_cert_flags(s,op) \
        SSL_ctrl((s),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL)

void SSL_CTX_set_msg_callback(SSL_CTX *ctx,
                              void (*cb) (int write_p, int version,
                                          int content_type, const void *buf,
                                          size_t len, SSL *ssl, void *arg));
void SSL_set_msg_callback(SSL *ssl,
                          void (*cb) (int write_p, int version,
                                      int content_type, const void *buf,
                                      size_t len, SSL *ssl, void *arg));
# define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
# define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))

# define SSL_get_extms_support(s) \
        SSL_ctrl((s),SSL_CTRL_GET_EXTMS_SUPPORT,0,NULL)

# ifndef OPENSSL_NO_SRP
/* see tls_srp.c */
#  ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 __owur int SSL_SRP_CTX_init(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx);
OSSL_DEPRECATEDIN_3_0 int SSL_SRP_CTX_free(SSL *ctx);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx);
OSSL_DEPRECATEDIN_3_0 __owur int SSL_srp_server_param_with_username(SSL *s,
                                                                    int *ad);
OSSL_DEPRECATEDIN_3_0 __owur int SRP_Calc_A_param(SSL *s);
#  endif
# endif

/* 100k max cert list */
# define SSL_MAX_CERT_LIST_DEFAULT (1024*100)

# define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT      (1024*20)

/*
 * This callback type is used inside SSL_CTX, SSL, and in the functions that
 * set them. It is used to override the generation of SSL/TLS session IDs in
 * a server. Return value should be zero on an error, non-zero to proceed.
 * Also, callbacks should themselves check if the id they generate is unique
 * otherwise the SSL handshake will fail with an error - callbacks can do
 * this using the 'ssl' value they're passed by;
 * SSL_has_matching_session_id(ssl, id, *id_len) The length value passed in
 * is set at the maximum size the session ID can be. In SSLv3/TLSv1 it is 32
 * bytes. The callback can alter this length to be less if desired. It is
 * also an error for the callback to set the size to zero.
 */
typedef int (*GEN_SESSION_CB) (SSL *ssl, unsigned char *id,
                               unsigned int *id_len);

# define SSL_SESS_CACHE_OFF                      0x0000
# define SSL_SESS_CACHE_CLIENT                   0x0001
# define SSL_SESS_CACHE_SERVER                   0x0002
# define SSL_SESS_CACHE_BOTH     (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
# define SSL_SESS_CACHE_NO_AUTO_CLEAR            0x0080
/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */
# define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP       0x0100
# define SSL_SESS_CACHE_NO_INTERNAL_STORE        0x0200
# define SSL_SESS_CACHE_NO_INTERNAL \
        (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE)
# define SSL_SESS_CACHE_UPDATE_TIME              0x0400

LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx);
# define SSL_CTX_sess_number(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
# define SSL_CTX_sess_connect(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
# define SSL_CTX_sess_connect_good(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
# define SSL_CTX_sess_connect_renegotiate(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
# define SSL_CTX_sess_accept(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
# define SSL_CTX_sess_accept_renegotiate(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
# define SSL_CTX_sess_accept_good(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
# define SSL_CTX_sess_hits(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
# define SSL_CTX_sess_cb_hits(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
# define SSL_CTX_sess_misses(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
# define SSL_CTX_sess_timeouts(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
# define SSL_CTX_sess_cache_full(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)

void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
                             int (*new_session_cb) (struct ssl_st *ssl,
                                                    SSL_SESSION *sess));
int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (struct ssl_st *ssl,
                                              SSL_SESSION *sess);
void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
                                void (*remove_session_cb) (struct ssl_ctx_st
                                                           *ctx,
                                                           SSL_SESSION *sess));
void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (struct ssl_ctx_st *ctx,
                                                  SSL_SESSION *sess);
void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
                             SSL_SESSION *(*get_session_cb) (struct ssl_st
                                                             *ssl,
                                                             const unsigned char
                                                             *data, int len,
                                                             int *copy));
SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (struct ssl_st *ssl,
                                                       const unsigned char *data,
                                                       int len, int *copy);
void SSL_CTX_set_info_callback(SSL_CTX *ctx,
                               void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type,
                                                 int val);
void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
                                int (*client_cert_cb) (SSL *ssl, X509 **x509,
                                                       EVP_PKEY **pkey));
int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509,
                                                 EVP_PKEY **pkey);
# ifndef OPENSSL_NO_ENGINE
__owur int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e);
# endif
void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
                                    int (*app_gen_cookie_cb) (SSL *ssl,
                                                              unsigned char
                                                              *cookie,
                                                              unsigned int
                                                              *cookie_len));
void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
                                  int (*app_verify_cookie_cb) (SSL *ssl,
                                                               const unsigned
                                                               char *cookie,
                                                               unsigned int
                                                               cookie_len));

void SSL_CTX_set_stateless_cookie_generate_cb(
    SSL_CTX *ctx,
    int (*gen_stateless_cookie_cb) (SSL *ssl,
                                    unsigned char *cookie,
                                    size_t *cookie_len));
void SSL_CTX_set_stateless_cookie_verify_cb(
    SSL_CTX *ctx,
    int (*verify_stateless_cookie_cb) (SSL *ssl,
                                       const unsigned char *cookie,
                                       size_t cookie_len));
# ifndef OPENSSL_NO_NEXTPROTONEG

typedef int (*SSL_CTX_npn_advertised_cb_func)(SSL *ssl,
                                              const unsigned char **out,
                                              unsigned int *outlen,
                                              void *arg);
void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s,
                                           SSL_CTX_npn_advertised_cb_func cb,
                                           void *arg);
#  define SSL_CTX_set_npn_advertised_cb SSL_CTX_set_next_protos_advertised_cb

typedef int (*SSL_CTX_npn_select_cb_func)(SSL *s,
                                          unsigned char **out,
                                          unsigned char *outlen,
                                          const unsigned char *in,
                                          unsigned int inlen,
                                          void *arg);
void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s,
                                      SSL_CTX_npn_select_cb_func cb,
                                      void *arg);
#  define SSL_CTX_set_npn_select_cb SSL_CTX_set_next_proto_select_cb

void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
                                    unsigned *len);
#  define SSL_get0_npn_negotiated SSL_get0_next_proto_negotiated
# endif

__owur int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
                                 const unsigned char *in, unsigned int inlen,
                                 const unsigned char *client,
                                 unsigned int client_len);

# define OPENSSL_NPN_UNSUPPORTED 0
# define OPENSSL_NPN_NEGOTIATED  1
# define OPENSSL_NPN_NO_OVERLAP  2

__owur int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
                                   unsigned int protos_len);
__owur int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
                               unsigned int protos_len);
typedef int (*SSL_CTX_alpn_select_cb_func)(SSL *ssl,
                                           const unsigned char **out,
                                           unsigned char *outlen,
                                           const unsigned char *in,
                                           unsigned int inlen,
                                           void *arg);
void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
                                SSL_CTX_alpn_select_cb_func cb,
                                void *arg);
void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
                            unsigned int *len);

# ifndef OPENSSL_NO_PSK
/*
 * the maximum length of the buffer given to callbacks containing the
 * resulting identity/psk
 */
#  define PSK_MAX_IDENTITY_LEN 256
#  define PSK_MAX_PSK_LEN 512
typedef unsigned int (*SSL_psk_client_cb_func)(SSL *ssl,
                                               const char *hint,
                                               char *identity,
                                               unsigned int max_identity_len,
                                               unsigned char *psk,
                                               unsigned int max_psk_len);
void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, SSL_psk_client_cb_func cb);
void SSL_set_psk_client_callback(SSL *ssl, SSL_psk_client_cb_func cb);

typedef unsigned int (*SSL_psk_server_cb_func)(SSL *ssl,
                                               const char *identity,
                                               unsigned char *psk,
                                               unsigned int max_psk_len);
void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, SSL_psk_server_cb_func cb);
void SSL_set_psk_server_callback(SSL *ssl, SSL_psk_server_cb_func cb);

__owur int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint);
__owur int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint);
const char *SSL_get_psk_identity_hint(const SSL *s);
const char *SSL_get_psk_identity(const SSL *s);
# endif

typedef int (*SSL_psk_find_session_cb_func)(SSL *ssl,
                                            const unsigned char *identity,
                                            size_t identity_len,
                                            SSL_SESSION **sess);
typedef int (*SSL_psk_use_session_cb_func)(SSL *ssl, const EVP_MD *md,
                                           const unsigned char **id,
                                           size_t *idlen,
                                           SSL_SESSION **sess);

void SSL_set_psk_find_session_callback(SSL *s, SSL_psk_find_session_cb_func cb);
void SSL_CTX_set_psk_find_session_callback(SSL_CTX *ctx,
                                           SSL_psk_find_session_cb_func cb);
void SSL_set_psk_use_session_callback(SSL *s, SSL_psk_use_session_cb_func cb);
void SSL_CTX_set_psk_use_session_callback(SSL_CTX *ctx,
                                          SSL_psk_use_session_cb_func cb);

/* Register callbacks to handle custom TLS Extensions for client or server. */

__owur int SSL_CTX_has_client_custom_ext(const SSL_CTX *ctx,
                                         unsigned int ext_type);

__owur int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx,
                                         unsigned int ext_type,
                                         custom_ext_add_cb add_cb,
                                         custom_ext_free_cb free_cb,
                                         void *add_arg,
                                         custom_ext_parse_cb parse_cb,
                                         void *parse_arg);

__owur int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx,
                                         unsigned int ext_type,
                                         custom_ext_add_cb add_cb,
                                         custom_ext_free_cb free_cb,
                                         void *add_arg,
                                         custom_ext_parse_cb parse_cb,
                                         void *parse_arg);

__owur int SSL_CTX_add_custom_ext(SSL_CTX *ctx, unsigned int ext_type,
                                  unsigned int context,
                                  SSL_custom_ext_add_cb_ex add_cb,
                                  SSL_custom_ext_free_cb_ex free_cb,
                                  void *add_arg,
                                  SSL_custom_ext_parse_cb_ex parse_cb,
                                  void *parse_arg);

__owur int SSL_extension_supported(unsigned int ext_type);

# define SSL_NOTHING            1
# define SSL_WRITING            2
# define SSL_READING            3
# define SSL_X509_LOOKUP        4
# define SSL_ASYNC_PAUSED       5
# define SSL_ASYNC_NO_JOBS      6
# define SSL_CLIENT_HELLO_CB    7
# define SSL_RETRY_VERIFY       8

/* These will only be used when doing non-blocking IO */
# define SSL_want_nothing(s)         (SSL_want(s) == SSL_NOTHING)
# define SSL_want_read(s)            (SSL_want(s) == SSL_READING)
# define SSL_want_write(s)           (SSL_want(s) == SSL_WRITING)
# define SSL_want_x509_lookup(s)     (SSL_want(s) == SSL_X509_LOOKUP)
# define SSL_want_retry_verify(s)    (SSL_want(s) == SSL_RETRY_VERIFY)
# define SSL_want_async(s)           (SSL_want(s) == SSL_ASYNC_PAUSED)
# define SSL_want_async_job(s)       (SSL_want(s) == SSL_ASYNC_NO_JOBS)
# define SSL_want_client_hello_cb(s) (SSL_want(s) == SSL_CLIENT_HELLO_CB)

# define SSL_MAC_FLAG_READ_MAC_STREAM 1
# define SSL_MAC_FLAG_WRITE_MAC_STREAM 2
# define SSL_MAC_FLAG_READ_MAC_TLSTREE 4
# define SSL_MAC_FLAG_WRITE_MAC_TLSTREE 8

/*
 * A callback for logging out TLS key material. This callback should log out
 * |line| followed by a newline.
 */
typedef void (*SSL_CTX_keylog_cb_func)(const SSL *ssl, const char *line);

/*
 * SSL_CTX_set_keylog_callback configures a callback to log key material. This
 * is intended for debugging use with tools like Wireshark. The cb function
 * should log line followed by a newline.
 */
void SSL_CTX_set_keylog_callback(SSL_CTX *ctx, SSL_CTX_keylog_cb_func cb);

/*
 * SSL_CTX_get_keylog_callback returns the callback configured by
 * SSL_CTX_set_keylog_callback.
 */
SSL_CTX_keylog_cb_func SSL_CTX_get_keylog_callback(const SSL_CTX *ctx);

int SSL_CTX_set_max_early_data(SSL_CTX *ctx, uint32_t max_early_data);
uint32_t SSL_CTX_get_max_early_data(const SSL_CTX *ctx);
int SSL_set_max_early_data(SSL *s, uint32_t max_early_data);
uint32_t SSL_get_max_early_data(const SSL *s);
int SSL_CTX_set_recv_max_early_data(SSL_CTX *ctx, uint32_t recv_max_early_data);
uint32_t SSL_CTX_get_recv_max_early_data(const SSL_CTX *ctx);
int SSL_set_recv_max_early_data(SSL *s, uint32_t recv_max_early_data);
uint32_t SSL_get_recv_max_early_data(const SSL *s);

#ifdef __cplusplus
}
#endif

# include <openssl/ssl2.h>
# include <openssl/ssl3.h>
# include <openssl/tls1.h>      /* This is mostly sslv3 with a few tweaks */
# include <openssl/dtls1.h>     /* Datagram TLS */
# include <openssl/srtp.h>      /* Support for the use_srtp extension */

#ifdef  __cplusplus
extern "C" {
#endif

/*
 * These need to be after the above set of includes due to a compiler bug
 * in VisualStudio 2015
 */
SKM_DEFINE_STACK_OF_INTERNAL(SSL_CIPHER, const SSL_CIPHER, SSL_CIPHER)
#define sk_SSL_CIPHER_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_value(sk, idx) ((const SSL_CIPHER *)OPENSSL_sk_value(ossl_check_const_SSL_CIPHER_sk_type(sk), (idx)))
#define sk_SSL_CIPHER_new(cmp) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new(ossl_check_SSL_CIPHER_compfunc_type(cmp)))
#define sk_SSL_CIPHER_new_null() ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new_null())
#define sk_SSL_CIPHER_new_reserve(cmp, n) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_new_reserve(ossl_check_SSL_CIPHER_compfunc_type(cmp), (n)))
#define sk_SSL_CIPHER_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SSL_CIPHER_sk_type(sk), (n))
#define sk_SSL_CIPHER_free(sk) OPENSSL_sk_free(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_zero(sk) OPENSSL_sk_zero(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_delete(sk, i) ((const SSL_CIPHER *)OPENSSL_sk_delete(ossl_check_SSL_CIPHER_sk_type(sk), (i)))
#define sk_SSL_CIPHER_delete_ptr(sk, ptr) ((const SSL_CIPHER *)OPENSSL_sk_delete_ptr(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr)))
#define sk_SSL_CIPHER_push(sk, ptr) OPENSSL_sk_push(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_pop(sk) ((const SSL_CIPHER *)OPENSSL_sk_pop(ossl_check_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_shift(sk) ((const SSL_CIPHER *)OPENSSL_sk_shift(ossl_check_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SSL_CIPHER_sk_type(sk),ossl_check_SSL_CIPHER_freefunc_type(freefunc))
#define sk_SSL_CIPHER_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr), (idx))
#define sk_SSL_CIPHER_set(sk, idx, ptr) ((const SSL_CIPHER *)OPENSSL_sk_set(ossl_check_SSL_CIPHER_sk_type(sk), (idx), ossl_check_SSL_CIPHER_type(ptr)))
#define sk_SSL_CIPHER_find(sk, ptr) OPENSSL_sk_find(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr))
#define sk_SSL_CIPHER_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_type(ptr), pnum)
#define sk_SSL_CIPHER_sort(sk) OPENSSL_sk_sort(ossl_check_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SSL_CIPHER_sk_type(sk))
#define sk_SSL_CIPHER_dup(sk) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_dup(ossl_check_const_SSL_CIPHER_sk_type(sk)))
#define sk_SSL_CIPHER_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_CIPHER) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_copyfunc_type(copyfunc), ossl_check_SSL_CIPHER_freefunc_type(freefunc)))
#define sk_SSL_CIPHER_set_cmp_func(sk, cmp) ((sk_SSL_CIPHER_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_CIPHER_sk_type(sk), ossl_check_SSL_CIPHER_compfunc_type(cmp)))
SKM_DEFINE_STACK_OF_INTERNAL(SSL_COMP, SSL_COMP, SSL_COMP)
#define sk_SSL_COMP_num(sk) OPENSSL_sk_num(ossl_check_const_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_value(sk, idx) ((SSL_COMP *)OPENSSL_sk_value(ossl_check_const_SSL_COMP_sk_type(sk), (idx)))
#define sk_SSL_COMP_new(cmp) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new(ossl_check_SSL_COMP_compfunc_type(cmp)))
#define sk_SSL_COMP_new_null() ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new_null())
#define sk_SSL_COMP_new_reserve(cmp, n) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_new_reserve(ossl_check_SSL_COMP_compfunc_type(cmp), (n)))
#define sk_SSL_COMP_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SSL_COMP_sk_type(sk), (n))
#define sk_SSL_COMP_free(sk) OPENSSL_sk_free(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_zero(sk) OPENSSL_sk_zero(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_delete(sk, i) ((SSL_COMP *)OPENSSL_sk_delete(ossl_check_SSL_COMP_sk_type(sk), (i)))
#define sk_SSL_COMP_delete_ptr(sk, ptr) ((SSL_COMP *)OPENSSL_sk_delete_ptr(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr)))
#define sk_SSL_COMP_push(sk, ptr) OPENSSL_sk_push(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_pop(sk) ((SSL_COMP *)OPENSSL_sk_pop(ossl_check_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_shift(sk) ((SSL_COMP *)OPENSSL_sk_shift(ossl_check_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SSL_COMP_sk_type(sk),ossl_check_SSL_COMP_freefunc_type(freefunc))
#define sk_SSL_COMP_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr), (idx))
#define sk_SSL_COMP_set(sk, idx, ptr) ((SSL_COMP *)OPENSSL_sk_set(ossl_check_SSL_COMP_sk_type(sk), (idx), ossl_check_SSL_COMP_type(ptr)))
#define sk_SSL_COMP_find(sk, ptr) OPENSSL_sk_find(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr))
#define sk_SSL_COMP_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_type(ptr), pnum)
#define sk_SSL_COMP_sort(sk) OPENSSL_sk_sort(ossl_check_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SSL_COMP_sk_type(sk))
#define sk_SSL_COMP_dup(sk) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_dup(ossl_check_const_SSL_COMP_sk_type(sk)))
#define sk_SSL_COMP_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SSL_COMP) *)OPENSSL_sk_deep_copy(ossl_check_const_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_copyfunc_type(copyfunc), ossl_check_SSL_COMP_freefunc_type(freefunc)))
#define sk_SSL_COMP_set_cmp_func(sk, cmp) ((sk_SSL_COMP_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SSL_COMP_sk_type(sk), ossl_check_SSL_COMP_compfunc_type(cmp)))


/* compatibility */
# define SSL_set_app_data(s,arg)         (SSL_set_ex_data(s,0,(char *)(arg)))
# define SSL_get_app_data(s)             (SSL_get_ex_data(s,0))
# define SSL_SESSION_set_app_data(s,a)   (SSL_SESSION_set_ex_data(s,0, \
                                                                  (char *)(a)))
# define SSL_SESSION_get_app_data(s)     (SSL_SESSION_get_ex_data(s,0))
# define SSL_CTX_get_app_data(ctx)       (SSL_CTX_get_ex_data(ctx,0))
# define SSL_CTX_set_app_data(ctx,arg)   (SSL_CTX_set_ex_data(ctx,0, \
                                                              (char *)(arg)))
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 void SSL_set_debug(SSL *s, int debug);
# endif

/* TLSv1.3 KeyUpdate message types */
/* -1 used so that this is an invalid value for the on-the-wire protocol */
#define SSL_KEY_UPDATE_NONE             -1
/* Values as defined for the on-the-wire protocol */
#define SSL_KEY_UPDATE_NOT_REQUESTED     0
#define SSL_KEY_UPDATE_REQUESTED         1

/*
 * The valid handshake states (one for each type message sent and one for each
 * type of message received). There are also two "special" states:
 * TLS = TLS or DTLS state
 * DTLS = DTLS specific state
 * CR/SR = Client Read/Server Read
 * CW/SW = Client Write/Server Write
 *
 * The "special" states are:
 * TLS_ST_BEFORE = No handshake has been initiated yet
 * TLS_ST_OK = A handshake has been successfully completed
 */
typedef enum {
    TLS_ST_BEFORE,
    TLS_ST_OK,
    DTLS_ST_CR_HELLO_VERIFY_REQUEST,
    TLS_ST_CR_SRVR_HELLO,
    TLS_ST_CR_CERT,
    TLS_ST_CR_CERT_STATUS,
    TLS_ST_CR_KEY_EXCH,
    TLS_ST_CR_CERT_REQ,
    TLS_ST_CR_SRVR_DONE,
    TLS_ST_CR_SESSION_TICKET,
    TLS_ST_CR_CHANGE,
    TLS_ST_CR_FINISHED,
    TLS_ST_CW_CLNT_HELLO,
    TLS_ST_CW_CERT,
    TLS_ST_CW_KEY_EXCH,
    TLS_ST_CW_CERT_VRFY,
    TLS_ST_CW_CHANGE,
    TLS_ST_CW_NEXT_PROTO,
    TLS_ST_CW_FINISHED,
    TLS_ST_SW_HELLO_REQ,
    TLS_ST_SR_CLNT_HELLO,
    DTLS_ST_SW_HELLO_VERIFY_REQUEST,
    TLS_ST_SW_SRVR_HELLO,
    TLS_ST_SW_CERT,
    TLS_ST_SW_KEY_EXCH,
    TLS_ST_SW_CERT_REQ,
    TLS_ST_SW_SRVR_DONE,
    TLS_ST_SR_CERT,
    TLS_ST_SR_KEY_EXCH,
    TLS_ST_SR_CERT_VRFY,
    TLS_ST_SR_NEXT_PROTO,
    TLS_ST_SR_CHANGE,
    TLS_ST_SR_FINISHED,
    TLS_ST_SW_SESSION_TICKET,
    TLS_ST_SW_CERT_STATUS,
    TLS_ST_SW_CHANGE,
    TLS_ST_SW_FINISHED,
    TLS_ST_SW_ENCRYPTED_EXTENSIONS,
    TLS_ST_CR_ENCRYPTED_EXTENSIONS,
    TLS_ST_CR_CERT_VRFY,
    TLS_ST_SW_CERT_VRFY,
    TLS_ST_CR_HELLO_REQ,
    TLS_ST_SW_KEY_UPDATE,
    TLS_ST_CW_KEY_UPDATE,
    TLS_ST_SR_KEY_UPDATE,
    TLS_ST_CR_KEY_UPDATE,
    TLS_ST_EARLY_DATA,
    TLS_ST_PENDING_EARLY_DATA_END,
    TLS_ST_CW_END_OF_EARLY_DATA,
    TLS_ST_SR_END_OF_EARLY_DATA
} OSSL_HANDSHAKE_STATE;

/*
 * Most of the following state values are no longer used and are defined to be
 * the closest equivalent value in the current state machine code. Not all
 * defines have an equivalent and are set to a dummy value (-1). SSL_ST_CONNECT
 * and SSL_ST_ACCEPT are still in use in the definition of SSL_CB_ACCEPT_LOOP,
 * SSL_CB_ACCEPT_EXIT, SSL_CB_CONNECT_LOOP and SSL_CB_CONNECT_EXIT.
 */

# define SSL_ST_CONNECT                  0x1000
# define SSL_ST_ACCEPT                   0x2000

# define SSL_ST_MASK                     0x0FFF

# define SSL_CB_LOOP                     0x01
# define SSL_CB_EXIT                     0x02
# define SSL_CB_READ                     0x04
# define SSL_CB_WRITE                    0x08
# define SSL_CB_ALERT                    0x4000/* used in callback */
# define SSL_CB_READ_ALERT               (SSL_CB_ALERT|SSL_CB_READ)
# define SSL_CB_WRITE_ALERT              (SSL_CB_ALERT|SSL_CB_WRITE)
# define SSL_CB_ACCEPT_LOOP              (SSL_ST_ACCEPT|SSL_CB_LOOP)
# define SSL_CB_ACCEPT_EXIT              (SSL_ST_ACCEPT|SSL_CB_EXIT)
# define SSL_CB_CONNECT_LOOP             (SSL_ST_CONNECT|SSL_CB_LOOP)
# define SSL_CB_CONNECT_EXIT             (SSL_ST_CONNECT|SSL_CB_EXIT)
# define SSL_CB_HANDSHAKE_START          0x10
# define SSL_CB_HANDSHAKE_DONE           0x20

/* Is the SSL_connection established? */
# define SSL_in_connect_init(a)          (SSL_in_init(a) && !SSL_is_server(a))
# define SSL_in_accept_init(a)           (SSL_in_init(a) && SSL_is_server(a))
int SSL_in_init(const SSL *s);
int SSL_in_before(const SSL *s);
int SSL_is_init_finished(const SSL *s);

/*
 * The following 3 states are kept in ssl->rlayer.rstate when reads fail, you
 * should not need these
 */
# define SSL_ST_READ_HEADER                      0xF0
# define SSL_ST_READ_BODY                        0xF1
# define SSL_ST_READ_DONE                        0xF2

/*-
 * Obtain latest Finished message
 *   -- that we sent (SSL_get_finished)
 *   -- that we expected from peer (SSL_get_peer_finished).
 * Returns length (0 == no Finished so far), copies up to 'count' bytes.
 */
size_t SSL_get_finished(const SSL *s, void *buf, size_t count);
size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);

/*
 * use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 3 options are
 * 'ored' with SSL_VERIFY_PEER if they are desired
 */
# define SSL_VERIFY_NONE                 0x00
# define SSL_VERIFY_PEER                 0x01
# define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
# define SSL_VERIFY_CLIENT_ONCE          0x04
# define SSL_VERIFY_POST_HANDSHAKE       0x08

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define OpenSSL_add_ssl_algorithms()   SSL_library_init()
#  define SSLeay_add_ssl_algorithms()    SSL_library_init()
# endif

/* More backward compatibility */
# define SSL_get_cipher(s) \
                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
# define SSL_get_cipher_bits(s,np) \
                SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
# define SSL_get_cipher_version(s) \
                SSL_CIPHER_get_version(SSL_get_current_cipher(s))
# define SSL_get_cipher_name(s) \
                SSL_CIPHER_get_name(SSL_get_current_cipher(s))
# define SSL_get_time(a)         SSL_SESSION_get_time(a)
# define SSL_set_time(a,b)       SSL_SESSION_set_time((a),(b))
# define SSL_get_timeout(a)      SSL_SESSION_get_timeout(a)
# define SSL_set_timeout(a,b)    SSL_SESSION_set_timeout((a),(b))

# define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id)
# define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id)

DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
# define SSL_AD_REASON_OFFSET            1000/* offset to get SSL_R_... value
                                              * from SSL_AD_... */
/* These alert types are for SSLv3 and TLSv1 */
# define SSL_AD_CLOSE_NOTIFY             SSL3_AD_CLOSE_NOTIFY
/* fatal */
# define SSL_AD_UNEXPECTED_MESSAGE       SSL3_AD_UNEXPECTED_MESSAGE
/* fatal */
# define SSL_AD_BAD_RECORD_MAC           SSL3_AD_BAD_RECORD_MAC
# define SSL_AD_DECRYPTION_FAILED        TLS1_AD_DECRYPTION_FAILED
# define SSL_AD_RECORD_OVERFLOW          TLS1_AD_RECORD_OVERFLOW
/* fatal */
# define SSL_AD_DECOMPRESSION_FAILURE    SSL3_AD_DECOMPRESSION_FAILURE
/* fatal */
# define SSL_AD_HANDSHAKE_FAILURE        SSL3_AD_HANDSHAKE_FAILURE
/* Not for TLS */
# define SSL_AD_NO_CERTIFICATE           SSL3_AD_NO_CERTIFICATE
# define SSL_AD_BAD_CERTIFICATE          SSL3_AD_BAD_CERTIFICATE
# define SSL_AD_UNSUPPORTED_CERTIFICATE  SSL3_AD_UNSUPPORTED_CERTIFICATE
# define SSL_AD_CERTIFICATE_REVOKED      SSL3_AD_CERTIFICATE_REVOKED
# define SSL_AD_CERTIFICATE_EXPIRED      SSL3_AD_CERTIFICATE_EXPIRED
# define SSL_AD_CERTIFICATE_UNKNOWN      SSL3_AD_CERTIFICATE_UNKNOWN
/* fatal */
# define SSL_AD_ILLEGAL_PARAMETER        SSL3_AD_ILLEGAL_PARAMETER
/* fatal */
# define SSL_AD_UNKNOWN_CA               TLS1_AD_UNKNOWN_CA
/* fatal */
# define SSL_AD_ACCESS_DENIED            TLS1_AD_ACCESS_DENIED
/* fatal */
# define SSL_AD_DECODE_ERROR             TLS1_AD_DECODE_ERROR
# define SSL_AD_DECRYPT_ERROR            TLS1_AD_DECRYPT_ERROR
/* fatal */
# define SSL_AD_EXPORT_RESTRICTION       TLS1_AD_EXPORT_RESTRICTION
/* fatal */
# define SSL_AD_PROTOCOL_VERSION         TLS1_AD_PROTOCOL_VERSION
/* fatal */
# define SSL_AD_INSUFFICIENT_SECURITY    TLS1_AD_INSUFFICIENT_SECURITY
/* fatal */
# define SSL_AD_INTERNAL_ERROR           TLS1_AD_INTERNAL_ERROR
# define SSL_AD_USER_CANCELLED           TLS1_AD_USER_CANCELLED
# define SSL_AD_NO_RENEGOTIATION         TLS1_AD_NO_RENEGOTIATION
# define SSL_AD_MISSING_EXTENSION        TLS13_AD_MISSING_EXTENSION
# define SSL_AD_CERTIFICATE_REQUIRED     TLS13_AD_CERTIFICATE_REQUIRED
# define SSL_AD_UNSUPPORTED_EXTENSION    TLS1_AD_UNSUPPORTED_EXTENSION
# define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE
# define SSL_AD_UNRECOGNIZED_NAME        TLS1_AD_UNRECOGNIZED_NAME
# define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE
# define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE
/* fatal */
# define SSL_AD_UNKNOWN_PSK_IDENTITY     TLS1_AD_UNKNOWN_PSK_IDENTITY
/* fatal */
# define SSL_AD_INAPPROPRIATE_FALLBACK   TLS1_AD_INAPPROPRIATE_FALLBACK
# define SSL_AD_NO_APPLICATION_PROTOCOL  TLS1_AD_NO_APPLICATION_PROTOCOL
# define SSL_ERROR_NONE                  0
# define SSL_ERROR_SSL                   1
# define SSL_ERROR_WANT_READ             2
# define SSL_ERROR_WANT_WRITE            3
# define SSL_ERROR_WANT_X509_LOOKUP      4
# define SSL_ERROR_SYSCALL               5/* look at error stack/return
                                           * value/errno */
# define SSL_ERROR_ZERO_RETURN           6
# define SSL_ERROR_WANT_CONNECT          7
# define SSL_ERROR_WANT_ACCEPT           8
# define SSL_ERROR_WANT_ASYNC            9
# define SSL_ERROR_WANT_ASYNC_JOB       10
# define SSL_ERROR_WANT_CLIENT_HELLO_CB 11
# define SSL_ERROR_WANT_RETRY_VERIFY    12

# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTRL_SET_TMP_DH                    3
#  define SSL_CTRL_SET_TMP_ECDH                  4
#  define SSL_CTRL_SET_TMP_DH_CB                 6
# endif

# define SSL_CTRL_GET_CLIENT_CERT_REQUEST        9
# define SSL_CTRL_GET_NUM_RENEGOTIATIONS         10
# define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS       11
# define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS       12
# define SSL_CTRL_GET_FLAGS                      13
# define SSL_CTRL_EXTRA_CHAIN_CERT               14
# define SSL_CTRL_SET_MSG_CALLBACK               15
# define SSL_CTRL_SET_MSG_CALLBACK_ARG           16
/* only applies to datagram connections */
# define SSL_CTRL_SET_MTU                17
/* Stats */
# define SSL_CTRL_SESS_NUMBER                    20
# define SSL_CTRL_SESS_CONNECT                   21
# define SSL_CTRL_SESS_CONNECT_GOOD              22
# define SSL_CTRL_SESS_CONNECT_RENEGOTIATE       23
# define SSL_CTRL_SESS_ACCEPT                    24
# define SSL_CTRL_SESS_ACCEPT_GOOD               25
# define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE        26
# define SSL_CTRL_SESS_HIT                       27
# define SSL_CTRL_SESS_CB_HIT                    28
# define SSL_CTRL_SESS_MISSES                    29
# define SSL_CTRL_SESS_TIMEOUTS                  30
# define SSL_CTRL_SESS_CACHE_FULL                31
# define SSL_CTRL_MODE                           33
# define SSL_CTRL_GET_READ_AHEAD                 40
# define SSL_CTRL_SET_READ_AHEAD                 41
# define SSL_CTRL_SET_SESS_CACHE_SIZE            42
# define SSL_CTRL_GET_SESS_CACHE_SIZE            43
# define SSL_CTRL_SET_SESS_CACHE_MODE            44
# define SSL_CTRL_GET_SESS_CACHE_MODE            45
# define SSL_CTRL_GET_MAX_CERT_LIST              50
# define SSL_CTRL_SET_MAX_CERT_LIST              51
# define SSL_CTRL_SET_MAX_SEND_FRAGMENT          52
/* see tls1.h for macros based on these */
# define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB       53
# define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG      54
# define SSL_CTRL_SET_TLSEXT_HOSTNAME            55
# define SSL_CTRL_SET_TLSEXT_DEBUG_CB            56
# define SSL_CTRL_SET_TLSEXT_DEBUG_ARG           57
# define SSL_CTRL_GET_TLSEXT_TICKET_KEYS         58
# define SSL_CTRL_SET_TLSEXT_TICKET_KEYS         59
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT    60 */
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB 61 */
/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG 62 */
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB       63
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG   64
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE     65
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS     66
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS     67
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS      68
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS      69
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP        70
# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP        71
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB      72
# endif
# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB    75
# define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB                76
# define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB             77
# define SSL_CTRL_SET_SRP_ARG            78
# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME               79
# define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH               80
# define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD               81
# define DTLS_CTRL_GET_TIMEOUT           73
# define DTLS_CTRL_HANDLE_TIMEOUT        74
# define SSL_CTRL_GET_RI_SUPPORT                 76
# define SSL_CTRL_CLEAR_MODE                     78
# define SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB      79
# define SSL_CTRL_GET_EXTRA_CHAIN_CERTS          82
# define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS        83
# define SSL_CTRL_CHAIN                          88
# define SSL_CTRL_CHAIN_CERT                     89
# define SSL_CTRL_GET_GROUPS                     90
# define SSL_CTRL_SET_GROUPS                     91
# define SSL_CTRL_SET_GROUPS_LIST                92
# define SSL_CTRL_GET_SHARED_GROUP               93
# define SSL_CTRL_SET_SIGALGS                    97
# define SSL_CTRL_SET_SIGALGS_LIST               98
# define SSL_CTRL_CERT_FLAGS                     99
# define SSL_CTRL_CLEAR_CERT_FLAGS               100
# define SSL_CTRL_SET_CLIENT_SIGALGS             101
# define SSL_CTRL_SET_CLIENT_SIGALGS_LIST        102
# define SSL_CTRL_GET_CLIENT_CERT_TYPES          103
# define SSL_CTRL_SET_CLIENT_CERT_TYPES          104
# define SSL_CTRL_BUILD_CERT_CHAIN               105
# define SSL_CTRL_SET_VERIFY_CERT_STORE          106
# define SSL_CTRL_SET_CHAIN_CERT_STORE           107
# define SSL_CTRL_GET_PEER_SIGNATURE_NID         108
# define SSL_CTRL_GET_PEER_TMP_KEY               109
# define SSL_CTRL_GET_RAW_CIPHERLIST             110
# define SSL_CTRL_GET_EC_POINT_FORMATS           111
# define SSL_CTRL_GET_CHAIN_CERTS                115
# define SSL_CTRL_SELECT_CURRENT_CERT            116
# define SSL_CTRL_SET_CURRENT_CERT               117
# define SSL_CTRL_SET_DH_AUTO                    118
# define DTLS_CTRL_SET_LINK_MTU                  120
# define DTLS_CTRL_GET_LINK_MIN_MTU              121
# define SSL_CTRL_GET_EXTMS_SUPPORT              122
# define SSL_CTRL_SET_MIN_PROTO_VERSION          123
# define SSL_CTRL_SET_MAX_PROTO_VERSION          124
# define SSL_CTRL_SET_SPLIT_SEND_FRAGMENT        125
# define SSL_CTRL_SET_MAX_PIPELINES              126
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE     127
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB       128
# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG   129
# define SSL_CTRL_GET_MIN_PROTO_VERSION          130
# define SSL_CTRL_GET_MAX_PROTO_VERSION          131
# define SSL_CTRL_GET_SIGNATURE_NID              132
# define SSL_CTRL_GET_TMP_KEY                    133
# define SSL_CTRL_GET_NEGOTIATED_GROUP           134
# define SSL_CTRL_SET_RETRY_VERIFY               136
# define SSL_CTRL_GET_VERIFY_CERT_STORE          137
# define SSL_CTRL_GET_CHAIN_CERT_STORE           138
# define SSL_CERT_SET_FIRST                      1
# define SSL_CERT_SET_NEXT                       2
# define SSL_CERT_SET_SERVER                     3
# define DTLSv1_get_timeout(ssl, arg) \
        SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)(arg))
# define DTLSv1_handle_timeout(ssl) \
        SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL)
# define SSL_num_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
# define SSL_clear_num_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
# define SSL_total_renegotiations(ssl) \
        SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTX_set_tmp_dh(ctx,dh) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
# endif
# define SSL_CTX_set_dh_auto(ctx, onoff) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
# define SSL_set_dh_auto(s, onoff) \
        SSL_ctrl(s,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_set_tmp_dh(ssl,dh) \
        SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
# endif
# ifndef OPENSSL_NO_DEPRECATED_3_0
#  define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
#  define SSL_set_tmp_ecdh(ssl,ecdh) \
        SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
# endif
# define SSL_CTX_add_extra_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)(x509))
# define SSL_CTX_get_extra_chain_certs(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,0,px509)
# define SSL_CTX_get_extra_chain_certs_only(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,1,px509)
# define SSL_CTX_clear_extra_chain_certs(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS,0,NULL)
# define SSL_CTX_set0_chain(ctx,sk) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,0,(char *)(sk))
# define SSL_CTX_set1_chain(ctx,sk) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,1,(char *)(sk))
# define SSL_CTX_add0_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,0,(char *)(x509))
# define SSL_CTX_add1_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,1,(char *)(x509))
# define SSL_CTX_get0_chain_certs(ctx,px509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERTS,0,px509)
# define SSL_CTX_clear_chain_certs(ctx) \
        SSL_CTX_set0_chain(ctx,NULL)
# define SSL_CTX_build_cert_chain(ctx, flags) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL)
# define SSL_CTX_select_current_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509))
# define SSL_CTX_set_current_cert(ctx, op) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CURRENT_CERT, op, NULL)
# define SSL_CTX_set0_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set1_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st))
# define SSL_CTX_get0_verify_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set0_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_CTX_set1_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st))
# define SSL_CTX_get0_chain_cert_store(ctx,st) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_set0_chain(s,sk) \
        SSL_ctrl(s,SSL_CTRL_CHAIN,0,(char *)(sk))
# define SSL_set1_chain(s,sk) \
        SSL_ctrl(s,SSL_CTRL_CHAIN,1,(char *)(sk))
# define SSL_add0_chain_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,0,(char *)(x509))
# define SSL_add1_chain_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,1,(char *)(x509))
# define SSL_get0_chain_certs(s,px509) \
        SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERTS,0,px509)
# define SSL_clear_chain_certs(s) \
        SSL_set0_chain(s,NULL)
# define SSL_build_cert_chain(s, flags) \
        SSL_ctrl(s,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL)
# define SSL_select_current_cert(s,x509) \
        SSL_ctrl(s,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509))
# define SSL_set_current_cert(s,op) \
        SSL_ctrl(s,SSL_CTRL_SET_CURRENT_CERT, op, NULL)
# define SSL_set0_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_set1_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st))
#define SSL_get0_verify_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_GET_VERIFY_CERT_STORE,0,(char *)(st))
# define SSL_set0_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st))
# define SSL_set1_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st))
#define SSL_get0_chain_cert_store(s,st) \
        SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERT_STORE,0,(char *)(st))

# define SSL_get1_groups(s, glist) \
        SSL_ctrl(s,SSL_CTRL_GET_GROUPS,0,(int*)(glist))
# define SSL_CTX_set1_groups(ctx, glist, glistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS,glistlen,(int *)(glist))
# define SSL_CTX_set1_groups_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(s))
# define SSL_set1_groups(s, glist, glistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_GROUPS,glistlen,(char *)(glist))
# define SSL_set1_groups_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(str))
# define SSL_get_shared_group(s, n) \
        SSL_ctrl(s,SSL_CTRL_GET_SHARED_GROUP,n,NULL)
# define SSL_get_negotiated_group(s) \
        SSL_ctrl(s,SSL_CTRL_GET_NEGOTIATED_GROUP,0,NULL)
# define SSL_CTX_set1_sigalgs(ctx, slist, slistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist))
# define SSL_CTX_set1_sigalgs_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(s))
# define SSL_set1_sigalgs(s, slist, slistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist))
# define SSL_set1_sigalgs_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(str))
# define SSL_CTX_set1_client_sigalgs(ctx, slist, slistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist))
# define SSL_CTX_set1_client_sigalgs_list(ctx, s) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(s))
# define SSL_set1_client_sigalgs(s, slist, slistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist))
# define SSL_set1_client_sigalgs_list(s, str) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(str))
# define SSL_get0_certificate_types(s, clist) \
        SSL_ctrl(s, SSL_CTRL_GET_CLIENT_CERT_TYPES, 0, (char *)(clist))
# define SSL_CTX_set1_client_certificate_types(ctx, clist, clistlen) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen, \
                     (char *)(clist))
# define SSL_set1_client_certificate_types(s, clist, clistlen) \
        SSL_ctrl(s,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen,(char *)(clist))
# define SSL_get_signature_nid(s, pn) \
        SSL_ctrl(s,SSL_CTRL_GET_SIGNATURE_NID,0,pn)
# define SSL_get_peer_signature_nid(s, pn) \
        SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NID,0,pn)
# define SSL_get_peer_tmp_key(s, pk) \
        SSL_ctrl(s,SSL_CTRL_GET_PEER_TMP_KEY,0,pk)
# define SSL_get_tmp_key(s, pk) \
        SSL_ctrl(s,SSL_CTRL_GET_TMP_KEY,0,pk)
# define SSL_get0_raw_cipherlist(s, plst) \
        SSL_ctrl(s,SSL_CTRL_GET_RAW_CIPHERLIST,0,plst)
# define SSL_get0_ec_point_formats(s, plst) \
        SSL_ctrl(s,SSL_CTRL_GET_EC_POINT_FORMATS,0,plst)
# define SSL_CTX_set_min_proto_version(ctx, version) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
# define SSL_CTX_set_max_proto_version(ctx, version) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
# define SSL_CTX_get_min_proto_version(ctx) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL)
# define SSL_CTX_get_max_proto_version(ctx) \
        SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL)
# define SSL_set_min_proto_version(s, version) \
        SSL_ctrl(s, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
# define SSL_set_max_proto_version(s, version) \
        SSL_ctrl(s, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
# define SSL_get_min_proto_version(s) \
        SSL_ctrl(s, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL)
# define SSL_get_max_proto_version(s) \
        SSL_ctrl(s, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL)

const char *SSL_group_to_name(SSL *s, int id);

/* Backwards compatibility, original 1.1.0 names */
# define SSL_CTRL_GET_SERVER_TMP_KEY \
         SSL_CTRL_GET_PEER_TMP_KEY
# define SSL_get_server_tmp_key(s, pk) \
         SSL_get_peer_tmp_key(s, pk)

int SSL_set0_tmp_dh_pkey(SSL *s, EVP_PKEY *dhpkey);
int SSL_CTX_set0_tmp_dh_pkey(SSL_CTX *ctx, EVP_PKEY *dhpkey);

/*
 * The following symbol names are old and obsolete. They are kept
 * for compatibility reasons only and should not be used anymore.
 */
# define SSL_CTRL_GET_CURVES           SSL_CTRL_GET_GROUPS
# define SSL_CTRL_SET_CURVES           SSL_CTRL_SET_GROUPS
# define SSL_CTRL_SET_CURVES_LIST      SSL_CTRL_SET_GROUPS_LIST
# define SSL_CTRL_GET_SHARED_CURVE     SSL_CTRL_GET_SHARED_GROUP

# define SSL_get1_curves               SSL_get1_groups
# define SSL_CTX_set1_curves           SSL_CTX_set1_groups
# define SSL_CTX_set1_curves_list      SSL_CTX_set1_groups_list
# define SSL_set1_curves               SSL_set1_groups
# define SSL_set1_curves_list          SSL_set1_groups_list
# define SSL_get_shared_curve          SSL_get_shared_group


# ifndef OPENSSL_NO_DEPRECATED_1_1_0
/* Provide some compatibility macros for removed functionality. */
#  define SSL_CTX_need_tmp_RSA(ctx)                0
#  define SSL_CTX_set_tmp_rsa(ctx,rsa)             1
#  define SSL_need_tmp_RSA(ssl)                    0
#  define SSL_set_tmp_rsa(ssl,rsa)                 1
#  define SSL_CTX_set_ecdh_auto(dummy, onoff)      ((onoff) != 0)
#  define SSL_set_ecdh_auto(dummy, onoff)          ((onoff) != 0)
/*
 * We "pretend" to call the callback to avoid warnings about unused static
 * functions.
 */
#  define SSL_CTX_set_tmp_rsa_callback(ctx, cb)    while(0) (cb)(NULL, 0, 0)
#  define SSL_set_tmp_rsa_callback(ssl, cb)        while(0) (cb)(NULL, 0, 0)
# endif
__owur const BIO_METHOD *BIO_f_ssl(void);
__owur BIO *BIO_new_ssl(SSL_CTX *ctx, int client);
__owur BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
__owur BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
__owur int BIO_ssl_copy_session_id(BIO *to, BIO *from);
void BIO_ssl_shutdown(BIO *ssl_bio);

__owur int SSL_CTX_set_cipher_list(SSL_CTX *, const char *str);
__owur SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);
__owur SSL_CTX *SSL_CTX_new_ex(OSSL_LIB_CTX *libctx, const char *propq,
                               const SSL_METHOD *meth);
int SSL_CTX_up_ref(SSL_CTX *ctx);
void SSL_CTX_free(SSL_CTX *);
__owur long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
__owur long SSL_CTX_get_timeout(const SSL_CTX *ctx);
__owur X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *);
void SSL_CTX_set_cert_store(SSL_CTX *, X509_STORE *);
void SSL_CTX_set1_cert_store(SSL_CTX *, X509_STORE *);
__owur int SSL_want(const SSL *s);
__owur int SSL_clear(SSL *s);

void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm);

__owur const SSL_CIPHER *SSL_get_current_cipher(const SSL *s);
__owur const SSL_CIPHER *SSL_get_pending_cipher(const SSL *s);
__owur int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits);
__owur const char *SSL_CIPHER_get_version(const SSL_CIPHER *c);
__owur const char *SSL_CIPHER_get_name(const SSL_CIPHER *c);
__owur const char *SSL_CIPHER_standard_name(const SSL_CIPHER *c);
__owur const char *OPENSSL_cipher_name(const char *rfc_name);
__owur uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *c);
__owur uint16_t SSL_CIPHER_get_protocol_id(const SSL_CIPHER *c);
__owur int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *c);
__owur int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *c);
__owur const EVP_MD *SSL_CIPHER_get_handshake_digest(const SSL_CIPHER *c);
__owur int SSL_CIPHER_is_aead(const SSL_CIPHER *c);

__owur int SSL_get_fd(const SSL *s);
__owur int SSL_get_rfd(const SSL *s);
__owur int SSL_get_wfd(const SSL *s);
__owur const char *SSL_get_cipher_list(const SSL *s, int n);
__owur char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size);
__owur int SSL_get_read_ahead(const SSL *s);
__owur int SSL_pending(const SSL *s);
__owur int SSL_has_pending(const SSL *s);
# ifndef OPENSSL_NO_SOCK
__owur int SSL_set_fd(SSL *s, int fd);
__owur int SSL_set_rfd(SSL *s, int fd);
__owur int SSL_set_wfd(SSL *s, int fd);
# endif
void SSL_set0_rbio(SSL *s, BIO *rbio);
void SSL_set0_wbio(SSL *s, BIO *wbio);
void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio);
__owur BIO *SSL_get_rbio(const SSL *s);
__owur BIO *SSL_get_wbio(const SSL *s);
__owur int SSL_set_cipher_list(SSL *s, const char *str);
__owur int SSL_CTX_set_ciphersuites(SSL_CTX *ctx, const char *str);
__owur int SSL_set_ciphersuites(SSL *s, const char *str);
void SSL_set_read_ahead(SSL *s, int yes);
__owur int SSL_get_verify_mode(const SSL *s);
__owur int SSL_get_verify_depth(const SSL *s);
__owur SSL_verify_cb SSL_get_verify_callback(const SSL *s);
void SSL_set_verify(SSL *s, int mode, SSL_verify_cb callback);
void SSL_set_verify_depth(SSL *s, int depth);
void SSL_set_cert_cb(SSL *s, int (*cb) (SSL *ssl, void *arg), void *arg);
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 __owur int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
OSSL_DEPRECATEDIN_3_0
__owur int SSL_use_RSAPrivateKey_ASN1(SSL *ssl,
                                      const unsigned char *d, long len);
# endif
__owur int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
__owur int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d,
                                   long len);
__owur int SSL_use_certificate(SSL *ssl, X509 *x);
__owur int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
__owur int SSL_use_cert_and_key(SSL *ssl, X509 *x509, EVP_PKEY *privatekey,
                                STACK_OF(X509) *chain, int override);


/* serverinfo file format versions */
# define SSL_SERVERINFOV1   1
# define SSL_SERVERINFOV2   2

/* Set serverinfo data for the current active cert. */
__owur int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo,
                                  size_t serverinfo_length);
__owur int SSL_CTX_use_serverinfo_ex(SSL_CTX *ctx, unsigned int version,
                                     const unsigned char *serverinfo,
                                     size_t serverinfo_length);
__owur int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file);

#ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
#endif

__owur int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
__owur int SSL_use_certificate_file(SSL *ssl, const char *file, int type);

#ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file,
                                          int type);
#endif
__owur int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file,
                                       int type);
__owur int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file,
                                        int type);
/* PEM type */
__owur int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file);
__owur int SSL_use_certificate_chain_file(SSL *ssl, const char *file);
__owur STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
__owur STACK_OF(X509_NAME)
*SSL_load_client_CA_file_ex(const char *file, OSSL_LIB_CTX *libctx,
                            const char *propq);
__owur int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                               const char *file);
int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                       const char *dir);
int SSL_add_store_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
                                       const char *uri);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_load_error_strings() \
    OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS \
                     | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL)
# endif

__owur const char *SSL_state_string(const SSL *s);
__owur const char *SSL_rstate_string(const SSL *s);
__owur const char *SSL_state_string_long(const SSL *s);
__owur const char *SSL_rstate_string_long(const SSL *s);
__owur long SSL_SESSION_get_time(const SSL_SESSION *s);
__owur long SSL_SESSION_set_time(SSL_SESSION *s, long t);
__owur long SSL_SESSION_get_timeout(const SSL_SESSION *s);
__owur long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
__owur int SSL_SESSION_get_protocol_version(const SSL_SESSION *s);
__owur int SSL_SESSION_set_protocol_version(SSL_SESSION *s, int version);

__owur const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s);
__owur int SSL_SESSION_set1_hostname(SSL_SESSION *s, const char *hostname);
void SSL_SESSION_get0_alpn_selected(const SSL_SESSION *s,
                                    const unsigned char **alpn,
                                    size_t *len);
__owur int SSL_SESSION_set1_alpn_selected(SSL_SESSION *s,
                                          const unsigned char *alpn,
                                          size_t len);
__owur const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s);
__owur int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher);
__owur int SSL_SESSION_has_ticket(const SSL_SESSION *s);
__owur unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s);
void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick,
                             size_t *len);
__owur uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s);
__owur int SSL_SESSION_set_max_early_data(SSL_SESSION *s,
                                          uint32_t max_early_data);
__owur int SSL_copy_session_id(SSL *to, const SSL *from);
__owur X509 *SSL_SESSION_get0_peer(SSL_SESSION *s);
__owur int SSL_SESSION_set1_id_context(SSL_SESSION *s,
                                       const unsigned char *sid_ctx,
                                       unsigned int sid_ctx_len);
__owur int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid,
                               unsigned int sid_len);
__owur int SSL_SESSION_is_resumable(const SSL_SESSION *s);

__owur SSL_SESSION *SSL_SESSION_new(void);
__owur SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src);
const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s,
                                        unsigned int *len);
const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s,
                                                 unsigned int *len);
__owur unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s);
# ifndef OPENSSL_NO_STDIO
int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *ses);
# endif
int SSL_SESSION_print(BIO *fp, const SSL_SESSION *ses);
int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x);
int SSL_SESSION_up_ref(SSL_SESSION *ses);
void SSL_SESSION_free(SSL_SESSION *ses);
__owur int i2d_SSL_SESSION(const SSL_SESSION *in, unsigned char **pp);
__owur int SSL_set_session(SSL *to, SSL_SESSION *session);
int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *session);
int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *session);
__owur int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb);
__owur int SSL_set_generate_session_id(SSL *s, GEN_SESSION_CB cb);
__owur int SSL_has_matching_session_id(const SSL *s,
                                       const unsigned char *id,
                                       unsigned int id_len);
SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
                             long length);

# ifdef OPENSSL_X509_H
__owur X509 *SSL_get0_peer_certificate(const SSL *s);
__owur X509 *SSL_get1_peer_certificate(const SSL *s);
/* Deprecated in 3.0.0 */
#  ifndef OPENSSL_NO_DEPRECATED_3_0
#   define SSL_get_peer_certificate SSL_get1_peer_certificate
#  endif
# endif

__owur STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s);

__owur int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
__owur int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
__owur SSL_verify_cb SSL_CTX_get_verify_callback(const SSL_CTX *ctx);
void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, SSL_verify_cb callback);
void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,
                                      int (*cb) (X509_STORE_CTX *, void *),
                                      void *arg);
void SSL_CTX_set_cert_cb(SSL_CTX *c, int (*cb) (SSL *ssl, void *arg),
                         void *arg);
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d,
                                          long len);
# endif
__owur int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
__owur int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx,
                                       const unsigned char *d, long len);
__owur int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
__owur int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len,
                                        const unsigned char *d);
__owur int SSL_CTX_use_cert_and_key(SSL_CTX *ctx, X509 *x509, EVP_PKEY *privatekey,
                                    STACK_OF(X509) *chain, int override);

void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx);
void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx);
void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb);
void SSL_set_default_passwd_cb_userdata(SSL *s, void *u);
pem_password_cb *SSL_get_default_passwd_cb(SSL *s);
void *SSL_get_default_passwd_cb_userdata(SSL *s);

__owur int SSL_CTX_check_private_key(const SSL_CTX *ctx);
__owur int SSL_check_private_key(const SSL *ctx);

__owur int SSL_CTX_set_session_id_context(SSL_CTX *ctx,
                                          const unsigned char *sid_ctx,
                                          unsigned int sid_ctx_len);

SSL *SSL_new(SSL_CTX *ctx);
int SSL_up_ref(SSL *s);
int SSL_is_dtls(const SSL *s);
__owur int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx,
                                      unsigned int sid_ctx_len);

__owur int SSL_CTX_set_purpose(SSL_CTX *ctx, int purpose);
__owur int SSL_set_purpose(SSL *ssl, int purpose);
__owur int SSL_CTX_set_trust(SSL_CTX *ctx, int trust);
__owur int SSL_set_trust(SSL *ssl, int trust);

__owur int SSL_set1_host(SSL *s, const char *hostname);
__owur int SSL_add1_host(SSL *s, const char *hostname);
__owur const char *SSL_get0_peername(SSL *s);
void SSL_set_hostflags(SSL *s, unsigned int flags);

__owur int SSL_CTX_dane_enable(SSL_CTX *ctx);
__owur int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md,
                                  uint8_t mtype, uint8_t ord);
__owur int SSL_dane_enable(SSL *s, const char *basedomain);
__owur int SSL_dane_tlsa_add(SSL *s, uint8_t usage, uint8_t selector,
                             uint8_t mtype, const unsigned char *data, size_t dlen);
__owur int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki);
__owur int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector,
                              uint8_t *mtype, const unsigned char **data,
                              size_t *dlen);
/*
 * Bridge opacity barrier between libcrypt and libssl, also needed to support
 * offline testing in test/danetest.c
 */
SSL_DANE *SSL_get0_dane(SSL *ssl);
/*
 * DANE flags
 */
unsigned long SSL_CTX_dane_set_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_CTX_dane_clear_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_dane_set_flags(SSL *ssl, unsigned long flags);
unsigned long SSL_dane_clear_flags(SSL *ssl, unsigned long flags);

__owur int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
__owur int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm);

__owur X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx);
__owur X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl);

# ifndef OPENSSL_NO_SRP
#  ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password);
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength);
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx,
                                        char *(*cb) (SSL *, void *));
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx,
                                          int (*cb) (SSL *, void *));
OSSL_DEPRECATEDIN_3_0
int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx,
                                      int (*cb) (SSL *, int *, void *));
OSSL_DEPRECATEDIN_3_0 int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg);

OSSL_DEPRECATEDIN_3_0
int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g,
                             BIGNUM *sa, BIGNUM *v, char *info);
OSSL_DEPRECATEDIN_3_0
int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass,
                                const char *grp);

OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_g(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur BIGNUM *SSL_get_srp_N(SSL *s);

OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_username(SSL *s);
OSSL_DEPRECATEDIN_3_0 __owur char *SSL_get_srp_userinfo(SSL *s);
#  endif
# endif

/*
 * ClientHello callback and helpers.
 */

# define SSL_CLIENT_HELLO_SUCCESS 1
# define SSL_CLIENT_HELLO_ERROR   0
# define SSL_CLIENT_HELLO_RETRY   (-1)

typedef int (*SSL_client_hello_cb_fn) (SSL *s, int *al, void *arg);
void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_fn cb,
                                 void *arg);
int SSL_client_hello_isv2(SSL *s);
unsigned int SSL_client_hello_get0_legacy_version(SSL *s);
size_t SSL_client_hello_get0_random(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_session_id(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_compression_methods(SSL *s,
                                                 const unsigned char **out);
int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen);
int SSL_client_hello_get0_ext(SSL *s, unsigned int type,
                              const unsigned char **out, size_t *outlen);

void SSL_certs_clear(SSL *s);
void SSL_free(SSL *ssl);
# ifdef OSSL_ASYNC_FD
/*
 * Windows application developer has to include windows.h to use these.
 */
__owur int SSL_waiting_for_async(SSL *s);
__owur int SSL_get_all_async_fds(SSL *s, OSSL_ASYNC_FD *fds, size_t *numfds);
__owur int SSL_get_changed_async_fds(SSL *s, OSSL_ASYNC_FD *addfd,
                                     size_t *numaddfds, OSSL_ASYNC_FD *delfd,
                                     size_t *numdelfds);
__owur int SSL_CTX_set_async_callback(SSL_CTX *ctx, SSL_async_callback_fn callback);
__owur int SSL_CTX_set_async_callback_arg(SSL_CTX *ctx, void *arg);
__owur int SSL_set_async_callback(SSL *s, SSL_async_callback_fn callback);
__owur int SSL_set_async_callback_arg(SSL *s, void *arg);
__owur int SSL_get_async_status(SSL *s, int *status);

# endif
__owur int SSL_accept(SSL *ssl);
__owur int SSL_stateless(SSL *s);
__owur int SSL_connect(SSL *ssl);
__owur int SSL_read(SSL *ssl, void *buf, int num);
__owur int SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);

# define SSL_READ_EARLY_DATA_ERROR   0
# define SSL_READ_EARLY_DATA_SUCCESS 1
# define SSL_READ_EARLY_DATA_FINISH  2

__owur int SSL_read_early_data(SSL *s, void *buf, size_t num,
                               size_t *readbytes);
__owur int SSL_peek(SSL *ssl, void *buf, int num);
__owur int SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);
__owur ossl_ssize_t SSL_sendfile(SSL *s, int fd, off_t offset, size_t size,
                                 int flags);
__owur int SSL_write(SSL *ssl, const void *buf, int num);
__owur int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
__owur int SSL_write_early_data(SSL *s, const void *buf, size_t num,
                                size_t *written);
long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg);
long SSL_callback_ctrl(SSL *, int, void (*)(void));
long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void));

# define SSL_EARLY_DATA_NOT_SENT    0
# define SSL_EARLY_DATA_REJECTED    1
# define SSL_EARLY_DATA_ACCEPTED    2

__owur int SSL_get_early_data_status(const SSL *s);

__owur int SSL_get_error(const SSL *s, int ret_code);
__owur const char *SSL_get_version(const SSL *s);

/* This sets the 'default' SSL version that SSL_new() will create */
# ifndef OPENSSL_NO_DEPRECATED_3_0
OSSL_DEPRECATEDIN_3_0
__owur int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
# endif

# ifndef OPENSSL_NO_SSL3_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_method(void); /* SSLv3 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *SSLv3_client_method(void);
#  endif
# endif

#define SSLv23_method           TLS_method
#define SSLv23_server_method    TLS_server_method
#define SSLv23_client_method    TLS_client_method

/* Negotiate highest available SSL/TLS version */
__owur const SSL_METHOD *TLS_method(void);
__owur const SSL_METHOD *TLS_server_method(void);
__owur const SSL_METHOD *TLS_client_method(void);

# ifndef OPENSSL_NO_TLS1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_TLS1_1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_method(void); /* TLSv1.1 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_TLS1_2_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_method(void); /* TLSv1.2 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *TLSv1_2_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_DTLS1_METHOD
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_method(void); /* DTLSv1.0 */
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_client_method(void);
#  endif
# endif

# ifndef OPENSSL_NO_DTLS1_2_METHOD
/* DTLSv1.2 */
#  ifndef OPENSSL_NO_DEPRECATED_1_1_0
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_server_method(void);
OSSL_DEPRECATEDIN_1_1_0 __owur const SSL_METHOD *DTLSv1_2_client_method(void);
#  endif
# endif

__owur const SSL_METHOD *DTLS_method(void); /* DTLS 1.0 and 1.2 */
__owur const SSL_METHOD *DTLS_server_method(void); /* DTLS 1.0 and 1.2 */
__owur const SSL_METHOD *DTLS_client_method(void); /* DTLS 1.0 and 1.2 */

__owur size_t DTLS_get_data_mtu(const SSL *s);

__owur STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s);
__owur STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx);
__owur STACK_OF(SSL_CIPHER) *SSL_get_client_ciphers(const SSL *s);
__owur STACK_OF(SSL_CIPHER) *SSL_get1_supported_ciphers(SSL *s);

__owur int SSL_do_handshake(SSL *s);
int SSL_key_update(SSL *s, int updatetype);
int SSL_get_key_update_type(const SSL *s);
int SSL_renegotiate(SSL *s);
int SSL_renegotiate_abbreviated(SSL *s);
__owur int SSL_renegotiate_pending(const SSL *s);
int SSL_new_session_ticket(SSL *s);
int SSL_shutdown(SSL *s);
__owur int SSL_verify_client_post_handshake(SSL *s);
void SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val);
void SSL_set_post_handshake_auth(SSL *s, int val);

__owur const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx);
__owur const SSL_METHOD *SSL_get_ssl_method(const SSL *s);
__owur int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method);
__owur const char *SSL_alert_type_string_long(int value);
__owur const char *SSL_alert_type_string(int value);
__owur const char *SSL_alert_desc_string_long(int value);
__owur const char *SSL_alert_desc_string(int value);

void SSL_set0_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
void SSL_CTX_set0_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
__owur const STACK_OF(X509_NAME) *SSL_get0_CA_list(const SSL *s);
__owur const STACK_OF(X509_NAME) *SSL_CTX_get0_CA_list(const SSL_CTX *ctx);
__owur int SSL_add1_to_CA_list(SSL *ssl, const X509 *x);
__owur int SSL_CTX_add1_to_CA_list(SSL_CTX *ctx, const X509 *x);
__owur const STACK_OF(X509_NAME) *SSL_get0_peer_CA_list(const SSL *s);

void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
__owur STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s);
__owur STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s);
__owur int SSL_add_client_CA(SSL *ssl, X509 *x);
__owur int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);

void SSL_set_connect_state(SSL *s);
void SSL_set_accept_state(SSL *s);

__owur long SSL_get_default_timeout(const SSL *s);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_library_init() OPENSSL_init_ssl(0, NULL)
# endif

__owur char *SSL_CIPHER_description(const SSL_CIPHER *, char *buf, int size);
__owur STACK_OF(X509_NAME) *SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk);

__owur SSL *SSL_dup(SSL *ssl);

__owur X509 *SSL_get_certificate(const SSL *ssl);
/*
 * EVP_PKEY
 */
struct evp_pkey_st *SSL_get_privatekey(const SSL *ssl);

__owur X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx);
__owur EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx);

void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode);
__owur int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
void SSL_set_quiet_shutdown(SSL *ssl, int mode);
__owur int SSL_get_quiet_shutdown(const SSL *ssl);
void SSL_set_shutdown(SSL *ssl, int mode);
__owur int SSL_get_shutdown(const SSL *ssl);
__owur int SSL_version(const SSL *ssl);
__owur int SSL_client_version(const SSL *s);
__owur int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_file(SSL_CTX *ctx);
__owur int SSL_CTX_set_default_verify_store(SSL_CTX *ctx);
__owur int SSL_CTX_load_verify_file(SSL_CTX *ctx, const char *CAfile);
__owur int SSL_CTX_load_verify_dir(SSL_CTX *ctx, const char *CApath);
__owur int SSL_CTX_load_verify_store(SSL_CTX *ctx, const char *CAstore);
__owur int SSL_CTX_load_verify_locations(SSL_CTX *ctx,
                                                        const char *CAfile,
                                                        const char *CApath);
# define SSL_get0_session SSL_get_session/* just peek at pointer */
__owur SSL_SESSION *SSL_get_session(const SSL *ssl);
__owur SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
__owur SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx);
void SSL_set_info_callback(SSL *ssl,
                           void (*cb) (const SSL *ssl, int type, int val));
void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type,
                                               int val);
__owur OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl);

void SSL_set_verify_result(SSL *ssl, long v);
__owur long SSL_get_verify_result(const SSL *ssl);
__owur STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s);

__owur size_t SSL_get_client_random(const SSL *ssl, unsigned char *out,
                                    size_t outlen);
__owur size_t SSL_get_server_random(const SSL *ssl, unsigned char *out,
                                    size_t outlen);
__owur size_t SSL_SESSION_get_master_key(const SSL_SESSION *sess,
                                         unsigned char *out, size_t outlen);
__owur int SSL_SESSION_set1_master_key(SSL_SESSION *sess,
                                       const unsigned char *in, size_t len);
uint8_t SSL_SESSION_get_max_fragment_length(const SSL_SESSION *sess);

#define SSL_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, l, p, newf, dupf, freef)
__owur int SSL_set_ex_data(SSL *ssl, int idx, void *data);
void *SSL_get_ex_data(const SSL *ssl, int idx);
#define SSL_SESSION_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, l, p, newf, dupf, freef)
__owur int SSL_SESSION_set_ex_data(SSL_SESSION *ss, int idx, void *data);
void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss, int idx);
#define SSL_CTX_get_ex_new_index(l, p, newf, dupf, freef) \
    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, l, p, newf, dupf, freef)
__owur int SSL_CTX_set_ex_data(SSL_CTX *ssl, int idx, void *data);
void *SSL_CTX_get_ex_data(const SSL_CTX *ssl, int idx);

__owur int SSL_get_ex_data_X509_STORE_CTX_idx(void);

# define SSL_CTX_sess_set_cache_size(ctx,t) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
# define SSL_CTX_sess_get_cache_size(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
# define SSL_CTX_set_session_cache_mode(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
# define SSL_CTX_get_session_cache_mode(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)

# define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
# define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
# define SSL_CTX_get_read_ahead(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
# define SSL_CTX_set_read_ahead(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL)
# define SSL_CTX_get_max_cert_list(ctx) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
# define SSL_CTX_set_max_cert_list(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
# define SSL_get_max_cert_list(ssl) \
        SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
# define SSL_set_max_cert_list(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)

# define SSL_CTX_set_max_send_fragment(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
# define SSL_set_max_send_fragment(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
# define SSL_CTX_set_split_send_fragment(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL)
# define SSL_set_split_send_fragment(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL)
# define SSL_CTX_set_max_pipelines(ctx,m) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
# define SSL_set_max_pipelines(ssl,m) \
        SSL_ctrl(ssl,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
# define SSL_set_retry_verify(ssl) \
        (SSL_ctrl(ssl,SSL_CTRL_SET_RETRY_VERIFY,0,NULL) > 0)

void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len);
void SSL_set_default_read_buffer_len(SSL *s, size_t len);

# ifndef OPENSSL_NO_DH
#  ifndef OPENSSL_NO_DEPRECATED_3_0
/* NB: the |keylength| is only applicable when is_export is true */
OSSL_DEPRECATEDIN_3_0
void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
                                 DH *(*dh) (SSL *ssl, int is_export,
                                            int keylength));
OSSL_DEPRECATEDIN_3_0
void SSL_set_tmp_dh_callback(SSL *ssl,
                             DH *(*dh) (SSL *ssl, int is_export,
                                        int keylength));
#  endif
# endif

__owur const COMP_METHOD *SSL_get_current_compression(const SSL *s);
__owur const COMP_METHOD *SSL_get_current_expansion(const SSL *s);
__owur const char *SSL_COMP_get_name(const COMP_METHOD *comp);
__owur const char *SSL_COMP_get0_name(const SSL_COMP *comp);
__owur int SSL_COMP_get_id(const SSL_COMP *comp);
STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
__owur STACK_OF(SSL_COMP) *SSL_COMP_set0_compression_methods(STACK_OF(SSL_COMP)
                                                             *meths);
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_COMP_free_compression_methods() while(0) continue
# endif
__owur int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm);

const SSL_CIPHER *SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr);
int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c);
int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c);
int SSL_bytes_to_cipher_list(SSL *s, const unsigned char *bytes, size_t len,
                             int isv2format, STACK_OF(SSL_CIPHER) **sk,
                             STACK_OF(SSL_CIPHER) **scsvs);

/* TLS extensions functions */
__owur int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);

__owur int SSL_set_session_ticket_ext_cb(SSL *s,
                                         tls_session_ticket_ext_cb_fn cb,
                                         void *arg);

/* Pre-shared secret session resumption functions */
__owur int SSL_set_session_secret_cb(SSL *s,
                                     tls_session_secret_cb_fn session_secret_cb,
                                     void *arg);

void SSL_CTX_set_not_resumable_session_callback(SSL_CTX *ctx,
                                                int (*cb) (SSL *ssl,
                                                           int
                                                           is_forward_secure));

void SSL_set_not_resumable_session_callback(SSL *ssl,
                                            int (*cb) (SSL *ssl,
                                                       int is_forward_secure));

void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx,
                                         size_t (*cb) (SSL *ssl, int type,
                                                       size_t len, void *arg));
void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg);
void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx);
int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size);

int SSL_set_record_padding_callback(SSL *ssl,
                                    size_t (*cb) (SSL *ssl, int type,
                                                  size_t len, void *arg));
void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg);
void *SSL_get_record_padding_callback_arg(const SSL *ssl);
int SSL_set_block_padding(SSL *ssl, size_t block_size);

int SSL_set_num_tickets(SSL *s, size_t num_tickets);
size_t SSL_get_num_tickets(const SSL *s);
int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets);
size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx);

# ifndef OPENSSL_NO_DEPRECATED_1_1_0
#  define SSL_cache_hit(s) SSL_session_reused(s)
# endif

__owur int SSL_session_reused(const SSL *s);
__owur int SSL_is_server(const SSL *s);

__owur __owur SSL_CONF_CTX *SSL_CONF_CTX_new(void);
int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx);
void SSL_CONF_CTX_free(SSL_CONF_CTX *cctx);
unsigned int SSL_CONF_CTX_set_flags(SSL_CONF_CTX *cctx, unsigned int flags);
__owur unsigned int SSL_CONF_CTX_clear_flags(SSL_CONF_CTX *cctx,
                                             unsigned int flags);
__owur int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre);

void SSL_CONF_CTX_set_ssl(SSL_CONF_CTX *cctx, SSL *ssl);
void SSL_CONF_CTX_set_ssl_ctx(SSL_CONF_CTX *cctx, SSL_CTX *ctx);

__owur int SSL_CONF_cmd(SSL_CONF_CTX *cctx, const char *cmd, const char *value);
__owur int SSL_CONF_cmd_argv(SSL_CONF_CTX *cctx, int *pargc, char ***pargv);
__owur int SSL_CONF_cmd_value_type(SSL_CONF_CTX *cctx, const char *cmd);

void SSL_add_ssl_module(void);
int SSL_config(SSL *s, const char *name);
int SSL_CTX_config(SSL_CTX *ctx, const char *name);

# ifndef OPENSSL_NO_SSL_TRACE
void SSL_trace(int write_p, int version, int content_type,
               const void *buf, size_t len, SSL *ssl, void *arg);
# endif

# ifndef OPENSSL_NO_SOCK
int DTLSv1_listen(SSL *s, BIO_ADDR *client);
# endif

# ifndef OPENSSL_NO_CT

/*
 * A callback for verifying that the received SCTs are sufficient.
 * Expected to return 1 if they are sufficient, otherwise 0.
 * May return a negative integer if an error occurs.
 * A connection should be aborted if the SCTs are deemed insufficient.
 */
typedef int (*ssl_ct_validation_cb)(const CT_POLICY_EVAL_CTX *ctx,
                                    const STACK_OF(SCT) *scts, void *arg);

/*
 * Sets a |callback| that is invoked upon receipt of ServerHelloDone to validate
 * the received SCTs.
 * If the callback returns a non-positive result, the connection is terminated.
 * Call this function before beginning a handshake.
 * If a NULL |callback| is provided, SCT validation is disabled.
 * |arg| is arbitrary userdata that will be passed to the callback whenever it
 * is invoked. Ownership of |arg| remains with the caller.
 *
 * NOTE: A side-effect of setting a CT callback is that an OCSP stapled response
 *       will be requested.
 */
int SSL_set_ct_validation_callback(SSL *s, ssl_ct_validation_cb callback,
                                   void *arg);
int SSL_CTX_set_ct_validation_callback(SSL_CTX *ctx,
                                       ssl_ct_validation_cb callback,
                                       void *arg);
#define SSL_disable_ct(s) \
        ((void) SSL_set_validation_callback((s), NULL, NULL))
#define SSL_CTX_disable_ct(ctx) \
        ((void) SSL_CTX_set_validation_callback((ctx), NULL, NULL))

/*
 * The validation type enumerates the available behaviours of the built-in SSL
 * CT validation callback selected via SSL_enable_ct() and SSL_CTX_enable_ct().
 * The underlying callback is a static function in libssl.
 */
enum {
    SSL_CT_VALIDATION_PERMISSIVE = 0,
    SSL_CT_VALIDATION_STRICT
};

/*
 * Enable CT by setting up a callback that implements one of the built-in
 * validation variants.  The SSL_CT_VALIDATION_PERMISSIVE variant always
 * continues the handshake, the application can make appropriate decisions at
 * handshake completion.  The SSL_CT_VALIDATION_STRICT variant requires at
 * least one valid SCT, or else handshake termination will be requested.  The
 * handshake may continue anyway if SSL_VERIFY_NONE is in effect.
 */
int SSL_enable_ct(SSL *s, int validation_mode);
int SSL_CTX_enable_ct(SSL_CTX *ctx, int validation_mode);

/*
 * Report whether a non-NULL callback is enabled.
 */
int SSL_ct_is_enabled(const SSL *s);
int SSL_CTX_ct_is_enabled(const SSL_CTX *ctx);

/* Gets the SCTs received from a connection */
const STACK_OF(SCT) *SSL_get0_peer_scts(SSL *s);

/*
 * Loads the CT log list from the default location.
 * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store,
 * the log information loaded from this file will be appended to the
 * CTLOG_STORE.
 * Returns 1 on success, 0 otherwise.
 */
int SSL_CTX_set_default_ctlog_list_file(SSL_CTX *ctx);

/*
 * Loads the CT log list from the specified file path.
 * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store,
 * the log information loaded from this file will be appended to the
 * CTLOG_STORE.
 * Returns 1 on success, 0 otherwise.
 */
int SSL_CTX_set_ctlog_list_file(SSL_CTX *ctx, const char *path);

/*
 * Sets the CT log list used by all SSL connections created from this SSL_CTX.
 * Ownership of the CTLOG_STORE is transferred to the SSL_CTX.
 */
void SSL_CTX_set0_ctlog_store(SSL_CTX *ctx, CTLOG_STORE *logs);

/*
 * Gets the CT log list used by all SSL connections created from this SSL_CTX.
 * This will be NULL unless one of the following functions has been called:
 * - SSL_CTX_set_default_ctlog_list_file
 * - SSL_CTX_set_ctlog_list_file
 * - SSL_CTX_set_ctlog_store
 */
const CTLOG_STORE *SSL_CTX_get0_ctlog_store(const SSL_CTX *ctx);

# endif /* OPENSSL_NO_CT */

/* What the "other" parameter contains in security callback */
/* Mask for type */
# define SSL_SECOP_OTHER_TYPE    0xffff0000
# define SSL_SECOP_OTHER_NONE    0
# define SSL_SECOP_OTHER_CIPHER  (1 << 16)
# define SSL_SECOP_OTHER_CURVE   (2 << 16)
# define SSL_SECOP_OTHER_DH      (3 << 16)
# define SSL_SECOP_OTHER_PKEY    (4 << 16)
# define SSL_SECOP_OTHER_SIGALG  (5 << 16)
# define SSL_SECOP_OTHER_CERT    (6 << 16)

/* Indicated operation refers to peer key or certificate */
# define SSL_SECOP_PEER          0x1000

/* Values for "op" parameter in security callback */

/* Called to filter ciphers */
/* Ciphers client supports */
# define SSL_SECOP_CIPHER_SUPPORTED      (1 | SSL_SECOP_OTHER_CIPHER)
/* Cipher shared by client/server */
# define SSL_SECOP_CIPHER_SHARED         (2 | SSL_SECOP_OTHER_CIPHER)
/* Sanity check of cipher server selects */
# define SSL_SECOP_CIPHER_CHECK          (3 | SSL_SECOP_OTHER_CIPHER)
/* Curves supported by client */
# define SSL_SECOP_CURVE_SUPPORTED       (4 | SSL_SECOP_OTHER_CURVE)
/* Curves shared by client/server */
# define SSL_SECOP_CURVE_SHARED          (5 | SSL_SECOP_OTHER_CURVE)
/* Sanity check of curve server selects */
# define SSL_SECOP_CURVE_CHECK           (6 | SSL_SECOP_OTHER_CURVE)
/* Temporary DH key */
# define SSL_SECOP_TMP_DH                (7 | SSL_SECOP_OTHER_PKEY)
/* SSL/TLS version */
# define SSL_SECOP_VERSION               (9 | SSL_SECOP_OTHER_NONE)
/* Session tickets */
# define SSL_SECOP_TICKET                (10 | SSL_SECOP_OTHER_NONE)
/* Supported signature algorithms sent to peer */
# define SSL_SECOP_SIGALG_SUPPORTED      (11 | SSL_SECOP_OTHER_SIGALG)
/* Shared signature algorithm */
# define SSL_SECOP_SIGALG_SHARED         (12 | SSL_SECOP_OTHER_SIGALG)
/* Sanity check signature algorithm allowed */
# define SSL_SECOP_SIGALG_CHECK          (13 | SSL_SECOP_OTHER_SIGALG)
/* Used to get mask of supported public key signature algorithms */
# define SSL_SECOP_SIGALG_MASK           (14 | SSL_SECOP_OTHER_SIGALG)
/* Use to see if compression is allowed */
# define SSL_SECOP_COMPRESSION           (15 | SSL_SECOP_OTHER_NONE)
/* EE key in certificate */
# define SSL_SECOP_EE_KEY                (16 | SSL_SECOP_OTHER_CERT)
/* CA key in certificate */
# define SSL_SECOP_CA_KEY                (17 | SSL_SECOP_OTHER_CERT)
/* CA digest algorithm in certificate */
# define SSL_SECOP_CA_MD                 (18 | SSL_SECOP_OTHER_CERT)
/* Peer EE key in certificate */
# define SSL_SECOP_PEER_EE_KEY           (SSL_SECOP_EE_KEY | SSL_SECOP_PEER)
/* Peer CA key in certificate */
# define SSL_SECOP_PEER_CA_KEY           (SSL_SECOP_CA_KEY | SSL_SECOP_PEER)
/* Peer CA digest algorithm in certificate */
# define SSL_SECOP_PEER_CA_MD            (SSL_SECOP_CA_MD | SSL_SECOP_PEER)

void SSL_set_security_level(SSL *s, int level);
__owur int SSL_get_security_level(const SSL *s);
void SSL_set_security_callback(SSL *s,
                               int (*cb) (const SSL *s, const SSL_CTX *ctx,
                                          int op, int bits, int nid,
                                          void *other, void *ex));
int (*SSL_get_security_callback(const SSL *s)) (const SSL *s,
                                                const SSL_CTX *ctx, int op,
                                                int bits, int nid, void *other,
                                                void *ex);
void SSL_set0_security_ex_data(SSL *s, void *ex);
__owur void *SSL_get0_security_ex_data(const SSL *s);

void SSL_CTX_set_security_level(SSL_CTX *ctx, int level);
__owur int SSL_CTX_get_security_level(const SSL_CTX *ctx);
void SSL_CTX_set_security_callback(SSL_CTX *ctx,
                                   int (*cb) (const SSL *s, const SSL_CTX *ctx,
                                              int op, int bits, int nid,
                                              void *other, void *ex));
int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx)) (const SSL *s,
                                                          const SSL_CTX *ctx,
                                                          int op, int bits,
                                                          int nid,
                                                          void *other,
                                                          void *ex);
void SSL_CTX_set0_security_ex_data(SSL_CTX *ctx, void *ex);
__owur void *SSL_CTX_get0_security_ex_data(const SSL_CTX *ctx);

/* OPENSSL_INIT flag 0x010000 reserved for internal use */
# define OPENSSL_INIT_NO_LOAD_SSL_STRINGS    0x00100000L
# define OPENSSL_INIT_LOAD_SSL_STRINGS       0x00200000L

# define OPENSSL_INIT_SSL_DEFAULT \
        (OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS)

int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);

# ifndef OPENSSL_NO_UNIT_TEST
__owur const struct openssl_ssl_test_functions *SSL_test_functions(void);
# endif

__owur int SSL_free_buffers(SSL *ssl);
__owur int SSL_alloc_buffers(SSL *ssl);

/* Status codes passed to the decrypt session ticket callback. Some of these
 * are for internal use only and are never passed to the callback. */
typedef int SSL_TICKET_STATUS;

/* Support for ticket appdata */
/* fatal error, malloc failure */
# define SSL_TICKET_FATAL_ERR_MALLOC 0
/* fatal error, either from parsing or decrypting the ticket */
# define SSL_TICKET_FATAL_ERR_OTHER  1
/* No ticket present */
# define SSL_TICKET_NONE             2
/* Empty ticket present */
# define SSL_TICKET_EMPTY            3
/* the ticket couldn't be decrypted */
# define SSL_TICKET_NO_DECRYPT       4
/* a ticket was successfully decrypted */
# define SSL_TICKET_SUCCESS          5
/* same as above but the ticket needs to be renewed */
# define SSL_TICKET_SUCCESS_RENEW    6

/* Return codes for the decrypt session ticket callback */
typedef int SSL_TICKET_RETURN;

/* An error occurred */
#define SSL_TICKET_RETURN_ABORT             0
/* Do not use the ticket, do not send a renewed ticket to the client */
#define SSL_TICKET_RETURN_IGNORE            1
/* Do not use the ticket, send a renewed ticket to the client */
#define SSL_TICKET_RETURN_IGNORE_RENEW      2
/* Use the ticket, do not send a renewed ticket to the client */
#define SSL_TICKET_RETURN_USE               3
/* Use the ticket, send a renewed ticket to the client */
#define SSL_TICKET_RETURN_USE_RENEW         4

typedef int (*SSL_CTX_generate_session_ticket_fn)(SSL *s, void *arg);
typedef SSL_TICKET_RETURN (*SSL_CTX_decrypt_session_ticket_fn)(SSL *s, SSL_SESSION *ss,
                                                               const unsigned char *keyname,
                                                               size_t keyname_length,
                                                               SSL_TICKET_STATUS status,
                                                               void *arg);
int SSL_CTX_set_session_ticket_cb(SSL_CTX *ctx,
                                  SSL_CTX_generate_session_ticket_fn gen_cb,
                                  SSL_CTX_decrypt_session_ticket_fn dec_cb,
                                  void *arg);
int SSL_SESSION_set1_ticket_appdata(SSL_SESSION *ss, const void *data, size_t len);
int SSL_SESSION_get0_ticket_appdata(SSL_SESSION *ss, void **data, size_t *len);

typedef unsigned int (*DTLS_timer_cb)(SSL *s, unsigned int timer_us);

void DTLS_set_timer_cb(SSL *s, DTLS_timer_cb cb);


typedef int (*SSL_allow_early_data_cb_fn)(SSL *s, void *arg);
void SSL_CTX_set_allow_early_data_cb(SSL_CTX *ctx,
                                     SSL_allow_early_data_cb_fn cb,
                                     void *arg);
void SSL_set_allow_early_data_cb(SSL *s,
                                 SSL_allow_early_data_cb_fn cb,
                                 void *arg);

/* store the default cipher strings inside the library */
const char *OSSL_default_cipher_list(void);
const char *OSSL_default_ciphersuites(void);

#  ifndef OPENSSL_NO_QUIC
/*
 * QUIC integration - The QUIC interface matches BoringSSL
 *
 * ssl_encryption_level_t represents a specific QUIC encryption level used to
 * transmit handshake messages. BoringSSL has this as an 'enum'.
 */
#include <openssl/quic.h>

/* Used by Chromium/QUIC - moved from evp.h to avoid breaking FIPS checksums */
# define X25519_PRIVATE_KEY_LEN          32
# define X25519_PUBLIC_VALUE_LEN         32

/* moved from types.h to avoid breaking FIPS checksums */
typedef struct ssl_quic_method_st SSL_QUIC_METHOD;

typedef enum ssl_encryption_level_t {
    ssl_encryption_initial = 0,
    ssl_encryption_early_data,
    ssl_encryption_handshake,
    ssl_encryption_application
} OSSL_ENCRYPTION_LEVEL;

struct ssl_quic_method_st {
    int (*set_encryption_secrets)(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                                  const uint8_t *read_secret,
                                  const uint8_t *write_secret, size_t secret_len);
    int (*add_handshake_data)(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                              const uint8_t *data, size_t len);
    int (*flush_flight)(SSL *ssl);
    int (*send_alert)(SSL *ssl, enum ssl_encryption_level_t level, uint8_t alert);
};

__owur int SSL_CTX_set_quic_method(SSL_CTX *ctx, const SSL_QUIC_METHOD *quic_method);
__owur int SSL_set_quic_method(SSL *ssl, const SSL_QUIC_METHOD *quic_method);
__owur int SSL_set_quic_transport_params(SSL *ssl,
                                         const uint8_t *params,
                                         size_t params_len);
void SSL_get_peer_quic_transport_params(const SSL *ssl,
                                        const uint8_t **out_params,
                                        size_t *out_params_len);
__owur size_t SSL_quic_max_handshake_flight_len(const SSL *ssl, OSSL_ENCRYPTION_LEVEL level);
__owur OSSL_ENCRYPTION_LEVEL SSL_quic_read_level(const SSL *ssl);
__owur OSSL_ENCRYPTION_LEVEL SSL_quic_write_level(const SSL *ssl);
__owur int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
                                 const uint8_t *data, size_t len);
__owur int SSL_process_quic_post_handshake(SSL *ssl);

__owur int SSL_is_quic(SSL *ssl);

/* BoringSSL API */
void SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy);

/*
 * Set an explicit value that you want to use
 * If 0 (default) the server will use the highest extenstion the client sent
 * If 0 (default) the client will send both extensions
 */
void SSL_set_quic_transport_version(SSL *ssl, int version);
__owur int SSL_get_quic_transport_version(const SSL *ssl);
/* Returns the negotiated version, or -1 on error */
__owur int SSL_get_peer_quic_transport_version(const SSL *ssl);

int SSL_CIPHER_get_prf_nid(const SSL_CIPHER *c);

void SSL_set_quic_early_data_enabled(SSL *ssl, int enabled);

#  endif

# ifdef  __cplusplus
}
# endif
#endif
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     orators || node !== firstAccessorWithDecorators) {
      return false;
    }
    parameters = setAccessor == null ? void 0 : setAccessor.parameters;
  } else if (isMethodDeclaration(node)) {
    parameters = node.parameters;
  }
  if (nodeIsDecorated(useLegacyDecorators, node, parent2)) {
    return true;
  }
  if (parameters) {
    for (const parameter of parameters) {
      if (parameterIsThisKeyword(parameter)) continue;
      if (nodeIsDecorated(useLegacyDecorators, parameter, node, parent2)) return true;
    }
  }
  return false;
}
function isEmptyStringLiteral(node) {
  if (node.textSourceNode) {
    switch (node.textSourceNode.kind) {
      case 11 /* StringLiteral */:
        return isEmptyStringLiteral(node.textSourceNode);
      case 15 /* NoSubstitutionTemplateLiteral */:
        return node.text === "";
    }
    return false;
  }
  return node.text === "";
}
function isJSXTagName(node) {
  const { parent: parent2 } = node;
  if (parent2.kind === 286 /* JsxOpeningElement */ || parent2.kind === 285 /* JsxSelfClosingElement */ || parent2.kind === 287 /* JsxClosingElement */) {
    return parent2.tagName === node;
  }
  return false;
}
function isExpressionNode(node) {
  switch (node.kind) {
    case 108 /* SuperKeyword */:
    case 106 /* NullKeyword */:
    case 112 /* TrueKeyword */:
    case 97 /* FalseKeyword */:
    case 14 /* RegularExpressionLiteral */:
    case 209 /* ArrayLiteralExpression */:
    case 210 /* ObjectLiteralExpression */:
    case 211 /* PropertyAccessExpression */:
    case 212 /* ElementAccessExpression */:
    case 213 /* CallExpression */:
    case 214 /* NewExpression */:
    case 215 /* TaggedTemplateExpression */:
    case 234 /* AsExpression */:
    case 216 /* TypeAssertionExpression */:
    case 238 /* SatisfiesExpression */:
    case 235 /* NonNullExpression */:
    case 217 /* ParenthesizedExpression */:
    case 218 /* FunctionExpression */:
    case 231 /* ClassExpression */:
    case 219 /* ArrowFunction */:
    case 222 /* VoidExpression */:
    case 220 /* DeleteExpression */:
    case 221 /* TypeOfExpression */:
    case 224 /* PrefixUnaryExpression */:
    case 225 /* PostfixUnaryExpression */:
    case 226 /* BinaryExpression */:
    case 227 /* ConditionalExpression */:
    case 230 /* SpreadElement */:
    case 228 /* TemplateExpression */:
    case 232 /* OmittedExpression */:
    case 284 /* JsxElement */:
    case 285 /* JsxSelfClosingElement */:
    case 288 /* JsxFragment */:
    case 229 /* YieldExpression */:
    case 223 /* AwaitExpression */:
    case 236 /* MetaProperty */:
      return true;
    case 233 /* ExpressionWithTypeArguments */:
      return !isHeritageClause(node.parent) && !isJSDocAugmentsTag(node.parent);
    case 166 /* QualifiedName */:
      while (node.parent.kind === 166 /* QualifiedName */) {
        node = node.parent;
      }
      return node.parent.kind === 186 /* TypeQuery */ || isJSDocLinkLike(node.parent) || isJSDocNameReference(node.parent) || isJSDocMemberName(node.parent) || isJSXTagName(node);
    case 311 /* JSDocMemberName */:
      while (isJSDocMemberName(node.parent)) {
        node = node.parent;
      }
      return node.parent.kind === 186 /* TypeQuery */ || isJSDocLinkLike(node.parent) || isJSDocNameReference(node.parent) || isJSDocMemberName(node.parent) || isJSXTagName(node);
    case 81 /* PrivateIdentifier */:
      return isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === 103 /* InKeyword */;
    case 80 /* Identifier */:
      if (node.parent.kind === 186 /* TypeQuery */ || isJSDocLinkLike(node.parent) || isJSDocNameReference(node.parent) || isJSDocMemberName(node.parent) || isJSXTagName(node)) {
        return true;
      }
    // falls through
    case 9 /* NumericLiteral */:
    case 10 /* BigIntLiteral */:
    case 11 /* StringLiteral */:
    case 15 /* NoSubstitutionTemplateLiteral */:
    case 110 /* ThisKeyword */:
      return isInExpressionContext(node);
    default:
      return false;
  }
}
function isInExpressionContext(node) {
  const { parent: parent2 } = node;
  switch (parent2.kind) {
    case 260 /* VariableDeclaration */:
    case 169 /* Parameter */:
    case 172 /* PropertyDeclaration */:
    case 171 /* PropertySignature */:
    case 306 /* EnumMember */:
    case 303 /* PropertyAssignment */:
    case 208 /* BindingElement */:
      return parent2.initializer === node;
    case 244 /* ExpressionStatement */:
    case 245 /* IfStatement */:
    case 246 /* DoStatement */:
    case 247 /* WhileStatement */:
    case 253 /* ReturnStatement */:
    case 254 /* WithStatement */:
    case 255 /* SwitchStatement */:
    case 296 /* CaseClause */:
    case 257 /* ThrowStatement */:
      return parent2.expression === node;
    case 248 /* ForStatement */:
      const forStatement = parent2;
      return forStatement.initializer === node && forStatement.initializer.kind !== 261 /* VariableDeclarationList */ || forStatement.condition === node || forStatement.incrementor === node;
    case 249 /* ForInStatement */:
    case 250 /* ForOfStatement */:
      const forInOrOfStatement = parent2;
      return forInOrOfStatement.initializer === node && forInOrOfStatement.initializer.kind !== 261 /* VariableDeclarationList */ || forInOrOfStatement.expression === node;
    case 216 /* TypeAssertionExpression */:
    case 234 /* AsExpression */:
      return node === parent2.expression;
    case 239 /* TemplateSpan */:
      return node === parent2.expression;
    case 167 /* ComputedPropertyName */:
      return node === parent2.expression;
    case 170 /* Decorator */:
    case 294 /* JsxExpression */:
    case 293 /* JsxSpreadAttribute */:
    case 305 /* SpreadAssignment */:
      return true;
    case 233 /* ExpressionWithTypeArguments */:
      return parent2.expression === node && !isPartOfTypeNode(parent2);
    case 304 /* ShorthandPropertyAssignment */:
      return parent2.objectAssignmentInitializer === node;
    case 238 /* SatisfiesExpression */:
      return node === parent2.expression;
    default:
      return isExpressionNode(parent2);
  }
}
function isPartOfTypeQuery(node) {
  while (node.kind === 166 /* QualifiedName */ || node.kind === 80 /* Identifier */) {
    node = node.parent;
  }
  return node.kind === 186 /* TypeQuery */;
}
function isNamespaceReexportDeclaration(node) {
  return isNamespaceExport(node) && !!node.parent.moduleSpecifier;
}
function isExternalModuleImportEqualsDeclaration(node) {
  return node.kind === 271 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 283 /* ExternalModuleReference */;
}
function getExternalModuleImportEqualsDeclarationExpression(node) {
  Debug.assert(isExternalModuleImportEqualsDeclaration(node));
  return node.moduleReference.expression;
}
function getExternalModuleRequireArgument(node) {
  return isVariableDeclarationInitializedToBareOrAccessedRequire(node) && getLeftmostAccessExpression(node.initializer).arguments[0];
}
function isInternalModuleImportEqualsDeclaration(node) {
  return node.kind === 271 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 283 /* ExternalModuleReference */;
}
function isFullSourceFile(sourceFile) {
  return (sourceFile == null ? void 0 : sourceFile.kind) === 307 /* SourceFile */;
}
function isSourceFileJS(file) {
  return isInJSFile(file);
}
function isInJSFile(node) {
  return !!node && !!(node.flags & 524288 /* JavaScriptFile */);
}
function isInJsonFile(node) {
  return !!node && !!(node.flags & 134217728 /* JsonFile */);
}
function isSourceFileNotJson(file) {
  return !isJsonSourceFile(file);
}
function isInJSDoc(node) {
  return !!node && !!(node.flags & 16777216 /* JSDoc */);
}
function isJSDocIndexSignature(node) {
  return isTypeReferenceNode(node) && isIdentifier(node.typeName) && node.typeName.escapedText === "Object" && node.typeArguments && node.typeArguments.length === 2 && (node.typeArguments[0].kind === 154 /* StringKeyword */ || node.typeArguments[0].kind === 150 /* NumberKeyword */);
}
function isRequireCall(callExpression, requireStringLiteralLikeArgument) {
  if (callExpression.kind !== 213 /* CallExpression */) {
    return false;
  }
  const { expression, arguments: args } = callExpression;
  if (expression.kind !== 80 /* Identifier */ || expression.escapedText !== "require") {
    return false;
  }
  if (args.length !== 1) {
    return false;
  }
  const arg = args[0];
  return !requireStringLiteralLikeArgument || isStringLiteralLike(arg);
}
function isVariableDeclarationInitializedToRequire(node) {
  return isVariableDeclarationInitializedWithRequireHelper(
    node,
    /*allowAccessedRequire*/
    false
  );
}
function isVariableDeclarationInitializedToBareOrAccessedRequire(node) {
  return isVariableDeclarationInitializedWithRequireHelper(
    node,
    /*allowAccessedRequire*/
    true
  );
}
function isBindingElementOfBareOrAccessedRequire(node) {
  return isBindingElement(node) && isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent);
}
function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) {
  return isVariableDeclaration(node) && !!node.initializer && isRequireCall(
    allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer,
    /*requireStringLiteralLikeArgument*/
    true
  );
}
function isRequireVariableStatement(node) {
  return isVariableStatement(node) && node.declarationList.declarations.length > 0 && every(node.declarationList.declarations, (decl) => isVariableDeclarationInitializedToRequire(decl));
}
function isSingleOrDoubleQuote(charCode) {
  return charCode === 39 /* singleQuote */ || charCode === 34 /* doubleQuote */;
}
function isStringDoubleQuoted(str, sourceFile) {
  return getSourceTextOfNodeFromSourceFile(sourceFile, str).charCodeAt(0) === 34 /* doubleQuote */;
}
function isAssignmentDeclaration(decl) {
  return isBinaryExpression(decl) || isAccessExpression(decl) || isIdentifier(decl) || isCallExpression(decl);
}
function getEffectiveInitializer(node) {
  if (isInJSFile(node) && node.initializer && isBinaryExpression(node.initializer) && (node.initializer.operatorToken.kind === 57 /* BarBarToken */ || node.initializer.operatorToken.kind === 61 /* QuestionQuestionToken */) && node.name && isEntityNameExpression(node.name) && isSameEntityName(node.name, node.initializer.left)) {
    return node.initializer.right;
  }
  return node.initializer;
}
function getDeclaredExpandoInitializer(node) {
  const init = getEffectiveInitializer(node);
  return init && getExpandoInitializer(init, isPrototypeAccess(node.name));
}
function hasExpandoValueProperty(node, isPrototypeAssignment) {
  return forEach(node.properties, (p) => isPropertyAssignment(p) && isIdentifier(p.name) && p.name.escapedText === "value" && p.initializer && getExpandoInitializer(p.initializer, isPrototypeAssignment));
}
function getAssignedExpandoInitializer(node) {
  if (node && node.parent && isBinaryExpression(node.parent) && node.parent.operatorToken.kind === 64 /* EqualsToken */) {
    const isPrototypeAssignment = isPrototypeAccess(node.parent.left);
    return getExpandoInitializer(node.parent.right, isPrototypeAssignment) || getDefaultedExpandoInitializer(node.parent.left, node.parent.right, isPrototypeAssignment);
  }
  if (node && isCallExpression(node) && isBindableObjectDefinePropertyCall(node)) {
    const result = hasExpandoValueProperty(node.arguments[2], node.arguments[1].text === "prototype");
    if (result) {
      return result;
    }
  }
}
function getExpandoInitializer(initializer, isPrototypeAssignment) {
  if (isCallExpression(initializer)) {
    const e = skipParentheses(initializer.expression);
    return e.kind === 218 /* FunctionExpression */ || e.kind === 219 /* ArrowFunction */ ? initializer : void 0;
  }
  if (initializer.kind === 218 /* FunctionExpression */ || initializer.kind === 231 /* ClassExpression */ || initializer.kind === 219 /* ArrowFunction */) {
    return initializer;
  }
  if (isObjectLiteralExpression(initializer) && (initializer.properties.length === 0 || isPrototypeAssignment)) {
    return initializer;
  }
}
function getDefaultedExpandoInitializer(name, initializer, isPrototypeAssignment) {
  const e = isBinaryExpression(initializer) && (initializer.operatorToken.kind === 57 /* BarBarToken */ || initializer.operatorToken.kind === 61 /* QuestionQuestionToken */) && getExpandoInitializer(initializer.right, isPrototypeAssignment);
  if (e && isSameEntityName(name, initializer.left)) {
    return e;
  }
}
function isDefaultedExpandoInitializer(node) {
  const name = isVariableDeclaration(node.parent) ? node.parent.name : isBinaryExpression(node.parent) && node.parent.operatorToken.kind === 64 /* EqualsToken */ ? node.parent.left : void 0;
  return name && getExpandoInitializer(node.right, isPrototypeAccess(name)) && isEntityNameExpression(name) && isSameEntityName(name, node.left);
}
function getNameOfExpando(node) {
  if (isBinaryExpression(node.parent)) {
    const parent2 = (node.parent.operatorToken.kind === 57 /* BarBarToken */ || node.parent.operatorToken.kind === 61 /* QuestionQuestionToken */) && isBinaryExpression(node.parent.parent) ? node.parent.parent : node.parent;
    if (parent2.operatorToken.kind === 64 /* EqualsToken */ && isIdentifier(parent2.left)) {
      return parent2.left;
    }
  } else if (isVariableDeclaration(node.parent)) {
    return node.parent.name;
  }
}
function isSameEntityName(name, initializer) {
  if (isPropertyNameLiteral(name) && isPropertyNameLiteral(initializer)) {
    return getTextOfIdentifierOrLiteral(name) === getTextOfIdentifierOrLiteral(initializer);
  }
  if (isMemberName(name) && isLiteralLikeAccess(initializer) && (initializer.expression.kind === 110 /* ThisKeyword */ || isIdentifier(initializer.expression) && (initializer.expression.escapedText === "window" || initializer.expression.escapedText === "self" || initializer.expression.escapedText === "global"))) {
    return isSameEntityName(name, getNameOrArgument(initializer));
  }
  if (isLiteralLikeAccess(name) && isLiteralLikeAccess(initializer)) {
    return getElementOrPropertyAccessName(name) === getElementOrPropertyAccessName(initializer) && isSameEntityName(name.expression, initializer.expression);
  }
  return false;
}
function getRightMostAssignedExpression(node) {
  while (isAssignmentExpression(
    node,
    /*excludeCompoundAssignment*/
    true
  )) {
    node = node.right;
  }
  return node;
}
function isExportsIdentifier(node) {
  return isIdentifier(node) && node.escapedText === "exports";
}
function isModuleIdentifier(node) {
  return isIdentifier(node) && node.escapedText === "module";
}
function isModuleExportsAccessExpression(node) {
  return (isPropertyAccessExpression(node) || isLiteralLikeElementAccess(node)) && isModuleIdentifier(node.expression) && getElementOrPropertyAccessName(node) === "exports";
}
function getAssignmentDeclarationKind(expr) {
  const special = getAssignmentDeclarationKindWorker(expr);
  return special === 5 /* Property */ || isInJSFile(expr) ? special : 0 /* None */;
}
function isBindableObjectDefinePropertyCall(expr) {
  return length(expr.arguments) === 3 && isPropertyAccessExpression(expr.expression) && isIdentifier(expr.expression.expression) && idText(expr.expression.expression) === "Object" && idText(expr.expression.name) === "defineProperty" && isStringOrNumericLiteralLike(expr.arguments[1]) && isBindableStaticNameExpression(
    expr.arguments[0],
    /*excludeThisKeyword*/
    true
  );
}
function isLiteralLikeAccess(node) {
  return isPropertyAccessExpression(node) || isLiteralLikeElementAccess(node);
}
function isLiteralLikeElementAccess(node) {
  return isElementAccessExpression(node) && isStringOrNumericLiteralLike(node.argumentExpression);
}
function isBindableStaticAccessExpression(node, excludeThisKeyword) {
  return isPropertyAccessExpression(node) && (!excludeThisKeyword && node.expression.kind === 110 /* ThisKeyword */ || isIdentifier(node.name) && isBindableStaticNameExpression(
    node.expression,
    /*excludeThisKeyword*/
    true
  )) || isBindableStaticElementAccessExpression(node, excludeThisKeyword);
}
function isBindableStaticElementAccessExpression(node, excludeThisKeyword) {
  return isLiteralLikeElementAccess(node) && (!excludeThisKeyword && node.expression.kind === 110 /* ThisKeyword */ || isEntityNameExpression(node.expression) || isBindableStaticAccessExpression(
    node.expression,
    /*excludeThisKeyword*/
    true
  ));
}
function isBindableStaticNameExpression(node, excludeThisKeyword) {
  return isEntityNameExpression(node) || isBindableStaticAccessExpression(node, excludeThisKeyword);
}
function getNameOrArgument(expr) {
  if (isPropertyAccessExpression(expr)) {
    return expr.name;
  }
  return expr.argumentExpression;
}
function getAssignmentDeclarationKindWorker(expr) {
  if (isCallExpression(expr)) {
    if (!isBindableObjectDefinePropertyCall(expr)) {
      return 0 /* None */;
    }
    const entityName = expr.arguments[0];
    if (isExportsIdentifier(entityName) || isModuleExportsAccessExpression(entityName)) {
      return 8 /* ObjectDefinePropertyExports */;
    }
    if (isBindableStaticAccessExpression(entityName) && getElementOrPropertyAccessName(entityName) === "prototype") {
      return 9 /* ObjectDefinePrototypeProperty */;
    }
    return 7 /* ObjectDefinePropertyValue */;
  }
  if (expr.operatorToken.kind !== 64 /* EqualsToken */ || !isAccessExpression(expr.left) || isVoidZero(getRightMostAssignedExpression(expr))) {
    return 0 /* None */;
  }
  if (isBindableStaticNameExpression(
    expr.left.expression,
    /*excludeThisKeyword*/
    true
  ) && getElementOrPropertyAccessName(expr.left) === "prototype" && isObjectLiteralExpression(getInitializerOfBinaryExpression(expr))) {
    return 6 /* Prototype */;
  }
  return getAssignmentDeclarationPropertyAccessKind(expr.left);
}
function isVoidZero(node) {
  return isVoidExpression(node) && isNumericLiteral(node.expression) && node.expression.text === "0";
}
function getElementOrPropertyAccessArgumentExpressionOrName(node) {
  if (isPropertyAccessExpression(node)) {
    return node.name;
  }
  const arg = skipParentheses(node.argumentExpression);
  if (isNumericLiteral(arg) || isStringLiteralLike(arg)) {
    return arg;
  }
  return node;
}
function getElementOrPropertyAccessName(node) {
  const name = getElementOrPropertyAccessArgumentExpressionOrName(node);
  if (name) {
    if (isIdentifier(name)) {
      return name.escapedText;
    }
    if (isStringLiteralLike(name) || isNumericLiteral(name)) {
      return escapeLeadingUnderscores(name.text);
    }
  }
  return void 0;
}
function getAssignmentDeclarationPropertyAccessKind(lhs) {
  if (lhs.expression.kind === 110 /* ThisKeyword */) {
    return 4 /* ThisProperty */;
  } else if (isModuleExportsAccessExpression(lhs)) {
    return 2 /* ModuleExports */;
  } else if (isBindableStaticNameExpression(
    lhs.expression,
    /*excludeThisKeyword*/
    true
  )) {
    if (isPrototypeAccess(lhs.expression)) {
      return 3 /* PrototypeProperty */;
    }
    let nextToLast = lhs;
    while (!isIdentifier(nextToLast.expression)) {
      nextToLast = nextToLast.expression;
    }
    const id = nextToLast.expression;
    if ((id.escapedText === "exports" || id.escapedText === "module" && getElementOrPropertyAccessName(nextToLast) === "exports") && // ExportsProperty does not support binding with computed names
    isBindableStaticAccessExpression(lhs)) {
      return 1 /* ExportsProperty */;
    }
    if (isBindableStaticNameExpression(
      lhs,
      /*excludeThisKeyword*/
      true
    ) || isElementAccessExpression(lhs) && isDynamicName(lhs)) {
      return 5 /* Property */;
    }
  }
  return 0 /* None */;
}
function getInitializerOfBinaryExpression(expr) {
  while (isBinaryExpression(expr.right)) {
    expr = expr.right;
  }
  return expr.right;
}
function isPrototypePropertyAssignment(node) {
  return isBinaryExpression(node) && getAssignmentDeclarationKind(node) === 3 /* PrototypeProperty */;
}
function isSpecialPropertyDeclaration(expr) {
  return isInJSFile(expr) && expr.parent && expr.parent.kind === 244 /* ExpressionStatement */ && (!isElementAccessExpression(expr) || isLiteralLikeElementAccess(expr)) && !!getJSDocTypeTag(expr.parent);
}
function setValueDeclaration(symbol, node) {
  const { valueDeclaration } = symbol;
  if (!valueDeclaration || !(node.flags & 33554432 /* Ambient */ && !isInJSFile(node) && !(valueDeclaration.flags & 33554432 /* Ambient */)) && (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) || valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration)) {
    symbol.valueDeclaration = node;
  }
}
function isFunctionSymbol(symbol) {
  if (!symbol || !symbol.valueDeclaration) {
    return false;
  }
  const decl = symbol.valueDeclaration;
  return decl.kind === 262 /* FunctionDeclaration */ || isVariableDeclaration(decl) && decl.initializer && isFunctionLike(decl.initializer);
}
function canHaveModuleSpecifier(node) {
  switch (node == null ? void 0 : node.kind) {
    case 260 /* VariableDeclaration */:
    case 208 /* BindingElement */:
    case 272 /* ImportDeclaration */:
    case 278 /* ExportDeclaration */:
    case 271 /* ImportEqualsDeclaration */:
    case 273 /* ImportClause */:
    case 280 /* NamespaceExport */:
    case 274 /* NamespaceImport */:
    case 281 /* ExportSpecifier */:
    case 276 /* ImportSpecifier */:
    case 205 /* ImportType */:
      return true;
  }
  return false;
}
function tryGetModuleSpecifierFromDeclaration(node) {
  var _a, _b;
  switch (node.kind) {
    case 260 /* VariableDeclaration */:
    case 208 /* BindingElement */:
      return (_a = findAncestor(node.initializer, (node2) => isRequireCall(
        node2,
        /*requireStringLiteralLikeArgument*/
        true
      ))) == null ? void 0 : _a.arguments[0];
    case 272 /* ImportDeclaration */:
    case 278 /* ExportDeclaration */:
    case 351 /* JSDocImportTag */:
      return tryCast(node.moduleSpecifier, isStringLiteralLike);
    case 271 /* ImportEqualsDeclaration */:
      return tryCast((_b = tryCast(node.moduleReference, isExternalModuleReference)) == null ? void 0 : _b.expression, isStringLiteralLike);
    case 273 /* ImportClause */:
    case 280 /* NamespaceExport */:
      return tryCast(node.parent.moduleSpecifier, isStringLiteralLike);
    case 274 /* NamespaceImport */:
    case 281 /* ExportSpecifier */:
      return tryCast(node.parent.parent.moduleSpecifier, isStringLiteralLike);
    case 276 /* ImportSpecifier */:
      return tryCast(node.parent.parent.parent.moduleSpecifier, isStringLiteralLike);
    case 205 /* ImportType */:
      return isLiteralImportTypeNode(node) ? node.argument.literal : void 0;
    default:
      Debug.assertNever(node);
  }
}
function importFromModuleSpecifier(node) {
  return tryGetImportFromModuleSpecifier(node) || Debug.failBadSyntaxKind(node.parent);
}
function tryGetImportFromModuleSpecifier(node) {
  switch (node.parent.kind) {
    case 272 /* ImportDeclaration */:
    case 278 /* ExportDeclaration */:
    case 351 /* JSDocImportTag */:
      return node.parent;
    case 283 /* ExternalModuleReference */:
      return node.parent.parent;
    case 213 /* CallExpression */:
      return isImportCall(node.parent) || isRequireCall(
        node.parent,
        /*requireStringLiteralLikeArgument*/
        false
      ) ? node.parent : void 0;
    case 201 /* LiteralType */:
      if (!isStringLiteral(node)) {
        break;
      }
      return tryCast(node.parent.parent, isImportTypeNode);
    default:
      return void 0;
  }
}
function shouldRewriteModuleSpecifier(specifier, compilerOptions) {
  return !!compilerOptions.rewriteRelativeImportExtensions && pathIsRelative(specifier) && !isDeclarationFileName(specifier) && hasTSFileExtension(specifier);
}
function getExternalModuleName(node) {
  switch (node.kind) {
    case 272 /* ImportDeclaration */:
    case 278 /* ExportDeclaration */:
    case 351 /* JSDocImportTag */:
      return node.moduleSpecifier;
    case 271 /* ImportEqualsDeclaration */:
      return node.moduleReference.kind === 283 /* ExternalModuleReference */ ? node.moduleReference.expression : void 0;
    case 205 /* ImportType */:
      return isLiteralImportTypeNode(node) ? node.argument.literal : void 0;
    case 213 /* CallExpression */:
      return node.arguments[0];
    case 267 /* ModuleDeclaration */:
      return node.name.kind === 11 /* StringLiteral */ ? node.name : void 0;
    default:
      return Debug.assertNever(node);
  }
}
function getNamespaceDeclarationNode(node) {
  switch (node.kind) {
    case 272 /* ImportDeclaration */:
      return node.importClause && tryCast(node.importClause.namedBindings, isNamespaceImport);
    case 271 /* ImportEqualsDeclaration */:
      return node;
    case 278 /* ExportDeclaration */:
      return node.exportClause && tryCast(node.exportClause, isNamespaceExport);
    default:
      return Debug.assertNever(node);
  }
}
function isDefaultImport(node) {
  return (node.kind === 272 /* ImportDeclaration */ || node.kind === 351 /* JSDocImportTag */) && !!node.importClause && !!node.importClause.name;
}
function forEachImportClauseDeclaration(node, action) {
  if (node.name) {
    const result = action(node);
    if (result) return result;
  }
  if (node.namedBindings) {
    const result = isNamespaceImport(node.namedBindings) ? action(node.namedBindings) : forEach(node.namedBindings.elements, action);
    if (result) return result;
  }
}
function hasQuestionToken(node) {
  switch (node.kind) {
    case 169 /* Parameter */:
    case 174 /* MethodDeclaration */:
    case 173 /* MethodSignature */:
    case 304 /* ShorthandPropertyAssignment */:
    case 303 /* PropertyAssignment */:
    case 172 /* PropertyDeclaration */:
    case 171 /* PropertySignature */:
      return node.questionToken !== void 0;
  }
  return false;
}
function isJSDocConstructSignature(node) {
  const param = isJSDocFunctionType(node) ? firstOrUndefined(node.parameters) : void 0;
  const name = tryCast(param && param.name, isIdentifier);
  return !!name && name.escapedText === "new";
}
function isJSDocTypeAlias(node) {
  return node.kind === 346 /* JSDocTypedefTag */ || node.kind === 338 /* JSDocCallbackTag */ || node.kind === 340 /* JSDocEnumTag */;
}
function isTypeAlias(node) {
  return isJSDocTypeAlias(node) || isTypeAliasDeclaration(node);
}
function getSourceOfAssignment(node) {
  return isExpressionStatement(node) && isBinaryExpression(node.expression) && node.expression.operatorToken.kind === 64 /* EqualsToken */ ? getRightMostAssignedExpression(node.expression) : void 0;
}
function getSourceOfDefaultedAssignment(node) {
  return isExpressionStatement(node) && isBinaryExpression(node.expression) && getAssignmentDeclarationKind(node.expression) !== 0 /* None */ && isBinaryExpression(node.expression.right) && (node.expression.right.operatorToken.kind === 57 /* BarBarToken */ || node.expression.right.operatorToken.kind === 61 /* QuestionQuestionToken */) ? node.expression.right.right : void 0;
}
function getSingleInitializerOfVariableStatementOrPropertyDeclaration(node) {
  switch (node.kind) {
    case 243 /* VariableStatement */:
      const v = getSingleVariableOfVariableStatement(node);
      return v && v.initializer;
    case 172 /* PropertyDeclaration */:
      return node.initializer;
    case 303 /* PropertyAssignment */:
      return node.initializer;
  }
}
function getSingleVariableOfVariableStatement(node) {
  return isVariableStatement(node) ? firstOrUndefined(node.declarationList.declarations) : void 0;
}
function getNestedModuleDeclaration(node) {
  return isModuleDeclaration(node) && node.body && node.body.kind === 267 /* ModuleDeclaration */ ? node.body : void 0;
}
function canHaveFlowNode(node) {
  if (node.kind >= 243 /* FirstStatement */ && node.kind <= 259 /* LastStatement */) {
    return true;
  }
  switch (node.kind) {
    case 80 /* Identifier */:
    case 110 /* ThisKeyword */:
    case 108 /* SuperKeyword */:
    case 166 /* QualifiedName */:
    case 236 /* MetaProperty */:
    case 212 /* ElementAccessExpression */:
    case 211 /* PropertyAccessExpression */:
    case 208 /* BindingElement */:
    case 218 /* FunctionExpression */:
    case 219 /* ArrowFunction */:
    case 174 /* MethodDeclaration */:
    case 177 /* GetAccessor */:
    case 178 /* SetAccessor */:
      return true;
    default:
      return false;
  }
}
function canHaveJSDoc(node) {
  switch (node.kind) {
    case 219 /* ArrowFunction */:
    case 226 /* BinaryExpression */:
    case 241 /* Block */:
    case 252 /* BreakStatement */:
    case 179 /* CallSignature */:
    case 296 /* CaseClause */:
    case 263 /* ClassDeclaration */:
    case 231 /* ClassExpression */:
    case 175 /* ClassStaticBlockDeclaration */:
    case 176 /* Constructor */:
    case 185 /* ConstructorType */:
    case 180 /* ConstructSignature */:
    case 251 /* ContinueStatement */:
    case 259 /* DebuggerStatement */:
    case 246 /* DoStatement */:
    case 212 /* ElementAccessExpression */:
    case 242 /* EmptyStatement */:
    case 1 /* EndOfFileToken */:
    case 266 /* EnumDeclaration */:
    case 306 /* EnumMember */:
    case 277 /* ExportAssignment */:
    case 278 /* ExportDeclaration */:
    case 281 /* ExportSpecifier */:
    case 244 /* ExpressionStatement */:
    case 249 /* ForInStatement */:
    case 250 /* ForOfStatement */:
    case 248 /* ForStatement */:
    case 262 /* FunctionDeclaration */:
    case 218 /* FunctionExpression */:
    case 184 /* FunctionType */:
    case 177 /* GetAccessor */:
    case 80 /* Identifier */:
    case 245 /* IfStatement */:
    case 272 /* ImportDeclaration */:
    case 271 /* ImportEqualsDeclaration */:
    case 181 /* IndexSignature */:
    case 264 /* InterfaceDeclaration */:
    case 317 /* JSDocFunctionType */:
    case 323 /* JSDocSignature */:
    case 256 /* LabeledStatement */:
    case 174 /* MethodDeclaration */:
    case 173 /* MethodSignature */:
    case 267 /* ModuleDeclaration */:
    case 202 /* NamedTupleMember */:
    case 270 /* NamespaceExportDeclaration */:
    case 210 /* ObjectLiteralExpression */:
    case 169 /* Parameter */:
    case 217 /* ParenthesizedExpression */:
    case 211 /* PropertyAccessExpression */:
    case 303 /* PropertyAssignment */:
    case 172 /* PropertyDeclaration */:
    case 171 /* PropertySignature */:
    case 253 /* ReturnStatement */:
    case 240 /* SemicolonClassElement */:
    case 178 /* SetAccessor */:
    case 304 /* ShorthandPropertyAssignment */:
    case 305 /* SpreadAssignment */:
    case 255 /* SwitchStatement */:
    case 257 /* ThrowStatement */:
    case 258 /* TryStatement */:
    case 265 /* TypeAliasDeclaration */:
    case 168 /* TypeParameter */:
    case 260 /* VariableDeclaration */:
    case 243 /* VariableStatement */:
    case 247 /* WhileStatement */:
    case 254 /* WithStatement */:
      return true;
    default:
      return false;
  }
}
function getJSDocCommentsAndTags(hostNode, noCache) {
  let result;
  if (isVariableLike(hostNode) && hasInitializer(hostNode) && hasJSDocNodes(hostNode.initializer)) {
    result = addRange(result, filterOwnedJSDocTags(hostNode, hostNode.initializer.jsDoc));
  }
  let node = hostNode;
  while (node && node.parent) {
    if (hasJSDocNodes(node)) {
      result = addRange(result, filterOwnedJSDocTags(hostNode, node.jsDoc));
    }
    if (node.kind === 169 /* Parameter */) {
      result = addRange(result, (noCache ? getJSDocParameterTagsNoCache : getJSDocParameterTags)(node));
      break;
    }
    if (node.kind === 168 /* TypeParameter */) {
      result = addRange(result, (noCache ? getJSDocTypeParameterTagsNoCache : getJSDocTypeParameterTags)(node));
      break;
    }
    node = getNextJSDocCommentLocation(node);
  }
  return result || emptyArray;
}
function filterOwnedJSDocTags(hostNode, comments) {
  const lastJsDoc = last(comments);
  return flatMap(comments, (jsDoc) => {
    if (jsDoc === lastJsDoc) {
      const ownedTags = filter(jsDoc.tags, (tag) => ownsJSDocTag(hostNode, tag));
      return jsDoc.tags === ownedTags ? [jsDoc] : ownedTags;
    } else {
      return filter(jsDoc.tags, isJSDocOverloadTag);
    }
  });
}
function ownsJSDocTag(hostNode, tag) {
  return !(isJSDocTypeTag(tag) || isJSDocSatisfiesTag(tag)) || !tag.parent || !isJSDoc(tag.parent) || !isParenthesizedExpression(tag.parent.parent) || tag.parent.parent === hostNode;
}
function getNextJSDocCommentLocation(node) {
  const parent2 = node.parent;
  if (parent2.kind === 303 /* PropertyAssignment */ || parent2.kind === 277 /* ExportAssignment */ || parent2.kind === 172 /* PropertyDeclaration */ || parent2.kind === 244 /* ExpressionStatement */ && node.kind === 211 /* PropertyAccessExpression */ || parent2.kind === 253 /* ReturnStatement */ || getNestedModuleDeclaration(parent2) || isAssignmentExpression(node)) {
    return parent2;
  } else if (parent2.parent && (getSingleVariableOfVariableStatement(parent2.parent) === node || isAssignmentExpression(parent2))) {
    return parent2.parent;
  } else if (parent2.parent && parent2.parent.parent && (getSingleVariableOfVariableStatement(parent2.parent.parent) || getSingleInitializerOfVariableStatementOrPropertyDeclaration(parent2.parent.parent) === node || getSourceOfDefaultedAssignment(parent2.parent.parent))) {
    return parent2.parent.parent;
  }
}
function getParameterSymbolFromJSDoc(node) {
  if (node.symbol) {
    return node.symbol;
  }
  if (!isIdentifier(node.name)) {
    return void 0;
  }
  const name = node.name.escapedText;
  const decl = getHostSignatureFromJSDoc(node);
  if (!decl) {
    return void 0;
  }
  const parameter = find(decl.parameters, (p) => p.name.kind === 80 /* Identifier */ && p.name.escapedText === name);
  return parameter && parameter.symbol;
}
function getEffectiveContainerForJSDocTemplateTag(node) {
  if (isJSDoc(node.parent) && node.parent.tags) {
    const typeAlias = find(node.parent.tags, isJSDocTypeAlias);
    if (typeAlias) {
      return typeAlias;
    }
  }
  return getHostSignatureFromJSDoc(node);
}
function getJSDocOverloadTags(node) {
  return getAllJSDocTags(node, isJSDocOverloadTag);
}
function getHostSignatureFromJSDoc(node) {
  const host = getEffectiveJSDocHost(node);
  if (host) {
    return isPropertySignature(host) && host.type && isFunctionLike(host.type) ? host.type : isFunctionLike(host) ? host : void 0;
  }
  return void 0;
}
function getEffectiveJSDocHost(node) {
  const host = getJSDocHost(node);
  if (host) {
    return getSourceOfDefaultedAssignment(host) || getSourceOfAssignment(host) || getSingleInitializerOfVariableStatementOrPropertyDeclaration(host) || getSingleVariableOfVariableStatement(host) || getNestedModuleDeclaration(host) || host;
  }
}
function getJSDocHost(node) {
  const jsDoc = getJSDocRoot(node);
  if (!jsDoc) {
    return void 0;
  }
  const host = jsDoc.parent;
  if (host && host.jsDoc && jsDoc === lastOrUndefined(host.jsDoc)) {
    return host;
  }
}
function getJSDocRoot(node) {
  return findAncestor(node.parent, isJSDoc);
}
function getTypeParameterFromJsDoc(node) {
  const name = node.name.escapedText;
  const { typeParameters } = node.parent.parent.parent;
  return typeParameters && find(typeParameters, (p) => p.name.escapedText === name);
}
function hasTypeArguments(node) {
  return !!node.typeArguments;
}
var AssignmentKind = /* @__PURE__ */ ((AssignmentKind2) => {
  AssignmentKind2[AssignmentKind2["None"] = 0] = "None";
  AssignmentKind2[AssignmentKind2["Definite"] = 1] = "Definite";
  AssignmentKind2[AssignmentKind2["Compound"] = 2] = "Compound";
  return AssignmentKind2;
})(AssignmentKind || {});
function getAssignmentTarget(node) {
  let parent2 = node.parent;
  while (true) {
    switch (parent2.kind) {
      case 226 /* BinaryExpression */:
        const binaryExpression = parent2;
        const binaryOperator = binaryExpression.operatorToken.kind;
        return isAssignmentOperator(binaryOperator) && binaryExpression.left === node ? binaryExpression : void 0;
      case 224 /* PrefixUnaryExpression */:
      case 225 /* PostfixUnaryExpression */:
        const unaryExpression = parent2;
        const unaryOperator = unaryExpression.operator;
        return unaryOperator === 46 /* PlusPlusToken */ || unaryOperator === 47 /* MinusMinusToken */ ? unaryExpression : void 0;
      case 249 /* ForInStatement */:
      case 250 /* ForOfStatement */:
        const forInOrOfStatement = parent2;
        return forInOrOfStatement.initializer === node ? forInOrOfStatement : void 0;
      case 217 /* ParenthesizedExpression */:
      case 209 /* ArrayLiteralExpression */:
      case 230 /* SpreadElement */:
      case 235 /* NonNullExpression */:
        node = parent2;
        break;
      case 305 /* SpreadAssignment */:
        node = parent2.parent;
        break;
      case 304 /* ShorthandPropertyAssignment */:
        if (parent2.name !== node) {
          return void 0;
        }
        node = parent2.parent;
        break;
      case 303 /* PropertyAssignment */:
        if (parent2.name === node) {
          return void 0;
        }
        node = parent2.parent;
        break;
      default:
        return void 0;
    }
    parent2 = node.parent;
  }
}
function getAssignmentTargetKind(node) {
  const target = getAssignmentTarget(node);
  if (!target) {
    return 0 /* None */;
  }
  switch (target.kind) {
    case 226 /* BinaryExpression */:
      const binaryOperator = target.operatorToken.kind;
      return binaryOperator === 64 /* EqualsToken */ || isLogicalOrCoalescingAssignmentOperator(binaryOperator) ? 1 /* Definite */ : 2 /* Compound */;
    case 224 /* PrefixUnaryExpression */:
    case 225 /* PostfixUnaryExpression */:
      return 2 /* Compound */;
    case 249 /* ForInStatement */:
    case 250 /* ForOfStatement */:
      return 1 /* Definite */;
  }
}
function isAssignmentTarget(node) {
  return !!getAssignmentTarget(node);
}
function isCompoundLikeAssignment(assignment) {
  const right = skipParentheses(assignment.right);
  return right.kind === 226 /* BinaryExpression */ && isShiftOperatorOrHigher(right.operatorToken.kind);
}
function isInCompoundLikeAssignment(node) {
  const target = getAssignmentTarget(node);
  return !!target && isAssignmentExpression(
    target,
    /*excludeCompoundAssignment*/
    true
  ) && isCompoundLikeAssignment(target);
}
function isNodeWithPossibleHoistedDeclaration(node) {
  switch (node.kind) {
    case 241 /* Block */:
    case 243 /* VariableStatement */:
    case 254 /* WithStatement */:
    case 245 /* IfStatement */:
    case 255 /* SwitchStatement */:
    case 269 /* CaseBlock */:
    case 296 /* CaseClause */:
    case 297 /* DefaultClause */:
    case 256 /* LabeledStatement */:
    case 248 /* ForStatement */:
    case 249 /* ForInStatement */:
    case 250 /* ForOfStatement */:
    case 246 /* DoStatement */:
    case 247 /* WhileStatement */:
    case 258 /* TryStatement */:
    case 299 /* CatchClause */:
      return true;
  }
  return false;
}
function isValueSignatureDeclaration(node) {
  return isFunctionExpression(node) || isArrowFunction(node) || isMethodOrAccessor(node) || isFunctionDeclaration(node) || isConstructorDeclaration(node);
}
function walkUp(node, kind) {
  while (node && node.kind === kind) {
    node = node.parent;
  }
  return node;
}
function walkUpParenthesizedTypes(node) {
  return walkUp(node, 196 /* ParenthesizedType */);
}
function walkUpParenthesizedExpressions(node) {
  return walkUp(node, 217 /* ParenthesizedExpression */);
}
function walkUpParenthesizedTypesAndGetParentAndChild(node) {
  let child;
  while (node && node.kind === 196 /* ParenthesizedType */) {
    child = node;
    node = node.parent;
  }
  return [child, node];
}
function skipTypeParentheses(node) {
  while (isParenthesizedTypeNode(node)) node = node.type;
  return node;
}
function skipParentheses(node, excludeJSDocTypeAssertions) {
  const flags = excludeJSDocTypeAssertions ? 1 /* Parentheses */ | -2147483648 /* ExcludeJSDocTypeAssertion */ : 1 /* Parentheses */;
  return skipOuterExpressions(node, flags);
}
function isDeleteTarget(node) {
  if (node.kind !== 211 /* PropertyAccessExpression */ && node.kind !== 212 /* ElementAccessExpression */) {
    return false;
  }
  node = walkUpParenthesizedExpressions(node.parent);
  return node && node.kind === 220 /* DeleteExpression */;
}
function isNodeDescendantOf(node, ancestor) {
  while (node) {
    if (node === ancestor) return true;
    node = node.parent;
  }
  return false;
}
function isDeclarationName(name) {
  return !isSourceFile(name) && !isBindingPattern(name) && isDeclaration(name.parent) && name.parent.name === name;
}
function getDeclarationFromName(name) {
  const parent2 = name.parent;
  switch (name.kind) {
    case 11 /* StringLiteral */:
    case 15 /* NoSubstitutionTemplateLiteral */:
    case 9 /* NumericLiteral */:
      if (isComputedPropertyName(parent2)) return parent2.parent;
    // falls through
    case 80 /* Identifier */:
      if (isDeclaration(parent2)) {
        return parent2.name === name ? parent2 : void 0;
      } else if (isQualifiedName(parent2)) {
        const tag = parent2.parent;
        return isJSDocParameterTag(tag) && tag.name === parent2 ? tag : void 0;
      } else {
        const binExp = parent2.parent;
        return isBinaryExpression(binExp) && getAssignmentDeclarationKind(binExp) !== 0 /* None */ && (binExp.left.symbol || binExp.symbol) && getNameOfDeclaration(binExp) === name ? binExp : void 0;
      }
    case 81 /* PrivateIdentifier */:
      return isDeclaration(parent2) && parent2.name === name ? parent2 : void 0;
    default:
      return void 0;
  }
}
function isLiteralComputedPropertyDeclarationName(node) {
  return isStringOrNumericLiteralLike(node) && node.parent.kind === 167 /* ComputedPropertyName */ && isDeclaration(node.parent.parent);
}
function isIdentifierName(node) {
  const parent2 = node.parent;
  switch (parent2.kind) {
    case 172 /* PropertyDeclaration */:
    case 171 /* PropertySignature */:
    case 174 /* MethodDeclaration */:
    case 173 /* MethodSignature */:
    case 177 /* GetAccessor */:
    case 178 /* SetAccessor */:
    case 306 /* EnumMember */:
    case 303 /* PropertyAssignment */:
    case 211 /* PropertyAccessExpression */:
      return parent2.name === node;
    case 166 /* QualifiedName */:
      return parent2.right === node;
    case 208 /* BindingElement */:
    case 276 /* ImportSpecifier */:
      return parent2.propertyName === node;
    case 281 /* ExportSpecifier */:
    case 291 /* JsxAttribute */:
    case 285 /* JsxSelfClosingElement */:
    case 286 /* JsxOpeningElement */:
    case 287 /* JsxClosingElement */:
      return true;
  }
  return false;
}
function getAliasDeclarationFromName(node) {
  switch (node.parent.kind) {
    case 273 /* ImportClause */:
    case 276 /* ImportSpecifier */:
    case 274 /* NamespaceImport */:
    case 281 /* ExportSpecifier */:
    case 277 /* ExportAssignment */:
    case 271 /* ImportEqualsDeclaration */:
    case 280 /* NamespaceExport */:
      return node.parent;
    case 166 /* QualifiedName */:
      do {
        node = node.parent;
      } while (node.parent.kind === 166 /* QualifiedName */);
      return getAliasDeclarationFromName(node);
  }
}
function isAliasableExpression(e) {
  return isEntityNameExpression(e) || isClassExpression(e);
}
function exportAssignmentIsAlias(node) {
  const e = getExportAssignmentExpression(node);
  return isAliasableExpression(e);
}
function getExportAssignmentExpression(node) {
  return isExportAssignment(node) ? node.expression : node.right;
}
function getPropertyAssignmentAliasLikeExpression(node) {
  return node.kind === 304 /* ShorthandPropertyAssignment */ ? node.name : node.kind === 303 /* PropertyAssignment */ ? node.initializer : node.parent.right;
}
function getEffectiveBaseTypeNode(node) {
  const baseType = getClassExtendsHeritageElement(node);
  if (baseType && isInJSFile(node)) {
    const tag = getJSDocAugmentsTag(node);
    if (tag) {
      return tag.class;
    }
  }
  return baseType;
}
function getClassExtendsHeritageElement(node) {
  const heritageClause = getHeritageClause(node.heritageClauses, 96 /* ExtendsKeyword */);
  return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : void 0;
}
function getEffectiveImplementsTypeNodes(node) {
  if (isInJSFile(node)) {
    return getJSDocImplementsTags(node).map((n) => n.class);
  } else {
    const heritageClause = getHeritageClause(node.heritageClauses, 119 /* ImplementsKeyword */);
    return heritageClause == null ? void 0 : heritageClause.types;
  }
}
function getAllSuperTypeNodes(node) {
  return isInterfaceDeclaration(node) ? getInterfaceBaseTypeNodes(node) || emptyArray : isClassLike(node) ? concatenate(singleElementArray(getEffectiveBaseTypeNode(node)), getEffectiveImplementsTypeNodes(node)) || emptyArray : emptyArray;
}
function getInterfaceBaseTypeNodes(node) {
  const heritageClause = getHeritageClause(node.heritageClauses, 96 /* ExtendsKeyword */);
  return heritageClause ? heritageClause.types : void 0;
}
function getHeritageClause(clauses, kind) {
  if (clauses) {
    for (const clause of clauses) {
      if (clause.token === kind) {
        return clause;
      }
    }
  }
  return void 0;
}
function getAncestor(node, kind) {
  while (node) {
    if (node.kind === kind) {
      return node;
    }
    node = node.parent;
  }
  return void 0;
}
function isKeyword(token) {
  return 83 /* FirstKeyword */ <= token && token <= 165 /* LastKeyword */;
}
function isPunctuation(token) {
  return 19 /* FirstPunctuation */ <= token && token <= 79 /* LastPunctuation */;
}
function isKeywordOrPunctuation(token) {
  return isKeyword(token) || isPunctuation(token);
}
function isContextualKeyword(token) {
  return 128 /* FirstContextualKeyword */ <= token && token <= 165 /* LastContextualKeyword */;
}
function isNonContextualKeyword(token) {
  return isKeyword(token) && !isContextualKeyword(token);
}
function isStringANonContextualKeyword(name) {
  const token = stringToToken(name);
  return token !== void 0 && isNonContextualKeyword(token);
}
function isIdentifierANonContextualKeyword(node) {
  const originalKeywordKind = identifierToKeywordKind(node);
  return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind);
}
function isTrivia(token) {
  return 2 /* FirstTriviaToken */ <= token && token <= 7 /* LastTriviaToken */;
}
var FunctionFlags = /* @__PURE__ */ ((FunctionFlags2) => {
  FunctionFlags2[FunctionFlags2["Normal"] = 0] = "Normal";
  FunctionFlags2[FunctionFlags2["Generator"] = 1] = "Generator";
  FunctionFlags2[FunctionFlags2["Async"] = 2] = "Async";
  FunctionFlags2[FunctionFlags2["Invalid"] = 4] = "Invalid";
  FunctionFlags2[FunctionFlags2["AsyncGenerator"] = 3] = "AsyncGenerator";
  return FunctionFlags2;
})(FunctionFlags || {});
function getFunctionFlags(node) {
  if (!node) {
    return 4 /* Invalid */;
  }
  let flags = 0 /* Normal */;
  switch (node.kind) {
    case 262 /* FunctionDeclaration */:
    case 218 /* FunctionExpression */:
    case 174 /* MethodDeclaration */:
      if (node.asteriskToken) {
        flags |= 1 /* Generator */;
      }
    // falls through
    case 219 /* ArrowFunction */:
      if (hasSyntacticModifier(node, 1024 /* Async */)) {
        flags |= 2 /* Async */;
      }
      break;
  }
  if (!node.body) {
    flags |= 4 /* Invalid */;
  }
  return flags;
}
function isAsyncFunction(node) {
  switch (node.kind) {
    case 262 /* FunctionDeclaration */:
    case 218 /* FunctionExpression */:
    case 219 /* ArrowFunction */:
    case 174 /* MethodDeclaration */:
      return node.body !== void 0 && node.asteriskToken === void 0 && hasSyntacticModifier(node, 1024 /* Async */);
  }
  return false;
}
function isStringOrNumericLiteralLike(node) {
  return isStringLiteralLike(node) || isNumericLiteral(node);
}
function isSignedNumericLiteral(node) {
  return isPrefixUnaryExpression(node) && (node.operator === 40 /* PlusToken */ || node.operator === 41 /* MinusToken */) && isNumericLiteral(node.operand);
}
function hasDynamicName(declaration) {
  const name = getNameOfDeclaration(declaration);
  return !!name && isDynamicName(name);
}
function isDynamicName(name) {
  if (!(name.kind === 167 /* ComputedPropertyName */ || name.kind === 212 /* ElementAccessExpression */)) {
    return false;
  }
  const expr = isElementAccessExpression(name) ? skipParentheses(name.argumentExpression) : name.expression;
  return !isStringOrNumericLiteralLike(expr) && !isSignedNumericLiteral(expr);
}
function getPropertyNameForPropertyNameNode(name) {
  switch (name.kind) {
    case 80 /* Identifier */:
    case 81 /* PrivateIdentifier */:
      return name.escapedText;
    case 11 /* StringLiteral */:
    case 15 /* NoSubstitutionTemplateLiteral */:
    case 9 /* NumericLiteral */:
    case 10 /* BigIntLiteral */:
      return escapeLeadingUnderscores(name.text);
    case 167 /* ComputedPropertyName */:
      const nameExpression = name.expression;
      if (isStringOrNumericLiteralLike(nameExpression)) {
        return escapeLeadingUnderscores(nameExpression.text);
      } else if (isSignedNumericLiteral(nameExpression)) {
        if (nameExpression.operator === 41 /* MinusToken */) {
          return tokenToString(nameExpression.operator) + nameExpression.operand.text;
        }
        return nameExpression.operand.text;
      }
      return void 0;
    case 295 /* JsxNamespacedName */:
      return getEscapedTextOfJsxNamespacedName(name);
    default:
      return Debug.assertNever(name);
  }
}
function isPropertyNameLiteral(node) {
  switch (node.kind) {
    case 80 /* Identifier */:
    case 11 /* StringLiteral */:
    case 15 /* NoSubstitutionTemplateLiteral */:
    case 9 /* NumericLiteral */:
      return true;
    default:
      return false;
  }
}
function getTextOfIdentifierOrLiteral(node) {
  return isMemberName(node) ? idText(node) : isJsxNamespacedName(node) ? getTextOfJsxNamespacedName(node) : node.text;
}
function getEscapedTextOfIdentifierOrLiteral(node) {
  return isMemberName(node) ? node.escapedText : isJsxNamespacedName(node) ? getEscapedTextOfJsxNamespacedName(node) : escapeLeadingUnderscores(node.text);
}
function getSymbolNameForPrivateIdentifier(containingClassSymbol, description3) {
  return `__#${getSymbolId(containingClassSymbol)}@${description3}`;
}
function isKnownSymbol(symbol) {
  return startsWith(symbol.escapedName, "__@");
}
function isPrivateIdentifierSymbol(symbol) {
  return startsWith(symbol.escapedName, "__#");
}
function isProtoSetter(node) {
  return isIdentifier(node) ? idText(node) === "__proto__" : isStringLiteral(node) && node.text === "__proto__";
}
function isAnonymousFunctionDefinition(node, cb) {
  node = skipOuterExpressions(node);
  switch (node.kind) {
    case 231 /* ClassExpression */:
      if (classHasDeclaredOrExplicitlyAssignedName(node)) {
        return false;
      }
      break;
    case 218 /* FunctionExpression */:
      if (node.name) {
        return false;
      }
      break;
    case 219 /* ArrowFunction */:
      break;
    default:
      return false;
  }
  return typeof cb === "function" ? cb(node) : true;
}
function isNamedEvaluationSource(node) {
  switch (node.kind) {
    case 303 /* PropertyAssignment */:
      return !isProtoSetter(node.name);
    case 304 /* ShorthandPropertyAssignment */:
      return !!node.objectAssignmentInitializer;
    case 260 /* VariableDeclaration */:
      return isIdentifier(node.name) && !!node.initializer;
    case 169 /* Parameter */:
      return isIdentifier(node.name) && !!node.initializer && !node.dotDotDotToken;
    case 208 /* BindingElement */:
      return isIdentifier(node.name) && !!node.initializer && !node.dotDotDotToken;
    case 172 /* PropertyDeclaration */:
      return !!node.initializer;
    case 226 /* BinaryExpression */:
      switch (node.operatorToken.kind) {
        case 64 /* EqualsToken */:
        case 77 /* AmpersandAmpersandEqualsToken */:
        case 76 /* BarBarEqualsToken */:
        case 78 /* QuestionQuestionEqualsToken */:
          return isIdentifier(node.left);
      }
      break;
    case 277 /* ExportAssignment */:
      return true;
  }
  return false;
}
function isNamedEvaluation(node, cb) {
  if (!isNamedEvaluationSource(node)) return false;
  switch (node.kind) {
    case 303 /* PropertyAssignment */:
      return isAnonymousFunctionDefinition(node.initializer, cb);
    case 304 /* ShorthandPropertyAssignment */:
      return isAnonymousFunctionDefinition(node.objectAssignmentInitializer, cb);
    case 260 /* VariableDeclaration */:
    case 169 /* Parameter */:
    case 208 /* BindingElement */:
    case 172 /* PropertyDeclaration */:
      return isAnonymousFunctionDefinition(node.initializer, cb);
    case 226 /* BinaryExpression */:
      return isAnonymousFunctionDefinition(node.right, cb);
    case 277 /* ExportAssignment */:
      return isAnonymousFunctionDefinition(node.expression, cb);
  }
}
function isPushOrUnshiftIdentifier(node) {
  return node.escapedText === "push" || node.escapedText === "unshift";
}
function isPartOfParameterDeclaration(node) {
  const root = getRootDeclaration(node);
  return root.kind === 169 /* Parameter */;
}
function getRootDeclaration(node) {
  while (node.kind === 208 /* BindingElement */) {
    node = node.parent.parent;
  }
  return node;
}
function nodeStartsNewLexicalEnvironment(node) {
  const kind = node.kind;
  return kind === 176 /* Constructor */ || kind === 218 /* FunctionExpression */ || kind === 262 /* FunctionDeclaration */ || kind === 219 /* ArrowFunction */ || kind === 174 /* MethodDeclaration */ || kind === 177 /* GetAccessor */ || kind === 178 /* SetAccessor */ || kind === 267 /* ModuleDeclaration */ || kind === 307 /* SourceFile */;
}
function nodeIsSynthesized(range) {
  return positionIsSynthesized(range.pos) || positionIsSynthesized(range.end);
}
var Associativity = /* @__PURE__ */ ((Associativity2) => {
  Associativity2[Associativity2["Left"] = 0] = "Left";
  Associativity2[Associativity2["Right"] = 1] = "Right";
  return Associativity2;
})(Associativity || {});
function getExpressionAssociativity(expression) {
  const operator = getOperator(expression);
  const hasArguments = expression.kind === 214 /* NewExpression */ && expression.arguments !== void 0;
  return getOperatorAssociativity(expression.kind, operator, hasArguments);
}
function getOperatorAssociativity(kind, operator, hasArguments) {
  switch (kind) {
    case 214 /* NewExpression */:
      return hasArguments ? 0 /* Left */ : 1 /* Right */;
    case 224 /* PrefixUnaryExpression */:
    case 221 /* TypeOfExpression */:
    case 222 /* VoidExpression */:
    case 220 /* DeleteExpression */:
    case 223 /* AwaitExpression */:
    case 227 /* ConditionalExpression */:
    case 229 /* YieldExpression */:
      return 1 /* Right */;
    case 226 /* BinaryExpression */:
      switch (operator) {
        case 43 /* AsteriskAsteriskToken */:
        case 64 /* EqualsToken */:
        case 65 /* PlusEqualsToken */:
        case 66 /* MinusEqualsToken */:
        case 68 /* AsteriskAsteriskEqualsToken */:
        case 67 /* AsteriskEqualsToken */:
        case 69 /* SlashEqualsToken */:
        case 70 /* PercentEqualsToken */:
        case 71 /* LessThanLessThanEqualsToken */:
        case 72 /* GreaterThanGreaterThanEqualsToken */:
        case 73 /* GreaterThanGreaterThanGreaterThanEqualsToken */:
        case 74 /* AmpersandEqualsToken */:
        case 79 /* CaretEqualsToken */:
        case 75 /* BarEqualsToken */:
        case 76 /* BarBarEqualsToken */:
        case 77 /* AmpersandAmpersandEqualsToken */:
        case 78 /* QuestionQuestionEqualsToken */:
          return 1 /* Right */;
      }
  }
  return 0 /* Left */;
}
function getExpressionPrecedence(expression) {
  const operator = getOperator(expression);
  const hasArguments = expression.kind === 214 /* NewExpression */ && expression.arguments !== void 0;
  return getOperatorPrecedence(expression.kind, operator, hasArguments);
}
function getOperator(expression) {
  if (expression.kind === 226 /* BinaryExpression */) {
    return expression.operatorToken.kind;
  } else if (expression.kind === 224 /* PrefixUnaryExpression */ || expression.kind === 225 /* PostfixUnaryExpression */) {
    return expression.operator;
  } else {
    return expression.kind;
  }
}
var OperatorPrecedence = /* @__PURE__ */ ((OperatorPrecedence2) => {
  OperatorPrecedence2[OperatorPrecedence2["Comma"] = 0] = "Comma";
  OperatorPrecedence2[OperatorPrecedence2["Spread"] = 1] = "Spread";
  OperatorPrecedence2[OperatorPrecedence2["Yield"] = 2] = "Yield";
  OperatorPrecedence2[OperatorPrecedence2["Assignment"] = 3] = "Assignment";
  OperatorPrecedence2[OperatorPrecedence2["Conditional"] = 4] = "Conditional";
  OperatorPrecedence2[OperatorPrecedence2["Coalesce"] = 4 /* Conditional */] = "Coalesce";
  OperatorPrecedence2[OperatorPrecedence2["LogicalOR"] = 5] = "LogicalOR";
  OperatorPrecedence2[OperatorPrecedence2["LogicalAND"] = 6] = "LogicalAND";
  OperatorPrecedence2[OperatorPrecedence2["BitwiseOR"] = 7] = "BitwiseOR";
  OperatorPrecedence2[OperatorPrecedence2["BitwiseXOR"] = 8] = "BitwiseXOR";
  OperatorPrecedence2[OperatorPrecedence2["BitwiseAND"] = 9] = "BitwiseAND";
  OperatorPrecedence2[OperatorPrecedence2["Equality"] = 10] = "Equality";
  OperatorPrecedence2[OperatorPrecedence2["Relational"] = 11] = "Relational";
  OperatorPrecedence2[OperatorPrecedence2["Shift"] = 12] = "Shift";
  OperatorPrecedence2[OperatorPrecedence2["Additive"] = 13] = "Additive";
  OperatorPrecedence2[OperatorPrecedence2["Multiplicative"] = 14] = "Multiplicative";
  OperatorPrecedence2[OperatorPrecedence2["Exponentiation"] = 15] = "Exponentiation";
  OperatorPrecedence2[OperatorPrecedence2["Unary"] = 16] = "Unary";
  OperatorPrecedence2[OperatorPrecedence2["Update"] = 17] = "Update";
  OperatorPrecedence2[OperatorPrecedence2["LeftHandSide"] = 18] = "LeftHandSide";
  OperatorPrecedence2[OperatorPrecedence2["Member"] = 19] = "Member";
  OperatorPrecedence2[OperatorPrecedence2["Primary"] = 20] = "Primary";
  OperatorPrecedence2[OperatorPrecedence2["Highest"] = 20 /* Primary */] = "Highest";
  OperatorPrecedence2[OperatorPrecedence2["Lowest"] = 0 /* Comma */] = "Lowest";
  OperatorPrecedence2[OperatorPrecedence2["Invalid"] = -1] = "Invalid";
  return OperatorPrecedence2;
})(OperatorPrecedence || {});
function getOperatorPrecedence(nodeKind, operatorKind, hasArguments) {
  switch (nodeKind) {
    case 356 /* CommaListExpression */:
      return 0 /* Comma */;
    case 230 /* SpreadElement */:
      return 1 /* Spread */;
    case 229 /* YieldExpression */:
      return 2 /* Yield */;
    case 227 /* ConditionalExpression */:
      return 4 /* Conditional */;
    case 226 /* BinaryExpression */:
      switch (operatorKind) {
        case 28 /* CommaToken */:
          return 0 /* Comma */;
        case 64 /* EqualsToken */:
        case 65 /* PlusEqualsToken */:
        case 66 /* MinusEqualsToken */:
        case 68 /* AsteriskAsteriskEqualsToken */:
        case 67 /* AsteriskEqualsToken */:
        case 69 /* SlashEqualsToken */:
        case 70 /* PercentEqualsToken */:
        case 71 /* LessThanLessThanEqualsToken */:
        case 72 /* GreaterThanGreaterThanEqualsToken */:
        case 73 /* GreaterThanGreaterThanGreaterThanEqualsToken */:
        case 74 /* AmpersandEqualsToken */:
        case 79 /* CaretEqualsToken */:
        case 75 /* BarEqualsToken */:
        case 76 /* BarBarEqualsToken */:
        case 77 /* AmpersandAmpersandEqualsToken */:
        case 78 /* QuestionQuestionEqualsToken */:
          return 3 /* Assignment */;
        default:
          return getBinaryOperatorPrecedence(operatorKind);
      }
    // TODO: Should prefix `++` and `--` be moved to the `Update` precedence?
    case 216 /* TypeAssertionExpression */:
    case 235 /* NonNullExpression */:
    case 224 /* PrefixUnaryExpression */:
    case 221 /* TypeOfExpression */:
    case 222 /* VoidExpression */:
    case 220 /* DeleteExpression */:
    case 223 /* AwaitExpression */:
      return 16 /* Unary */;
    case 225 /* PostfixUnaryExpression */:
      return 17 /* Update */;
    case 213 /* CallExpression */:
      return 18 /* LeftHandSide */;
    case 214 /* NewExpression */:
      return hasArguments ? 19 /* Member */ : 18 /* LeftHandSide */;
    case 215 /* TaggedTemplateExpression */:
    case 211 /* PropertyAccessExpression */:
    case 212 /* ElementAccessExpression */:
    case 236 /* MetaProperty */:
      return 19 /* Member */;
    case 234 /* AsExpression */:
    case 238 /* SatisfiesExpression */:
      return 11 /* Relational */;
    case 110 /* ThisKeyword */:
    case 108 /* SuperKeyword */:
    case 80 /* Identifier */:
    case 81 /* PrivateIdentifier */:
    case 106 /* NullKeyword */:
    case 112 /* TrueKeyword */:
    case 97 /* FalseKeyword */:
    case 9 /* NumericLiteral */:
    case 10 /* BigIntLiteral */:
    case 11 /* StringLiteral */:
    case 209 /* ArrayLiteralExpression */:
    case 210 /* ObjectLiteralExpression */:
    case 218 /* FunctionExpression */:
    case 219 /* ArrowFunction */:
    case 231 /* ClassExpression */:
    case 14 /* RegularExpressionLiteral */:
    case 15 /* NoSubstitutionTemplateLiteral */:
    case 228 /* TemplateExpression */:
    case 217 /* ParenthesizedExpression */:
    case 232 /* OmittedExpression */:
    case 284 /* JsxElement */:
    case 285 /* JsxSelfClosingElement */:
    case 288 /* JsxFragment */:
      return 20 /* Primary */;
    default:
      return -1 /* Invalid */;
  }
}
function getBinaryOperatorPrecedence(kind) {
  switch (kind) {
    case 61 /* QuestionQuestionToken */:
      return 4 /* Coalesce */;
    case 57 /* BarBarToken */:
      return 5 /* LogicalOR */;
    case 56 /* AmpersandAmpersandToken */:
      return 6 /* LogicalAND */;
    case 52 /* BarToken */:
      return 7 /* BitwiseOR */;
    case 53 /* CaretToken */:
      return 8 /* BitwiseXOR */;
    case 51 /* AmpersandToken */:
      return 9 /* BitwiseAND */;
    case 35 /* EqualsEqualsToken */:
    case 36 /* ExclamationEqualsToken */:
    case 37 /* EqualsEqualsEqualsToken */:
    case 38 /* ExclamationEqualsEqualsToken */:
      return 10 /* Equality */;
    case 30 /* LessThanToken */:
    case 32 /* GreaterThanToken */:
    case 33 /* LessThanEqualsToken */:
    case 34 /* GreaterThanEqualsToken */:
    case 104 /* InstanceOfKeyword */:
    case 103 /* InKeyword */:
    case 130 /* AsKeyword */:
    case 152 /* SatisfiesKeyword */:
      return 11 /* Relational */;
    case 48 /* LessThanLessThanToken */:
    case 49 /* GreaterThanGreaterThanToken */:
    case 50 /* GreaterThanGreaterThanGreaterThanToken */:
      return 12 /* Shift */;
    case 40 /* PlusToken */:
    case 41 /* MinusToken */:
      return 13 /* Additive */;
    case 42 /* AsteriskToken */:
    case 44 /* SlashToken */:
    case 45 /* PercentToken */:
      return 14 /* Multiplicative */;
    case 43 /* AsteriskAsteriskToken */:
      return 15 /* Exponentiation */;
  }
  return -1;
}
function getSemanticJsxChildren(children) {
  return filter(children, (i) => {
    switch (i.kind) {
      case 294 /* JsxExpression */:
        return !!i.expression;
      case 12 /* JsxText */:
        return !i.containsOnlyTriviaWhiteSpaces;
      default:
        return true;
    }
  });
}
function createDiagnosticCollection() {
  let nonFileDiagnostics = [];
  const filesWithDiagnostics = [];
  const fileDiagnostics = /* @__PURE__ */ new Map();
  let hasReadNonFileDiagnostics = false;
  return {
    add,
    lookup,
    getGlobalDiagnostics,
    getDiagnostics: getDiagnostics2
  };
  function lookup(diagnostic) {
    let diagnostics;
    if (diagnostic.file) {
      diagnostics = fileDiagnostics.get(diagnostic.file.fileName);
    } else {
      diagnostics = nonFileDiagnostics;
    }
    if (!diagnostics) {
      return void 0;
    }
    const result = binarySearch(diagnostics, diagnostic, identity, compareDiagnosticsSkipRelatedInformation);
    if (result >= 0) {
      return diagnostics[result];
    }
    if (~result > 0 && diagnosticsEqualityComparer(diagnostic, diagnostics[~result - 1])) {
      return diagnostics[~result - 1];
    }
    return void 0;
  }
  function add(diagnostic) {
    let diagnostics;
    if (diagnostic.file) {
      diagnostics = fileDiagnostics.get(diagnostic.file.fileName);
      if (!diagnostics) {
        diagnostics = [];
        fileDiagnostics.set(diagnostic.file.fileName, diagnostics);
        insertSorted(filesWithDiagnostics, diagnostic.file.fileName, compareStringsCaseSensitive);
      }
    } else {
      if (hasReadNonFileDiagnostics) {
        hasReadNonFileDiagnostics = false;
        nonFileDiagnostics = nonFileDiagnostics.slice();
      }
      diagnostics = nonFileDiagnostics;
    }
    insertSorted(diagnostics, diagnostic, compareDiagnosticsSkipRelatedInformation, diagnosticsEqualityComparer);
  }
  function getGlobalDiagnostics() {
    hasReadNonFileDiagnostics = true;
    return nonFileDiagnostics;
  }
  function getDiagnostics2(fileName) {
    if (fileName) {
      return fileDiagnostics.get(fileName) || [];
    }
    const fileDiags = flatMapToMutable(filesWithDiagnostics, (f) => fileDiagnostics.get(f));
    if (!nonFileDiagnostics.length) {
      return fileDiags;
    }
    fileDiags.unshift(...nonFileDiagnostics);
    return fileDiags;
  }
}
var templateSubstitutionRegExp = /\$\{/g;
function escapeTemplateSubstitution(str) {
  return str.replace(templateSubstitutionRegExp, "\\${");
}
function containsInvalidEscapeFlag(node) {
  return !!((node.templateFlags || 0) & 2048 /* ContainsInvalidEscape */);
}
function hasInvalidEscape(template) {
  return template && !!(isNoSubstitutionTemplateLiteral(template) ? containsInvalidEscapeFlag(template) : containsInvalidEscapeFlag(template.head) || some(template.templateSpans, (span) => containsInvalidEscapeFlag(span.literal)));
}
var doubleQuoteEscapedCharsRegExp = /[\\"\u0000-\u001f\u2028\u2029\u0085]/g;
var singleQuoteEscapedCharsRegExp = /[\\'\u0000-\u001f\u2028\u2029\u0085]/g;
var backtickQuoteEscapedCharsRegExp = /\r\n|[\\`\u0000-\u0009\u000b-\u001f\u2028\u2029\u0085]/g;
var escapedCharsMap = new Map(Object.entries({
  "	": "\\t",
  "\v": "\\v",
  "\f": "\\f",
  "\b": "\\b",
  "\r": "\\r",
  "\n": "\\n",
  "\\": "\\\\",
  '"': '\\"',
  "'": "\\'",
  "`": "\\`",
  "\u2028": "\\u2028",
  // lineSeparator
  "\u2029": "\\u2029",
  // paragraphSeparator
  "\x85": "\\u0085",
  // nextLine
  "\r\n": "\\r\\n"
  // special case for CRLFs in backticks
}));
function encodeUtf16EscapeSequence(charCode) {
  const hexCharCode = charCode.toString(16).toUpperCase();
  const paddedHexCode = ("0000" + hexCharCode).slice(-4);
  return "\\u" + paddedHexCode;
}
function getReplacement(c, offset, input) {
  if (c.charCodeAt(0) === 0 /* nullCharacter */) {
    const lookAhead = input.charCodeAt(offset + c.length);
    if (lookAhead >= 48 /* _0 */ && lookAhead <= 57 /* _9 */) {
      return "\\x00";
    }
    return "\\0";
  }
  return escapedCharsMap.get(c) || encodeUtf16EscapeSequence(c.charCodeAt(0));
}
function escapeString(s, quoteChar) {
  const escapedCharsRegExp = quoteChar === 96 /* backtick */ ? backtickQuoteEscapedCharsRegExp : quoteChar === 39 /* singleQuote */ ? singleQuoteEscapedCharsRegExp : doubleQuoteEscapedCharsRegExp;
  return s.replace(escapedCharsRegExp, getReplacement);
}
var nonAsciiCharacters = /[^\u0000-\u007F]/g;
function escapeNonAsciiString(s, quoteChar) {
  s = escapeString(s, quoteChar);
  return nonAsciiCharacters.test(s) ? s.replace(nonAsciiCharacters, (c) => encodeUtf16EscapeSequence(c.charCodeAt(0))) : s;
}
var jsxDoubleQuoteEscapedCharsRegExp = /["\u0000-\u001f\u2028\u2029\u0085]/g;
var jsxSingleQuoteEscapedCharsRegExp = /['\u0000-\u001f\u2028\u2029\u0085]/g;
var jsxEscapedCharsMap = new Map(Object.entries({
  '"': "&quot;",
  "'": "&apos;"
}));
function encodeJsxCharacterEntity(charCode) {
  const hexCharCode = charCode.toString(16).toUpperCase();
  return "&#x" + hexCharCode + ";";
}
function getJsxAttributeStringReplacement(c) {
  if (c.charCodeAt(0) === 0 /* nullCharacter */) {
    return "&#0;";
  }
  return jsxEscapedCharsMap.get(c) || encodeJsxCharacterEntity(c.charCodeAt(0));
}
function escapeJsxAttributeString(s, quoteChar) {
  const escapedCharsRegExp = quoteChar === 39 /* singleQuote */ ? jsxSingleQuoteEscapedCharsRegExp : jsxDoubleQuoteEscapedCharsRegExp;
  return s.replace(escapedCharsRegExp, getJsxAttributeStringReplacement);
}
function stripQuotes(name) {
  const length2 = name.length;
  if (length2 >= 2 && name.charCodeAt(0) === name.charCodeAt(length2 - 1) && isQuoteOrBacktick(name.charCodeAt(0))) {
    return name.substring(1, length2 - 1);
  }
  return name;
}
function isQuoteOrBacktick(charCode) {
  return charCode === 39 /* singleQuote */ || charCode === 34 /* doubleQuote */ || charCode === 96 /* backtick */;
}
function isIntrinsicJsxName(name) {
  const ch = name.charCodeAt(0);
  return ch >= 97 /* a */ && ch <= 122 /* z */ || name.includes("-");
}
var indentStrings = ["", "    "];
function getIndentString(level) {
  const singleLevel = indentStrings[1];
  for (let current = indentStrings.length; current <= level; current++) {
    indentStrings.push(indentStrings[current - 1] + singleLevel);
  }
  return indentStrings[level];
}
function getIndentSize() {
  return indentStrings[1].length;
}
function createTextWriter(newLine) {
  var output;
  var indent3;
  var lineStart;
  var lineCount;
  var linePos;
  var hasTrailingComment = false;
  function updateLineCountAndPosFor(s) {
    const lineStartsOfS = computeLineStarts(s);
    if (lineStartsOfS.length > 1) {
      lineCount = lineCount + lineStartsOfS.length - 1;
      linePos = output.length - s.length + last(lineStartsOfS);
      lineStart = linePos - output.length === 0;
    } else {
      lineStart = false;
    }
  }
  function writeText(s) {
    if (s && s.length) {
      if (lineStart) {
        s = getIndentString(indent3) + s;
        lineStart = false;
      }
      output += s;
      updateLineCountAndPosFor(s);
    }
  }
  function write(s) {
    if (s) hasTrailingComment = false;
    writeText(s);
  }
  function writeComment(s) {
    if (s) hasTrailingComment = true;
    writeText(s);
  }
  function reset2() {
    output = "";
    indent3 = 0;
    lineStart = true;
    lineCount = 0;
    linePos = 0;
    hasTrailingComment = false;
  }
  function rawWrite(s) {
    if (s !== void 0) {
      output += s;
      updateLineCountAndPosFor(s);
      hasTrailingComment = false;
    }
  }
  function writeLiteral(s) {
    if (s && s.length) {
      write(s);
    }
  }
  function writeLine(force) {
    if (!lineStart || force) {
      output += newLine;
      lineCount++;
      linePos = output.length;
      lineStart = true;
      hasTrailingComment = false;
    }
  }
  reset2();
  return {
    write,
    rawWrite,
    writeLiteral,
    writeLine,
    increaseIndent: () => {
      indent3++;
    },
    decreaseIndent: () => {
      indent3--;
    },
    getIndent: () => indent3,
    getTextPos: () => output.length,
    getLine: () => lineCount,
    getColumn: () => lineStart ? indent3 * getIndentSize() : output.length - linePos,
    getText: () => output,
    isAtStartOfLine: () => lineStart,
    hasTrailingComment: () => hasTrailingComment,
    hasTrailingWhitespace: () => !!output.length && isWhiteSpaceLike(output.charCodeAt(output.length - 1)),
    clear: reset2,
    writeKeyword: write,
    writeOperator: write,
    writeParameter: write,
    writeProperty: write,
    writePunctuation: write,
    writeSpace: write,
    writeStringLiteral: write,
    writeSymbol: (s, _) => write(s),
    writeTrailingSemicolon: write,
    writeComment
  };
}
function getTrailingSemicolonDeferringWriter(writer) {
  let pendingTrailingSemicolon = false;
  function commitPendingTrailingSemicolon() {
    if (pendingTrailingSemicolon) {
      writer.writeTrailingSemicolon(";");
      pendingTrailingSemicolon = false;
    }
  }
  return {
    ...writer,
    writeTrailingSemicolon() {
      pendingTrailingSemicolon = true;
    },
    writeLiteral(s) {
      commitPendingTrailingSemicolon();
      writer.writeLiteral(s);
    },
    writeStringLiteral(s) {
      commitPendingTrailingSemicolon();
      writer.writeStringLiteral(s);
    },
    writeSymbol(s, sym) {
      commitPendingTrailingSemicolon();
      writer.writeSymbol(s, sym);
    },
    writePunctuation(s) {
      commitPendingTrailingSemicolon();
      writer.writePunctuation(s);
    },
    writeKeyword(s) {
      commitPendingTrailingSemicolon();
      writer.writeKeyword(s);
    },
    writeOperator(s) {
      commitPendingTrailingSemicolon();
      writer.writeOperator(s);
    },
    writeParameter(s) {
      commitPendingTrailingSemicolon();
      writer.writeParameter(s);
    },
    writeSpace(s) {
      commitPendingTrailingSemicolon();
      writer.writeSpace(s);
    },
    writeProperty(s) {
      commitPendingTrailingSemicolon();
      writer.writeProperty(s);
    },
    writeComment(s) {
      commitPendingTrailingSemicolon();
      writer.writeComment(s);
    },
    writeLine() {
      commitPendingTrailingSemicolon();
      writer.writeLine();
    },
    increaseIndent() {
      commitPendingTrailingSemicolon();
      writer.increaseIndent();
    },
    decreaseIndent() {
      commitPendingTrailingSemicolon();
      writer.decreaseIndent();
    }
  };
}
function hostUsesCaseSensitiveFileNames(host) {
  return host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : false;
}
function hostGetCanonicalFileName(host) {
  return createGetCanonicalFileName(hostUsesCaseSensitiveFileNames(host));
}
function getResolvedExternalModuleName(host, file, referenceFile) {
  return file.moduleName || getExternalModuleNameFromPath(host, file.fileName, referenceFile && referenceFile.fileName);
}
function getCanonicalAbsolutePath(host, path) {
  return host.getCanonicalFileName(getNormalizedAbsolutePath(path, host.getCurrentDirectory()));
}
function getExternalModuleNameFromDeclaration(host, resolver, declaration) {
  const file = resolver.getExternalModuleFileFromDeclaration(declaration);
  if (!file || file.isDeclarationFile) {
    return void 0;
  }
  const specifier = getExternalModuleName(declaration);
  if (specifier && isStringLiteralLike(specifier) && !pathIsRelative(specifier.text) && !getCanonicalAbsolutePath(host, file.path).includes(getCanonicalAbsolutePath(host, ensureTrailingDirectorySeparator(host.getCommonSourceDirectory())))) {
    return void 0;
  }
  return getResolvedExternalModuleName(host, file);
}
function getExternalModuleNameFromPath(host, fileName, referencePath) {
  const getCanonicalFileName = (f) => host.getCanonicalFileName(f);
  const dir = toPath(referencePath ? getDirectoryPath(referencePath) : host.getCommonSourceDirectory(), host.getCurrentDirectory(), getCanonicalFileName);
  const filePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
  const relativePath = getRelativePathToDirectoryOrUrl(
    dir,
    filePath,
    dir,
    getCanonicalFileName,
    /*isAbsolutePathAnUrl*/
    false
  );
  const extensionless = removeFileExtension(relativePath);
  return referencePath ? ensurePathIsNonModuleName(extensionless) : extensionless;
}
function getOwnEmitOutputFilePath(fileName, host, extension) {
  const compilerOptions = host.getCompilerOptions();
  let emitOutputFilePathWithoutExtension;
  if (compilerOptions.outDir) {
    emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(fileName, host, compilerOptions.outDir));
  } else {
    emitOutputFilePathWithoutExtension = removeFileExtension(fileName);
  }
  return emitOutputFilePathWithoutExtension + extension;
}
function getDeclarationEmitOutputFilePath(fileName, host) {
  return getDeclarationEmitOutputFilePathWorker(fileName, host.getCompilerOptions(), host);
}
function getDeclarationEmitOutputFilePathWorker(fileName, options, host) {
  const outputDir = options.declarationDir || options.outDir;
  const path = outputDir ? getSourceFilePathInNewDirWorker(fileName, outputDir, host.getCurrentDirectory(), host.getCommonSourceDirectory(), (f) => host.getCanonicalFileName(f)) : fileName;
  const declarationExtension = getDeclarationEmitExtensionForPath(path);
  return removeFileExtension(path) + declarationExtension;
}
function getDeclarationEmitExtensionForPath(path) {
  return fileExtensionIsOneOf(path, [".mjs" /* Mjs */, ".mts" /* Mts */]) ? ".d.mts" /* Dmts */ : fileExtensionIsOneOf(path, [".cjs" /* Cjs */, ".cts" /* Cts */]) ? ".d.cts" /* Dcts */ : fileExtensionIsOneOf(path, [".json" /* Json */]) ? `.d.json.ts` : (
    // Drive-by redefinition of json declaration file output name so if it's ever enabled, it behaves well
    ".d.ts" /* Dts */
  );
}
function getPossibleOriginalInputExtensionForExtension(path) {
  return fileExtensionIsOneOf(path, [".d.mts" /* Dmts */, ".mjs" /* Mjs */, ".mts" /* Mts */]) ? [".mts" /* Mts */, ".mjs" /* Mjs */] : fileExtensionIsOneOf(path, [".d.cts" /* Dcts */, ".cjs" /* Cjs */, ".cts" /* Cts */]) ? [".cts" /* Cts */, ".cjs" /* Cjs */] : fileExtensionIsOneOf(path, [`.d.json.ts`]) ? [".json" /* Json */] : [".tsx" /* Tsx */, ".ts" /* Ts */, ".jsx" /* Jsx */, ".js" /* Js */];
}
function getPossibleOriginalInputPathWithoutChangingExt(filePath, ignoreCase, outputDir, getCommonSourceDirectory2) {
  return outputDir ? resolvePath(
    getCommonSourceDirectory2(),
    getRelativePathFromDirectory(outputDir, filePath, ignoreCase)
  ) : filePath;
}
function getPathsBasePath(options, host) {
  var _a;
  if (!options.paths) return void 0;
  return options.baseUrl ?? Debug.checkDefined(options.pathsBasePath || ((_a = host.getCurrentDirectory) == null ? void 0 : _a.call(host)), "Encountered 'paths' without a 'baseUrl', config file, or host 'getCurrentDirectory'.");
}
function getSourceFilesToEmit(host, targetSourceFile, forceDtsEmit) {
  const options = host.getCompilerOptions();
  if (options.outFile) {
    const moduleKind = getEmitModuleKind(options);
    const moduleEmitEnabled = options.emitDeclarationOnly || moduleKind === 2 /* AMD */ || moduleKind === 4 /* System */;
    return filter(
      host.getSourceFiles(),
      (sourceFile) => (moduleEmitEnabled || !isExternalModule(sourceFile)) && sourceFileMayBeEmitted(sourceFile, host, forceDtsEmit)
    );
  } else {
    const sourceFiles = targetSourceFile === void 0 ? host.getSourceFiles() : [targetSourceFile];
    return filter(
      sourceFiles,
      (sourceFile) => sourceFileMayBeEmitted(sourceFile, host, forceDtsEmit)
    );
  }
}
function sourceFileMayBeEmitted(sourceFile, host, forceDtsEmit) {
  const options = host.getCompilerOptions();
  if (options.noEmitForJsFiles && isSourceFileJS(sourceFile)) return false;
  if (sourceFile.isDeclarationFile) return false;
  if (host.isSourceFileFromExternalLibrary(sourceFile)) return false;
  if (forceDtsEmit) return true;
  if (host.isSourceOfProjectReferenceRedirect(sourceFile.fileName)) return false;
  if (!isJsonSourceFile(sourceFile)) return true;
  if (host.getResolvedProjectReferenceToRedirect(sourceFile.fileName)) return false;
  if (options.outFile) return true;
  if (!options.outDir) return false;
  if (options.rootDir || options.composite && options.configFilePath) {
    const commonDir = getNormalizedAbsolutePath(getCommonSourceDirectory(options, () => [], host.getCurrentDirectory(), host.getCanonicalFileName), host.getCurrentDirectory());
    const outputPath = getSourceFilePathInNewDirWorker(sourceFile.fileName, options.outDir, host.getCurrentDirectory(), commonDir, host.getCanonicalFileName);
    if (comparePaths(sourceFile.fileName, outputPath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === 0 /* EqualTo */) return false;
  }
  return true;
}
function getSourceFilePathInNewDir(fileName, host, newDirPath) {
  return getSourceFilePathInNewDirWorker(fileName, newDirPath, host.getCurrentDirectory(), host.getCommonSourceDirectory(), (f) => host.getCanonicalFileName(f));
}
function getSourceFilePathInNewDirWorker(fileName, newDirPath, currentDirectory, commonSourceDirectory, getCanonicalFileName) {
  let sourceFilePath = getNormalizedAbsolutePath(fileName, currentDirectory);
  const isSourceFileInCommonSourceDirectory = getCanonicalFileName(sourceFilePath).indexOf(getCanonicalFileName(commonSourceDirectory)) === 0;
  sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath;
  return combinePaths(newDirPath, sourceFilePath);
}
function writeFile(host, diagnostics, fileName, text, writeByteOrderMark, sourceFiles, data) {
  host.writeFile(
    fileName,
    text,
    writeByteOrderMark,
    (hostErrorMessage) => {
      diagnostics.add(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
    },
    sourceFiles,
    data
  );
}
function ensureDirectoriesExist(directoryPath, createDirectory, directoryExists) {
  if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) {
    const parentDirectory = getDirectoryPath(directoryPath);
    ensureDirectoriesExist(parentDirectory, createDirectory, directoryExists);
    createDirectory(directoryPath);
  }
}
function writeFileEnsuringDirectories(path, data, writeByteOrderMark, writeFile2, createDirectory, directoryExists) {
  try {
    writeFile2(path, data, writeByteOrderMark);
  } catch {
    ensureDirectoriesExist(getDirectoryPath(normalizePath(path)), createDirectory, directoryExists);
    writeFile2(path, data, writeByteOrderMark);
  }
}
function getLineOfLocalPosition(sourceFile, pos) {
  const lineStarts = getLineStarts(sourceFile);
  return computeLineOfPosition(lineStarts, pos);
}
function getLineOfLocalPositionFromLineMap(lineMap, pos) {
  return computeLineOfPosition(lineMap, pos);
}
function getFirstConstructorWithBody(node) {
  return find(node.members, (member) => isConstructorDeclaration(member) && nodeIsPresent(member.body));
}
function getSetAccessorValueParameter(accessor) {
  if (accessor && accessor.parameters.length > 0) {
    const hasThis = accessor.parameters.length === 2 && parameterIsThisKeyword(accessor.parameters[0]);
    return accessor.parameters[hasThis ? 1 : 0];
  }
}
function getSetAccessorTypeAnnotationNode(accessor) {
  const parameter = getSetAccessorValueParameter(accessor);
  return parameter && parameter.type;
}
function getThisParameter(signature) {
  if (signature.parameters.length && !isJSDocSignature(signature)) {
    const thisParameter = signature.parameters[0];
    if (parameterIsThisKeyword(thisParameter)) {
      return thisParameter;
    }
  }
}
function parameterIsThisKeyword(parameter) {
  return isThisIdentifier(parameter.name);
}
function isThisIdentifier(node) {
  return !!node && node.kind === 80 /* Identifier */ && identifierIsThisKeyword(node);
}
function isInTypeQuery(node) {
  return !!findAncestor(
    node,
    (n) => n.kind === 186 /* TypeQuery */ ? true : n.kind === 80 /* Identifier */ || n.kind === 166 /* QualifiedName */ ? false : "quit"
  );
}
function isThisInTypeQuery(node) {
  if (!isThisIdentifier(node)) {
    return false;
  }
  while (isQualifiedName(node.parent) && node.parent.left === node) {
    node = node.parent;
  }
  return node.parent.kind === 186 /* TypeQuery */;
}
function identifierIsThisKeyword(id) {
  return id.escapedText === "this";
}
function getAllAccessorDeclarations(declarations, accessor) {
  let firstAccessor;
  let secondAccessor;
  let getAccessor;
  let setAccessor;
  if (hasDynamicName(accessor)) {
    firstAccessor = accessor;
    if (accessor.kind === 177 /* GetAccessor */) {
      getAccessor = accessor;
    } else if (accessor.kind === 178 /* SetAccessor */) {
      setAccessor = accessor;
    } else {
      Debug.fail("Accessor has wrong kind");
    }
  } else {
    forEach(declarations, (member) => {
      if (isAccessor(member) && isStatic(member) === isStatic(accessor)) {
        const memberName = getPropertyNameForPropertyNameNode(member.name);
        const accessorName = getPropertyNameForPropertyNameNode(accessor.name);
        if (memberName === accessorName) {
          if (!firstAccessor) {
            firstAccessor = member;
          } else if (!secondAccessor) {
            secondAccessor = member;
          }
          if (member.kind === 177 /* GetAccessor */ && !getAccessor) {
            getAccessor = member;
          }
          if (member.kind === 178 /* SetAccessor */ && !setAccessor) {
            setAccessor = member;
          }
        }
      }
    });
  }
  return {
    firstAccessor,
    secondAccessor,
    getAccessor,
    setAccessor
  };
}
function getEffectiveTypeAnnotationNode(node) {
  if (!isInJSFile(node) && isFunctionDeclaration(node)) return void 0;
  if (isTypeAliasDeclaration(node)) return void 0;
  const type = node.type;
  if (type || !isInJSFile(node)) return type;
  return isJSDocPropertyLikeTag(node) ? node.typeExpression && node.typeExpression.type : getJSDocType(node);
}
function getTypeAnnotationNode(node) {
  return node.type;
}
function getEffectiveReturnTypeNode(node) {
  return isJSDocSignature(node) ? node.type && node.type.typeExpression && node.type.typeExpression.type : node.type || (isInJSFile(node) ? getJSDocReturnType(node) : void 0);
}
function getJSDocTypeParameterDeclarations(node) {
  return flatMap(getJSDocTags(node), (tag) => isNonTypeAliasTemplate(tag) ? tag.typeParameters : void 0);
}
function isNonTypeAliasTemplate(tag) {
  return isJSDocTemplateTag(tag) && !(tag.parent.kind === 320 /* JSDoc */ && (tag.parent.tags.some(isJSDocTypeAlias) || tag.parent.tags.some(isJSDocOverloadTag)));
}
function getEffectiveSetAccessorTypeAnnotationNode(node) {
  const parameter = getSetAccessorValueParameter(node);
  return parameter && getEffectiveTypeAnnotationNode(parameter);
}
function emitNewLineBeforeLeadingComments(lineMap, writer, node, leadingComments) {
  emitNewLineBeforeLeadingCommentsOfPosition(lineMap, writer, node.pos, leadingComments);
}
function emitNewLineBeforeLeadingCommentsOfPosition(lineMap, writer, pos, leadingComments) {
  if (leadingComments && leadingComments.length && pos !== leadingComments[0].pos && getLineOfLocalPositionFromLineMap(lineMap, pos) !== getLineOfLocalPositionFromLineMap(lineMap, leadingComments[0].pos)) {
    writer.writeLine();
  }
}
function emitNewLineBeforeLeadingCommentOfPosition(lineMap, writer, pos, commentPos) {
  if (pos !== commentPos && getLineOfLocalPositionFromLineMap(lineMap, pos) !== getLineOfLocalPositionFromLineMap(lineMap, commentPos)) {
    writer.writeLine();
  }
}
function emitComments(text, lineMap, writer, comments, leadingSeparator, trailingSeparator, newLine, writeComment) {
  if (comments && comments.length > 0) {
    if (leadingSeparator) {
      writer.writeSpace(" ");
    }
    let emitInterveningSeparator = false;
    for (const comment of comments) {
      if (emitInterveningSeparator) {
        writer.writeSpace(" ");
        emitInterveningSeparator = false;
      }
      writeComment(text, lineMap, writer, comment.pos, comment.end, newLine);
      if (comment.hasTrailingNewLine) {
        writer.writeLine();
      } else {
        emitInterveningSeparator = true;
      }
    }
    if (emitInterveningSeparator && trailingSeparator) {
      writer.writeSpace(" ");
    }
  }
}
function emitDetachedComments(text, lineMap, writer, writeComment, node, newLine, removeComments) {
  let leadingComments;
  let currentDetachedCommentInfo;
  if (removeComments) {
    if (node.pos === 0) {
      leadingComments = filter(getLeadingCommentRanges(text, node.pos), isPinnedCommentLocal);
    }
  } else {
    leadingComments = getLeadingCommentRanges(text, node.pos);
  }
  if (leadingComments) {
    const detachedComments = [];
    let lastComment;
    for (const comment of leadingComments) {
      if (lastComment) {
        const lastCommentLine = getLineOfLocalPositionFromLineMap(lineMap, lastComment.end);
        const commentLine = getLineOfLocalPositionFromLineMap(lineMap, comment.pos);
        if (commentLine >= lastCommentLine + 2) {
          break;
        }
      }
      detachedComments.push(comment);
      lastComment = comment;
    }
    if (detachedComments.length) {
      const lastCommentLine = getLineOfLocalPositionFromLineMap(lineMap, last(detachedComments).end);
      const nodeLine = getLineOfLocalPositionFromLineMap(lineMap, skipTrivia(text, node.pos));
      if (nodeLine >= lastCommentLine + 2) {
        emitNewLineBeforeLeadingComments(lineMap, writer, node, leadingComments);
        emitComments(
          text,
          lineMap,
          writer,
          detachedComments,
          /*leadingSeparator*/
          false,
          /*trailingSeparator*/
          true,
          newLine,
          writeComment
        );
        currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: last(detachedComments).end };
      }
    }
  }
  return currentDetachedCommentInfo;
  function isPinnedCommentLocal(comment) {
    return isPinnedComment(text, comment.pos);
  }
}
function writeCommentRange(text, lineMap, writer, commentPos, commentEnd, newLine) {
  if (text.charCodeAt(commentPos + 1) === 42 /* asterisk */) {
    const firstCommentLineAndCharacter = computeLineAndCharacterOfPosition(lineMap, commentPos);
    const lineCount = lineMap.length;
    let firstCommentLineIndent;
    for (let pos = commentPos, currentLine = firstCommentLineAndCharacter.line; pos < commentEnd; currentLine++) {
      const nextLineStart = currentLine + 1 === lineCount ? text.length + 1 : lineMap[currentLine + 1];
      if (pos !== commentPos) {
        if (firstCommentLineIndent === void 0) {
          firstCommentLineIndent = calculateIndent(text, lineMap[firstCommentLineAndCharacter.line], commentPos);
        }
        const currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
        const spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(text, pos, nextLineStart);
        if (spacesToEmit > 0) {
          let numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
          const indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
          writer.rawWrite(indentSizeSpaceString);
          while (numberOfSingleSpacesToEmit) {
            writer.rawWrite(" ");
            numberOfSingleSpacesToEmit--;
          }
        } else {
          writer.rawWrite("");
        }
      }
      writeTrimmedCurrentLine(text, commentEnd, writer, newLine, pos, nextLineStart);
      pos = nextLineStart;
    }
  } else {
    writer.writeComment(text.substring(commentPos, commentEnd));
  }
}
function writeTrimmedCurrentLine(text, commentEnd, writer, newLine, pos, nextLineStart) {
  const end = Math.min(commentEnd, nextLineStart - 1);
  const currentLineText = text.substring(pos, end).trim();
  if (currentLineText) {
    writer.writeComment(currentLineText);
    if (end !== commentEnd) {
      writer.writeLine();
    }
  } else {
    writer.rawWrite(newLine);
  }
}
function calculateIndent(text, pos, end) {
  let currentLineIndent = 0;
  for (; pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos)); pos++) {
    if (text.charCodeAt(pos) === 9 /* tab */) {
      currentLineIndent += getIndentSize() - currentLineIndent % getIndentSize();
    } else {
      currentLineIndent++;
    }
  }
  return currentLineIndent;
}
function hasEffectiveModifiers(node) {
  return getEffectiveModifierFlags(node) !== 0 /* None */;
}
function hasSyntacticModifiers(node) {
  return getSyntacticModifierFlags(node) !== 0 /* None */;
}
function hasEffectiveModifier(node, flags) {
  return !!getSelectedEffectiveModifierFlags(node, flags);
}
function hasSyntacticModifier(node, flags) {
  return !!getSelectedSyntacticModifierFlags(node, flags);
}
function isStatic(node) {
  return isClassElement(node) && hasStaticModifier(node) || isClassStaticBlockDeclaration(node);
}
function hasStaticModifier(node) {
  return hasSyntacticModifier(node, 256 /* Static */);
}
function hasOverrideModifier(node) {
  return hasEffectiveModifier(node, 16 /* Override */);
}
function hasAbstractModifier(node) {
  return hasSyntacticModifier(node, 64 /* Abstract */);
}
function hasAmbientModifier(node) {
  return hasSyntacticModifier(node, 128 /* Ambient */);
}
function hasAccessorModifier(node) {
  return hasSyntacticModifier(node, 512 /* Accessor */);
}
function hasEffectiveReadonlyModifier(node) {
  return hasEffectiveModifier(node, 8 /* Readonly */);
}
function hasDecorators(node) {
  return hasSyntacticModifier(node, 32768 /* Decorator */);
}
function getSelectedEffectiveModifierFlags(node, flags) {
  return getEffectiveModifierFlags(node) & flags;
}
function getSelectedSyntacticModifierFlags(node, flags) {
  return getSyntacticModifierFlags(node) & flags;
}
function getModifierFlagsWorker(node, includeJSDoc, alwaysIncludeJSDoc) {
  if (node.kind >= 0 /* FirstToken */ && node.kind <= 165 /* LastToken */) {
    return 0 /* None */;
  }
  if (!(node.modifierFlagsCache & 536870912 /* HasComputedFlags */)) {
    node.modifierFlagsCache = getSyntacticModifierFlagsNoCache(node) | 536870912 /* HasComputedFlags */;
  }
  if (alwaysIncludeJSDoc || includeJSDoc && isInJSFile(node)) {
    if (!(node.modifierFlagsCache & 268435456 /* HasComputedJSDocModifiers */) && node.parent) {
      node.modifierFlagsCache |= getRawJSDocModifierFlagsNoCache(node) | 268435456 /* HasComputedJSDocModifiers */;
    }
    return selectEffectiveModifierFlags(node.modifierFlagsCache);
  }
  return selectSyntacticModifierFlags(node.modifierFlagsCache);
}
function getEffectiveModifierFlags(node) {
  return getModifierFlagsWorker(
    node,
    /*includeJSDoc*/
    true
  );
}
function getEffectiveModifierFlagsAlwaysIncludeJSDoc(node) {
  return getModifierFlagsWorker(
    node,
    /*includeJSDoc*/
    true,
    /*alwaysIncludeJSDoc*/
    true
  );
}
function getSyntacticModifierFlags(node) {
  return getModifierFlagsWorker(
    node,
    /*includeJSDoc*/
    false
  );
}
function getRawJSDocModifierFlagsNoCache(node) {
  let flags = 0 /* None */;
  if (!!node.parent && !isParameter(node)) {
    if (isInJSFile(node)) {
      if (getJSDocPublicTagNoCache(node)) flags |= 8388608 /* JSDocPublic */;
      if (getJSDocPrivateTagNoCache(node)) flags |= 16777216 /* JSDocPrivate */;
      if (getJSDocProtectedTagNoCache(node)) flags |= 33554432 /* JSDocProtected */;
      if (getJSDocReadonlyTagNoCache(node)) flags |= 67108864 /* JSDocReadonly */;
      if (getJSDocOverrideTagNoCache(node)) flags |= 134217728 /* JSDocOverride */;
    }
    if (getJSDocDeprecatedTagNoCache(node)) flags |= 65536 /* Deprecated */;
  }
  return flags;
}
function selectSyntacticModifierFlags(flags) {
  return flags & 65535 /* SyntacticModifiers */;
}
function selectEffectiveModifierFlags(flags) {
  return flags & 131071 /* NonCacheOnlyModifiers */ | (flags & 260046848 /* JSDocCacheOnlyModifiers */) >>> 23;
}
function getJSDocModifierFlagsNoCache(node) {
  return selectEffectiveModifierFlags(getRawJSDocModifierFlagsNoCache(node));
}
function getEffectiveModifierFlagsNoCache(node) {
  return getSyntacticModifierFlagsNoCache(node) | getJSDocModifierFlagsNoCache(node);
}
function getSyntacticModifierFlagsNoCache(node) {
  let flags = canHaveModifiers(node) ? modifiersToFlags(node.modifiers) : 0 /* None */;
  if (node.flags & 8 /* NestedNamespace */ || node.kind === 80 /* Identifier */ && node.flags & 4096 /* IdentifierIsInJSDocNamespace */) {
    flags |= 32 /* Export */;
  }
  return flags;
}
function modifiersToFlags(modifiers) {
  let flags = 0 /* None */;
  if (modifiers) {
    for (const modifier of modifiers) {
      flags |= modifierToFlag(modifier.kind);
    }
  }
  return flags;
}
function modifierToFlag(token) {
  switch (token) {
    case 126 /* StaticKeyword */:
      return 256 /* Static */;
    case 125 /* PublicKeyword */:
      return 1 /* Public */;
    case 124 /* ProtectedKeyword */:
      return 4 /* Protected */;
    case 123 /* PrivateKeyword */:
      return 2 /* Private */;
    case 128 /* AbstractKeyword */:
      return 64 /* Abstract */;
    case 129 /* AccessorKeyword */:
      return 512 /* Accessor */;
    case 95 /* ExportKeyword */:
      return 32 /* Export */;
    case 138 /* DeclareKeyword */:
      return 128 /* Ambient */;
    case 87 /* ConstKeyword */:
      return 4096 /* Const */;
    case 90 /* DefaultKeyword */:
      return 2048 /* Default */;
    case 134 /* AsyncKeyword */:
      return 1024 /* Async */;
    case 148 /* ReadonlyKeyword */:
      return 8 /* Readonly */;
    case 164 /* OverrideKeyword */:
      return 16 /* Override */;
    case 103 /* InKeyword */:
      return 8192 /* In */;
    case 147 /* OutKeyword */:
      return 16384 /* Out */;
    case 170 /* Decorator */:
      return 32768 /* Decorator */;
  }
  return 0 /* None */;
}
function isBinaryLogicalOperator(token) {
  return token === 57 /* BarBarToken */ || token === 56 /* AmpersandAmpersandToken */;
}
function isLogicalOperator(token) {
  return isBinaryLogicalOperator(token) || token === 54 /* ExclamationToken */;
}
function isLogicalOrCoalescingAssignmentOperator(token) {
  return token === 76 /* BarBarEqualsToken */ || token === 77 /* AmpersandAmpersandEqualsToken */ || token === 78 /* QuestionQuestionEqualsToken */;
}
function isLogicalOrCoalescingAssignmentExpression(expr) {
  return isBinaryExpression(expr) && isLogicalOrCoalescingAssignmentOperator(expr.operatorToken.kind);
}
function isLogicalOrCoalescingBinaryOperator(token) {
  return isBinaryLogicalOperator(token) || token === 61 /* QuestionQuestionToken */;
}
function isLogicalOrCoalescingBinaryExpression(expr) {
  return isBinaryExpression(expr) && isLogicalOrCoalescingBinaryOperator(expr.operatorToken.kind);
}
function isAssignmentOperator(token) {
  return token >= 64 /* FirstAssignment */ && token <= 79 /* LastAssignment */;
}
function tryGetClassExtendingExpressionWithTypeArguments(node) {
  const cls = tryGetClassImplementingOrExtendingExpressionWithTypeArguments(node);
  return cls && !cls.isImplements ? cls.class : void 0;
}
function tryGetClassImplementingOrExtendingExpressionWithTypeArguments(node) {
  if (isExpressionWithTypeArguments(node)) {
    if (isHeritageClause(node.parent) && isClassLike(node.parent.parent)) {
      return { class: node.parent.parent, isImplements: node.parent.token === 119 /* ImplementsKeyword */ };
    }
    if (isJSDocAugmentsTag(node.parent)) {
      const host = getEffectiveJSDocHost(node.parent);
      if (host && isClassLike(host)) {
        return { class: host, isImplements: false };
      }
    }
  }
  return void 0;
}
function isAssignmentExpression(node, excludeCompoundAssignment) {
  return isBinaryExpression(node) && (excludeCompoundAssignment ? node.operatorToken.kind === 64 /* EqualsToken */ : isAssignmentOperator(node.operatorToken.kind)) && isLeftHandSideExpression(node.left);
}
function isDestructuringAssignment(node) {
  if (isAssignmentExpression(
    node,
    /*excludeCompoundAssignment*/
    true
  )) {
    const kind = node.left.kind;
    return kind === 210 /* ObjectLiteralExpression */ || kind === 209 /* ArrayLiteralExpression */;
  }
  return false;
}
function isExpressionWithTypeArgumentsInClassExtendsClause(node) {
  return tryGetClassExtendingExpressionWithTypeArguments(node) !== void 0;
}
function isEntityNameExpression(node) {
  return node.kind === 80 /* Identifier */ || isPropertyAccessEntityNameExpression(node);
}
function getFirstIdentifier(node) {
  switch (node.kind) {
    case 80 /* Identifier */:
      return node;
    case 166 /* QualifiedName */:
      do {
        node = node.left;
      } while (node.kind !== 80 /* Identifier */);
      return node;
    case 211 /* PropertyAccessExpression */:
      do {
        node = node.expression;
      } while (node.kind !== 80 /* Identifier */);
      return node;
  }
}
function isDottedName(node) {
  return node.kind === 80 /* Identifier */ || node.kind === 110 /* ThisKeyword */ || node.kind === 108 /* SuperKeyword */ || node.kind === 236 /* MetaProperty */ || node.kind === 211 /* PropertyAccessExpression */ && isDottedName(node.expression) || node.kind === 217 /* ParenthesizedExpression */ && isDottedName(node.expression);
}
function isPropertyAccessEntityNameExpression(node) {
  return isPropertyAccessExpression(node) && isIdentifier(node.name) && isEntityNameExpression(node.expression);
}
function tryGetPropertyAccessOrIdentifierToString(expr) {
  if (isPropertyAccessExpression(expr)) {
    const baseStr = tryGetPropertyAccessOrIdentifierToString(expr.expression);
    if (baseStr !== void 0) {
      return baseStr + "." + entityNameToString(expr.name);
    }
  } else if (isElementAccessExpression(expr)) {
    const baseStr = tryGetPropertyAccessOrIdentifierToString(expr.expression);
    if (baseStr !== void 0 && isPropertyName(expr.argumentExpression)) {
      return baseStr + "." + getPropertyNameForPropertyNameNode(expr.argumentExpression);
    }
  } else if (isIdentifier(expr)) {
    return unescapeLeadingUnderscores(expr.escapedText);
  } else if (isJsxNamespacedName(expr)) {
    return getTextOfJsxNamespacedName(expr);
  }
  return void 0;
}
function isPrototypeAccess(node) {
  return isBindableStaticAccessExpression(node) && getElementOrPropertyAccessName(node) === "prototype";
}
function isRightSideOfQualifiedNameOrPropertyAccess(node) {
  return node.parent.kind === 166 /* QualifiedName */ && node.parent.right === node || node.parent.kind === 211 /* PropertyAccessExpression */ && node.parent.name === node || node.parent.kind === 236 /* MetaProperty */ && node.parent.name === node;
}
function isRightSideOfAccessExpression(node) {
  return !!node.parent && (isPropertyAccessExpression(node.parent) && node.parent.name === node || isElementAccessExpression(node.parent) && node.parent.argumentExpression === node);
}
function isRightSideOfQualifiedNameOrPropertyAccessOrJSDocMemberName(node) {
  return isQualifiedName(node.parent) && node.parent.right === node || isPropertyAccessExpression(node.parent) && node.parent.name === node || isJSDocMemberName(node.parent) && node.parent.right === node;
}
function isInstanceOfExpression(node) {
  return isBinaryExpression(node) && node.operatorToken.kind === 104 /* InstanceOfKeyword */;
}
function isRightSideOfInstanceofExpression(node) {
  return isInstanceOfExpression(node.parent) && node === node.parent.right;
}
function isEmptyObjectLiteral(expression) {
  return expression.kind === 210 /* ObjectLiteralExpression */ && expression.properties.length === 0;
}
function isEmptyArrayLiteral(expression) {
  return expression.kind === 209 /* ArrayLiteralExpression */ && expression.elements.length === 0;
}
function getLocalSymbolForExportDefault(symbol) {
  if (!isExportDefaultSymbol(symbol) || !symbol.declarations) return void 0;
  for (const decl of symbol.declarations) {
    if (decl.localSymbol) return decl.localSymbol;
  }
  return void 0;
}
function isExportDefaultSymbol(symbol) {
  return symbol && length(symbol.declarations) > 0 && hasSyntacticModifier(symbol.declarations[0], 2048 /* Default */);
}
function tryExtractTSExtension(fileName) {
  return find(supportedTSExtensionsForExtractExtension, (extension) => fileExtensionIs(fileName, extension));
}
function getExpandedCharCodes(input) {
  const output = [];
  const length2 = input.length;
  for (let i = 0; i < length2; i++) {
    const charCode = input.charCodeAt(i);
    if (charCode < 128) {
      output.push(charCode);
    } else if (charCode < 2048) {
      output.push(charCode >> 6 | 192);
      output.push(charCode & 63 | 128);
    } else if (charCode < 65536) {
      output.push(charCode >> 12 | 224);
      output.push(charCode >> 6 & 63 | 128);
      output.push(charCode & 63 | 128);
    } else if (charCode < 131072) {
      output.push(charCode >> 18 | 240);
      output.push(charCode >> 12 & 63 | 128);
      output.push(charCode >> 6 & 63 | 128);
      output.push(charCode & 63 | 128);
    } else {
      Debug.assert(false, "Unexpected code point");
    }
  }
  return output;
}
var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function convertToBase64(input) {
  let result = "";
  const charCodes = getExpandedCharCodes(input);
  let i = 0;
  const length2 = charCodes.length;
  let byte1, byte2, byte3, byte4;
  while (i < length2) {
    byte1 = charCodes[i] >> 2;
    byte2 = (charCodes[i] & 3) << 4 | charCodes[i + 1] >> 4;
    byte3 = (charCodes[i + 1] & 15) << 2 | charCodes[i + 2] >> 6;
    byte4 = charCodes[i + 2] & 63;
    if (i + 1 >= length2) {
      byte3 = byte4 = 64;
    } else if (i + 2 >= length2) {
      byte4 = 64;
    }
    result += base64Digits.charAt(byte1) + base64Digits.charAt(byte2) + base64Digits.charAt(byte3) + base64Digits.charAt(byte4);
    i += 3;
  }
  return result;
}
function getStringFromExpandedCharCodes(codes) {
  let output = "";
  let i = 0;
  const length2 = codes.length;
  while (i < length2) {
    const charCode = codes[i];
    if (charCode < 128) {
      output += String.fromCharCode(charCode);
      i++;
    } else if ((charCode & 192) === 192) {
      let value = charCode & 63;
      i++;
      let nextCode = codes[i];
      while ((nextCode & 192) === 128) {
        value = value << 6 | nextCode & 63;
        i++;
        nextCode = codes[i];
      }
      output += String.fromCharCode(value);
    } else {
      output += String.fromCharCode(charCode);
      i++;
    }
  }
  return output;
}
function base64encode(host, input) {
  if (host && host.base64encode) {
    return host.base64encode(input);
  }
  return convertToBase64(input);
}
function base64decode(host, input) {
  if (host && host.base64decode) {
    return host.base64decode(input);
  }
  const length2 = input.length;
  const expandedCharCodes = [];
  let i = 0;
  while (i < length2) {
    if (input.charCodeAt(i) === base64Digits.charCodeAt(64)) {
      break;
    }
    const ch1 = base64Digits.indexOf(input[i]);
    const ch2 = base64Digits.indexOf(input[i + 1]);
    const ch3 = base64Digits.indexOf(input[i + 2]);
    const ch4 = base64Digits.indexOf(input[i + 3]);
    const code1 = (ch1 & 63) << 2 | ch2 >> 4 & 3;
    const code2 = (ch2 & 15) << 4 | ch3 >> 2 & 15;
    const code3 = (ch3 & 3) << 6 | ch4 & 63;
    if (code2 === 0 && ch3 !== 0) {
      expandedCharCodes.push(code1);
    } else if (code3 === 0 && ch4 !== 0) {
      expandedCharCodes.push(code1, code2);
    } else {
      expandedCharCodes.push(code1, code2, code3);
    }
    i += 4;
  }
  return getStringFromExpandedCharCodes(expandedCharCodes);
}
function readJsonOrUndefined(path, hostOrText) {
  const jsonText = isString(hostOrText) ? hostOrText : hostOrText.readFile(path);
  if (!jsonText) return void 0;
  const result = parseConfigFileTextToJson(path, jsonText);
  return !result.error ? result.config : void 0;
}
function readJson(path, host) {
  return readJsonOrUndefined(path, host) || {};
}
function tryParseJson(text) {
  try {
    return JSON.parse(text);
  } catch {
    return void 0;
  }
}
function directoryProbablyExists(directoryName, host) {
  return !host.directoryExists || host.directoryExists(directoryName);
}
var carriageReturnLineFeed = "\r\n";
var lineFeed = "\n";
function getNewLineCharacter(options) {
  switch (options.newLine) {
    case 0 /* CarriageReturnLineFeed */:
      return carriageReturnLineFeed;
    case 1 /* LineFeed */:
    case void 0:
      return lineFeed;
  }
}
function createRange(pos, end = pos) {
  Debug.assert(end >= pos || end === -1);
  return { pos, end };
}
function moveRangeEnd(range, end) {
  return createRange(range.pos, end);
}
function moveRangePos(range, pos) {
  return createRange(pos, range.end);
}
function moveRangePastDecorators(node) {
  const lastDecorator = canHaveModifiers(node) ? findLast(node.modifiers, isDecorator) : void 0;
  return lastDecorator && !positionIsSynthesized(lastDecorator.end) ? moveRangePos(node, lastDecorator.end) : node;
}
function moveRangePastModifiers(node) {
  if (isPropertyDeclaration(node) || isMethodDeclaration(node)) {
    return moveRangePos(node, node.name.pos);
  }
  const lastModifier = canHaveModifiers(node) ? lastOrUndefined(node.modifiers) : void 0;
  return lastModifier && !positionIsSynthesized(lastModifier.end) ? moveRangePos(node, lastModifier.end) : moveRangePastDecorators(node);
}
function createTokenRange(pos, token) {
  return createRange(pos, pos + tokenToString(token).length);
}
function rangeIsOnSingleLine(range, sourceFile) {
  return rangeStartIsOnSameLineAsRangeEnd(range, range, sourceFile);
}
function rangeStartPositionsAreOnSameLine(range1, range2, sourceFile) {
  return positionsAreOnSameLine(
    getStartPositionOfRange(
      range1,
      sourceFile,
      /*includeComments*/
      false
    ),
    getStartPositionOfRange(
      range2,
      sourceFile,
      /*includeComments*/
      false
    ),
    sourceFile
  );
}
function rangeEndPositionsAreOnSameLine(range1, range2, sourceFile) {
  return positionsAreOnSameLine(range1.end, range2.end, sourceFile);
}
function rangeStartIsOnSameLineAsRangeEnd(range1, range2, sourceFile) {
  return positionsAreOnSameLine(getStartPositionOfRange(
    range1,
    sourceFile,
    /*includeComments*/
    false
  ), range2.end, sourceFile);
}
function rangeEndIsOnSameLineAsRangeStart(range1, range2, sourceFile) {
  return positionsAreOnSameLine(range1.end, getStartPositionOfRange(
    range2,
    sourceFile,
    /*includeComments*/
    false
  ), sourceFile);
}
function getLinesBetweenRangeEndAndRangeStart(range1, range2, sourceFile, includeSecondRangeComments) {
  const range2Start = getStartPositionOfRange(range2, sourceFile, includeSecondRangeComments);
  return getLinesBetweenPositions(sourceFile, range1.end, range2Start);
}
function getLinesBetweenRangeEndPositions(range1, range2, sourceFile) {
  return getLinesBetweenPositions(sourceFile, range1.end, range2.end);
}
function isNodeArrayMultiLine(list, sourceFile) {
  return !positionsAreOnSameLine(list.pos, list.end, sourceFile);
}
function positionsAreOnSameLine(pos1, pos2, sourceFile) {
  return getLinesBetweenPositions(sourceFile, pos1, pos2) === 0;
}
function getStartPositionOfRange(range, sourceFile, includeComments) {
  return positionIsSynthesized(range.pos) ? -1 : skipTrivia(
    sourceFile.text,
    range.pos,
    /*stopAfterLineBreak*/
    false,
    includeComments
  );
}
function getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter(pos, stopPos, sourceFile, includeComments) {
  const startPos = skipTrivia(
    sourceFile.text,
    pos,
    /*stopAfterLineBreak*/
    false,
    includeComments
  );
  const prevPos = getPreviousNonWhitespacePosition(startPos, stopPos, sourceFile);
  return getLinesBetweenPositions(sourceFile, prevPos ?? stopPos, startPos);
}
function getLinesBetweenPositionAndNextNonWhitespaceCharacter(pos, stopPos, sourceFile, includeComments) {
  const nextPos = skipTrivia(
    sourceFile.text,
    pos,
    /*stopAfterLineBreak*/
    false,
    includeComments
  );
  return getLinesBetweenPositions(sourceFile, pos, Math.min(stopPos, nextPos));
}
function rangeContainsRange(r1, r2) {
  return startEndContainsRange(r1.pos, r1.end, r2);
}
function startEndContainsRange(start, end, range) {
  return start <= range.pos && end >= range.end;
}
function getPreviousNonWhitespacePosition(pos, stopPos = 0, sourceFile) {
  while (pos-- > stopPos) {
    if (!isWhiteSpaceLike(sourceFile.text.charCodeAt(pos))) {
      return pos;
    }
  }
}
function isDeclarationNameOfEnumOrNamespace(node) {
  const parseNode = getParseTreeNode(node);
  if (parseNode) {
    switch (parseNode.parent.kind) {
      case 266 /* EnumDeclaration */:
      case 267 /* ModuleDeclaration */:
        return parseNode === parseNode.parent.name;
    }
  }
  return false;
}
function getInitializedVariables(node) {
  return filter(node.declarations, isInitializedVariable);
}
function isInitializedVariable(node) {
  return isVariableDeclaration(node) && node.initializer !== void 0;
}
function isWatchSet(options) {
  return options.watch && hasProperty(options, "watch");
}
function closeFileWatcher(watcher) {
  watcher.close();
}
function getCheckFlags(symbol) {
  return symbol.flags & 33554432 /* Transient */ ? symbol.links.checkFlags : 0;
}
function getDeclarationModifierFlagsFromSymbol(s, isWrite = false) {
  if (s.valueDeclaration) {
    const declaration = isWrite && s.declarations && find(s.declarations, isSetAccessorDeclaration) || s.flags & 32768 /* GetAccessor */ && find(s.declarations, isGetAccessorDeclaration) || s.valueDeclaration;
    const flags = getCombinedModifierFlags(declaration);
    return s.parent && s.parent.flags & 32 /* Class */ ? flags : flags & ~7 /* AccessibilityModifier */;
  }
  if (getCheckFlags(s) & 6 /* Synthetic */) {
    const checkFlags = s.links.checkFlags;
    const accessModifier = checkFlags & 1024 /* ContainsPrivate */ ? 2 /* Private */ : checkFlags & 256 /* ContainsPublic */ ? 1 /* Public */ : 4 /* Protected */;
    const staticModifier = checkFlags & 2048 /* ContainsStatic */ ? 256 /* Static */ : 0;
    return accessModifier | staticModifier;
  }
  if (s.flags & 4194304 /* Prototype */) {
    return 1 /* Public */ | 256 /* Static */;
  }
  return 0;
}
function skipAlias(symbol, checker) {
  return symbol.flags & 2097152 /* Alias */ ? checker.getAliasedSymbol(symbol) : symbol;
}
function getCombinedLocalAndExportSymbolFlags(symbol) {
  return symbol.exportSymbol ? symbol.exportSymbol.flags | symbol.flags : symbol.flags;
}
function isWriteOnlyAccess(node) {
  return accessKind(node) === 1 /* Write */;
}
function isWriteAccess(node) {
  return accessKind(node) !== 0 /* Read */;
}
function accessKind(node) {
  const { parent: parent2 } = node;
  switch (parent2 == null ? void 0 : parent2.kind) {
    case 217 /* ParenthesizedExpression */:
      return accessKind(parent2);
    case 225 /* PostfixUnaryExpression */:
    case 224 /* PrefixUnaryExpression */:
      const { operator } = parent2;
      return operator === 46 /* PlusPlusToken */ || operator === 47 /* MinusMinusToken */ ? 2 /* ReadWrite */ : 0 /* Read */;
    case 226 /* BinaryExpression */:
      const { left, operatorToken } = parent2;
      return left === node && isAssignmentOperator(operatorToken.kind) ? operatorToken.kind === 64 /* EqualsToken */ ? 1 /* Write */ : 2 /* ReadWrite */ : 0 /* Read */;
    case 211 /* PropertyAccessExpression */:
      return parent2.name !== node ? 0 /* Read */ : accessKind(parent2);
    case 303 /* PropertyAssignment */: {
      const parentAccess = accessKind(parent2.parent);
      return node === parent2.name ? reverseAccessKind(parentAccess) : parentAccess;
    }
    case 304 /* ShorthandPropertyAssignment */:
      return node === parent2.objectAssignmentInitializer ? 0 /* Read */ : accessKind(parent2.parent);
    case 209 /* ArrayLiteralExpression */:
      return accessKind(parent2);
    case 249 /* ForInStatement */:
    case 250 /* ForOfStatement */:
      return node === parent2.initializer ? 1 /* Write */ : 0 /* Read */;
    default:
      return 0 /* Read */;
  }
}
function reverseAccessKind(a) {
  switch (a) {
    case 0 /* Read */:
      return 1 /* Write */;
    case 1 /* Write */:
      return 0 /* Read */;
    case 2 /* ReadWrite */:
      return 2 /* ReadWrite */;
    default:
      return Debug.assertNever(a);
  }
}
function compareDataObjects(dst, src) {
  if (!dst || !src || Object.keys(dst).length !== Object.keys(src).length) {
    return false;
  }
  for (const e in dst) {
    if (typeof dst[e] === "object") {
      if (!compareDataObjects(dst[e], src[e])) {
        return false;
      }
    } else if (typeof dst[e] !== "function") {
      if (dst[e] !== src[e]) {
        return false;
      }
    }
  }
  return true;
}
function clearMap(map2, onDeleteValue) {
  map2.forEach(onDeleteValue);
  map2.clear();
}
function mutateMapSkippingNewValues(map2, newMap, options) {
  const { onDeleteValue, onExistingValue } = options;
  map2.forEach((existingValue, key) => {
    var _a;
    if (!(newMap == null ? void 0 : newMap.has(key))) {
      map2.delete(key);
      onDeleteValue(existingValue, key);
    } else if (onExistingValue) {
      onExistingValue(existingValue, (_a = newMap.get) == null ? void 0 : _a.call(newMap, key), key);
    }
  });
}
function mutateMap(map2, newMap, options) {
  mutateMapSkippingNewValues(map2, newMap, options);
  const { createNewValue } = options;
  newMap == null ? void 0 : newMap.forEach((valueInNewMap, key) => {
    if (!map2.has(key)) {
      map2.set(key, createNewValue(key, valueInNewMap));
    }
  });
}
function isAbstractConstructorSymbol(symbol) {
  if (symbol.flags & 32 /* Class */) {
    const declaration = getClassLikeDeclarationOfSymbol(symbol);
    return !!declaration && hasSyntacticModifier(declaration, 64 /* Abstract */);
  }
  return false;
}
function getClassLikeDeclarationOfSymbol(symbol) {
  var _a;
  return (_a = symbol.declarations) == null ? void 0 : _a.find(isClassLike);
}
function getObjectFlags(type) {
  return type.flags & 3899393 /* ObjectFlagsType */ ? type.objectFlags : 0;
}
function isUMDExportSymbol(symbol) {
  return !!symbol && !!symbol.declarations && !!symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
}
function showModuleSpecifier({ moduleSpecifier }) {
  return isStringLiteral(moduleSpecifier) ? moduleSpecifier.text : getTextOfNode(moduleSpecifier);
}
function getLastChild(node) {
  let lastChild;
  forEachChild(node, (child) => {
    if (nodeIsPresent(child)) lastChild = child;
  }, (children) => {
    for (let i = children.length - 1; i >= 0; i--) {
      if (nodeIsPresent(children[i])) {
        lastChild = children[i];
        break;
      }
    }
  });
  return lastChild;
}
function addToSeen(seen, key) {
  if (seen.has(key)) {
    return false;
  }
  seen.add(key);
  return true;
}
function isObjectTypeDeclaration(node) {
  return isClassLike(node) || isInterfaceDeclaration(node) || isTypeLiteralNode(node);
}
function isTypeNodeKind(kind) {
  return kind >= 182 /* FirstTypeNode */ && kind <= 205 /* LastTypeNode */ || kind === 133 /* AnyKeyword */ || kind === 159 /* UnknownKeyword */ || kind === 150 /* NumberKeyword */ || kind === 163 /* BigIntKeyword */ || kind === 151 /* ObjectKeyword */ || kind === 136 /* BooleanKeyword */ || kind === 154 /* StringKeyword */ || kind === 155 /* SymbolKeyword */ || kind === 116 /* VoidKeyword */ || kind === 157 /* UndefinedKeyword */ || kind === 146 /* NeverKeyword */ || kind === 141 /* IntrinsicKeyword */ || kind === 233 /* ExpressionWithTypeArguments */ || kind === 312 /* JSDocAllType */ || kind === 313 /* JSDocUnknownType */ || kind === 314 /* JSDocNullableType */ || kind === 315 /* JSDocNonNullableType */ || kind === 316 /* JSDocOptionalType */ || kind === 317 /* JSDocFunctionType */ || kind === 318 /* JSDocVariadicType */;
}
function isAccessExpression(node) {
  return node.kind === 211 /* PropertyAccessExpression */ || node.kind === 212 /* ElementAccessExpression */;
}
function getNameOfAccessExpression(node) {
  if (node.kind === 211 /* PropertyAccessExpression */) {
    return node.name;
  }
  Debug.assert(node.kind === 212 /* ElementAccessExpression */);
  return node.argumentExpression;
}
function isNamedImportsOrExports(node) {
  return node.kind === 275 /* NamedImports */ || node.kind === 279 /* NamedExports */;
}
function getLeftmostAccessExpression(expr) {
  while (isAccessExpression(expr)) {
    expr = expr.expression;
  }
  return expr;
}
function forEachNameInAccessChainWalkingLeft(name, action) {
  if (isAccessExpression(name.parent) && isRightSideOfAccessExpression(name)) {
    return walkAccessExpression(name.parent);
  }
  function walkAccessExpression(access) {
    if (access.kind === 211 /* PropertyAccessExpression */) {
      const res = action(access.name);
      if (res !== void 0) {
        return res;
      }
    } else if (access.kind === 212 /* ElementAccessExpression */) {
      if (isIdentifier(access.argumentExpression) || isStringLiteralLike(access.argumentExpression)) {
        const res = action(access.argumentExpression);
        if (res !== void 0) {
          return res;
        }
      } else {
        return void 0;
      }
    }
    if (isAccessExpression(access.expression)) {
      return walkAccessExpression(access.expression);
    }
    if (isIdentifier(access.expression)) {
      return action(access.expression);
    }
    return void 0;
  }
}
function getLeftmostExpression(node, stopAtCallExpressions) {
  while (true) {
    switch (node.kind) {
      case 225 /* PostfixUnaryExpression */:
        node = node.operand;
        continue;
      case 226 /* BinaryExpression */:
        node = node.left;
        continue;
      case 227 /* ConditionalExpression */:
        node = node.condition;
        continue;
      case 215 /* TaggedTemplateExpression */:
        node = node.tag;
        continue;
      case 213 /* CallExpression */:
        if (stopAtCallExpressions) {
          return node;
        }
      // falls through
      case 234 /* AsExpression */:
      case 212 /* ElementAccessExpression */:
      case 211 /* PropertyAccessExpression */:
      case 235 /* NonNullExpression */:
      case 355 /* PartiallyEmittedExpression */:
      case 238 /* SatisfiesExpression */:
        node = node.expression;
        continue;
    }
    return node;
  }
}
function Symbol4(flags, name) {
  this.flags = flags;
  this.escapedName = name;
  this.declarations = void 0;
  this.valueDeclaration = void 0;
  this.id = 0;
  this.mergeId = 0;
  this.parent = void 0;
  this.members = void 0;
  this.exports = void 0;
  this.exportSymbol = void 0;
  this.constEnumOnlyModule = void 0;
  this.isReferenced = void 0;
  this.lastAssignmentPos = void 0;
  this.links = void 0;
}
function Type3(checker, flags) {
  this.flags = flags;
  if (Debug.isDebugging || tracing) {
    this.checker = checker;
  }
}
function Signature2(checker, flags) {
  this.flags = flags;
  if (Debug.isDebugging) {
    this.checker = checker;
  }
}
function Node4(kind, pos, end) {
  this.pos = pos;
  this.end = end;
  this.kind = kind;
  this.id = 0;
  this.flags = 0 /* None */;
  this.modifierFlagsCache = 0 /* None */;
  this.transformFlags = 0 /* None */;
  this.parent = void 0;
  this.original = void 0;
  this.emitNode = void 0;
}
function Token(kind, pos, end) {
  this.pos = pos;
  this.end = end;
  this.kind = kind;
  this.id = 0;
  this.flags = 0 /* None */;
  this.transformFlags = 0 /* None */;
  this.parent = void 0;
  this.emitNode = void 0;
}
function Identifier2(kind, pos, end) {
  this.pos = pos;
  this.end = end;
  this.kind = kind;
  this.id = 0;
  this.flags = 0 /* None */;
  this.transformFlags = 0 /* None */;
  this.parent = void 0;
  this.original = void 0;
  this.emitNode = void 0;
}
function SourceMapSource(fileName, text, skipTrivia2) {
  this.fileName = fileName;
  this.text = text;
  this.skipTrivia = skipTrivia2 || ((pos) => pos);
}
var objectAllocator = {
  getNodeConstructor: () => Node4,
  getTokenConstructor: () => Token,
  getIdentifierConstructor: () => Identifier2,
  getPrivateIdentifierConstructor: () => Node4,
  getSourceFileConstructor: () => Node4,
  getSymbolConstructor: () => Symbol4,
  getTypeConstructor: () => Type3,
  getSignatureConstructor: () => Signature2,
  getSourceMapSourceConstructor: () => SourceMapSource
};
var objectAllocatorPatchers = [];
function addObjectAllocatorPatcher(fn) {
  objectAllocatorPatchers.push(fn);
  fn(objectAllocator);
}
function setObjectAllocator(alloc) {
  Object.assign(objectAllocator, alloc);
  forEach(objectAllocatorPatchers, (fn) => fn(objectAllocator));
}
function formatStringFromArgs(text, args) {
  return text.replace(/\{(\d+)\}/g, (_match, index) => "" + Debug.checkDefined(args[+index]));
}
var localizedDiagnosticMessages;
function setLocalizedDiagnosticMessages(messages) {
  localizedDiagnosticMessages = messages;
}
function maybeSetLocalizedDiagnosticMessages(getMessages) {
  if (!localizedDiagnosticMessages && getMessages) {
    localizedDiagnosticMessages = getMessages();
  }
}
function getLocaleSpecificMessage(message) {
  return localizedDiagnosticMessages && localizedDiagnosticMessages[message.key] || message.message;
}
function createDetachedDiagnostic(fileName, sourceText, start, length2, message, ...args) {
  if (start + length2 > sourceText.length) {
    length2 = sourceText.length - start;
  }
  assertDiagnosticLocation(sourceText, start, length2);
  let text = getLocaleSpecificMessage(message);
  if (some(args)) {
    text = formatStringFromArgs(text, args);
  }
  return {
    file: void 0,
    start,
    length: length2,
    messageText: text,
    category: message.category,
    code: message.code,
    reportsUnnecessary: message.reportsUnnecessary,
    fileName
  };
}
function isDiagnosticWithDetachedLocation(diagnostic) {
  return diagnostic.file === void 0 && diagnostic.start !== void 0 && diagnostic.length !== void 0 && typeof diagnostic.fileName === "string";
}
function attachFileToDiagnostic(diagnostic, file) {
  const fileName = file.fileName || "";
  const length2 = file.text.length;
  Debug.assertEqual(diagnostic.fileName, fileName);
  Debug.assertLessThanOrEqual(diagnostic.start, length2);
  Debug.assertLessThanOrEqual(diagnostic.start + diagnostic.length, length2);
  const diagnosticWithLocation = {
    file,
    start: diagnostic.start,
    length: diagnostic.length,
    messageText: diagnostic.messageText,
    category: diagnostic.category,
    code: diagnostic.code,
    reportsUnnecessary: diagnostic.reportsUnnecessary
  };
  if (diagnostic.relatedInformation) {
    diagnosticWithLocation.relatedInformation = [];
    for (const related of diagnostic.relatedInformation) {
      if (isDiagnosticWithDetachedLocation(related) && related.fileName === fileName) {
        Debug.assertLessThanOrEqual(related.start, length2);
        Debug.assertLessThanOrEqual(related.start + related.length, length2);
        diagnosticWithLocation.relatedInformation.push(attachFileToDiagnostic(related, file));
      } else {
        diagnosticWithLocation.relatedInformation.push(related);
      }
    }
  }
  return diagnosticWithLocation;
}
function attachFileToDiagnostics(diagnostics, file) {
  const diagnosticsWithLocation = [];
  for (const diagnostic of diagnostics) {
    diagnosticsWithLocation.push(attachFileToDiagnostic(diagnostic, file));
  }
  return diagnosticsWithLocation;
}
function createFileDiagnostic(file, start, length2, message, ...args) {
  assertDiagnosticLocation(file.text, start, length2);
  let text = getLocaleSpecificMessage(message);
  if (some(args)) {
    text = formatStringFromArgs(text, args);
  }
  return {
    file,
    start,
    length: length2,
    messageText: text,
    category: message.category,
    code: message.code,
    reportsUnnecessary: message.reportsUnnecessary,
    reportsDeprecated: message.reportsDeprecated
  };
}
function formatMessage(message, ...args) {
  let text = getLocaleSpecificMessage(message);
  if (some(args)) {
    text = formatStringFromArgs(text, args);
  }
  return text;
}
function createCompilerDiagnostic(message, ...args) {
  let text = getLocaleSpecificMessage(message);
  if (some(args)) {
    text = formatStringFromArgs(text, args);
  }
  return {
    file: void 0,
    start: void 0,
    length: void 0,
    messageText: text,
    category: message.category,
    code: message.code,
    reportsUnnecessary: message.reportsUnnecessary,
    reportsDeprecated: message.reportsDeprecated
  };
}
function createCompilerDiagnosticFromMessageChain(chain, relatedInformation) {
  return {
    file: void 0,
    start: void 0,
    length: void 0,
    code: chain.code,
    category: chain.category,
    messageText: chain.next ? chain : chain.messageText,
    relatedInformation
  };
}
function chainDiagnosticMessages(details, message, ...args) {
  let text = getLocaleSpecificMessage(message);
  if (some(args)) {
    text = formatStringFromArgs(text, args);
  }
  return {
    messageText: text,
    category: message.category,
    code: message.code,
    next: details === void 0 || Array.isArray(details) ? details : [details]
  };
}
function concatenateDiagnosticMessageChains(headChain, tailChain) {
  let lastChain = headChain;
  while (lastChain.next) {
    lastChain = lastChain.next[0];
  }
  lastChain.next = [tailChain];
}
function getDiagnosticFilePath(diagnostic) {
  return diagnostic.file ? diagnostic.file.path : void 0;
}
function compareDiagnostics(d1, d2) {
  return compareDiagnosticsSkipRelatedInformation(d1, d2) || compareRelatedInformation(d1, d2) || 0 /* EqualTo */;
}
function compareDiagnosticsSkipRelatedInformation(d1, d2) {
  const code1 = getDiagnosticCode(d1);
  const code2 = getDiagnosticCode(d2);
  return compareStringsCaseSensitive(getDiagnosticFilePath(d1), getDiagnosticFilePath(d2)) || compareValues(d1.start, d2.start) || compareValues(d1.length, d2.length) || compareValues(code1, code2) || compareMessageText(d1, d2) || 0 /* EqualTo */;
}
function compareRelatedInformation(d1, d2) {
  if (!d1.relatedInformation && !d2.relatedInformation) {
    return 0 /* EqualTo */;
  }
  if (d1.relatedInformation && d2.relatedInformation) {
    return compareValues(d2.relatedInformation.length, d1.relatedInformation.length) || forEach(d1.relatedInformation, (d1i, index) => {
      const d2i = d2.relatedInformation[index];
      return compareDiagnostics(d1i, d2i);
    }) || 0 /* EqualTo */;
  }
  return d1.relatedInformation ? -1 /* LessThan */ : 1 /* GreaterThan */;
}
function compareMessageText(d1, d2) {
  let headMsg1 = getDiagnosticMessage(d1);
  let headMsg2 = getDiagnosticMessage(d2);
  if (typeof headMsg1 !== "string") {
    headMsg1 = headMsg1.messageText;
  }
  if (typeof headMsg2 !== "string") {
    headMsg2 = headMsg2.messageText;
  }
  const chain1 = typeof d1.messageText !== "string" ? d1.messageText.next : void 0;
  const chain2 = typeof d2.messageText !== "string" ? d2.messageText.next : void 0;
  let res = compareStringsCaseSensitive(headMsg1, headMsg2);
  if (res) {
    return res;
  }
  res = compareMessageChain(chain1, chain2);
  if (res) {
    return res;
  }
  if (d1.canonicalHead && !d2.canonicalHead) {
    return -1 /* LessThan */;
  }
  if (d2.canonicalHead && !d1.canonicalHead) {
    return 1 /* GreaterThan */;
  }
  return 0 /* EqualTo */;
}
function compareMessageChain(c1, c2) {
  if (c1 === void 0 && c2 === void 0) {
    return 0 /* EqualTo */;
  }
  if (c1 === void 0) {
    return 1 /* GreaterThan */;
  }
  if (c2 === void 0) {
    return -1 /* LessThan */;
  }
  return compareMessageChainSize(c1, c2) || compareMessageChainContent(c1, c2);
}
function compareMessageChainSize(c1, c2) {
  if (c1 === void 0 && c2 === void 0) {
    return 0 /* EqualTo */;
  }
  if (c1 === void 0) {
    return 1 /* GreaterThan */;
  }
  if (c2 === void 0) {
    return -1 /* LessThan */;
  }
  let res = compareValues(c2.length, c1.length);
  if (res) {
    return res;
  }
  for (let i = 0; i < c2.length; i++) {
    res = compareMessageChainSize(c1[i].next, c2[i].next);
    if (res) {
      return res;
    }
  }
  return 0 /* EqualTo */;
}
function compareMessageChainContent(c1, c2) {
  let res;
  for (let i = 0; i < c2.length; i++) {
    res = compareStringsCaseSensitive(c1[i].messageText, c2[i].messageText);
    if (res) {
      return res;
    }
    if (c1[i].next === void 0) {
      continue;
    }
    res = compareMessageChainContent(c1[i].next, c2[i].next);
    if (res) {
      return res;
    }
  }
  return 0 /* EqualTo */;
}
function diagnosticsEqualityComparer(d1, d2) {
  const code1 = getDiagnosticCode(d1);
  const code2 = getDiagnosticCode(d2);
  const msg1 = getDiagnosticMessage(d1);
  const msg2 = getDiagnosticMessage(d2);
  return compareStringsCaseSensitive(getDiagnosticFilePath(d1), getDiagnosticFilePath(d2)) === 0 /* EqualTo */ && compareValues(d1.start, d2.start) === 0 /* EqualTo */ && compareValues(d1.length, d2.length) === 0 /* EqualTo */ && compareValues(code1, code2) === 0 /* EqualTo */ && messageTextEqualityComparer(msg1, msg2);
}
function getDiagnosticCode(d) {
  var _a;
  return ((_a = d.canonicalHead) == null ? void 0 : _a.code) || d.code;
}
function getDiagnosticMessage(d) {
  var _a;
  return ((_a = d.canonicalHead) == null ? void 0 : _a.messageText) || d.messageText;
}
function messageTextEqualityComparer(m1, m2) {
  const t1 = typeof m1 === "string" ? m1 : m1.messageText;
  const t2 = typeof m2 === "string" ? m2 : m2.messageText;
  return compareStringsCaseSensitive(t1, t2) === 0 /* EqualTo */;
}
function getLanguageVariant(scriptKind) {
  return scriptKind === 4 /* TSX */ || scriptKind === 2 /* JSX */ || scriptKind === 1 /* JS */ || scriptKind === 6 /* JSON */ ? 1 /* JSX */ : 0 /* Standard */;
}
function walkTreeForJSXTags(node) {
  if (!(node.transformFlags & 2 /* ContainsJsx */)) return void 0;
  return isJsxOpeningLikeElement(node) || isJsxFragment(node) ? node : forEachChild(node, walkTreeForJSXTags);
}
function isFileModuleFromUsingJSXTag(file) {
  return !file.isDeclarationFile ? walkTreeForJSXTags(file) : void 0;
}
function isFileForcedToBeModuleByFormat(file, options) {
  return (getImpliedNodeFormatForEmitWorker(file, options) === 99 /* ESNext */ || fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */])) && !file.isDeclarationFile ? true : void 0;
}
function getSetExternalModuleIndicator(options) {
  switch (getEmitModuleDetectionKind(options)) {
    case 3 /* Force */:
      return (file) => {
        file.externalModuleIndicator = isFileProbablyExternalModule(file) || !file.isDeclarationFile || void 0;
      };
    case 1 /* Legacy */:
      return (file) => {
        file.externalModuleIndicator = isFileProbablyExternalModule(file);
      };
    case 2 /* Auto */:
      const checks = [isFileProbablyExternalModule];
      if (options.jsx === 4 /* ReactJSX */ || options.jsx === 5 /* ReactJSXDev */) {
        checks.push(isFileModuleFromUsingJSXTag);
      }
      checks.push(isFileForcedToBeModuleByFormat);
      const combined = or(...checks);
      const callback = (file) => void (file.externalModuleIndicator = combined(file, options));
      return callback;
  }
}
function importSyntaxAffectsModuleResolution(options) {
  const moduleResolution = getEmitModuleResolutionKind(options);
  return 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */ || getResolvePackageJsonExports(options) || getResolvePackageJsonImports(options);
}
function createComputedCompilerOptions(options) {
  return options;
}
var _computedOptions = createComputedCompilerOptions({
  allowImportingTsExtensions: {
    dependencies: ["rewriteRelativeImportExtensions"],
    computeValue: (compilerOptions) => {
      return !!(compilerOptions.allowImportingTsExtensions || compilerOptions.rewriteRelativeImportExtensions);
    }
  },
  target: {
    dependencies: ["module"],
    computeValue: (compilerOptions) => {
      const target = compilerOptions.target === 0 /* ES3 */ ? void 0 : compilerOptions.target;
      return target ?? (compilerOptions.module === 100 /* Node16 */ && 9 /* ES2022 */ || compilerOptions.module === 199 /* NodeNext */ && 99 /* ESNext */ || 1 /* ES5 */);
    }
  },
  module: {
    dependencies: ["target"],
    computeValue: (compilerOptions) => {
      return typeof compilerOptions.module === "number" ? compilerOptions.module : _computedOptions.target.computeValue(compilerOptions) >= 2 /* ES2015 */ ? 5 /* ES2015 */ : 1 /* CommonJS */;
    }
  },
  moduleResolution: {
    dependencies: ["module", "target"],
    computeValue: (compilerOptions) => {
      let moduleResolution = compilerOptions.moduleResolution;
      if (moduleResolution === void 0) {
        switch (_computedOptions.module.computeValue(compilerOptions)) {
          case 1 /* CommonJS */:
            moduleResolution = 2 /* Node10 */;
            break;
          case 100 /* Node16 */:
            moduleResolution = 3 /* Node16 */;
            break;
          case 199 /* NodeNext */:
            moduleResolution = 99 /* NodeNext */;
            break;
          case 200 /* Preserve */:
            moduleResolution = 100 /* Bundler */;
            break;
          default:
            moduleResolution = 1 /* Classic */;
            break;
        }
      }
      return moduleResolution;
    }
  },
  moduleDetection: {
    dependencies: ["module", "target"],
    computeValue: (compilerOptions) => {
      return compilerOptions.moduleDetection || (_computedOptions.module.computeValue(compilerOptions) === 100 /* Node16 */ || _computedOptions.module.computeValue(compilerOptions) === 199 /* NodeNext */ ? 3 /* Force */ : 2 /* Auto */);
    }
  },
  isolatedModules: {
    dependencies: ["verbatimModuleSyntax"],
    computeValue: (compilerOptions) => {
      return !!(compilerOptions.isolatedModules || compilerOptions.verbatimModuleSyntax);
    }
  },
  esModuleInterop: {
    dependencies: ["module", "target"],
    computeValue: (compilerOptions) => {
      if (compilerOptions.esModuleInterop !== void 0) {
        return compilerOptions.esModuleInterop;
      }
      switch (_computedOptions.module.computeValue(compilerOptions)) {
        case 100 /* Node16 */:
        case 199 /* NodeNext */:
        case 200 /* Preserve */:
          return true;
      }
      return false;
    }
  },
  allowSyntheticDefaultImports: {
    dependencies: ["module", "target", "moduleResolution"],
    computeValue: (compilerOptions) => {
      if (compilerOptions.allowSyntheticDefaultImports !== void 0) {
        return compilerOptions.allowSyntheticDefaultImports;
      }
      return _computedOptions.esModuleInterop.computeValue(compilerOptions) || _computedOptions.module.computeValue(compilerOptions) === 4 /* System */ || _computedOptions.moduleResolution.computeValue(compilerOptions) === 100 /* Bundler */;
    }
  },
  resolvePackageJsonExports: {
    dependencies: ["moduleResolution"],
    computeValue: (compilerOptions) => {
      const moduleResolution = _computedOptions.moduleResolution.computeValue(compilerOptions);
      if (!moduleResolutionSupportsPackageJsonExportsAndImports(moduleResolution)) {
        return false;
      }
      if (compilerOptions.resolvePackageJsonExports !== void 0) {
        return compilerOptions.resolvePackageJsonExports;
      }
      switch (moduleResolution) {
        case 3 /* Node16 */:
        case 99 /* NodeNext */:
        case 100 /* Bundler */:
          return true;
      }
      return false;
    }
  },
  resolvePackageJsonImports: {
    dependencies: ["moduleResolution", "resolvePackageJsonExports"],
    computeValue: (compilerOptions) => {
      const moduleResolution = _computedOptions.moduleResolution.computeValue(compilerOptions);
      if (!moduleResolutionSupportsPackageJsonExportsAndImports(moduleResolution)) {
        return false;
      }
      if (compilerOptions.resolvePackageJsonExports !== void 0) {
        return compilerOptions.resolvePackageJsonExports;
      }
      switch (moduleResolution) {
        case 3 /* Node16 */:
        case 99 /* NodeNext */:
        case 100 /* Bundler */:
          return true;
      }
      return false;
    }
  },
  resolveJsonModule: {
    dependencies: ["moduleResolution", "module", "target"],
    computeValue: (compilerOptions) => {
      if (compilerOptions.resolveJsonModule !== void 0) {
        return compilerOptions.resolveJsonModule;
      }
      return _computedOptions.moduleResolution.computeValue(compilerOptions) === 100 /* Bundler */;
    }
  },
  declaration: {
    dependencies: ["composite"],
    computeValue: (compilerOptions) => {
      return !!(compilerOptions.declaration || compilerOptions.composite);
    }
  },
  preserveConstEnums: {
    dependencies: ["isolatedModules", "verbatimModuleSyntax"],
    computeValue: (compilerOptions) => {
      return !!(compilerOptions.preserveConstEnums || _computedOptions.isolatedModules.computeValue(compilerOptions));
    }
  },
  incremental: {
    dependencies: ["composite"],
    computeValue: (compilerOptions) => {
      return !!(compilerOptions.incremental || compilerOptions.composite);
    }
  },
  declarationMap: {
    dependencies: ["declaration", "composite"],
    computeValue: (compilerOptions) => {
      return !!(compilerOptions.declarationMap && _computedOptions.declaration.computeValue(compilerOptions));
    }
  },
  allowJs: {
    dependencies: ["checkJs"],
    computeValue: (compilerOptions) => {
      return compilerOptions.allowJs === void 0 ? !!compilerOptions.checkJs : compilerOptions.allowJs;
    }
  },
  useDefineForClassFields: {
    dependencies: ["target", "module"],
    computeValue: (compilerOptions) => {
      return compilerOptions.useDefineForClassFields === void 0 ? _computedOptions.target.computeValue(compilerOptions) >= 9 /* ES2022 */ : compilerOptions.useDefineForClassFields;
    }
  },
  noImplicitAny: {
    dependencies: ["strict"],
    computeValue: (compilerOptions) => {
      return getStrictOptionValue(compilerOptions, "noImplicitAny");
    }
  },
  noImplicitThis: {
    dependencies: ["strict"],
    computeValue: (compilerOptions) => {
      return getStrictOptionValue(compilerOptions, "noImplicitThis");
    }
  },
  strictNullChecks: {
    dependencies: ["strict"],
    computeValue: (compilerOptions) => {
      return getStrictOptionValue(compilerOptions, "strictNullChecks");
    }
  },
  strictFunctionTypes: {
    dependencies: ["strict"],
    computeValue: (compilerOptions) => {
      return getStrictOptionValue(compilerOptions, "strictFunctionTypes");
    }
  },
  strictBindCallApply: {
    dependencies: ["strict"],
    computeValue: (compilerOptions) => {
      return getStrictOptionValue(compilerOptions, "strictBindCallApply");
    }
  },
  strictPropertyInitialization: {
    dependencies: ["strict"],
    computeValue: (compilerOptions) => {
      return getStrictOptionValue(compilerOptions, "strictPropertyInitialization");
    }
  },
  strictBuiltinIteratorReturn: {
    dependencies: ["strict"],
    computeValue: (compilerOptions) => {
      return getStrictOptionValue(compilerOptions, "strictBuiltinIteratorReturn");
    }
  },
  alwaysStrict: {
    dependencies: ["strict"],
    computeValue: (compilerOptions) => {
      return getStrictOptionValue(compilerOptions, "alwaysStrict");
    }
  },
  useUnknownInCatchVariables: {
    dependencies: ["strict"],
    computeValue: (compilerOptions) => {
      return getStrictOptionValue(compilerOptions, "useUnknownInCatchVariables");
    }
  }
});
var computedOptions = _computedOptions;
var getAllowImportingTsExtensions = _computedOptions.allowImportingTsExtensions.computeValue;
var getEmitScriptTarget = _computedOptions.target.computeValue;
var getEmitModuleKind = _computedOptions.module.computeValue;
var getEmitModuleResolutionKind = _computedOptions.moduleResolution.computeValue;
var getEmitModuleDetectionKind = _computedOptions.moduleDetection.computeValue;
var getIsolatedModules = _computedOptions.isolatedModules.computeValue;
var getESModuleInterop = _computedOptions.esModuleInterop.computeValue;
var getAllowSyntheticDefaultImports = _computedOptions.allowSyntheticDefaultImports.computeValue;
var getResolvePackageJsonExports = _computedOptions.resolvePackageJsonExports.computeValue;
var getResolvePackageJsonImports = _computedOptions.resolvePackageJsonImports.computeValue;
var getResolveJsonModule = _computedOptions.resolveJsonModule.computeValue;
var getEmitDeclarations = _computedOptions.declaration.computeValue;
var shouldPreserveConstEnums = _computedOptions.preserveConstEnums.computeValue;
var isIncrementalCompilation = _computedOptions.incremental.computeValue;
var getAreDeclarationMapsEnabled = _computedOptions.declarationMap.computeValue;
var getAllowJSCompilerOption = _computedOptions.allowJs.computeValue;
var getUseDefineForClassFields = _computedOptions.useDefineForClassFields.computeValue;
function emitModuleKindIsNonNodeESM(moduleKind) {
  return moduleKind >= 5 /* ES2015 */ && moduleKind <= 99 /* ESNext */;
}
function hasJsonModuleEmitEnabled(options) {
  switch (getEmitModuleKind(options)) {
    case 0 /* None */:
    case 4 /* System */:
    case 3 /* UMD */:
      return false;
  }
  return true;
}
function unreachableCodeIsError(options) {
  return options.allowUnreachableCode === false;
}
function unusedLabelIsError(options) {
  return options.allowUnusedLabels === false;
}
function moduleResolutionSupportsPackageJsonExportsAndImports(moduleResolution) {
  return moduleResolution >= 3 /* Node16 */ && moduleResolution <= 99 /* NodeNext */ || moduleResolution === 100 /* Bundler */;
}
function getStrictOptionValue(compilerOptions, flag) {
  return compilerOptions[flag] === void 0 ? !!compilerOptions.strict : !!compilerOptions[flag];
}
function getNameOfScriptTarget(scriptTarget) {
  return forEachEntry(targetOptionDeclaration.type, (value, key) => value === scriptTarget ? key : void 0);
}
function getEmitStandardClassFields(compilerOptions) {
  return compilerOptions.useDefineForClassFields !== false && getEmitScriptTarget(compilerOptions) >= 9 /* ES2022 */;
}
function compilerOptionsAffectSemanticDiagnostics(newOptions, oldOptions) {
  return optionsHaveChanges(oldOptions, newOptions, semanticDiagnosticsOptionDeclarations);
}
function compilerOptionsAffectEmit(newOptions, oldOptions) {
  return optionsHaveChanges(oldOptions, newOptions, affectsEmitOptionDeclarations);
}
function compilerOptionsAffectDeclarationPath(newOptions, oldOptions) {
  return optionsHaveChanges(oldOptions, newOptions, affectsDeclarationPathOptionDeclarations);
}
function getCompilerOptionValue(options, option) {
  return option.strictFlag ? getStrictOptionValue(options, option.name) : option.allowJsFlag ? getAllowJSCompilerOption(options) : options[option.name];
}
function getJSXTransformEnabled(options) {
  const jsx = options.jsx;
  return jsx === 2 /* React */ || jsx === 4 /* ReactJSX */ || jsx === 5 /* ReactJSXDev */;
}
function getJSXImplicitImportBase(compilerOptions, file) {
  const jsxImportSourcePragmas = file == null ? void 0 : file.pragmas.get("jsximportsource");
  const jsxImportSourcePragma = isArray(jsxImportSourcePragmas) ? jsxImportSourcePragmas[jsxImportSourcePragmas.length - 1] : jsxImportSourcePragmas;
  const jsxRuntimePragmas = file == null ? void 0 : file.pragmas.get("jsxruntime");
  const jsxRuntimePragma = isArray(jsxRuntimePragmas) ? jsxRuntimePragmas[jsxRuntimePragmas.length - 1] : jsxRuntimePragmas;
  if ((jsxRuntimePragma == null ? void 0 : jsxRuntimePragma.arguments.factory) === "classic") {
    return void 0;
  }
  return compilerOptions.jsx === 4 /* ReactJSX */ || compilerOptions.jsx === 5 /* ReactJSXDev */ || compilerOptions.jsxImportSource || jsxImportSourcePragma || (jsxRuntimePragma == null ? void 0 : jsxRuntimePragma.arguments.factory) === "automatic" ? (jsxImportSourcePragma == null ? void 0 : jsxImportSourcePragma.arguments.factory) || compilerOptions.jsxImportSource || "react" : void 0;
}
function getJSXRuntimeImport(base, options) {
  return base ? `${base}/${options.jsx === 5 /* ReactJSXDev */ ? "jsx-dev-runtime" : "jsx-runtime"}` : void 0;
}
function hasZeroOrOneAsteriskCharacter(str) {
  let seenAsterisk = false;
  for (let i = 0; i < str.length; i++) {
    if (str.charCodeAt(i) === 42 /* asterisk */) {
      if (!seenAsterisk) {
        seenAsterisk = true;
      } else {
        return false;
      }
    }
  }
  return true;
}
function createSymlinkCache(cwd, getCanonicalFileName) {
  let symlinkedDirectories;
  let symlinkedDirectoriesByRealpath;
  let symlinkedFiles;
  let hasProcessedResolutions = false;
  return {
    getSymlinkedFiles: () => symlinkedFiles,
    getSymlinkedDirectories: () => symlinkedDirectories,
    getSymlinkedDirectoriesByRealpath: () => symlinkedDirectoriesByRealpath,
    setSymlinkedFile: (path, real) => (symlinkedFiles || (symlinkedFiles = /* @__PURE__ */ new Map())).set(path, real),
    setSymlinkedDirectory: (symlink, real) => {
      let symlinkPath = toPath(symlink, cwd, getCanonicalFileName);
      if (!containsIgnoredPath(symlinkPath)) {
        symlinkPath = ensureTrailingDirectorySeparator(symlinkPath);
        if (real !== false && !(symlinkedDirectories == null ? void 0 : symlinkedDirectories.has(symlinkPath))) {
          (symlinkedDirectoriesByRealpath || (symlinkedDirectoriesByRealpath = createMultiMap())).add(real.realPath, symlink);
        }
        (symlinkedDirectories || (symlinkedDirectories = /* @__PURE__ */ new Map())).set(symlinkPath, real);
      }
    },
    setSymlinksFromResolutions(forEachResolvedModule, forEachResolvedTypeReferenceDirective, typeReferenceDirectives) {
      Debug.assert(!hasProcessedResolutions);
      hasProcessedResolutions = true;
      forEachResolvedModule((resolution) => processResolution(this, resolution.resolvedModule));
      forEachResolvedTypeReferenceDirective((resolution) => processResolution(this, resolution.resolvedTypeReferenceDirective));
      typeReferenceDirectives.forEach((resolution) => processResolution(this, resolution.resolvedTypeReferenceDirective));
    },
    hasProcessedResolutions: () => hasProcessedResolutions,
    setSymlinksFromResolution(resolution) {
      processResolution(this, resolution);
    },
    hasAnySymlinks
  };
  function hasAnySymlinks() {
    return !!(symlinkedFiles == null ? void 0 : symlinkedFiles.size) || !!symlinkedDirectories && !!forEachEntry(symlinkedDirectories, (value) => !!value);
  }
  function processResolution(cache, resolution) {
    if (!resolution || !resolution.originalPath || !resolution.resolvedFileName) return;
    const { resolvedFileName, originalPath } = resolution;
    cache.setSymlinkedFile(toPath(originalPath, cwd, getCanonicalFileName), resolvedFileName);
    const [commonResolved, commonOriginal] = guessDirectorySymlink(resolvedFileName, originalPath, cwd, getCanonicalFileName) || emptyArray;
    if (commonResolved && commonOriginal) {
      cache.setSymlinkedDirectory(
        commonOriginal,
        {
          real: ensureTrailingDirectorySeparator(commonResolved),
          realPath: ensureTrailingDirectorySeparator(toPath(commonResolved, cwd, getCanonicalFileName))
        }
      );
    }
  }
}
function guessDirectorySymlink(a, b, cwd, getCanonicalFileName) {
  const aParts = getPathComponents(getNormalizedAbsolutePath(a, cwd));
  const bParts = getPathComponents(getNormalizedAbsolutePath(b, cwd));
  let isDirectory = false;
  while (aParts.length >= 2 && bParts.length >= 2 && !isNodeModulesOrScopedPackageDirectory(aParts[aParts.length - 2], getCanonicalFileName) && !isNodeModulesOrScopedPackageDirectory(bParts[bParts.length - 2], getCanonicalFileName) && getCanonicalFileName(aParts[aParts.length - 1]) === getCanonicalFileName(bParts[bParts.length - 1])) {
    aParts.pop();
    bParts.pop();
    isDirectory = true;
  }
  return isDirectory ? [getPathFromPathComponents(aParts), getPathFromPathComponents(bParts)] : void 0;
}
function isNodeModulesOrScopedPackageDirectory(s, getCanonicalFileName) {
  return s !== void 0 && (getCanonicalFileName(s) === "node_modules" || startsWith(s, "@"));
}
function stripLeadingDirectorySeparator(s) {
  return isAnyDirectorySeparator(s.charCodeAt(0)) ? s.slice(1) : void 0;
}
function tryRemoveDirectoryPrefix(path, dirPath, getCanonicalFileName) {
  const withoutPrefix = tryRemovePrefix(path, dirPath, getCanonicalFileName);
  return withoutPrefix === void 0 ? void 0 : stripLeadingDirectorySeparator(withoutPrefix);
}
var reservedCharacterPattern = /[^\w\s/]/g;
function regExpEscape(text) {
  return text.replace(reservedCharacterPattern, escapeRegExpCharacter);
}
function escapeRegExpCharacter(match) {
  return "\\" + match;
}
var wildcardCharCodes = [42 /* asterisk */, 63 /* question */];
var commonPackageFolders = ["node_modules", "bower_components", "jspm_packages"];
var implicitExcludePathRegexPattern = `(?!(${commonPackageFolders.join("|")})(/|$))`;
var filesMatcher = {
  /**
   * Matches any single directory segment unless it is the last segment and a .min.js file
   * Breakdown:
   *  [^./]                   # matches everything up to the first . character (excluding directory separators)
   *  (\\.(?!min\\.js$))?     # matches . characters but not if they are part of the .min.js file extension
   */
  singleAsteriskRegexFragment: "([^./]|(\\.(?!min\\.js$))?)*",
  /**
   * Regex for the ** wildcard. Matches any number of subdirectories. When used for including
   * files or directories, does not match subdirectories that start with a . character
   */
  doubleAsteriskRegexFragment: `(/${implicitExcludePathRegexPattern}[^/.][^/]*)*?`,
  replaceWildcardCharacter: (match) => replaceWildcardCharacter(match, filesMatcher.singleAsteriskRegexFragment)
};
var directoriesMatcher = {
  singleAsteriskRegexFragment: "[^/]*",
  /**
   * Regex for the ** wildcard. Matches any number of subdirectories. When used for including
   * files or directories, does not match subdirectories that start with a . character
   */
  doubleAsteriskRegexFragment: `(/${implicitExcludePathRegexPattern}[^/.][^/]*)*?`,
  replaceWildcardCharacter: (match) => replaceWildcardCharacter(match, directoriesMatcher.singleAsteriskRegexFragment)
};
var excludeMatcher = {
  singleAsteriskRegexFragment: "[^/]*",
  doubleAsteriskRegexFragment: "(/.+?)?",
  replaceWildcardCharacter: (match) => replaceWildcardCharacter(match, excludeMatcher.singleAsteriskRegexFragment)
};
var wildcardMatchers = {
  files: filesMatcher,
  directories: directoriesMatcher,
  exclude: excludeMatcher
};
function getRegularExpressionForWildcard(specs, basePath, usage) {
  const patterns = getRegularExpressionsForWildcards(specs, basePath, usage);
  if (!patterns || !patterns.length) {
    return void 0;
  }
  const pattern = patterns.map((pattern2) => `(${pattern2})`).join("|");
  const terminator = usage === "exclude" ? "($|/)" : "$";
  return `^(${pattern})${terminator}`;
}
function getRegularExpressionsForWildcards(specs, basePath, usage) {
  if (specs === void 0 || specs.length === 0) {
    return void 0;
  }
  return flatMap(specs, (spec) => spec && getSubPatternFromSpec(spec, basePath, usage, wildcardMatchers[usage]));
}
function isImplicitGlob(lastPathComponent) {
  return !/[.*?]/.test(lastPathComponent);
}
function getPatternFromSpec(spec, basePath, usage) {
  const pattern = spec && getSubPatternFromSpec(spec, basePath, usage, wildcardMatchers[usage]);
  return pattern && `^(${pattern})${usage === "exclude" ? "($|/)" : "$"}`;
}
function getSubPatternFromSpec(spec, basePath, usage, { singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter: replaceWildcardCharacter2 } = wildcardMatchers[usage]) {
  let subpattern = "";
  let hasWrittenComponent = false;
  const components = getNormalizedPathComponents(spec, basePath);
  const lastComponent = last(components);
  if (usage !== "exclude" && lastComponent === "**") {
    return void 0;
  }
  components[0] = removeTrailingDirectorySeparator(components[0]);
  if (isImplicitGlob(lastComponent)) {
    components.push("**", "*");
  }
  let optionalCount = 0;
  for (let component of components) {
    if (component === "**") {
      subpattern += doubleAsteriskRegexFragment;
    } else {
      if (usage === "directories") {
        subpattern += "(";
        optionalCount++;
      }
      if (hasWrittenComponent) {
        subpattern += directorySeparator;
      }
      if (usage !== "exclude") {
        let componentPattern = "";
        if (component.charCodeAt(0) === 42 /* asterisk */) {
          componentPattern += "([^./]" + singleAsteriskRegexFragment + ")?";
          component = component.substr(1);
        } else if (component.charCodeAt(0) === 63 /* question */) {
          componentPattern += "[^./]";
          component = component.substr(1);
        }
        componentPattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter2);
        if (componentPattern !== component) {
          subpattern += implicitExcludePathRegexPattern;
        }
        subpattern += componentPattern;
      } else {
        subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter2);
      }
    }
    hasWrittenComponent = true;
  }
  while (optionalCount > 0) {
    subpattern += ")?";
    optionalCount--;
  }
  return subpattern;
}
function replaceWildcardCharacter(match, singleAsteriskRegexFragment) {
  return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match;
}
function getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames2, currentDirectory) {
  path = normalizePath(path);
  currentDirectory = normalizePath(currentDirectory);
  const absolutePath = combinePaths(currentDirectory, path);
  return {
    includeFilePatterns: map(getRegularExpressionsForWildcards(includes, absolutePath, "files"), (pattern) => `^${pattern}$`),
    includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"),
    includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"),
    excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"),
    basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames2)
  };
}
function getRegexFromPattern(pattern, useCaseSensitiveFileNames2) {
  return new RegExp(pattern, useCaseSensitiveFileNames2 ? "" : "i");
}
function matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames2, currentDirectory, depth, getFileSystemEntries, realpath) {
  path = normalizePath(path);
  currentDirectory = normalizePath(currentDirectory);
  const patterns = getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames2, currentDirectory);
  const includeFileRegexes = patterns.includeFilePatterns && patterns.includeFilePatterns.map((pattern) => getRegexFromPattern(pattern, useCaseSensitiveFileNames2));
  const includeDirectoryRegex = patterns.includeDirectoryPattern && getRegexFromPattern(patterns.includeDirectoryPattern, useCaseSensitiveFileNames2);
  const excludeRegex = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, useCaseSensitiveFileNames2);
  const results = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]];
  const visited = /* @__PURE__ */ new Map();
  const toCanonical = createGetCanonicalFileName(useCaseSensitiveFileNames2);
  for (const basePath of patterns.basePaths) {
    visitDirectory(basePath, combinePaths(currentDirectory, basePath), depth);
  }
  return flatten(results);
  function visitDirectory(path2, absolutePath, depth2) {
    const canonicalPath = toCanonical(realpath(absolutePath));
    if (visited.has(canonicalPath)) return;
    visited.set(canonicalPath, true);
    const { files, directories } = getFileSystemEntries(path2);
    for (const current of toSorted(files, compareStringsCaseSensitive)) {
      const name = combinePaths(path2, current);
      const absoluteName = combinePaths(absolutePath, current);
      if (extensions && !fileExtensionIsOneOf(name, extensions)) continue;
      if (excludeRegex && excludeRegex.test(absoluteName)) continue;
      if (!includeFileRegexes) {
        results[0].push(name);
      } else {
        const includeIndex = findIndex(includeFileRegexes, (re) => re.test(absoluteName));
        if (includeIndex !== -1) {
          results[includeIndex].push(name);
        }
      }
    }
    if (depth2 !== void 0) {
      depth2--;
      if (depth2 === 0) {
        return;
      }
    }
    for (const current of toSorted(directories, compareStringsCaseSensitive)) {
      const name = combinePaths(path2, current);
      const absoluteName = combinePaths(absolutePath, current);
      if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) && (!excludeRegex || !excludeRegex.test(absoluteName))) {
        visitDirectory(name, absoluteName, depth2);
      }
    }
  }
}
function getBasePaths(path, includes, useCaseSensitiveFileNames2) {
  const basePaths = [path];
  if (includes) {
    const includeBasePaths = [];
    for (const include of includes) {
      const absolute = isRootedDiskPath(include) ? include : normalizePath(combinePaths(path, include));
      includeBasePaths.push(getIncludeBasePath(absolute));
    }
    includeBasePaths.sort(getStringComparer(!useCaseSensitiveFileNames2));
    for (const includeBasePath of includeBasePaths) {
      if (every(basePaths, (basePath) => !containsPath(basePath, includeBasePath, path, !useCaseSensitiveFileNames2))) {
        basePaths.push(includeBasePath);
      }
    }
  }
  return basePaths;
}
function getIncludeBasePath(absolute) {
  const wildcardOffset = indexOfAnyCharCode(absolute, wildcardCharCodes);
  if (wildcardOffset < 0) {
    return !hasExtension(absolute) ? absolute : removeTrailingDirectorySeparator(getDirectoryPath(absolute));
  }
  return absolute.substring(0, absolute.lastIndexOf(directorySeparator, wildcardOffset));
}
function ensureScriptKind(fileName, scriptKind) {
  return scriptKind || getScriptKindFromFileName(fileName) || 3 /* TS */;
}
function getScriptKindFromFileName(fileName) {
  const ext = fileName.substr(fileName.lastIndexOf("."));
  switch (ext.toLowerCase()) {
    case ".js" /* Js */:
    case ".cjs" /* Cjs */:
    case ".mjs" /* Mjs */:
      return 1 /* JS */;
    case ".jsx" /* Jsx */:
      return 2 /* JSX */;
    case ".ts" /* Ts */:
    case ".cts" /* Cts */:
    case ".mts" /* Mts */:
      return 3 /* TS */;
    case ".tsx" /* Tsx */:
      return 4 /* TSX */;
    case ".json" /* Json */:
      return 6 /* JSON */;
    default:
      return 0 /* Unknown */;
  }
}
var supportedTSExtensions = [[".ts" /* Ts */, ".tsx" /* Tsx */, ".d.ts" /* Dts */], [".cts" /* Cts */, ".d.cts" /* Dcts */], [".mts" /* Mts */, ".d.mts" /* Dmts */]];
var supportedTSExtensionsFlat = flatten(supportedTSExtensions);
var supportedTSExtensionsWithJson = [...supportedTSExtensions, [".json" /* Json */]];
var supportedTSExtensionsForExtractExtension = [".d.ts" /* Dts */, ".d.cts" /* Dcts */, ".d.mts" /* Dmts */, ".cts" /* Cts */, ".mts" /* Mts */, ".ts" /* Ts */, ".tsx" /* Tsx */];
var supportedJSExtensions = [[".js" /* Js */, ".jsx" /* Jsx */], [".mjs" /* Mjs */], [".cjs" /* Cjs */]];
var supportedJSExtensionsFlat = flatten(supportedJSExtensions);
var allSupportedExtensions = [[".ts" /* Ts */, ".tsx" /* Tsx */, ".d.ts" /* Dts */, ".js" /* Js */, ".jsx" /* Jsx */], [".cts" /* Cts */, ".d.cts" /* Dcts */, ".cjs" /* Cjs */], [".mts" /* Mts */, ".d.mts" /* Dmts */, ".mjs" /* Mjs */]];
var allSupportedExtensionsWithJson = [...allSupportedExtensions, [".json" /* Json */]];
var supportedDeclarationExtensions = [".d.ts" /* Dts */, ".d.cts" /* Dcts */, ".d.mts" /* Dmts */];
var supportedTSImplementationExtensions = [".ts" /* Ts */, ".cts" /* Cts */, ".mts" /* Mts */, ".tsx" /* Tsx */];
var extensionsNotSupportingExtensionlessResolution = [".mts" /* Mts */, ".d.mts" /* Dmts */, ".mjs" /* Mjs */, ".cts" /* Cts */, ".d.cts" /* Dcts */, ".cjs" /* Cjs */];
function getSupportedExtensions(options, extraFileExtensions) {
  const needJsExtensions = options && getAllowJSCompilerOption(options);
  if (!extraFileExtensions || extraFileExtensions.length === 0) {
    return needJsExtensions ? allSupportedExtensions : supportedTSExtensions;
  }
  const builtins = needJsExtensions ? allSupportedExtensions : supportedTSExtensions;
  const flatBuiltins = flatten(builtins);
  const extensions = [
    ...builtins,
    ...mapDefined(extraFileExtensions, (x) => x.scriptKind === 7 /* Deferred */ || needJsExtensions && isJSLike(x.scriptKind) && !flatBuiltins.includes(x.extension) ? [x.extension] : void 0)
  ];
  return extensions;
}
function getSupportedExtensionsWithJsonIfResolveJsonModule(options, supportedExtensions) {
  if (!options || !getResolveJsonModule(options)) return supportedExtensions;
  if (supportedExtensions === allSupportedExtensions) return allSupportedExtensionsWithJson;
  if (supportedExtensions === supportedTSExtensions) return supportedTSExtensionsWithJson;
  return [...supportedExtensions, [".json" /* Json */]];
}
function isJSLike(scriptKind) {
  return scriptKind === 1 /* JS */ || scriptKind === 2 /* JSX */;
}
function hasJSFileExtension(fileName) {
  return some(supportedJSExtensionsFlat, (extension) => fileExtensionIs(fileName, extension));
}
function hasTSFileExtension(fileName) {
  return some(supportedTSExtensionsFlat, (extension) => fileExtensionIs(fileName, extension));
}
function hasImplementationTSFileExtension(fileName) {
  return some(supportedTSImplementationExtensions, (extension) => fileExtensionIs(fileName, extension)) && !isDeclarationFileName(fileName);
}
var ModuleSpecifierEnding = /* @__PURE__ */ ((ModuleSpecifierEnding2) => {
  ModuleSpecifierEnding2[ModuleSpecifierEnding2["Minimal"] = 0] = "Minimal";
  ModuleSpecifierEnding2[ModuleSpecifierEnding2["Index"] = 1] = "Index";
  ModuleSpecifierEnding2[ModuleSpecifierEnding2["JsExtension"] = 2] = "JsExtension";
  ModuleSpecifierEnding2[ModuleSpecifierEnding2["TsExtension"] = 3] = "TsExtension";
  return ModuleSpecifierEnding2;
})(ModuleSpecifierEnding || {});
function usesExtensionsOnImports({ imports }, hasExtension2 = or(hasJSFileExtension, hasTSFileExtension)) {
  return firstDefined(imports, ({ text }) => pathIsRelative(text) && !fileExtensionIsOneOf(text, extensionsNotSupportingExtensionlessResolution) ? hasExtension2(text) : void 0) || false;
}
function getModuleSpecifierEndingPreference(preference, resolutionMode, compilerOptions, sourceFile) {
  const moduleResolution = getEmitModuleResolutionKind(compilerOptions);
  const moduleResolutionIsNodeNext = 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */;
  if (preference === "js" || resolutionMode === 99 /* ESNext */ && moduleResolutionIsNodeNext) {
    if (!shouldAllowImportingTsExtension(compilerOptions)) {
      return 2 /* JsExtension */;
    }
    return inferPreference() !== 2 /* JsExtension */ ? 3 /* TsExtension */ : 2 /* JsExtension */;
  }
  if (preference === "minimal") {
    return 0 /* Minimal */;
  }
  if (preference === "index") {
    return 1 /* Index */;
  }
  if (!shouldAllowImportingTsExtension(compilerOptions)) {
    return sourceFile && usesExtensionsOnImports(sourceFile) ? 2 /* JsExtension */ : 0 /* Minimal */;
  }
  return inferPreference();
  function inferPreference() {
    let usesJsExtensions = false;
    const specifiers = (sourceFile == null ? void 0 : sourceFile.imports.length) ? sourceFile.imports : sourceFile && isSourceFileJS(sourceFile) ? getRequiresAtTopOfFile(sourceFile).map((r) => r.arguments[0]) : emptyArray;
    for (const specifier of specifiers) {
      if (pathIsRelative(specifier.text)) {
        if (moduleResolutionIsNodeNext && resolutionMode === 1 /* CommonJS */ && getModeForUsageLocation(sourceFile, specifier, compilerOptions) === 99 /* ESNext */) {
          continue;
        }
        if (fileExtensionIsOneOf(specifier.text, extensionsNotSupportingExtensionlessResolution)) {
          continue;
        }
        if (hasTSFileExtension(specifier.text)) {
          return 3 /* TsExtension */;
        }
        if (hasJSFileExtension(specifier.text)) {
          usesJsExtensions = true;
        }
      }
    }
    return usesJsExtensions ? 2 /* JsExtension */ : 0 /* Minimal */;
  }
}
function getRequiresAtTopOfFile(sourceFile) {
  let nonRequireStatementCount = 0;
  let requires;
  for (const statement of sourceFile.statements) {
    if (nonRequireStatementCount > 3) {
      break;
    }
    if (isRequireVariableStatement(statement)) {
      requires = concatenate(requires, statement.declarationList.declarations.map((d) => d.initializer));
    } else if (isExpressionStatement(statement) && isRequireCall(
      statement.expression,
      /*requireStringLiteralLikeArgument*/
      true
    )) {
      requires = append(requires, statement.expression);
    } else {
      nonRequireStatementCount++;
    }
  }
  return requires || emptyArray;
}
function isSupportedSourceFileName(fileName, compilerOptions, extraFileExtensions) {
  if (!fileName) return false;
  const supportedExtensions = getSupportedExtensions(compilerOptions, extraFileExtensions);
  for (const extension of flatten(getSupportedExtensionsWithJsonIfResolveJsonModule(compilerOptions, supportedExtensions))) {
    if (fileExtensionIs(fileName, extension)) {
      return true;
    }
  }
  return false;
}
function numberOfDirectorySeparators(str) {
  const match = str.match(/\//g);
  return match ? match.length : 0;
}
function compareNumberOfDirectorySeparators(path1, path2) {
  return compareValues(
    numberOfDirectorySeparators(path1),
    numberOfDirectorySeparators(path2)
  );
}
var extensionsToRemove = [".d.ts" /* Dts */, ".d.mts" /* Dmts */, ".d.cts" /* Dcts */, ".mjs" /* Mjs */, ".mts" /* Mts */, ".cjs" /* Cjs */, ".cts" /* Cts */, ".ts" /* Ts */, ".js" /* Js */, ".tsx" /* Tsx */, ".jsx" /* Jsx */, ".json" /* Json */];
function removeFileExtension(path) {
  for (const ext of extensionsToRemove) {
    const extensionless = tryRemoveExtension(path, ext);
    if (extensionless !== void 0) {
      return extensionless;
    }
  }
  return path;
}
function tryRemoveExtension(path, extension) {
  return fileExtensionIs(path, extension) ? removeExtension(path, extension) : void 0;
}
function removeExtension(path, extension) {
  return path.substring(0, path.length - extension.length);
}
function changeExtension(path, newExtension) {
  return changeAnyExtension(
    path,
    newExtension,
    extensionsToRemove,
    /*ignoreCase*/
    false
  );
}
function tryParsePattern(pattern) {
  const indexOfStar = pattern.indexOf("*");
  if (indexOfStar === -1) {
    return pattern;
  }
  return pattern.indexOf("*", indexOfStar + 1) !== -1 ? void 0 : {
    prefix: pattern.substr(0, indexOfStar),
    suffix: pattern.substr(indexOfStar + 1)
  };
}
var parsedPatternsCache = /* @__PURE__ */ new WeakMap();
function tryParsePatterns(paths) {
  let result = parsedPatternsCache.get(paths);
  if (result !== void 0) {
    return result;
  }
  let matchableStringSet;
  let patterns;
  const pathList = getOwnKeys(paths);
  for (const path of pathList) {
    const patternOrStr = tryParsePattern(path);
    if (patternOrStr === void 0) {
      continue;
    } else if (typeof patternOrStr === "string") {
      (matchableStringSet ?? (matchableStringSet = /* @__PURE__ */ new Set())).add(patternOrStr);
    } else {
      (patterns ?? (patterns = [])).push(patternOrStr);
    }
  }
  parsedPatternsCache.set(
    paths,
    result = {
      matchableStringSet,
      patterns
    }
  );
  return result;
}
function positionIsSynthesized(pos) {
  return !(pos >= 0);
}
function extensionIsTS(ext) {
  return ext === ".ts" /* Ts */ || ext === ".tsx" /* Tsx */ || ext === ".d.ts" /* Dts */ || ext === ".cts" /* Cts */ || ext === ".mts" /* Mts */ || ext === ".d.mts" /* Dmts */ || ext === ".d.cts" /* Dcts */ || startsWith(ext, ".d.") && endsWith(ext, ".ts");
}
function resolutionExtensionIsTSOrJson(ext) {
  return extensionIsTS(ext) || ext === ".json" /* Json */;
}
function extensionFromPath(path) {
  const ext = tryGetExtensionFromPath2(path);
  return ext !== void 0 ? ext : Debug.fail(`File ${path} has unknown extension.`);
}
function isAnySupportedFileExtension(path) {
  return tryGetExtensionFromPath2(path) !== void 0;
}
function tryGetExtensionFromPath2(path) {
  return find(extensionsToRemove, (e) => fileExtensionIs(path, e));
}
function isCheckJsEnabledForFile(sourceFile, compilerOptions) {
  return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs;
}
var emptyFileSystemEntries = {
  files: emptyArray,
  directories: emptyArray
};
function matchPatternOrExact(parsedPatterns, candidate) {
  const { matchableStringSet, patterns } = parsedPatterns;
  if (matchableStringSet == null ? void 0 : matchableStringSet.has(candidate)) {
    return candidate;
  }
  if (patterns === void 0 || patterns.length === 0) {
    return void 0;
  }
  return findBestPatternMatch(patterns, (_) => _, candidate);
}
function sliceAfter(arr, value) {
  const index = arr.indexOf(value);
  Debug.assert(index !== -1);
  return arr.slice(index);
}
function addRelatedInfo(diagnostic, ...relatedInformation) {
  if (!relatedInformation.length) {
    return diagnostic;
  }
  if (!diagnostic.relatedInformation) {
    diagnostic.relatedInformation = [];
  }
  Debug.assert(diagnostic.relatedInformation !== emptyArray, "Diagnostic had empty array singleton for related info, but is still being constructed!");
  diagnostic.relatedInformation.push(...relatedInformation);
  return diagnostic;
}
function minAndMax(arr, getValue) {
  Debug.assert(arr.length !== 0);
  let min2 = getValue(arr[0]);
  let max = min2;
  for (let i = 1; i < arr.length; i++) {
    const value = getValue(arr[i]);
    if (value < min2) {
      min2 = value;
    } else if (value > max) {
      max = value;
    }
  }
  return { min: min2, max };
}
function rangeOfNode(node) {
  return { pos: getTokenPosOfNode(node), end: node.end };
}
function rangeOfTypeParameters(sourceFile, typeParameters) {
  const pos = typeParameters.pos - 1;
  const end = Math.min(sourceFile.text.length, skipTrivia(sourceFile.text, typeParameters.end) + 1);
  return { pos, end };
}
function skipTypeChecking(sourceFile, options, host) {
  return skipTypeCheckingWorker(
    sourceFile,
    options,
    host,
    /*ignoreNoCheck*/
    false
  );
}
function skipTypeCheckingIgnoringNoCheck(sourceFile, options, host) {
  return skipTypeCheckingWorker(
    sourceFile,
    options,
    host,
    /*ignoreNoCheck*/
    true
  );
}
function skipTypeCheckingWorker(sourceFile, options, host, ignoreNoCheck) {
  return options.skipLibCheck && sourceFile.isDeclarationFile || options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib || !ignoreNoCheck && options.noCheck || host.isSourceOfProjectReferenceRedirect(sourceFile.fileName) || !canIncludeBindAndCheckDiagnostics(sourceFile, options);
}
function canIncludeBindAndCheckDiagnostics(sourceFile, options) {
  if (!!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false) return false;
  if (sourceFile.scriptKind === 3 /* TS */ || sourceFile.scriptKind === 4 /* TSX */ || sourceFile.scriptKind === 5 /* External */) return true;
  const isJs = sourceFile.scriptKind === 1 /* JS */ || sourceFile.scriptKind === 2 /* JSX */;
  const isCheckJs = isJs && isCheckJsEnabledForFile(sourceFile, options);
  const isPlainJs = isPlainJsFile(sourceFile, options.checkJs);
  return isPlainJs || isCheckJs || sourceFile.scriptKind === 7 /* Deferred */;
}
function isJsonEqual(a, b) {
  return a === b || typeof a === "object" && a !== null && typeof b === "object" && b !== null && equalOwnProperties(a, b, isJsonEqual);
}
function parsePseudoBigInt(stringValue) {
  let log2Base;
  switch (stringValue.charCodeAt(1)) {
    // "x" in "0x123"
    case 98 /* b */:
    case 66 /* B */:
      log2Base = 1;
      break;
    case 111 /* o */:
    case 79 /* O */:
      log2Base = 3;
      break;
    case 120 /* x */:
    case 88 /* X */:
      log2Base = 4;
      break;
    default:
      const nIndex = stringValue.length - 1;
      let nonZeroStart = 0;
      while (stringValue.charCodeAt(nonZeroStart) === 48 /* _0 */) {
        nonZeroStart++;
      }
      return stringValue.slice(nonZeroStart, nIndex) || "0";
  }
  const startIndex = 2, endIndex = stringValue.length - 1;
  const bitsNeeded = (endIndex - startIndex) * log2Base;
  const segments = new Uint16Array((bitsNeeded >>> 4) + (bitsNeeded & 15 ? 1 : 0));
  for (let i = endIndex - 1, bitOffset = 0; i >= startIndex; i--, bitOffset += log2Base) {
    const segment = bitOffset >>> 4;
    const digitChar = stringValue.charCodeAt(i);
    const digit = digitChar <= 57 /* _9 */ ? digitChar - 48 /* _0 */ : 10 + digitChar - (digitChar <= 70 /* F */ ? 65 /* A */ : 97 /* a */);
    const shiftedDigit = digit << (bitOffset & 15);
    segments[segment] |= shiftedDigit;
    const residual = shiftedDigit >>> 16;
    if (residual) segments[segment + 1] |= residual;
  }
  let base10Value = "";
  let firstNonzeroSegment = segments.length - 1;
  let segmentsRemaining = true;
  while (segmentsRemaining) {
    let mod10 = 0;
    segmentsRemaining = false;
    for (let segment = firstNonzeroSegment; segment >= 0; segment--) {
      const newSegment = mod10 << 16 | segments[segment];
      const segmentValue = newSegment / 10 | 0;
      segments[segment] = segmentValue;
      mod10 = newSegment - segmentValue * 10;
      if (segmentValue && !segmentsRemaining) {
        firstNonzeroSegment = segment;
        segmentsRemaining = true;
      }
    }
    base10Value = mod10 + base10Value;
  }
  return base10Value;
}
function pseudoBigIntToString({ negative, base10Value }) {
  return (negative && base10Value !== "0" ? "-" : "") + base10Value;
}
function parseBigInt(text) {
  if (!isValidBigIntString(
    text,
    /*roundTripOnly*/
    false
  )) {
    return void 0;
  }
  return parseValidBigInt(text);
}
function parseValidBigInt(text) {
  const negative = text.startsWith("-");
  const base10Value = parsePseudoBigInt(`${negative ? text.slice(1) : text}n`);
  return { negative, base10Value };
}
function isValidBigIntString(s, roundTripOnly) {
  if (s === "") return false;
  const scanner2 = createScanner(
    99 /* ESNext */,
    /*skipTrivia*/
    false
  );
  let success = true;
  scanner2.setOnError(() => success = false);
  scanner2.setText(s + "n");
  let result = scanner2.scan();
  const negative = result === 41 /* MinusToken */;
  if (negative) {
    result = scanner2.scan();
  }
  const flags = scanner2.getTokenFlags();
  return success && result === 10 /* BigIntLiteral */ && scanner2.getTokenEnd() === s.length + 1 && !(flags & 512 /* ContainsSeparator */) && (!roundTripOnly || s === pseudoBigIntToString({ negative, base10Value: parsePseudoBigInt(scanner2.getTokenValue()) }));
}
function isValidTypeOnlyAliasUseSite(useSite) {
  return !!(useSite.flags & 33554432 /* Ambient */) || isPartOfTypeQuery(useSite) || isIdentifierInNonEmittingHeritageClause(useSite) || isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(useSite) || !(isExpressionNode(useSite) || isShorthandPropertyNameUseSite(useSite));
}
function isShorthandPropertyNameUseSite(useSite) {
  return isIdentifier(useSite) && isShorthandPropertyAssignment(useSite.parent) && useSite.parent.name === useSite;
}
function isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(node) {
  while (node.kind === 80 /* Identifier */ || node.kind === 211 /* PropertyAccessExpression */) {
    node = node.parent;
  }
  if (node.kind !== 167 /* ComputedPropertyName */) {
    return false;
  }
  if (hasSyntacticModifier(node.parent, 64 /* Abstract */)) {
    return true;
  }
  const containerKind = node.parent.parent.kind;
  return containerKind === 264 /* InterfaceDeclaration */ || containerKind === 187 /* TypeLiteral */;
}
function isIdentifierInNonEmittingHeritageClause(node) {
  if (node.kind !== 80 /* Identifier */) return false;
  const heritageClause = findAncestor(node.parent, (parent2) => {
    switch (parent2.kind) {
      case 298 /* HeritageClause */:
        return true;
      case 211 /* PropertyAccessExpression */:
      case 233 /* ExpressionWithTypeArguments */:
        return false;
      default:
        return "quit";
    }
  });
  return (heritageClause == null ? void 0 : heritageClause.token) === 119 /* ImplementsKeyword */ || (heritageClause == null ? void 0 : heritageClause.parent.kind) === 264 /* InterfaceDeclaration */;
}
function isIdentifierTypeReference(node) {
  return isTypeReferenceNode(node) && isIdentifier(node.typeName);
}
function arrayIsHomogeneous(array, comparer = equateValues) {
  if (array.length < 2) return true;
  const first2 = array[0];
  for (let i = 1, length2 = array.length; i < length2; i++) {
    const target = array[i];
    if (!comparer(first2, target)) return false;
  }
  return true;
}
function setTextRangePos(range, pos) {
  range.pos = pos;
  return range;
}
function setTextRangeEnd(range, end) {
  range.end = end;
  return range;
}
function setTextRangePosEnd(range, pos, end) {
  return setTextRangeEnd(setTextRangePos(range, pos), end);
}
function setTextRangePosWidth(range, pos, width) {
  return setTextRangePosEnd(range, pos, pos + width);
}
function setNodeFlags(node, newFlags) {
  if (node) {
    node.flags = newFlags;
  }
  return node;
}
function setParent(child, parent2) {
  if (child && parent2) {
    child.parent = parent2;
  }
  return child;
}
function setParentRecursive(rootNode, incremental) {
  if (!rootNode) return rootNode;
  forEachChildRecursively(rootNode, isJSDocNode(rootNode) ? bindParentToChildIgnoringJSDoc : bindParentToChild);
  return rootNode;
  function bindParentToChildIgnoringJSDoc(child, parent2) {
    if (incremental && child.parent === parent2) {
      return "skip";
    }
    setParent(child, parent2);
  }
  function bindJSDoc(child) {
    if (hasJSDocNodes(child)) {
      for (const doc of child.jsDoc) {
        bindParentToChildIgnoringJSDoc(doc, child);
        forEachChildRecursively(doc, bindParentToChildIgnoringJSDoc);
      }
    }
  }
  function bindParentToChild(child, parent2) {
    return bindParentToChildIgnoringJSDoc(child, parent2) || bindJSDoc(child);
  }
}
function isPackedElement(node) {
  return !isOmittedExpression(node);
}
function isPackedArrayLiteral(node) {
  return isArrayLiteralExpression(node) && every(node.elements, isPackedElement);
}
function expressionResultIsUnused(node) {
  Debug.assertIsDefined(node.parent);
  while (true) {
    const parent2 = node.parent;
    if (isParenthesizedExpression(parent2)) {
      node = parent2;
      continue;
    }
    if (isExpressionStatement(parent2) || isVoidExpression(parent2) || isForStatement(parent2) && (parent2.initializer === node || parent2.incrementor === node)) {
      return true;
    }
    if (isCommaListExpression(parent2)) {
      if (node !== last(parent2.elements)) return true;
      node = parent2;
      continue;
    }
    if (isBinaryExpression(parent2) && parent2.operatorToken.kind === 28 /* CommaToken */) {
      if (node === parent2.left) return true;
      node = parent2;
      continue;
    }
    return false;
  }
}
function containsIgnoredPath(path) {
  return some(ignoredPaths, (p) => path.includes(p));
}
function getContainingNodeArray(node) {
  if (!node.parent) return void 0;
  switch (node.kind) {
    case 168 /* TypeParameter */:
      const { parent: parent3 } = node;
      return parent3.kind === 195 /* InferType */ ? void 0 : parent3.typeParameters;
    case 169 /* Parameter */:
      return node.parent.parameters;
    case 204 /* TemplateLiteralTypeSpan */:
      return node.parent.templateSpans;
    case 239 /* TemplateSpan */:
      return node.parent.templateSpans;
    case 170 /* Decorator */: {
      const { parent: parent4 } = node;
      return canHaveDecorators(parent4) ? parent4.modifiers : void 0;
    }
    case 298 /* HeritageClause */:
      return node.parent.heritageClauses;
  }
  const { parent: parent2 } = node;
  if (isJSDocTag(node)) {
    return isJSDocTypeLiteral(node.parent) ? void 0 : node.parent.tags;
  }
  switch (parent2.kind) {
    case 187 /* TypeLiteral */:
    case 264 /* InterfaceDeclaration */:
      return isTypeElement(node) ? parent2.members : void 0;
    case 192 /* UnionType */:
    case 193 /* IntersectionType */:
      return parent2.types;
    case 189 /* TupleType */:
    case 209 /* ArrayLiteralExpression */:
    case 356 /* CommaListExpression */:
    case 275 /* NamedImports */:
    case 279 /* NamedExports */:
      return parent2.elements;
    case 210 /* ObjectLiteralExpression */:
    case 292 /* JsxAttributes */:
      return parent2.properties;
    case 213 /* CallExpression */:
    case 214 /* NewExpression */:
      return isTypeNode(node) ? parent2.typeArguments : parent2.expression === node ? void 0 : parent2.arguments;
    case 284 /* JsxElement */:
    case 288 /* JsxFragment */:
      return isJsxChild(node) ? parent2.children : void 0;
    case 286 /* JsxOpeningElement */:
    case 285 /* JsxSelfClosingElement */:
      return isTypeNode(node) ? parent2.typeArguments : void 0;
    case 241 /* Block */:
    case 296 /* CaseClause */:
    case 297 /* DefaultClause */:
    case 268 /* ModuleBlock */:
      return parent2.statements;
    case 269 /* CaseBlock */:
      return parent2.clauses;
    case 263 /* ClassDeclaration */:
    case 231 /* ClassExpression */:
      return isClassElement(node) ? parent2.members : void 0;
    case 266 /* EnumDeclaration */:
      return isEnumMember(node) ? parent2.members : void 0;
    case 307 /* SourceFile */:
      return parent2.statements;
  }
}
function hasContextSensitiveParameters(node) {
  if (!node.typeParameters) {
    if (some(node.parameters, (p) => !getEffectiveTypeAnnotationNode(p))) {
      return true;
    }
    if (node.kind !== 219 /* ArrowFunction */) {
      const parameter = firstOrUndefined(node.parameters);
      if (!(parameter && parameterIsThisKeyword(parameter))) {
        return true;
      }
    }
  }
  return false;
}
function isInfinityOrNaNString(name) {
  return name === "Infinity" || name === "-Infinity" || name === "NaN";
}
function isCatchClauseVariableDeclaration(node) {
  return node.kind === 260 /* VariableDeclaration */ && node.parent.kind === 299 /* CatchClause */;
}
function isFunctionExpressionOrArrowFunction(node) {
  return node.kind === 218 /* FunctionExpression */ || node.kind === 219 /* ArrowFunction */;
}
function escapeSnippetText(text) {
  return text.replace(/\$/g, () => "\\$");
}
function isNumericLiteralName(name) {
  return (+name).toString() === name;
}
function createPropertyNameNodeForIdentifierOrLiteral(name, target, singleQuote, stringNamed, isMethod) {
  const isMethodNamedNew = isMethod && name === "new";
  return !isMethodNamedNew && isIdentifierText(name, target) ? factory.createIdentifier(name) : !stringNamed && !isMethodNamedNew && isNumericLiteralName(name) && +name >= 0 ? factory.createNumericLiteral(+name) : factory.createStringLiteral(name, !!singleQuote);
}
function isThisTypeParameter(type) {
  return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
}
function getNodeModulePathParts(fullPath) {
  let topLevelNodeModulesIndex = 0;
  let topLevelPackageNameIndex = 0;
  let packageRootIndex = 0;
  let fileNameIndex = 0;
  let States;
  ((States2) => {
    States2[States2["BeforeNodeModules"] = 0] = "BeforeNodeModules";
    States2[States2["NodeModules"] = 1] = "NodeModules";
    States2[States2["Scope"] = 2] = "Scope";
    States2[States2["PackageContent"] = 3] = "PackageContent";
  })(States || (States = {}));
  let partStart = 0;
  let partEnd = 0;
  let state = 0 /* BeforeNodeModules */;
  while (partEnd >= 0) {
    partStart = partEnd;
    partEnd = fullPath.indexOf("/", partStart + 1);
    switch (state) {
      case 0 /* BeforeNodeModules */:
        if (fullPath.indexOf(nodeModulesPathPart, partStart) === partStart) {
          topLevelNodeModulesIndex = partStart;
          topLevelPackageNameIndex = partEnd;
          state = 1 /* NodeModules */;
        }
        break;
      case 1 /* NodeModules */:
      case 2 /* Scope */:
        if (state === 1 /* NodeModules */ && fullPath.charAt(partStart + 1) === "@") {
          state = 2 /* Scope */;
        } else {
          packageRootIndex = partEnd;
          state = 3 /* PackageContent */;
        }
        break;
      case 3 /* PackageContent */:
        if (fullPath.indexOf(nodeModulesPathPart, partStart) === partStart) {
          state = 1 /* NodeModules */;
        } else {
          state = 3 /* PackageContent */;
        }
        break;
    }
  }
  fileNameIndex = partStart;
  return state > 1 /* NodeModules */ ? { topLevelNodeModulesIndex, topLevelPackageNameIndex, packageRootIndex, fileNameIndex } : void 0;
}
function isTypeDeclaration(node) {
  switch (node.kind) {
    case 168 /* TypeParameter */:
    case 263 /* ClassDeclaration */:
    case 264 /* InterfaceDeclaration */:
    case 265 /* TypeAliasDeclaration */:
    case 266 /* EnumDeclaration */:
    case 346 /* JSDocTypedefTag */:
    case 338 /* JSDocCallbackTag */:
    case 340 /* JSDocEnumTag */:
      return true;
    case 273 /* ImportClause */:
      return node.isTypeOnly;
    case 276 /* ImportSpecifier */:
    case 281 /* ExportSpecifier */:
      return node.parent.parent.isTypeOnly;
    default:
      return false;
  }
}
function canHaveExportModifier(node) {
  return isEnumDeclaration(node) || isVariableStatement(node) || isFunctionDeclaration(node) || isClassDeclaration(node) || isInterfaceDeclaration(node) || isTypeDeclaration(node) || isModuleDeclaration(node) && !isExternalModuleAugmentation(node) && !isGlobalScopeAugmentation(node);
}
function isOptionalJSDocPropertyLikeTag(node) {
  if (!isJSDocPropertyLikeTag(node)) {
    return false;
  }
  const { isBracketed, typeExpression } = node;
  return isBracketed || !!typeExpression && typeExpression.type.kind === 316 /* JSDocOptionalType */;
}
function canUsePropertyAccess(name, languageVersion) {
  if (name.length === 0) {
    return false;
  }
  const firstChar = name.charCodeAt(0);
  return firstChar === 35 /* hash */ ? name.length > 1 && isIdentifierStart(name.charCodeAt(1), languageVersion) : isIdentifierStart(firstChar, languageVersion);
}
function hasTabstop(node) {
  var _a;
  return ((_a = getSnippetElement(node)) == null ? void 0 : _a.kind) === 0 /* TabStop */;
}
function isJSDocOptionalParameter(node) {
  return isInJSFile(node) && // node.type should only be a JSDocOptionalType when node is a parameter of a JSDocFunctionType
  (node.type && node.type.kind === 316 /* JSDocOptionalType */ || getJSDocParameterTags(node).some(isOptionalJSDocPropertyLikeTag));
}
function isOptionalDeclaration(declaration) {
  switch (declaration.kind) {
    case 172 /* PropertyDeclaration */:
    case 171 /* PropertySignature */:
      return !!declaration.questionToken;
    case 169 /* Parameter */:
      return !!declaration.questionToken || isJSDocOptionalParameter(declaration);
    case 348 /* JSDocPropertyTag */:
    case 341 /* JSDocParameterTag */:
      return isOptionalJSDocPropertyLikeTag(declaration);
    default:
      return false;
  }
}
function isNonNullAccess(node) {
  const kind = node.kind;
  return (kind === 211 /* PropertyAccessExpression */ || kind === 212 /* ElementAccessExpression */) && isNonNullExpression(node.expression);
}
function isJSDocSatisfiesExpression(node) {
  return isInJSFile(node) && isParenthesizedExpression(node) && hasJSDocNodes(node) && !!getJSDocSatisfiesTag(node);
}
function getJSDocSatisfiesExpressionType(node) {
  return Debug.checkDefined(tryGetJSDocSatisfiesTypeNode(node));
}
function tryGetJSDocSatisfiesTypeNode(node) {
  const tag = getJSDocSatisfiesTag(node);
  return tag && tag.typeExpression && tag.typeExpression.type;
}
function getEscapedTextOfJsxAttributeName(node) {
  return isIdentifier(node) ? node.escapedText : getEscapedTextOfJsxNamespacedName(node);
}
function getTextOfJsxAttributeName(node) {
  return isIdentifier(node) ? idText(node) : getTextOfJsxNamespacedName(node);
}
function isJsxAttributeName(node) {
  const kind = node.kind;
  return kind === 80 /* Identifier */ || kind === 295 /* JsxNamespacedName */;
}
function getEscapedTextOfJsxNamespacedName(node) {
  return `${node.namespace.escapedText}:${idText(node.name)}`;
}
function getTextOfJsxNamespacedName(node) {
  return `${idText(node.namespace)}:${idText(node.name)}`;
}
function intrinsicTagNameToString(node) {
  return isIdentifier(node) ? idText(node) : getTextOfJsxNamespacedName(node);
}
function isTypeUsableAsPropertyName(type) {
  return !!(type.flags & 8576 /* StringOrNumberLiteralOrUnique */);
}
function getPropertyNameFromType(type) {
  if (type.flags & 8192 /* UniqueESSymbol */) {
    return type.escapedName;
  }
  if (type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */)) {
    return escapeLeadingUnderscores("" + type.value);
  }
  return Debug.fail();
}
function isExpandoPropertyDeclaration(declaration) {
  return !!declaration && (isPropertyAccessExpression(declaration) || isElementAccessExpression(declaration) || isBinaryExpression(declaration));
}
function hasResolutionModeOverride(node) {
  if (node === void 0) {
    return false;
  }
  return !!getResolutionModeOverride(node.attributes);
}
var stringReplace = String.prototype.replace;
function replaceFirstStar(s, replacement) {
  return stringReplace.call(s, "*", replacement);
}
function getNameFromImportAttribute(node) {
  return isIdentifier(node.name) ? node.name.escapedText : escapeLeadingUnderscores(node.name.text);
}
function isSourceElement(node) {
  switch (node.kind) {
    case 168 /* TypeParameter */:
    case 169 /* Parameter */:
    case 172 /* PropertyDeclaration */:
    case 171 /* PropertySignature */:
    case 185 /* ConstructorType */:
    case 184 /* FunctionType */:
    case 179 /* CallSignature */:
    case 180 /* ConstructSignature */:
    case 181 /* IndexSignature */:
    case 174 /* MethodDeclaration */:
    case 173 /* MethodSignature */:
    case 175 /* ClassStaticBlockDeclaration */:
    case 176 /* Constructor */:
    case 177 /* GetAccessor */:
    case 178 /* SetAccessor */:
    case 183 /* TypeReference */:
    case 182 /* TypePredicate */:
    case 186 /* TypeQuery */:
    case 187 /* TypeLiteral */:
    case 188 /* ArrayType */:
    case 189 /* TupleType */:
    case 192 /* UnionType */:
    case 193 /* IntersectionType */:
    case 196 /* ParenthesizedType */:
    case 190 /* OptionalType */:
    case 191 /* RestType */:
    case 197 /* ThisType */:
    case 198 /* TypeOperator */:
    case 194 /* ConditionalType */:
    case 195 /* InferType */:
    case 203 /* TemplateLiteralType */:
    case 205 /* ImportType */:
    case 202 /* NamedTupleMember */:
    case 328 /* JSDocAugmentsTag */:
    case 329 /* JSDocImplementsTag */:
    case 346 /* JSDocTypedefTag */:
    case 338 /* JSDocCallbackTag */:
    case 340 /* JSDocEnumTag */:
    case 345 /* JSDocTemplateTag */:
    case 344 /* JSDocTypeTag */:
    case 324 /* JSDocLink */:
    case 325 /* JSDocLinkCode */:
    case 326 /* JSDocLinkPlain */:
    case 341 /* JSDocParameterTag */:
    case 348 /* JSDocPropertyTag */:
    case 317 /* JSDocFunctionType */:
    case 315 /* JSDocNonNullableType */:
    case 314 /* JSDocNullableType */:
    case 312 /* JSDocAllType */:
    case 313 /* JSDocUnknownType */:
    case 322 /* JSDocTypeLiteral */:
    case 318 /* JSDocVariadicType */:
    case 309 /* JSDocTypeExpression */:
    case 333 /* JSDocPublicTag */:
    case 335 /* JSDocProtectedTag */:
    case 334 /* JSDocPrivateTag */:
    case 350 /* JSDocSatisfiesTag */:
    case 343 /* JSDocThisTag */:
    case 199 /* IndexedAccessType */:
    case 200 /* MappedType */:
    case 262 /* FunctionDeclaration */:
    case 241 /* Block */:
    case 268 /* ModuleBlock */:
    case 243 /* VariableStatement */:
    case 244 /* ExpressionStatement */:
    case 245 /* IfStatement */:
    case 246 /* DoStatement */:
    case 247 /* WhileStatement */:
    case 248 /* ForStatement */:
    case 249 /* ForInStatement */:
    case 250 /* ForOfStatement */:
    case 251 /* ContinueStatement */:
    case 252 /* BreakStatement */:
    case 253 /* ReturnStatement */:
    case 254 /* WithStatement */:
    case 255 /* SwitchStatement */:
    case 256 /* LabeledStatement */:
    case 257 /* ThrowStatement */:
    case 258 /* TryStatement */:
    case 260 /* VariableDeclaration */:
    case 208 /* BindingElement */:
    case 263 /* ClassDeclaration */:
    case 264 /* InterfaceDeclaration */:
    case 265 /* TypeAliasDeclaration */:
    case 266 /* EnumDeclaration */:
    case 267 /* ModuleDeclaration */:
    case 272 /* ImportDeclaration */:
    case 271 /* ImportEqualsDeclaration */:
    case 278 /* ExportDeclaration */:
    case 277 /* ExportAssignment */:
    case 242 /* EmptyStatement */:
    case 259 /* DebuggerStatement */:
    case 282 /* MissingDeclaration */:
      return true;
  }
  return false;
}
function evaluatorResult(value, isSyntacticallyString = false, resolvedOtherFiles = false, hasExternalReferences = false) {
  return { value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences };
}
function createEvaluator({ evaluateElementAccessExpression, evaluateEntityNameExpression }) {
  function evaluate(expr, location) {
    let isSyntacticallyString = false;
    let resolvedOtherFiles = false;
    let hasExternalReferences = false;
    expr = skipParentheses(expr);
    switch (expr.kind) {
      case 224 /* PrefixUnaryExpression */:
        const result = evaluate(expr.operand, location);
        resolvedOtherFiles = result.resolvedOtherFiles;
        hasExternalReferences = result.hasExternalReferences;
        if (typeof result.value === "number") {
          switch (expr.operator) {
            case 40 /* PlusToken */:
              return evaluatorResult(result.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 41 /* MinusToken */:
              return evaluatorResult(-result.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 55 /* TildeToken */:
              return evaluatorResult(~result.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
          }
        }
        break;
      case 226 /* BinaryExpression */: {
        const left = evaluate(expr.left, location);
        const right = evaluate(expr.right, location);
        isSyntacticallyString = (left.isSyntacticallyString || right.isSyntacticallyString) && expr.operatorToken.kind === 40 /* PlusToken */;
        resolvedOtherFiles = left.resolvedOtherFiles || right.resolvedOtherFiles;
        hasExternalReferences = left.hasExternalReferences || right.hasExternalReferences;
        if (typeof left.value === "number" && typeof right.value === "number") {
          switch (expr.operatorToken.kind) {
            case 52 /* BarToken */:
              return evaluatorResult(left.value | right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 51 /* AmpersandToken */:
              return evaluatorResult(left.value & right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 49 /* GreaterThanGreaterThanToken */:
              return evaluatorResult(left.value >> right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 50 /* GreaterThanGreaterThanGreaterThanToken */:
              return evaluatorResult(left.value >>> right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 48 /* LessThanLessThanToken */:
              return evaluatorResult(left.value << right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 53 /* CaretToken */:
              return evaluatorResult(left.value ^ right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 42 /* AsteriskToken */:
              return evaluatorResult(left.value * right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 44 /* SlashToken */:
              return evaluatorResult(left.value / right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 40 /* PlusToken */:
              return evaluatorResult(left.value + right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 41 /* MinusToken */:
              return evaluatorResult(left.value - right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 45 /* PercentToken */:
              return evaluatorResult(left.value % right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
            case 43 /* AsteriskAsteriskToken */:
              return evaluatorResult(left.value ** right.value, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
          }
        } else if ((typeof left.value === "string" || typeof left.value === "number") && (typeof right.value === "string" || typeof right.value === "number") && expr.operatorToken.kind === 40 /* PlusToken */) {
          return evaluatorResult(
            "" + left.value + right.value,
            isSyntacticallyString,
            resolvedOtherFiles,
            hasExternalReferences
          );
        }
        break;
      }
      case 11 /* StringLiteral */:
      case 15 /* NoSubstitutionTemplateLiteral */:
        return evaluatorResult(
          expr.text,
          /*isSyntacticallyString*/
          true
        );
      case 228 /* TemplateExpression */:
        return evaluateTemplateExpression(expr, location);
      case 9 /* NumericLiteral */:
        return evaluatorResult(+expr.text);
      case 80 /* Identifier */:
        return evaluateEntityNameExpression(expr, location);
      case 211 /* PropertyAccessExpression */:
        if (isEntityNameExpression(expr)) {
          return evaluateEntityNameExpression(expr, location);
        }
        break;
      case 212 /* ElementAccessExpression */:
        return evaluateElementAccessExpression(expr, location);
    }
    return evaluatorResult(
      /*value*/
      void 0,
      isSyntacticallyString,
      resolvedOtherFiles,
      hasExternalReferences
    );
  }
  function evaluateTemplateExpression(expr, location) {
    let result = expr.head.text;
    let resolvedOtherFiles = false;
    let hasExternalReferences = false;
    for (const span of expr.templateSpans) {
      const spanResult = evaluate(span.expression, location);
      if (spanResult.value === void 0) {
        return evaluatorResult(
          /*value*/
          void 0,
          /*isSyntacticallyString*/
          true
        );
      }
      result += spanResult.value;
      result += span.literal.text;
      resolvedOtherFiles || (resolvedOtherFiles = spanResult.resolvedOtherFiles);
      hasExternalReferences || (hasExternalReferences = spanResult.hasExternalReferences);
    }
    return evaluatorResult(
      result,
      /*isSyntacticallyString*/
      true,
      resolvedOtherFiles,
      hasExternalReferences
    );
  }
  return evaluate;
}
function isConstAssertion(location) {
  return isAssertionExpression(location) && isConstTypeReference(location.type) || isJSDocTypeTag(location) && isConstTypeReference(location.typeExpression);
}
function findConstructorDeclaration(node) {
  const members = node.members;
  for (const member of members) {
    if (member.kind === 176 /* Constructor */ && nodeIsPresent(member.body)) {
      return member;
    }
  }
}
function createNameResolver({
  compilerOptions,
  requireSymbol,
  argumentsSymbol,
  error: error2,
  getSymbolOfDeclaration,
  globals,
  lookup,
  setRequiresScopeChangeCache = returnUndefined,
  getRequiresScopeChangeCache = returnUndefined,
  onPropertyWithInvalidInitializer = returnFalse,
  onFailedToResolveSymbol = returnUndefined,
  onSuccessfullyResolvedSymbol = returnUndefined
}) {
  var isolatedModulesLikeFlagName = compilerOptions.verbatimModuleSyntax ? "verbatimModuleSyntax" : "isolatedModules";
  var emitStandardClassFields = getEmitStandardClassFields(compilerOptions);
  var emptySymbols = createSymbolTable();
  return resolveNameHelper;
  function resolveNameHelper(location, nameArg, meaning, nameNotFoundMessage, isUse, excludeGlobals) {
    var _a, _b, _c;
    const originalLocation = location;
    let result;
    let lastLocation;
    let lastSelfReferenceLocation;
    let propertyWithInvalidInitializer;
    let associatedDeclarationForContainingInitializerOrBindingName;
    let withinDeferredContext = false;
    let grandparent;
    const name = isString(nameArg) ? nameArg : nameArg.escapedText;
    loop:
      while (location) {
        if (name === "const" && isConstAssertion(location)) {
          return void 0;
        }
        if (isModuleOrEnumDeclaration(location) && lastLocation && location.name === lastLocation) {
          lastLocation = location;
          location = location.parent;
        }
        if (canHaveLocals(location) && location.locals && !isGlobalSourceFile(location)) {
          if (result = lookup(location.locals, name, meaning)) {
            let useResult = true;
            if (isFunctionLike(location) && lastLocation && lastLocation !== location.body) {
              if (meaning & result.flags & 788968 /* Type */ && lastLocation.kind !== 320 /* JSDoc */) {
                useResult = result.flags & 262144 /* TypeParameter */ ? !!(lastLocation.flags & 16 /* Synthesized */) || // Synthetic fake scopes are added for signatures so type parameters are accessible from them
                lastLocation === location.type || lastLocation.kind === 169 /* Parameter */ || lastLocation.kind === 341 /* JSDocParameterTag */ || lastLocation.kind === 342 /* JSDocReturnTag */ || lastLocation.kind === 168 /* TypeParameter */ : false;
              }
              if (meaning & result.flags & 3 /* Variable */) {
                if (useOuterVariableScopeInParameter(result, location, lastLocation)) {
                  useResult = false;
                } else if (result.flags & 1 /* FunctionScopedVariable */) {
                  useResult = lastLocation.kind === 169 /* Parameter */ || !!(lastLocation.flags & 16 /* Synthesized */) || // Synthetic fake scopes are added for signatures so parameters are accessible from them
                  lastLocation === location.type && !!findAncestor(result.valueDeclaration, isParameter);
                }
              }
            } else if (location.kind === 194 /* ConditionalType */) {
              useResult = lastLocation === location.trueType;
            }
            if (useResult) {
              break loop;
            } else {
              result = void 0;
            }
          }
        }
        withinDeferredContext = withinDeferredContext || getIsDeferredContext(location, lastLocation);
        switch (location.kind) {
          case 307 /* SourceFile */:
            if (!isExternalOrCommonJsModule(location)) break;
          // falls through
          case 267 /* ModuleDeclaration */:
            const moduleExports = ((_a = getSymbolOfDeclaration(location)) == null ? void 0 : _a.exports) || emptySymbols;
            if (location.kind === 307 /* SourceFile */ || isModuleDeclaration(location) && location.flags & 33554432 /* Ambient */ && !isGlobalScopeAugmentation(location)) {
              if (result = moduleExports.get("default" /* Default */)) {
                const localSymbol = getLocalSymbolForExportDefault(result);
                if (localSymbol && result.flags & meaning && localSymbol.escapedName === name) {
                  break loop;
                }
                result = void 0;
              }
              const moduleExport = moduleExports.get(name);
              if (moduleExport && moduleExport.flags === 2097152 /* Alias */ && (getDeclarationOfKind(moduleExport, 281 /* ExportSpecifier */) || getDeclarationOfKind(moduleExport, 280 /* NamespaceExport */))) {
                break;
              }
            }
            if (name !== "default" /* Default */ && (result = lookup(moduleExports, name, meaning & 2623475 /* ModuleMember */))) {
              if (isSourceFile(location) && location.commonJsModuleIndicator && !((_b = result.declarations) == null ? void 0 : _b.some(isJSDocTypeAlias))) {
                result = void 0;
              } else {
                break loop;
              }
            }
            break;
          case 266 /* EnumDeclaration */:
            if (result = lookup(((_c = getSymbolOfDeclaration(location)) == null ? void 0 : _c.exports) || emptySymbols, name, meaning & 8 /* EnumMember */)) {
              if (nameNotFoundMessage && getIsolatedModules(compilerOptions) && !(location.flags & 33554432 /* Ambient */) && getSourceFileOfNode(location) !== getSourceFileOfNode(result.valueDeclaration)) {
                error2(
                  originalLocation,
                  Diagnostics.Cannot_access_0_from_another_file_without_qualification_when_1_is_enabled_Use_2_instead,
                  unescapeLeadingUnderscores(name),
                  isolatedModulesLikeFlagName,
                  `${unescapeLeadingUnderscores(getSymbolOfDeclaration(location).escapedName)}.${unescapeLeadingUnderscores(name)}`
                );
              }
              break loop;
            }
            break;
          case 172 /* PropertyDeclaration */:
            if (!isStatic(location)) {
              const ctor = findConstructorDeclaration(location.parent);
              if (ctor && ctor.locals) {
                if (lookup(ctor.locals, name, meaning & 111551 /* Value */)) {
                  Debug.assertNode(location, isPropertyDeclaration);
                  propertyWithInvalidInitializer = location;
                }
              }
            }
            break;
          case 263 /* ClassDeclaration */:
          case 231 /* ClassExpression */:
          case 264 /* InterfaceDeclaration */:
            if (result = lookup(getSymbolOfDeclaration(location).members || emptySymbols, name, meaning & 788968 /* Type */)) {
              if (!isTypeParameterSymbolDeclaredInContainer(result, location)) {
                result = void 0;
                break;
              }
              if (lastLocation && isStatic(lastLocation)) {
                if (nameNotFoundMessage) {
                  error2(originalLocation, Diagnostics.Static_members_cannot_reference_class_type_parameters);
                }
                return void 0;
              }
              break loop;
            }
            if (isClassExpression(location) && meaning & 32 /* Class */) {
              const className = location.name;
              if (className && name === className.escapedText) {
                result = location.symbol;
                break loop;
              }
            }
            break;
          case 233 /* ExpressionWithTypeArguments */:
            if (lastLocation === location.expression && location.parent.token === 96 /* ExtendsKeyword */) {
              const container = location.parent.parent;
              if (isClassLike(container) && (result = lookup(getSymbolOfDeclaration(container).members, name, meaning & 788968 /* Type */))) {
                if (nameNotFoundMessage) {
                  error2(originalLocation, Diagnostics.Base_class_expressions_cannot_reference_class_type_parameters);
                }
                return void 0;
              }
            }
            break;
          // It is not legal to reference a class's own type parameters from a computed property name that
          // belongs to the class. For example:
          //
          //   function foo<T>() { return '' }
          //   class C<T> { // <-- Class's own type parameter T
          //       [foo<T>()]() { } // <-- Reference to T from class's own computed property
          //   }
          //
          case 167 /* ComputedPropertyName */:
            grandparent = location.parent.parent;
            if (isClassLike(grandparent) || grandparent.kind === 264 /* InterfaceDeclaration */) {
              if (result = lookup(getSymbolOfDeclaration(grandparent).members, name, meaning & 788968 /* Type */)) {
                if (nameNotFoundMessage) {
                  error2(originalLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
                }
                return void 0;
              }
            }
            break;
          case 219 /* ArrowFunction */:
            if (getEmitScriptTarget(compilerOptions) >= 2 /* ES2015 */) {
              break;
            }
          // falls through
          case 174 /* MethodDeclaration */:
          case 176 /* Constructor */:
          case 177 /* GetAccessor */:
          case 178 /* SetAccessor */:
          case 262 /* FunctionDeclaration */:
            if (meaning & 3 /* Variable */ && name === "arguments") {
              result = argumentsSymbol;
              break loop;
            }
            break;
          case 218 /* FunctionExpression */:
            if (meaning & 3 /* Variable */ && name === "arguments") {
              result = argumentsSymbol;
              break loop;
            }
            if (meaning & 16 /* Function */) {
              const functionName = location.name;
              if (functionName && name === functionName.escapedText) {
                result = location.symbol;
                break loop;
              }
            }
            break;
          case 170 /* Decorator */:
            if (location.parent && location.parent.kind === 169 /* Parameter */) {
              location = location.parent;
            }
            if (location.parent && (isClassElement(location.parent) || location.parent.kind === 263 /* ClassDeclaration */)) {
              location = location.parent;
            }
            break;
          case 346 /* JSDocTypedefTag */:
          case 338 /* JSDocCallbackTag */:
          case 340 /* JSDocEnumTag */:
          case 351 /* JSDocImportTag */:
            const root = getJSDocRoot(location);
            if (root) {
              location = root.parent;
            }
            break;
          case 169 /* Parameter */:
            if (lastLocation && (lastLocation === location.initializer || lastLocation === location.name && isBindingPattern(lastLocation))) {
              if (!associatedDeclarationForContainingInitializerOrBindingName) {
                associatedDeclarationForContainingInitializerOrBindingName = location;
              }
            }
            break;
          case 208 /* BindingElement */:
            if (lastLocation && (lastLocation === location.initializer || lastLocation === location.name && isBindingPattern(lastLocation))) {
              if (isPartOfParameterDeclaration(location) && !associatedDeclarationForContainingInitializerOrBindingName) {
                associatedDeclarationForContainingInitializerOrBindingName = location;
              }
            }
            break;
          case 195 /* InferType */:
            if (meaning & 262144 /* TypeParameter */) {
              const parameterName = location.typeParameter.name;
              if (parameterName && name === parameterName.escapedText) {
                result = location.typeParameter.symbol;
                break loop;
              }
            }
            break;
          case 281 /* ExportSpecifier */:
            if (lastLocation && lastLocation === location.propertyName && location.parent.parent.moduleSpecifier) {
              location = location.parent.parent.parent;
            }
            break;
        }
        if (isSelfReferenceLocation(location, lastLocation)) {
          lastSelfReferenceLocation = location;
        }
        lastLocation = location;
        location = isJSDocTemplateTag(location) ? getEffectiveContainerForJSDocTemplateTag(location) || location.parent : isJSDocParameterTag(location) || isJSDocReturnTag(location) ? getHostSignatureFromJSDoc(location) || location.parent : location.parent;
      }
    if (isUse && result && (!lastSelfReferenceLocation || result !== lastSelfReferenceLocation.symbol)) {
      result.isReferenced |= meaning;
    }
    if (!result) {
      if (lastLocation) {
        Debug.assertNode(lastLocation, isSourceFile);
        if (lastLocation.commonJsModuleIndicator && name === "exports" && meaning & lastLocation.symbol.flags) {
          return lastLocation.symbol;
        }
      }
      if (!excludeGlobals) {
        result = lookup(globals, name, meaning);
      }
    }
    if (!result) {
      if (originalLocation && isInJSFile(originalLocation) && originalLocation.parent) {
        if (isRequireCall(
          originalLocation.parent,
          /*requireStringLiteralLikeArgument*/
          false
        )) {
          return requireSymbol;
        }
      }
    }
    if (nameNotFoundMessage) {
      if (propertyWithInvalidInitializer && onPropertyWithInvalidInitializer(originalLocation, name, propertyWithInvalidInitializer, result)) {
        return void 0;
      }
      if (!result) {
        onFailedToResolveSymbol(originalLocation, nameArg, meaning, nameNotFoundMessage);
      } else {
        onSuccessfullyResolvedSymbol(originalLocation, result, meaning, lastLocation, associatedDeclarationForContainingInitializerOrBindingName, withinDeferredContext);
      }
    }
    return result;
  }
  function useOuterVariableScopeInParameter(result, location, lastLocation) {
    const target = getEmitScriptTarget(compilerOptions);
    const functionLocation = location;
    if (isParameter(lastLocation) && functionLocation.body && result.valueDeclaration && result.valueDeclaration.pos >= functionLocation.body.pos && result.valueDeclaration.end <= functionLocation.body.end) {
      if (target >= 2 /* ES2015 */) {
        let declarationRequiresScopeChange = getRequiresScopeChangeCache(functionLocation);
        if (declarationRequiresScopeChange === void 0) {
          declarationRequiresScopeChange = forEach(functionLocation.parameters, requiresScopeChange) || false;
          setRequiresScopeChangeCache(functionLocation, declarationRequiresScopeChange);
        }
        return !declarationRequiresScopeChange;
      }
    }
    return false;
    function requiresScopeChange(node) {
      return requiresScopeChangeWorker(node.name) || !!node.initializer && requiresScopeChangeWorker(node.initializer);
    }
    function requiresScopeChangeWorker(node) {
      switch (node.kind) {
        case 219 /* ArrowFunction */:
        case 218 /* FunctionExpression */:
        case 262 /* FunctionDeclaration */:
        case 176 /* Constructor */:
          return false;
        case 174 /* MethodDeclaration */:
        case 177 /* GetAccessor */:
        case 178 /* SetAccessor */:
        case 303 /* PropertyAssignment */:
          return requiresScopeChangeWorker(node.name);
        case 172 /* PropertyDeclaration */:
          if (hasStaticModifier(node)) {
            return !emitStandardClassFields;
          }
          return requiresScopeChangeWorker(node.name);
        default:
          if (isNullishCoalesce(node) || isOptionalChain(node)) {
            return target < 7 /* ES2020 */;
          }
          if (isBindingElement(node) && node.dotDotDotToken && isObjectBindingPattern(node.parent)) {
            return target < 4 /* ES2017 */;
          }
          if (isTypeNode(node)) return false;
          return forEachChild(node, requiresScopeChangeWorker) || false;
      }
    }
  }
  function getIsDeferredContext(location, lastLocation) {
    if (location.kind !== 219 /* ArrowFunction */ && location.kind !== 218 /* FunctionExpression */) {
      return isTypeQueryNode(location) || (isFunctionLikeDeclaration(location) || location.kind === 172 /* PropertyDeclaration */ && !isStatic(location)) && (!lastLocation || lastLocation !== location.name);
    }
    if (lastLocation && lastLocation === location.name) {
      return false;
    }
    if (location.asteriskToken || hasSyntacticModifier(location, 1024 /* Async */)) {
      return true;
    }
    return !getImmediatelyInvokedFunctionExpression(location);
  }
  function isSelfReferenceLocation(node, lastLocation) {
    switch (node.kind) {
      case 169 /* Parameter */:
        return !!lastLocation && lastLocation === node.name;
      case 262 /* FunctionDeclaration */:
      case 263 /* ClassDeclaration */:
      case 264 /* InterfaceDeclaration */:
      case 266 /* EnumDeclaration */:
      case 265 /* TypeAliasDeclaration */:
      case 267 /* ModuleDeclaration */:
        return true;
      default:
        return false;
    }
  }
  function isTypeParameterSymbolDeclaredInContainer(symbol, container) {
    if (symbol.declarations) {
      for (const decl of symbol.declarations) {
        if (decl.kind === 168 /* TypeParameter */) {
          const parent2 = isJSDocTemplateTag(decl.parent) ? getJSDocHost(decl.parent) : decl.parent;
          if (parent2 === container) {
            return !(isJSDocTemplateTag(decl.parent) && find(decl.parent.parent.tags, isJSDocTypeAlias));
          }
        }
      }
    }
    return false;
  }
}
function isPrimitiveLiteralValue(node, includeBigInt = true) {
  Debug.type(node);
  switch (node.kind) {
    case 112 /* TrueKeyword */:
    case 97 /* FalseKeyword */:
    case 9 /* NumericLiteral */:
    case 11 /* StringLiteral */:
    case 15 /* NoSubstitutionTemplateLiteral */:
      return true;
    case 10 /* BigIntLiteral */:
      return includeBigInt;
    case 224 /* PrefixUnaryExpression */:
      if (node.operator === 41 /* MinusToken */) {
        return isNumericLiteral(node.operand) || includeBigInt && isBigIntLiteral(node.operand);
      }
      if (node.operator === 40 /* PlusToken */) {
        return isNumericLiteral(node.operand);
      }
      return false;
    default:
      assertType(node);
      return false;
  }
}
function unwrapParenthesizedExpression(o) {
  while (o.kind === 217 /* ParenthesizedExpression */) {
    o = o.expression;
  }
  return o;
}
function hasInferredType(node) {
  Debug.type(node);
  switch (node.kind) {
    case 169 /* Parameter */:
    case 171 /* PropertySignature */:
    case 172 /* PropertyDeclaration */:
    case 208 /* BindingElement */:
    case 211 /* PropertyAccessExpression */:
    case 212 /* ElementAccessExpression */:
    case 226 /* BinaryExpression */:
    case 260 /* VariableDeclaration */:
    case 277 /* ExportAssignment */:
    case 303 /* PropertyAssignment */:
    case 304 /* ShorthandPropertyAssignment */:
    case 341 /* JSDocParameterTag */:
    case 348 /* JSDocPropertyTag */:
      return true;
    default:
      assertType(node);
      return false;
  }
}
function isSideEffectImport(node) {
  const ancestor = findAncestor(node, isImportDeclaration);
  return !!ancestor && !ancestor.importClause;
}
var unprefixedNodeCoreModulesList = [
  "assert",
  "assert/strict",
  "async_hooks",
  "buffer",
  "child_process",
  "cluster",
  "console",
  "constants",
  "crypto",
  "dgram",
  "diagnostics_channel",
  "dns",
  "dns/promises",
  "domain",
  "events",
  "fs",
  "fs/promises",
  "http",
  "http2",
  "https",
  "inspector",
  "inspector/promises",
  "module",
  "net",
  "os",
  "path",
  "path/posix",
  "path/win32",
  "perf_hooks",
  "process",
  "punycode",
  "querystring",
  "readline",
  "readline/promises",
  "repl",
  "stream",
  "stream/consumers",
  "stream/promises",
  "stream/web",
  "string_decoder",
  "sys",
  "test/mock_loader",
  "timers",
  "timers/promises",
  "tls",
  "trace_events",
  "tty",
  "url",
  "util",
  "util/types",
  "v8",
  "vm",
  "wasi",
  "worker_threads",
  "zlib"
];
var unprefixedNodeCoreModules = new Set(unprefixedNodeCoreModulesList);
var exclusivelyPrefixedNodeCoreModules = /* @__PURE__ */ new Set([
  "node:sea",
  "node:sqlite",
  "node:test",
  "node:test/reporters"
]);
var nodeCoreModules = /* @__PURE__ */ new Set([
  ...unprefixedNodeCoreModulesList,
  ...unprefixedNodeCoreModulesList.map((name) => `node:${name}`),
  ...exclusivelyPrefixedNodeCoreModules
]);
function forEachDynamicImportOrRequireCall(file, includeTypeSpaceImports, requireStringLiteralLikeArgument, cb) {
  const isJavaScriptFile = isInJSFile(file);
  const r = /import|require/g;
  while (r.exec(file.text) !== null) {
    const node = getNodeAtPosition(
      file,
      r.lastIndex,
      /*includeJSDoc*/
      includeTypeSpaceImports
    );
    if (isJavaScriptFile && isRequireCall(node, requireStringLiteralLikeArgument)) {
      cb(node, node.arguments[0]);
    } else if (isImportCall(node) && node.arguments.length >= 1 && (!requireStringLiteralLikeArgument || isStringLiteralLike(node.arguments[0]))) {
      cb(node, node.arguments[0]);
    } else if (includeTypeSpaceImports && isLiteralImportTypeNode(node)) {
      cb(node, node.argument.literal);
    } else if (includeTypeSpaceImports && isJSDocImportTag(node)) {
      const moduleNameExpr = getExternalModuleName(node);
      if (moduleNameExpr && isStringLiteral(moduleNameExpr) && moduleNameExpr.text) {
        cb(node, moduleNameExpr);
      }
    }
  }
}
function getNodeAtPosition(sourceFile, position, includeJSDoc) {
  const isJavaScriptFile = isInJSFile(sourceFile);
  let current = sourceFile;
  const getContainingChild = (child) => {
    if (child.pos <= position && (position < child.end || position === child.end && child.kind === 1 /* EndOfFileToken */)) {
      return child;
    }
  };
  while (true) {
    const child = isJavaScriptFile && includeJSDoc && hasJSDocNodes(current) && forEach(current.jsDoc, getContainingChild) || forEachChild(current, getContainingChild);
    if (!child) {
      return current;
    }
    current = child;
  }
}
function isNewScopeNode(node) {
  return isFunctionLike(node) || isJSDocSignature(node) || isMappedTypeNode(node);
}

// src/compiler/factory/baseNodeFactory.ts
function createBaseNodeFactory() {
  let NodeConstructor2;
  let TokenConstructor2;
  let IdentifierConstructor2;
  let PrivateIdentifierConstructor2;
  let SourceFileConstructor2;
  return {
    createBaseSourceFileNode,
    createBaseIdentifierNode,
    createBasePrivateIdentifierNode,
    createBaseTokenNode,
    createBaseNode
  };
  function createBaseSourceFileNode(kind) {
    return new (SourceFileConstructor2 || (SourceFileConstructor2 = objectAllocator.getSourceFileConstructor()))(
      kind,
      /*pos*/
      -1,
      /*end*/
      -1
    );
  }
  function createBaseIdentifierNode(kind) {
    return new (IdentifierConstructor2 || (IdentifierConstructor2 = objectAllocator.getIdentifierConstructor()))(
      kind,
      /*pos*/
      -1,
      /*end*/
      -1
    );
  }
  function createBasePrivateIdentifierNode(kind) {
    return new (PrivateIdentifierConstructor2 || (PrivateIdentifierConstructor2 = objectAllocator.getPrivateIdentifierConstructor()))(
      kind,
      /*pos*/
      -1,
      /*end*/
      -1
    );
  }
  function createBaseTokenNode(kind) {
    return new (TokenConstructor2 || (TokenConstructor2 = objectAllocator.getTokenConstructor()))(
      kind,
      /*pos*/
      -1,
      /*end*/
      -1
    );
  }
  function createBaseNode(kind) {
    return new (NodeConstructor2 || (NodeConstructor2 = objectAllocator.getNodeConstructor()))(
      kind,
      /*pos*/
      -1,
      /*end*/
      -1
    );
  }
}

// src/compiler/factory/parenthesizerRules.ts
function createParenthesizerRules(factory2) {
  let binaryLeftOperandParenthesizerCache;
  let binaryRightOperandParenthesizerCache;
  return {
    getParenthesizeLeftSideOfBinaryForOperator,
    getParenthesizeRightSideOfBinaryForOperator,
    parenthesizeLeftSideOfBinary,
    parenthesizeRightSideOfBinary,
    parenthesizeExpressionOfComputedPropertyName,
    parenthesizeConditionOfConditionalExpression,
    parenthesizeBranchOfConditionalExpression,
    parenthesizeExpressionOfExportDefault,
    parenthesizeExpressionOfNew,
    parenthesizeLeftSideOfAccess,
    parenthesizeOperandOfPostfixUnary,
    parenthesizeOperandOfPrefixUnary,
    parenthesizeExpressionsOfCommaDelimitedList,
    parenthesizeExpressionForDisallowedComma,
    parenthesizeExpressionOfExpressionStatement,
    parenthesizeConciseBodyOfArrowFunction,
    parenthesizeCheckTypeOfConditionalType,
    parenthesizeExtendsTypeOfConditionalType,
    parenthesizeConstituentTypesOfUnionType,
    parenthesizeConstituentTypeOfUnionType,
    parenthesizeConstituentTypesOfIntersectionType,
    parenthesizeConstituentTypeOfIntersectionType,
    parenthesizeOperandOfTypeOperator,
    parenthesizeOperandOfReadonlyTypeOperator,
    parenthesizeNonArrayTypeOfPostfixType,
    parenthesizeElementTypesOfTupleType,
    parenthesizeElementTypeOfTupleType,
    parenthesizeTypeOfOptionalType,
    parenthesizeTypeArguments,
    parenthesizeLeadingTypeArgument
  };
  function getParenthesizeLeftSideOfBinaryForOperator(operatorKind) {
    binaryLeftOperandParenthesizerCache || (binaryLeftOperandParenthesizerCache = /* @__PURE__ */ new Map());
    let parenthesizerRule = binaryLeftOperandParenthesizerCache.get(operatorKind);
    if (!parenthesizerRule) {
      parenthesizerRule = (node) => parenthesizeLeftSideOfBinary(operatorKind, node);
      binaryLeftOperandParenthesizerCache.set(operatorKind, parenthesizerRule);
    }
    return parenthesizerRule;
  }
  function getParenthesizeRightSideOfBinaryForOperator(operatorKind) {
    binaryRightOperandParenthesizerCache || (binaryRightOperandParenthesizerCache = /* @__PURE__ */ new Map());
    let parenthesizerRule = binaryRightOperandParenthesizerCache.get(operatorKind);
    if (!parenthesizerRule) {
      parenthesizerRule = (node) => parenthesizeRightSideOfBinary(
        operatorKind,
        /*leftSide*/
        void 0,
        node
      );
      binaryRightOperandParenthesizerCache.set(operatorKind, parenthesizerRule);
    }
    return parenthesizerRule;
  }
  function binaryOperandNeedsParentheses(binaryOperator, operand, isLeftSideOfBinary, leftOperand) {
    const binaryOperatorPrecedence = getOperatorPrecedence(226 /* BinaryExpression */, binaryOperator);
    const binaryOperatorAssociativity = getOperatorAssociativity(226 /* BinaryExpression */, binaryOperator);
    const emittedOperand = skipPartiallyEmittedExpressions(operand);
    if (!isLeftSideOfBinary && operand.kind === 219 /* ArrowFunction */ && binaryOperatorPrecedence > 3 /* Assignment */) {
      return true;
    }
    const operandPrecedence = getExpressionPrecedence(emittedOperand);
    switch (compareValues(operandPrecedence, binaryOperatorPrecedence)) {
      case -1 /* LessThan */:
        if (!isLeftSideOfBinary && binaryOperatorAssociativity === 1 /* Right */ && operand.kind === 229 /* YieldExpression */) {
          return false;
        }
        return true;
      case 1 /* GreaterThan */:
        return false;
      case 0 /* EqualTo */:
        if (isLeftSideOfBinary) {
          return binaryOperatorAssociativity === 1 /* Right */;
        } else {
          if (isBinaryExpression(emittedOperand) && emittedOperand.operatorToken.kind === binaryOperator) {
            if (operatorHasAssociativeProperty(binaryOperator)) {
              return false;
            }
            if (binaryOperator === 40 /* PlusToken */) {
              const leftKind = leftOperand ? getLiteralKindOfBinaryPlusOperand(leftOperand) : 0 /* Unknown */;
              if (isLiteralKind(leftKind) && leftKind === getLiteralKindOfBinaryPlusOperand(emittedOperand)) {
                return false;
              }
            }
          }
          const operandAssociativity = getExpressionAssociativity(emittedOperand);
          return operandAssociativity === 0 /* Left */;
        }
    }
  }
  function operatorHasAssociativeProperty(binaryOperator) {
    return binaryOperator === 42 /* AsteriskToken */ || binaryOperator === 52 /* BarToken */ || binaryOperator === 51 /* AmpersandToken */ || binaryOperator === 53 /* CaretToken */ || binaryOperator === 28 /* CommaToken */;
  }
  function getLiteralKindOfBinaryPlusOperand(node) {
    node = skipPartiallyEmittedExpressions(node);
    if (isLiteralKind(node.kind)) {
      return node.kind;
    }
    if (node.kind === 226 /* BinaryExpression */ && node.operatorToken.kind === 40 /* PlusToken */) {
      if (node.cachedLiteralKind !== void 0) {
        return node.cachedLiteralKind;
      }
      const leftKind = getLiteralKindOfBinaryPlusOperand(node.left);
      const literalKind = isLiteralKind(leftKind) && leftKind === getLiteralKindOfBinaryPlusOperand(node.right) ? leftKind : 0 /* Unknown */;
      node.cachedLiteralKind = literalKind;
      return literalKind;
    }
    return 0 /* Unknown */;
  }
  function parenthesizeBinaryOperand(binaryOperator, operand, isLeftSideOfBinary, leftOperand) {
    const skipped = skipPartiallyEmittedExpressions(operand);
    if (skipped.kind === 217 /* ParenthesizedExpression */) {
      return operand;
    }
    return binaryOperandNeedsParentheses(binaryOperator, operand, isLeftSideOfBinary, leftOperand) ? factory2.createParenthesizedExpression(operand) : operand;
  }
  function parenthesizeLeftSideOfBinary(binaryOperator, leftSide) {
    return parenthesizeBinaryOperand(
      binaryOperator,
      leftSide,
      /*isLeftSideOfBinary*/
      true
    );
  }
  function parenthesizeRightSideOfBinary(binaryOperator, leftSide, rightSide) {
    return parenthesizeBinaryOperand(
      binaryOperator,
      rightSide,
      /*isLeftSideOfBinary*/
      false,
      leftSide
    );
  }
  function parenthesizeExpressionOfComputedPropertyName(expression) {
    return isCommaSequence(expression) ? factory2.createParenthesizedExpression(expression) : expression;
  }
  function parenthesizeConditionOfConditionalExpression(condition) {
    const conditionalPrecedence = getOperatorPrecedence(227 /* ConditionalExpression */, 58 /* QuestionToken */);
    const emittedCondition = skipPartiallyEmittedExpressions(condition);
    const conditionPrecedence = getExpressionPrecedence(emittedCondition);
    if (compareValues(conditionPrecedence, conditionalPrecedence) !== 1 /* GreaterThan */) {
      return factory2.createParenthesizedExpression(condition);
    }
    return condition;
  }
  function parenthesizeBranchOfConditionalExpression(branch) {
    const emittedExpression = skipPartiallyEmittedExpressions(branch);
    return isCommaSequence(emittedExpression) ? factory2.createParenthesizedExpression(branch) : branch;
  }
  function parenthesizeExpressionOfExportDefault(expression) {
    const check = skipPartiallyEmittedExpressions(expression);
    let needsParens = isCommaSequence(check);
    if (!needsParens) {
      switch (getLeftmostExpression(
        check,
        /*stopAtCallExpressions*/
        false
      ).kind) {
        case 231 /* ClassExpression */:
        case 218 /* FunctionExpression */:
          needsParens = true;
      }
    }
    return needsParens ? factory2.createParenthesizedExpression(expression) : expression;
  }
  function parenthesizeExpressionOfNew(expression) {
    const leftmostExpr = getLeftmostExpression(
      expression,
      /*stopAtCallExpressions*/
      true
    );
    switch (leftmostExpr.kind) {
      case 213 /* CallExpression */:
        return factory2.createParenthesizedExpression(expression);
      case 214 /* NewExpression */:
        return !leftmostExpr.arguments ? factory2.createParenthesizedExpression(expression) : expression;
    }
    return parenthesizeLeftSideOfAccess(expression);
  }
  function parenthesizeLeftSideOfAccess(expression, optionalChain) {
    const emittedExpression = skipPartiallyEmittedExpressions(expression);
    if (isLeftHandSideExpression(emittedExpression) && (emittedExpression.kind !== 214 /* NewExpression */ || emittedExpression.arguments) && (optionalChain || !isOptionalChain(emittedExpression))) {
      return expression;
    }
    return setTextRange(factory2.createParenthesizedExpression(expression), expression);
  }
  function parenthesizeOperandOfPostfixUnary(operand) {
    return isLeftHandSideExpression(operand) ? operand : setTextRange(factory2.createParenthesizedExpression(operand), operand);
  }
  function parenthesizeOperandOfPrefixUnary(operand) {
    return isUnaryExpression(operand) ? operand : setTextRange(factory2.createParenthesizedExpression(operand), operand);
  }
  function parenthesizeExpressionsOfCommaDelimitedList(elements) {
    const result = sameMap(elements, parenthesizeExpressionForDisallowedComma);
    return setTextRange(factory2.createNodeArray(result, elements.hasTrailingComma), elements);
  }
  function parenthesizeExpressionForDisallowedComma(expression) {
    const emittedExpression = skipPartiallyEmittedExpressions(expression);
    const expressionPrecedence = getExpressionPrecedence(emittedExpression);
    const commaPrecedence = getOperatorPrecedence(226 /* BinaryExpression */, 28 /* CommaToken */);
    return expressionPrecedence > commaPrecedence ? expression : setTextRange(factory2.createParenthesizedExpression(expression), expression);
  }
  function parenthesizeExpressionOfExpressionStatement(expression) {
    const emittedExpression = skipPartiallyEmittedExpressions(expression);
    if (isCallExpression(emittedExpression)) {
      const callee = emittedExpression.expression;
      const kind = skipPartiallyEmittedExpressions(callee).kind;
      if (kind === 218 /* FunctionExpression */ || kind === 219 /* ArrowFunction */) {
        const updated = factory2.updateCallExpression(
          emittedExpression,
          setTextRange(factory2.createParenthesizedExpression(callee), callee),
          emittedExpression.typeArguments,
          emittedExpression.arguments
        );
        return factory2.restoreOuterExpressions(expression, updated, 8 /* PartiallyEmittedExpressions */);
      }
    }
    const leftmostExpressionKind = getLeftmostExpression(
      emittedExpression,
      /*stopAtCallExpressions*/
      false
    ).kind;
    if (leftmostExpressionKind === 210 /* ObjectLiteralExpression */ || leftmostExpressionKind === 218 /* FunctionExpression */) {
      return setTextRange(factory2.createParenthesizedExpression(expression), expression);
    }
    return expression;
  }
  function parenthesizeConciseBodyOfArrowFunction(body) {
    if (!isBlock(body) && (isCommaSequence(body) || getLeftmostExpression(
      body,
      /*stopAtCallExpressions*/
      false
    ).kind === 210 /* ObjectLiteralExpression */)) {
      return setTextRange(factory2.createParenthesizedExpression(body), body);
    }
    return body;
  }
  function parenthesizeCheckTypeOfConditionalType(checkType) {
    switch (checkType.kind) {
      case 184 /* FunctionType */:
      case 185 /* ConstructorType */:
      case 194 /* ConditionalType */:
        return factory2.createParenthesizedType(checkType);
    }
    return checkType;
  }
  function parenthesizeExtendsTypeOfConditionalType(extendsType) {
    switch (extendsType.kind) {
      case 194 /* ConditionalType */:
        return factory2.createParenthesizedType(extendsType);
    }
    return extendsType;
  }
  function parenthesizeConstituentTypeOfUnionType(type) {
    switch (type.kind) {
      case 192 /* UnionType */:
      // Not strictly necessary, but a union containing a union should have been flattened
      case 193 /* IntersectionType */:
        return factory2.createParenthesizedType(type);
    }
    return parenthesizeCheckTypeOfConditionalType(type);
  }
  function parenthesizeConstituentTypesOfUnionType(members) {
    return factory2.createNodeArray(sameMap(members, parenthesizeConstituentTypeOfUnionType));
  }
  function parenthesizeConstituentTypeOfIntersectionType(type) {
    switch (type.kind) {
      case 192 /* UnionType */:
      case 193 /* IntersectionType */:
        return factory2.createParenthesizedType(type);
    }
    return parenthesizeConstituentTypeOfUnionType(type);
  }
  function parenthesizeConstituentTypesOfIntersectionType(members) {
    return factory2.createNodeArray(sameMap(members, parenthesizeConstituentTypeOfIntersectionType));
  }
  function parenthesizeOperandOfTypeOperator(type) {
    switch (type.kind) {
      case 193 /* IntersectionType */:
        return factory2.createParenthesizedType(type);
    }
    return parenthesizeConstituentTypeOfIntersectionType(type);
  }
  function parenthesizeOperandOfReadonlyTypeOperator(type) {
    switch (type.kind) {
      case 198 /* TypeOperator */:
        return factory2.createParenthesizedType(type);
    }
    return parenthesizeOperandOfTypeOperator(type);
  }
  function parenthesizeNonArrayTypeOfPostfixType(type) {
    switch (type.kind) {
      case 195 /* InferType */:
      case 198 /* TypeOperator */:
      case 186 /* TypeQuery */:
        return factory2.createParenthesizedType(type);
    }
    return parenthesizeOperandOfTypeOperator(type);
  }
  function parenthesizeElementTypesOfTupleType(types) {
    return factory2.createNodeArray(sameMap(types, parenthesizeElementTypeOfTupleType));
  }
  function parenthesizeElementTypeOfTupleType(type) {
    if (hasJSDocPostfixQuestion(type)) return factory2.createParenthesizedType(type);
    return type;
  }
  function hasJSDocPostfixQuestion(type) {
    if (isJSDocNullableType(type)) return type.postfix;
    if (isNamedTupleMember(type)) return hasJSDocPostfixQuestion(type.type);
    if (isFunctionTypeNode(type) || isConstructorTypeNode(type) || isTypeOperatorNode(type)) return hasJSDocPostfixQuestion(type.type);
    if (isConditionalTypeNode(type)) return hasJSDocPostfixQuestion(type.falseType);
    if (isUnionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.types));
    if (isIntersectionTypeNode(type)) return hasJSDocPostfixQuestion(last(type.types));
    if (isInferTypeNode(type)) return !!type.typeParameter.constraint && hasJSDocPostfixQuestion(type.typeParameter.constraint);
    return false;
  }
  function parenthesizeTypeOfOptionalType(type) {
    if (hasJSDocPostfixQuestion(type)) return factory2.createParenthesizedType(type);
    return parenthesizeNonArrayTypeOfPostfixType(type);
  }
  function parenthesizeLeadingTypeArgument(node) {
    return isFunctionOrConstructorTypeNode(node) && node.typeParameters ? factory2.createParenthesizedType(node) : node;
  }
  function parenthesizeOrdinalTypeArgument(node, i) {
    return i === 0 ? parenthesizeLeadingTypeArgument(node) : node;
  }
  function parenthesizeTypeArguments(typeArguments) {
    if (some(typeArguments)) {
      return factory2.createNodeArray(sameMap(typeArguments, parenthesizeOrdinalTypeArgument));
    }
  }
}
var nullParenthesizerRules = {
  getParenthesizeLeftSideOfBinaryForOperator: (_) => identity,
  getParenthesizeRightSideOfBinaryForOperator: (_) => identity,
  parenthesizeLeftSideOfBinary: (_binaryOperator, leftSide) => leftSide,
  parenthesizeRightSideOfBinary: (_binaryOperator, _leftSide, rightSide) => rightSide,
  parenthesizeExpressionOfComputedPropertyName: identity,
  parenthesizeConditionOfConditionalExpression: identity,
  parenthesizeBranchOfConditionalExpression: identity,
  parenthesizeExpressionOfExportDefault: identity,
  parenthesizeExpressionOfNew: (expression) => cast(expression, isLeftHandSideExpression),
  parenthesizeLeftSideOfAccess: (expression) => cast(expression, isLeftHandSideExpression),
  parenthesizeOperandOfPostfixUnary: (operand) => cast(operand, isLeftHandSideExpression),
  parenthesizeOperandOfPrefixUnary: (operand) => cast(operand, isUnaryExpression),
  parenthesizeExpressionsOfCommaDelimitedList: (nodes) => cast(nodes, isNodeArray),
  parenthesizeExpressionForDisallowedComma: identity,
  parenthesizeExpressionOfExpressionStatement: identity,
  parenthesizeConciseBodyOfArrowFunction: identity,
  parenthesizeCheckTypeOfConditionalType: identity,
  parenthesizeExtendsTypeOfConditionalType: identity,
  parenthesizeConstituentTypesOfUnionType: (nodes) => cast(nodes, isNodeArray),
  parenthesizeConstituentTypeOfUnionType: identity,
  parenthesizeConstituentTypesOfIntersectionType: (nodes) => cast(nodes, isNodeArray),
  parenthesizeConstituentTypeOfIntersectionType: identity,
  parenthesizeOperandOfTypeOperator: identity,
  parenthesizeOperandOfReadonlyTypeOperator: identity,
  parenthesizeNonArrayTypeOfPostfixType: identity,
  parenthesizeElementTypesOfTupleType: (nodes) => cast(nodes, isNodeArray),
  parenthesizeElementTypeOfTupleType: identity,
  parenthesizeTypeOfOptionalType: identity,
  parenthesizeTypeArguments: (nodes) => nodes && cast(nodes, isNodeArray),
  parenthesizeLeadingTypeArgument: identity
};

// src/compiler/factory/nodeConverters.ts
function createNodeConverters(factory2) {
  return {
    convertToFunctionBlock,
    convertToFunctionExpression,
    convertToClassExpression,
    convertToArrayAssignmentElement,
    convertToObjectAssignmentElement,
    convertToAssignmentPattern,
    convertToObjectAssignmentPattern,
    convertToArrayAssignmentPattern,
    convertToAssignmentElementTarget
  };
  function convertToFunctionBlock(node, multiLine) {
    if (isBlock(node)) return node;
    const returnStatement = factory2.createReturnStatement(node);
    setTextRange(returnStatement, node);
    const body = factory2.createBlock([returnStatement], multiLine);
    setTextRange(body, node);
    return body;
  }
  function convertToFunctionExpression(node) {
    var _a;
    if (!node.body) return Debug.fail(`Cannot convert a FunctionDeclaration without a body`);
    const updated = factory2.createFunctionExpression(
      (_a = getModifiers(node)) == null ? void 0 : _a.filter((modifier) => !isExportModifier(modifier) && !isDefaultModifier(modifier)),
      node.asteriskToken,
      node.name,
      node.typeParameters,
      node.parameters,
      node.type,
      node.body
    );
    setOriginalNode(updated, node);
    setTextRange(updated, node);
    if (getStartsOnNewLine(node)) {
      setStartsOnNewLine(
        updated,
        /*newLine*/
        true
      );
    }
    return updated;
  }
  function convertToClassExpression(node) {
    var _a;
    const updated = factory2.createClassExpression(
      (_a = node.modifiers) == null ? void 0 : _a.filter((modifier) => !isExportModifier(modifier) && !isDefaultModifier(modifier)),
      node.name,
      node.typeParameters,
      node.heritageClauses,
      node.members
    );
    setOriginalNode(updated, node);
    setTextRange(updated, node);
    if (getStartsOnNewLine(node)) {
      setStartsOnNewLine(
        updated,
        /*newLine*/
        true
      );
    }
    return updated;
  }
  function convertToArrayAssignmentElement(element) {
    if (isBindingElement(element)) {
      if (element.dotDotDotToken) {
        Debug.assertNode(element.name, isIdentifier);
        return setOriginalNode(setTextRange(factory2.createSpreadElement(element.name), element), element);
      }
      const expression = convertToAssignmentElementTarget(element.name);
      return element.initializer ? setOriginalNode(
        setTextRange(
          factory2.createAssignment(expression, element.initializer),
          element
        ),
        element
      ) : expression;
    }
    return cast(element, isExpression);
  }
  function convertToObjectAssignmentElement(element) {
    if (isBindingElement(element)) {
      if (element.dotDotDotToken) {
        Debug.assertNode(element.name, isIdentifier);
        return setOriginalNode(setTextRange(factory2.createSpreadAssignment(element.name), element), element);
      }
      if (element.propertyName) {
        const expression = convertToAssignmentElementTarget(element.name);
        return setOriginalNode(setTextRange(factory2.createPropertyAssignment(element.propertyName, element.initializer ? factory2.createAssignment(expression, element.initializer) : expression), element), element);
      }
      Debug.assertNode(element.name, isIdentifier);
      return setOriginalNode(setTextRange(factory2.createShorthandPropertyAssignment(element.name, element.initializer), element), element);
    }
    return cast(element, isObjectLiteralElementLike);
  }
  function convertToAssignmentPattern(node) {
    switch (node.kind) {
      case 207 /* ArrayBindingPattern */:
      case 209 /* ArrayLiteralExpression */:
        return convertToArrayAssignmentPattern(node);
      case 206 /* ObjectBindingPattern */:
      case 210 /* ObjectLiteralExpression */:
        return convertToObjectAssignmentPattern(node);
    }
  }
  function convertToObjectAssignmentPattern(node) {
    if (isObjectBindingPattern(node)) {
      return setOriginalNode(
        setTextRange(
          factory2.createObjectLiteralExpression(map(node.elements, convertToObjectAssignmentElement)),
          node
        ),
        node
      );
    }
    return cast(node, isObjectLiteralExpression);
  }
  function convertToArrayAssignmentPattern(node) {
    if (isArrayBindingPattern(node)) {
      return setOriginalNode(
        setTextRange(
          factory2.createArrayLiteralExpression(map(node.elements, convertToArrayAssignmentElement)),
          node
        ),
        node
      );
    }
    return cast(node, isArrayLiteralExpression);
  }
  function convertToAssignmentElementTarget(node) {
    if (isBindingPattern(node)) {
      return convertToAssignmentPattern(node);
    }
    return cast(node, isExpression);
  }
}
var nullNodeConverters = {
  convertToFunctionBlock: notImplemented,
  convertToFunctionExpression: notImplemented,
  convertToClassExpression: notImplemented,
  convertToArrayAssignmentElement: notImplemented,
  convertToObjectAssignmentElement: notImplemented,
  convertToAssignmentPattern: notImplemented,
  convertToObjectAssignmentPattern: notImplemented,
  convertToArrayAssignmentPattern: notImplemented,
  convertToAssignmentElementTarget: notImplemented
};

// src/compiler/factory/nodeFactory.ts
var nextAutoGenerateId = 0;
var NodeFactoryFlags = /* @__PURE__ */ ((NodeFactoryFlags2) => {
  NodeFactoryFlags2[NodeFactoryFlags2["None"] = 0] = "None";
  NodeFactoryFlags2[NodeFactoryFlags2["NoParenthesizerRules"] = 1] = "NoParenthesizerRules";
  NodeFactoryFlags2[NodeFactoryFlags2["NoNodeConverters"] = 2] = "NoNodeConverters";
  NodeFactoryFlags2[NodeFactoryFlags2["NoIndentationOnFreshPropertyAccess"] = 4] = "NoIndentationOnFreshPropertyAccess";
  NodeFactoryFlags2[NodeFactoryFlags2["NoOriginalNode"] = 8] = "NoOriginalNode";
  return NodeFactoryFlags2;
})(NodeFactoryFlags || {});
var nodeFactoryPatchers = [];
function addNodeFactoryPatcher(fn) {
  nodeFactoryPatchers.push(fn);
}
function createNodeFactory(flags, baseFactory2) {
  const setOriginal = flags & 8 /* NoOriginalNode */ ? identity : setOriginalNode;
  const parenthesizerRules = memoize(() => flags & 1 /* NoParenthesizerRules */ ? nullParenthesizerRules : createParenthesizerRules(factory2));
  const converters = memoize(() => flags & 2 /* NoNodeConverters */ ? nullNodeConverters : createNodeConverters(factory2));
  const getBinaryCreateFunction = memoizeOne((operator) => (left, right) => createBinaryExpression(left, operator, right));
  const getPrefixUnaryCreateFunction = memoizeOne((operator) => (operand) => createPrefixUnaryExpression(operator, operand));
  const getPostfixUnaryCreateFunction = memoizeOne((operator) => (operand) => createPostfixUnaryExpression(operand, operator));
  const getJSDocPrimaryTypeCreateFunction = memoizeOne((kind) => () => createJSDocPrimaryTypeWorker(kind));
  const getJSDocUnaryTypeCreateFunction = memoizeOne((kind) => (type) => createJSDocUnaryTypeWorker(kind, type));
  const getJSDocUnaryTypeUpdateFunction = memoizeOne((kind) => (node, type) => updateJSDocUnaryTypeWorker(kind, node, type));
  const getJSDocPrePostfixUnaryTypeCreateFunction = memoizeOne((kind) => (type, postfix) => createJSDocPrePostfixUnaryTypeWorker(kind, type, postfix));
  const getJSDocPrePostfixUnaryTypeUpdateFunction = memoizeOne((kind) => (node, type) => updateJSDocPrePostfixUnaryTypeWorker(kind, node, type));
  const getJSDocSimpleTagCreateFunction = memoizeOne((kind) => (tagName, comment) => createJSDocSimpleTagWorker(kind, tagName, comment));
  const getJSDocSimpleTagUpdateFunction = memoizeOne((kind) => (node, tagName, comment) => updateJSDocSimpleTagWorker(kind, node, tagName, comment));
  const getJSDocTypeLikeTagCreateFunction = memoizeOne((kind) => (tagName, typeExpression, comment) => createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment));
  const getJSDocTypeLikeTagUpdateFunction = memoizeOne((kind) => (node, tagName, typeExpression, comment) => updateJSDocTypeLikeTagWorker(kind, node, tagName, typeExpression, comment));
  const factory2 = {
    get parenthesizer() {
      return parenthesizerRules();
    },
    get converters() {
      return converters();
    },
    baseFactory: baseFactory2,
    flags,
    createNodeArray,
    createNumericLiteral,
    createBigIntLiteral,
    createStringLiteral,
    createStringLiteralFromNode,
    createRegularExpressionLiteral,
    createLiteralLikeNode,
    createIdentifier,
    createTempVariable,
    createLoopVariable,
    createUniqueName,
    getGeneratedNameForNode,
    createPrivateIdentifier,
    createUniquePrivateName,
    getGeneratedPrivateNameForNode,
    createToken,
    createSuper,
    createThis,
    createNull,
    createTrue,
    createFalse,
    createModifier,
    createModifiersFromModifierFlags,
    createQualifiedName,
    updateQualifiedName,
    createComputedPropertyName,
    updateComputedPropertyName,
    createTypeParameterDeclaration,
    updateTypeParameterDeclaration,
    createParameterDeclaration,
    updateParameterDeclaration,
    createDecorator,
    updateDecorator,
    createPropertySignature,
    updatePropertySignature,
    createPropertyDeclaration,
    updatePropertyDeclaration: updatePropertyDeclaration2,
    createMethodSignature,
    updateMethodSignature,
    createMethodDeclaration,
    updateMethodDeclaration,
    createConstructorDeclaration,
    updateConstructorDeclaration,
    createGetAccessorDeclaration,
    updateGetAccessorDeclaration,
    createSetAccessorDeclaration,
    updateSetAccessorDeclaration,
    createCallSignature,
    updateCallSignature,
    createConstructSignature,
    updateConstructSignature,
    createIndexSignature,
    updateIndexSignature,
    createClassStaticBlockDeclaration,
    updateClassStaticBlockDeclaration,
    createTemplateLiteralTypeSpan,
    updateTemplateLiteralTypeSpan,
    createKeywordTypeNode,
    createTypePredicateNode,
    updateTypePredicateNode,
    createTypeReferenceNode,
    updateTypeReferenceNode,
    createFunctionTypeNode,
    updateFunctionTypeNode,
    createConstructorTypeNode,
    updateConstructorTypeNode,
    createTypeQueryNode,
    updateTypeQueryNode,
    createTypeLiteralNode,
    updateTypeLiteralNode,
    createArrayTypeNode,
    updateArrayTypeNode,
    createTupleTypeNode,
    updateTupleTypeNode,
    createNamedTupleMember,
    updateNamedTupleMember,
    createOptionalTypeNode,
    updateOptionalTypeNode,
    createRestTypeNode,
    updateRestTypeNode,
    createUnionTypeNode,
    updateUnionTypeNode,
    createIntersectionTypeNode,
    updateIntersectionTypeNode,
    createConditionalTypeNode,
    updateConditionalTypeNode,
    createInferTypeNode,
    updateInferTypeNode,
    createImportTypeNode,
    updateImportTypeNode,
    createParenthesizedType,
    updateParenthesizedType,
    createThisTypeNode,
    createTypeOperatorNode,
    updateTypeOperatorNode,
    createIndexedAccessTypeNode,
    updateIndexedAccessTypeNode,
    createMappedTypeNode,
    updateMappedTypeNode,
    createLiteralTypeNode,
    updateLiteralTypeNode,
    createTemplateLiteralType,
    updateTemplateLiteralType,
    createObjectBindingPattern,
    updateObjectBindingPattern,
    createArrayBindingPattern,
    updateArrayBindingPattern,
    createBindingElement,
    updateBindingElement,
    createArrayLiteralExpression,
    updateArrayLiteralExpression,
    createObjectLiteralExpression,
    updateObjectLiteralExpression,
    createPropertyAccessExpression: flags & 4 /* NoIndentationOnFreshPropertyAccess */ ? (expression, name) => setEmitFlags(createPropertyAccessExpression(expression, name), 262144 /* NoIndentation */) : createPropertyAccessExpression,
    updatePropertyAccessExpression,
    createPropertyAccessChain: flags & 4 /* NoIndentationOnFreshPropertyAccess */ ? (expression, questionDotToken, name) => setEmitFlags(createPropertyAccessChain(expression, questionDotToken, name), 262144 /* NoIndentation */) : createPropertyAccessChain,
    updatePropertyAccessChain,
    createElementAccessExpression,
    updateElementAccessExpression,
    createElementAccessChain,
    updateElementAccessChain,
    createCallExpression,
    updateCallExpression,
    createCallChain,
    updateCallChain,
    createNewExpression,
    updateNewExpression,
    createTaggedTemplateExpression,
    updateTaggedTemplateExpression,
    createTypeAssertion,
    updateTypeAssertion,
    createParenthesizedExpression,
    updateParenthesizedExpression,
    createFunctionExpression,
    updateFunctionExpression,
    createArrowFunction,
    updateArrowFunction,
    createDeleteExpression,
    updateDeleteExpression,
    createTypeOfExpression,
    updateTypeOfExpression,
    createVoidExpression,
    updateVoidExpression,
    createAwaitExpression,
    updateAwaitExpression,
    createPrefixUnaryExpression,
    updatePrefixUnaryExpression,
    createPostfixUnaryExpression,
    updatePostfixUnaryExpression,
    createBinaryExpression,
    updateBinaryExpression,
    createConditionalExpression,
    updateConditionalExpression,
    createTemplateExpression,
    updateTemplateExpression,
    createTemplateHead,
    createTemplateMiddle,
    createTemplateTail,
    createNoSubstitutionTemplateLiteral,
    createTemplateLiteralLikeNode,
    createYieldExpression,
    updateYieldExpression,
    createSpreadElement,
    updateSpreadElement,
    createClassExpression,
    updateClassExpression,
    createOmittedExpression,
    createExpressionWithTypeArguments,
    updateExpressionWithTypeArguments,
    createAsExpression,
    updateAsExpression,
    createNonNullExpression,
    updateNonNullExpression,
    createSatisfiesExpression,
    updateSatisfiesExpression,
    createNonNullChain,
    updateNonNullChain,
    createMetaProperty,
    updateMetaProperty,
    createTemplateSpan,
    updateTemplateSpan,
    createSemicolonClassElement,
    createBlock,
    updateBlock,
    createVariableStatement,
    updateVariableStatement,
    createEmptyStatement,
    createExpressionStatement,
    updateExpressionStatement,
    createIfStatement,
    updateIfStatement,
    createDoStatement,
    updateDoStatement,
    createWhileStatement,
    updateWhileStatement,
    createForStatement,
    updateForStatement,
    createForInStatement,
    updateForInStatement,
    createForOfStatement,
    updateForOfStatement,
    createContinueStatement,
    updateContinueStatement,
    createBreakStatement,
    updateBreakStatement,
    createReturnStatement,
    updateReturnStatement,
    createWithStatement,
    updateWithStatement,
    createSwitchStatement,
    updateSwitchStatement,
    createLabeledStatement,
    updateLabeledStatement,
    createThrowStatement,
    updateThrowStatement,
    createTryStatement,
    updateTryStatement,
    createDebuggerStatement,
    createVariableDeclaration,
    updateVariableDeclaration,
    createVariableDeclarationList,
    updateVariableDeclarationList,
    createFunctionDeclaration,
    updateFunctionDeclaration,
    createClassDeclaration,
    updateClassDeclaration,
    createInterfaceDeclaration,
    updateInterfaceDeclaration,
    createTypeAliasDeclaration,
    updateTypeAliasDeclaration,
    createEnumDeclaration,
    updateEnumDeclaration,
    createModuleDeclaration,
    updateModuleDeclaration,
    createModuleBlock,
    updateModuleBlock,
    createCaseBlock,
    updateCaseBlock,
    createNamespaceExportDeclaration,
    updateNamespaceExportDeclaration,
    createImportEqualsDeclaration,
    updateImportEqualsDeclaration,
    createImportDeclaration,
    updateImportDeclaration,
    createImportClause: createImportClause2,
    updateImportClause,
    createAssertClause,
    updateAssertClause,
    createAssertEntry,
    updateAssertEntry,
    createImportTypeAssertionContainer,
    updateImportTypeAssertionContainer,
    createImportAttributes,
    updateImportAttributes,
    createImportAttribute,
    updateImportAttribute,
    createNamespaceImport,
    updateNamespaceImport,
    createNamespaceExport,
    updateNamespaceExport,
    createNamedImports,
    updateNamedImports,
    createImportSpecifier,
    updateImportSpecifier,
    createExportAssignment: createExportAssignment2,
    updateExportAssignment,
    createExportDeclaration,
    updateExportDeclaration,
    createNamedExports,
    updateNamedExports,
    createExportSpecifier,
    updateExportSpecifier,
    createMissingDeclaration,
    createExternalModuleReference,
    updateExternalModuleReference,
    // lazily load factory members for JSDoc types with similar structure
    get createJSDocAllType() {
      return getJSDocPrimaryTypeCreateFunction(312 /* JSDocAllType */);
    },
    get createJSDocUnknownType() {
      return getJSDocPrimaryTypeCreateFunction(313 /* JSDocUnknownType */);
    },
    get createJSDocNonNullableType() {
      return getJSDocPrePostfixUnaryTypeCreateFunction(315 /* JSDocNonNullableType */);
    },
    get updateJSDocNonNullableType() {
      return getJSDocPrePostfixUnaryTypeUpdateFunction(315 /* JSDocNonNullableType */);
    },
    get createJSDocNullableType() {
      return getJSDocPrePostfixUnaryTypeCreateFunction(314 /* JSDocNullableType */);
    },
    get updateJSDocNullableType() {
      return getJSDocPrePostfixUnaryTypeUpdateFunction(314 /* JSDocNullableType */);
    },
    get createJSDocOptionalType() {
      return getJSDocUnaryTypeCreateFunction(316 /* JSDocOptionalType */);
    },
    get updateJSDocOptionalType() {
      return getJSDocUnaryTypeUpdateFunction(316 /* JSDocOptionalType */);
    },
    get createJSDocVariadicType() {
      return getJSDocUnaryTypeCreateFunction(318 /* JSDocVariadicType */);
    },
    get updateJSDocVariadicType() {
      return getJSDocUnaryTypeUpdateFunction(318 /* JSDocVariadicType */);
    },
    get createJSDocNamepathType() {
      return getJSDocUnaryTypeCreateFunction(319 /* JSDocNamepathType */);
    },
    get updateJSDocNamepathType() {
      return getJSDocUnaryTypeUpdateFunction(319 /* JSDocNamepathType */);
    },
    createJSDocFunctionType,
    updateJSDocFunctionType,
    createJSDocTypeLiteral,
    updateJSDocTypeLiteral,
    createJSDocTypeExpression,
    updateJSDocTypeExpression,
    createJSDocSignature,
    updateJSDocSignature,
    createJSDocTemplateTag,
    updateJSDocTemplateTag,
    createJSDocTypedefTag,
    updateJSDocTypedefTag,
    createJSDocParameterTag,
    updateJSDocParameterTag,
    createJSDocPropertyTag,
    updateJSDocPropertyTag,
    createJSDocCallbackTag,
    updateJSDocCallbackTag,
    createJSDocOverloadTag,
    updateJSDocOverloadTag,
    createJSDocAugmentsTag,
    updateJSDocAugmentsTag,
    createJSDocImplementsTag,
    updateJSDocImplementsTag,
    createJSDocSeeTag,
    updateJSDocSeeTag,
    createJSDocImportTag,
    updateJSDocImportTag,
    createJSDocNameReference,
    updateJSDocNameReference,
    createJSDocMemberName,
    updateJSDocMemberName,
    createJSDocLink,
    updateJSDocLink,
    createJSDocLinkCode,
    updateJSDocLinkCode,
    createJSDocLinkPlain,
    updateJSDocLinkPlain,
    // lazily load factory members for JSDoc tags with similar structure
    get createJSDocTypeTag() {
      return getJSDocTypeLikeTagCreateFunction(344 /* JSDocTypeTag */);
    },
    get updateJSDocTypeTag() {
      return getJSDocTypeLikeTagUpdateFunction(344 /* JSDocTypeTag */);
    },
    get createJSDocReturnTag() {
      return getJSDocTypeLikeTagCreateFunction(342 /* JSDocReturnTag */);
    },
    get updateJSDocReturnTag() {
      return getJSDocTypeLikeTagUpdateFunction(342 /* JSDocReturnTag */);
    },
    get createJSDocThisTag() {
      return getJSDocTypeLikeTagCreateFunction(343 /* JSDocThisTag */);
    },
    get updateJSDocThisTag() {
      return getJSDocTypeLikeTagUpdateFunction(343 /* JSDocThisTag */);
    },
    get createJSDocAuthorTag() {
      return getJSDocSimpleTagCreateFunction(330 /* JSDocAuthorTag */);
    },
    get updateJSDocAuthorTag() {
      return getJSDocSimpleTagUpdateFunction(330 /* JSDocAuthorTag */);
    },
    get createJSDocClassTag() {
      return getJSDocSimpleTagCreateFunction(332 /* JSDocClassTag */);
    },
    get updateJSDocClassTag() {
      return getJSDocSimpleTagUpdateFunction(332 /* JSDocClassTag */);
    },
    get createJSDocPublicTag() {
      return getJSDocSimpleTagCreateFunction(333 /* JSDocPublicTag */);
    },
    get updateJSDocPublicTag() {
      return getJSDocSimpleTagUpdateFunction(333 /* JSDocPublicTag */);
    },
    get createJSDocPrivateTag() {
      return getJSDocSimpleTagCreateFunction(334 /* JSDocPrivateTag */);
    },
    get updateJSDocPrivateTag() {
      return getJSDocSimpleTagUpdateFunction(334 /* JSDocPrivateTag */);
    },
    get createJSDocProtectedTag() {
      return getJSDocSimpleTagCreateFunction(335 /* JSDocProtectedTag */);
    },
    get updateJSDocProtectedTag() {
      return getJSDocSimpleTagUpdateFunction(335 /* JSDocProtectedTag */);
    },
    get createJSDocReadonlyTag() {
      return getJSDocSimpleTagCreateFunction(336 /* JSDocReadonlyTag */);
    },
    get updateJSDocReadonlyTag() {
      return getJSDocSimpleTagUpdateFunction(336 /* JSDocReadonlyTag */);
    },
    get createJSDocOverrideTag() {
      return getJSDocSimpleTagCreateFunction(337 /* JSDocOverrideTag */);
    },
    get updateJSDocOverrideTag() {
      return getJSDocSimpleTagUpdateFunction(337 /* JSDocOverrideTag */);
    },
    get createJSDocDeprecatedTag() {
      return getJSDocSimpleTagCreateFunction(331 /* JSDocDeprecatedTag */);
    },
    get updateJSDocDeprecatedTag() {
      return getJSDocSimpleTagUpdateFunction(331 /* JSDocDeprecatedTag */);
    },
    get createJSDocThrowsTag() {
      return getJSDocTypeLikeTagCreateFunction(349 /* JSDocThrowsTag */);
    },
    get updateJSDocThrowsTag() {
      return getJSDocTypeLikeTagUpdateFunction(349 /* JSDocThrowsTag */);
    },
    get createJSDocSatisfiesTag() {
      return getJSDocTypeLikeTagCreateFunction(350 /* JSDocSatisfiesTag */);
    },
    get updateJSDocSatisfiesTag() {
      return getJSDocTypeLikeTagUpdateFunction(350 /* JSDocSatisfiesTag */);
    },
    createJSDocEnumTag,
    updateJSDocEnumTag,
    createJSDocUnknownTag,
    updateJSDocUnknownTag,
    createJSDocText,
    updateJSDocText,
    createJSDocComment,
    updateJSDocComment,
    createJsxElement,
    updateJsxElement,
    createJsxSelfClosingElement,
    updateJsxSelfClosingElement,
    createJsxOpeningElement,
    updateJsxOpeningElement,
    createJsxClosingElement,
    updateJsxClosingElement,
    createJsxFragment,
    createJsxText,
    updateJsxText,
    createJsxOpeningFragment,
    createJsxJsxClosingFragment,
    updateJsxFragment,
    createJsxAttribute,
    updateJsxAttribute,
    createJsxAttributes,
    updateJsxAttributes,
    createJsxSpreadAttribute,
    updateJsxSpreadAttribute,
    createJsxExpression,
    updateJsxExpression,
    createJsxNamespacedName,
    updateJsxNamespacedName,
    createCaseClause,
    updateCaseClause,
    createDefaultClause,
    updateDefaultClause,
    createHeritageClause,
    updateHeritageClause,
    createCatchClause,
    updateCatchClause,
    createPropertyAssignment,
    updatePropertyAssignment,
    createShorthandPropertyAssignment,
    updateShorthandPropertyAssignment,
    createSpreadAssignment,
    updateSpreadAssignment,
    createEnumMember,
    updateEnumMember,
    createSourceFile: createSourceFile2,
    updateSourceFile: updateSourceFile2,
    createRedirectedSourceFile,
    createBundle,
    updateBundle,
    createSyntheticExpression,
    createSyntaxList: createSyntaxList3,
    createNotEmittedStatement,
    createNotEmittedTypeElement,
    createPartiallyEmittedExpression,
    updatePartiallyEmittedExpression,
    createCommaListExpression,
    updateCommaListExpression,
    createSyntheticReferenceExpression,
    updateSyntheticReferenceExpression,
    cloneNode,
    // Lazily load factory methods for common operator factories and utilities
    get createComma() {
      return getBinaryCreateFunction(28 /* CommaToken */);
    },
    get createAssignment() {
      return getBinaryCreateFunction(64 /* EqualsToken */);
    },
    get createLogicalOr() {
      return getBinaryCreateFunction(57 /* BarBarToken */);
    },
    get createLogicalAnd() {
      return getBinaryCreateFunction(56 /* AmpersandAmpersandToken */);
    },
    get createBitwiseOr() {
      return getBinaryCreateFunction(52 /* BarToken */);
    },
    get createBitwiseXor() {
      return getBinaryCreateFunction(53 /* CaretToken */);
    },
    get createBitwiseAnd() {
      return getBinaryCreateFunction(51 /* AmpersandToken */);
    },
    get createStrictEquality() {
      return getBinaryCreateFunction(37 /* EqualsEqualsEqualsToken */);
    },
    get createStrictInequality() {
      return getBinaryCreateFunction(38 /* ExclamationEqualsEqualsToken */);
    },
    get createEquality() {
      return getBinaryCreateFunction(35 /* EqualsEqualsToken */);
    },
    get createInequality() {
      return getBinaryCreateFunction(36 /* ExclamationEqualsToken */);
    },
    get createLessThan() {
      return getBinaryCreateFunction(30 /* LessThanToken */);
    },
    get createLessThanEquals() {
      return getBinaryCreateFunction(33 /* LessThanEqualsToken */);
    },
    get createGreaterThan() {
      return getBinaryCreateFunction(32 /* GreaterThanToken */);
    },
    get createGreaterThanEquals() {
      return getBinaryCreateFunction(34 /* GreaterThanEqualsToken */);
    },
    get createLeftShift() {
      return getBinaryCreateFunction(48 /* LessThanLessThanToken */);
    },
    get createRightShift() {
      return getBinaryCreateFunction(49 /* GreaterThanGreaterThanToken */);
    },
    get createUnsignedRightShift() {
      return getBinaryCreateFunction(50 /* GreaterThanGreaterThanGreaterThanToken */);
    },
    get createAdd() {
      return getBinaryCreateFunction(40 /* PlusToken */);
    },
    get createSubtract() {
      return getBinaryCreateFunction(41 /* MinusToken */);
    },
    get createMultiply() {
      return getBinaryCreateFunction(42 /* AsteriskToken */);
    },
    get createDivide() {
      return getBinaryCreateFunction(44 /* SlashToken */);
    },
    get createModulo() {
      return getBinaryCreateFunction(45 /* PercentToken */);
    },
    get createExponent() {
      return getBinaryCreateFunction(43 /* AsteriskAsteriskToken */);
    },
    get createPrefixPlus() {
      return getPrefixUnaryCreateFunction(40 /* PlusToken */);
    },
    get createPrefixMinus() {
      return getPrefixUnaryCreateFunction(41 /* MinusToken */);
    },
    get createPrefixIncrement() {
      return getPrefixUnaryCreateFunction(46 /* PlusPlusToken */);
    },
    get createPrefixDecrement() {
      return getPrefixUnaryCreateFunction(47 /* MinusMinusToken */);
    },
    get createBitwiseNot() {
      return getPrefixUnaryCreateFunction(55 /* TildeToken */);
    },
    get createLogicalNot() {
      return getPrefixUnaryCreateFunction(54 /* ExclamationToken */);
    },
    get createPostfixIncrement() {
      return getPostfixUnaryCreateFunction(46 /* PlusPlusToken */);
    },
    get createPostfixDecrement() {
      return getPostfixUnaryCreateFunction(47 /* MinusMinusToken */);
    },
    // Compound nodes
    createImmediatelyInvokedFunctionExpression,
    createImmediatelyInvokedArrowFunction,
    createVoidZero,
    createExportDefault,
    createExternalModuleExport,
    createTypeCheck,
    createIsNotTypeCheck,
    createMethodCall,
    createGlobalMethodCall,
    createFunctionBindCall,
    createFunctionCallCall,
    createFunctionApplyCall,
    createArraySliceCall,
    createArrayConcatCall,
    createObjectDefinePropertyCall,
    createObjectGetOwnPropertyDescriptorCall,
    createReflectGetCall,
    createReflectSetCall,
    createPropertyDescriptor,
    createCallBinding,
    createAssignmentTargetWrapper,
    // Utilities
    inlineExpressions,
    getInternalName,
    getLocalName,
    getExportName,
    getDeclarationName,
    getNamespaceMemberName,
    getExternalModuleOrNamespaceExportName,
    restoreOuterExpressions,
    restoreEnclosingLabel,
    createUseStrictPrologue,
    copyPrologue,
    copyStandardPrologue,
    copyCustomPrologue,
    ensureUseStrict,
    liftToBlock,
    mergeLexicalEnvironment,
    replaceModifiers,
    replaceDecoratorsAndModifiers,
    replacePropertyName
  };
  forEach(nodeFactoryPatchers, (fn) => fn(factory2));
  return factory2;
  function createNodeArray(elements, hasTrailingComma) {
    if (elements === void 0 || elements === emptyArray) {
      elements = [];
    } else if (isNodeArray(elements)) {
      if (hasTrailingComma === void 0 || elements.hasTrailingComma === hasTrailingComma) {
        if (elements.transformFlags === void 0) {
          aggregateChildrenFlags(elements);
        }
        Debug.attachNodeArrayDebugInfo(elements);
        return elements;
      }
      const array2 = elements.slice();
      array2.pos = elements.pos;
      array2.end = elements.end;
      array2.hasTrailingComma = hasTrailingComma;
      array2.transformFlags = elements.transformFlags;
      Debug.attachNodeArrayDebugInfo(array2);
      return array2;
    }
    const length2 = elements.length;
    const array = length2 >= 1 && length2 <= 4 ? elements.slice() : elements;
    array.pos = -1;
    array.end = -1;
    array.hasTrailingComma = !!hasTrailingComma;
    array.transformFlags = 0 /* None */;
    aggregateChildrenFlags(array);
    Debug.attachNodeArrayDebugInfo(array);
    return array;
  }
  function createBaseNode(kind) {
    return baseFactory2.createBaseNode(kind);
  }
  function createBaseDeclaration(kind) {
    const node = createBaseNode(kind);
    node.symbol = void 0;
    node.localSymbol = void 0;
    return node;
  }
  function finishUpdateBaseSignatureDeclaration(updated, original) {
    if (updated !== original) {
      updated.typeArguments = original.typeArguments;
    }
    return update(updated, original);
  }
  function createNumericLiteral(value, numericLiteralFlags = 0 /* None */) {
    const text = typeof value === "number" ? value + "" : value;
    Debug.assert(text.charCodeAt(0) !== 45 /* minus */, "Negative numbers should be created in combination with createPrefixUnaryExpression");
    const node = createBaseDeclaration(9 /* NumericLiteral */);
    node.text = text;
    node.numericLiteralFlags = numericLiteralFlags;
    if (numericLiteralFlags & 384 /* BinaryOrOctalSpecifier */) node.transformFlags |= 1024 /* ContainsES2015 */;
    return node;
  }
  function createBigIntLiteral(value) {
    const node = createBaseToken(10 /* BigIntLiteral */);
    node.text = typeof value === "string" ? value : pseudoBigIntToString(value) + "n";
    node.transformFlags |= 32 /* ContainsES2020 */;
    return node;
  }
  function createBaseStringLiteral(text, isSingleQuote) {
    const node = createBaseDeclaration(11 /* StringLiteral */);
    node.text = text;
    node.singleQuote = isSingleQuote;
    return node;
  }
  function createStringLiteral(text, isSingleQuote, hasExtendedUnicodeEscape) {
    const node = createBaseStringLiteral(text, isSingleQuote);
    node.hasExtendedUnicodeEscape = hasExtendedUnicodeEscape;
    if (hasExtendedUnicodeEscape) node.transformFlags |= 1024 /* ContainsES2015 */;
    return node;
  }
  function createStringLiteralFromNode(sourceNode) {
    const node = createBaseStringLiteral(
      getTextOfIdentifierOrLiteral(sourceNode),
      /*isSingleQuote*/
      void 0
    );
    node.textSourceNode = sourceNode;
    return node;
  }
  function createRegularExpressionLiteral(text) {
    const node = createBaseToken(14 /* RegularExpressionLiteral */);
    node.text = text;
    return node;
  }
  function createLiteralLikeNode(kind, text) {
    switch (kind) {
      case 9 /* NumericLiteral */:
        return createNumericLiteral(
          text,
          /*numericLiteralFlags*/
          0
        );
      case 10 /* BigIntLiteral */:
        return createBigIntLiteral(text);
      case 11 /* StringLiteral */:
        return createStringLiteral(
          text,
          /*isSingleQuote*/
          void 0
        );
      case 12 /* JsxText */:
        return createJsxText(
          text,
          /*containsOnlyTriviaWhiteSpaces*/
          false
        );
      case 13 /* JsxTextAllWhiteSpaces */:
        return createJsxText(
          text,
          /*containsOnlyTriviaWhiteSpaces*/
          true
        );
      case 14 /* RegularExpressionLiteral */:
        return createRegularExpressionLiteral(text);
      case 15 /* NoSubstitutionTemplateLiteral */:
        return createTemplateLiteralLikeNode(
          kind,
          text,
          /*rawText*/
          void 0,
          /*templateFlags*/
          0
        );
    }
  }
  function createBaseIdentifier(escapedText) {
    const node = baseFactory2.createBaseIdentifierNode(80 /* Identifier */);
    node.escapedText = escapedText;
    node.jsDoc = void 0;
    node.flowNode = void 0;
    node.symbol = void 0;
    return node;
  }
  function createBaseGeneratedIdentifier(text, autoGenerateFlags, prefix, suffix) {
    const node = createBaseIdentifier(escapeLeadingUnderscores(text));
    setIdentifierAutoGenerate(node, {
      flags: autoGenerateFlags,
      id: nextAutoGenerateId,
      prefix,
      suffix
    });
    nextAutoGenerateId++;
    return node;
  }
  function createIdentifier(text, originalKeywordKind, hasExtendedUnicodeEscape) {
    if (originalKeywordKind === void 0 && text) {
      originalKeywordKind = stringToToken(text);
    }
    if (originalKeywordKind === 80 /* Identifier */) {
      originalKeywordKind = void 0;
    }
    const node = createBaseIdentifier(escapeLeadingUnderscores(text));
    if (hasExtendedUnicodeEscape) node.flags |= 256 /* IdentifierHasExtendedUnicodeEscape */;
    if (node.escapedText === "await") {
      node.transformFlags |= 67108864 /* ContainsPossibleTopLevelAwait */;
    }
    if (node.flags & 256 /* IdentifierHasExtendedUnicodeEscape */) {
      node.transformFlags |= 1024 /* ContainsES2015 */;
    }
    return node;
  }
  function createTempVariable(recordTempVariable, reservedInNestedScopes, prefix, suffix) {
    let flags2 = 1 /* Auto */;
    if (reservedInNestedScopes) flags2 |= 8 /* ReservedInNestedScopes */;
    const name = createBaseGeneratedIdentifier("", flags2, prefix, suffix);
    if (recordTempVariable) {
      recordTempVariable(name);
    }
    return name;
  }
  function createLoopVariable(reservedInNestedScopes) {
    let flags2 = 2 /* Loop */;
    if (reservedInNestedScopes) flags2 |= 8 /* ReservedInNestedScopes */;
    return createBaseGeneratedIdentifier(
      "",
      flags2,
      /*prefix*/
      void 0,
      /*suffix*/
      void 0
    );
  }
  function createUniqueName(text, flags2 = 0 /* None */, prefix, suffix) {
    Debug.assert(!(flags2 & 7 /* KindMask */), "Argument out of range: flags");
    Debug.assert((flags2 & (16 /* Optimistic */ | 32 /* FileLevel */)) !== 32 /* FileLevel */, "GeneratedIdentifierFlags.FileLevel cannot be set without also setting GeneratedIdentifierFlags.Optimistic");
    return createBaseGeneratedIdentifier(text, 3 /* Unique */ | flags2, prefix, suffix);
  }
  function getGeneratedNameForNode(node, flags2 = 0, prefix, suffix) {
    Debug.assert(!(flags2 & 7 /* KindMask */), "Argument out of range: flags");
    const text = !node ? "" : isMemberName(node) ? formatGeneratedName(
      /*privateName*/
      false,
      prefix,
      node,
      suffix,
      idText
    ) : `generated@${getNodeId(node)}`;
    if (prefix || suffix) flags2 |= 16 /* Optimistic */;
    const name = createBaseGeneratedIdentifier(text, 4 /* Node */ | flags2, prefix, suffix);
    name.original = node;
    return name;
  }
  function createBasePrivateIdentifier(escapedText) {
    const node = baseFactory2.createBasePrivateIdentifierNode(81 /* PrivateIdentifier */);
    node.escapedText = escapedText;
    node.transformFlags |= 16777216 /* ContainsClassFields */;
    return node;
  }
  function createPrivateIdentifier(text) {
    if (!startsWith(text, "#")) Debug.fail("First character of private identifier must be #: " + text);
    return createBasePrivateIdentifier(escapeLeadingUnderscores(text));
  }
  function createBaseGeneratedPrivateIdentifier(text, autoGenerateFlags, prefix, suffix) {
    const node = createBasePrivateIdentifier(escapeLeadingUnderscores(text));
    setIdentifierAutoGenerate(node, {
      flags: autoGenerateFlags,
      id: nextAutoGenerateId,
      prefix,
      suffix
    });
    nextAutoGenerateId++;
    return node;
  }
  function createUniquePrivateName(text, prefix, suffix) {
    if (text && !startsWith(text, "#")) Debug.fail("First character of private identifier must be #: " + text);
    const autoGenerateFlags = 8 /* ReservedInNestedScopes */ | (text ? 3 /* Unique */ : 1 /* Auto */);
    return createBaseGeneratedPrivateIdentifier(text ?? "", autoGenerateFlags, prefix, suffix);
  }
  function getGeneratedPrivateNameForNode(node, prefix, suffix) {
    const text = isMemberName(node) ? formatGeneratedName(
      /*privateName*/
      true,
      prefix,
      node,
      suffix,
      idText
    ) : `#generated@${getNodeId(node)}`;
    const flags2 = prefix || suffix ? 16 /* Optimistic */ : 0 /* None */;
    const name = createBaseGeneratedPrivateIdentifier(text, 4 /* Node */ | flags2, prefix, suffix);
    name.original = node;
    return name;
  }
  function createBaseToken(kind) {
    return baseFactory2.createBaseTokenNode(kind);
  }
  function createToken(token) {
    Debug.assert(token >= 0 /* FirstToken */ && token <= 165 /* LastToken */, "Invalid token");
    Debug.assert(token <= 15 /* FirstTemplateToken */ || token >= 18 /* LastTemplateToken */, "Invalid token. Use 'createTemplateLiteralLikeNode' to create template literals.");
    Debug.assert(token <= 9 /* FirstLiteralToken */ || token >= 15 /* LastLiteralToken */, "Invalid token. Use 'createLiteralLikeNode' to create literals.");
    Debug.assert(token !== 80 /* Identifier */, "Invalid token. Use 'createIdentifier' to create identifiers");
    const node = createBaseToken(token);
    let transformFlags = 0 /* None */;
    switch (token) {
      case 134 /* AsyncKeyword */:
        transformFlags = 256 /* ContainsES2017 */ | 128 /* ContainsES2018 */;
        break;
      case 160 /* UsingKeyword */:
        transformFlags = 4 /* ContainsESNext */;
        break;
      case 125 /* PublicKeyword */:
      case 123 /* PrivateKeyword */:
      case 124 /* ProtectedKeyword */:
      case 148 /* ReadonlyKeyword */:
      case 128 /* AbstractKeyword */:
      case 138 /* DeclareKeyword */:
      case 87 /* ConstKeyword */:
      case 133 /* AnyKeyword */:
      case 150 /* NumberKeyword */:
      case 163 /* BigIntKeyword */:
      case 146 /* NeverKeyword */:
      case 151 /* ObjectKeyword */:
      case 103 /* InKeyword */:
      case 147 /* OutKeyword */:
      case 164 /* OverrideKeyword */:
      case 154 /* StringKeyword */:
      case 136 /* BooleanKeyword */:
      case 155 /* SymbolKeyword */:
      case 116 /* VoidKeyword */:
      case 159 /* UnknownKeyword */:
      case 157 /* UndefinedKeyword */:
        transformFlags = 1 /* ContainsTypeScript */;
        break;
      case 108 /* SuperKeyword */:
        transformFlags = 1024 /* ContainsES2015 */ | 134217728 /* ContainsLexicalSuper */;
        node.flowNode = void 0;
        break;
      case 126 /* StaticKeyword */:
        transformFlags = 1024 /* ContainsES2015 */;
        break;
      case 129 /* AccessorKeyword */:
        transformFlags = 16777216 /* ContainsClassFields */;
        break;
      case 110 /* ThisKeyword */:
        transformFlags = 16384 /* ContainsLexicalThis */;
        node.flowNode = void 0;
        break;
    }
    if (transformFlags) {
      node.transformFlags |= transformFlags;
    }
    return node;
  }
  function createSuper() {
    return createToken(108 /* SuperKeyword */);
  }
  function createThis() {
    return createToken(110 /* ThisKeyword */);
  }
  function createNull() {
    return createToken(106 /* NullKeyword */);
  }
  function createTrue() {
    return createToken(112 /* TrueKeyword */);
  }
  function createFalse() {
    return createToken(97 /* FalseKeyword */);
  }
  function createModifier(kind) {
    return createToken(kind);
  }
  function createModifiersFromModifierFlags(flags2) {
    const result = [];
    if (flags2 & 32 /* Export */) result.push(createModifier(95 /* ExportKeyword */));
    if (flags2 & 128 /* Ambient */) result.push(createModifier(138 /* DeclareKeyword */));
    if (flags2 & 2048 /* Default */) result.push(createModifier(90 /* DefaultKeyword */));
    if (flags2 & 4096 /* Const */) result.push(createModifier(87 /* ConstKeyword */));
    if (flags2 & 1 /* Public */) result.push(createModifier(125 /* PublicKeyword */));
    if (flags2 & 2 /* Private */) result.push(createModifier(123 /* PrivateKeyword */));
    if (flags2 & 4 /* Protected */) result.push(createModifier(124 /* ProtectedKeyword */));
    if (flags2 & 64 /* Abstract */) result.push(createModifier(128 /* AbstractKeyword */));
    if (flags2 & 256 /* Static */) result.push(createModifier(126 /* StaticKeyword */));
    if (flags2 & 16 /* Override */) result.push(createModifier(164 /* OverrideKeyword */));
    if (flags2 & 8 /* Readonly */) result.push(createModifier(148 /* ReadonlyKeyword */));
    if (flags2 & 512 /* Accessor */) result.push(createModifier(129 /* AccessorKeyword */));
    if (flags2 & 1024 /* Async */) result.push(createModifier(134 /* AsyncKeyword */));
    if (flags2 & 8192 /* In */) result.push(createModifier(103 /* InKeyword */));
    if (flags2 & 16384 /* Out */) result.push(createModifier(147 /* OutKeyword */));
    return result.length ? result : void 0;
  }
  function createQualifiedName(left, right) {
    const node = createBaseNode(166 /* QualifiedName */);
    node.left = left;
    node.right = asName(right);
    node.transformFlags |= propagateChildFlags(node.left) | propagateIdentifierNameFlags(node.right);
    node.flowNode = void 0;
    return node;
  }
  function updateQualifiedName(node, left, right) {
    return node.left !== left || node.right !== right ? update(createQualifiedName(left, right), node) : node;
  }
  function createComputedPropertyName(expression) {
    const node = createBaseNode(167 /* ComputedPropertyName */);
    node.expression = parenthesizerRules().parenthesizeExpressionOfComputedPropertyName(expression);
    node.transformFlags |= propagateChildFlags(node.expression) | 1024 /* ContainsES2015 */ | 131072 /* ContainsComputedPropertyName */;
    return node;
  }
  function updateComputedPropertyName(node, expression) {
    return node.expression !== expression ? update(createComputedPropertyName(expression), node) : node;
  }
  function createTypeParameterDeclaration(modifiers, name, constraint, defaultType) {
    const node = createBaseDeclaration(168 /* TypeParameter */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.constraint = constraint;
    node.default = defaultType;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.expression = void 0;
    node.jsDoc = void 0;
    return node;
  }
  function updateTypeParameterDeclaration(node, modifiers, name, constraint, defaultType) {
    return node.modifiers !== modifiers || node.name !== name || node.constraint !== constraint || node.default !== defaultType ? update(createTypeParameterDeclaration(modifiers, name, constraint, defaultType), node) : node;
  }
  function createParameterDeclaration(modifiers, dotDotDotToken, name, questionToken, type, initializer) {
    const node = createBaseDeclaration(169 /* Parameter */);
    node.modifiers = asNodeArray(modifiers);
    node.dotDotDotToken = dotDotDotToken;
    node.name = asName(name);
    node.questionToken = questionToken;
    node.type = type;
    node.initializer = asInitializer(initializer);
    if (isThisIdentifier(node.name)) {
      node.transformFlags = 1 /* ContainsTypeScript */;
    } else {
      node.transformFlags = propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.dotDotDotToken) | propagateNameFlags(node.name) | propagateChildFlags(node.questionToken) | propagateChildFlags(node.initializer) | (node.questionToken ?? node.type ? 1 /* ContainsTypeScript */ : 0 /* None */) | (node.dotDotDotToken ?? node.initializer ? 1024 /* ContainsES2015 */ : 0 /* None */) | (modifiersToFlags(node.modifiers) & 31 /* ParameterPropertyModifier */ ? 8192 /* ContainsTypeScriptClassSyntax */ : 0 /* None */);
    }
    node.jsDoc = void 0;
    return node;
  }
  function updateParameterDeclaration(node, modifiers, dotDotDotToken, name, questionToken, type, initializer) {
    return node.modifiers !== modifiers || node.dotDotDotToken !== dotDotDotToken || node.name !== name || node.questionToken !== questionToken || node.type !== type || node.initializer !== initializer ? update(createParameterDeclaration(modifiers, dotDotDotToken, name, questionToken, type, initializer), node) : node;
  }
  function createDecorator(expression) {
    const node = createBaseNode(170 /* Decorator */);
    node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(
      expression,
      /*optionalChain*/
      false
    );
    node.transformFlags |= propagateChildFlags(node.expression) | 1 /* ContainsTypeScript */ | 8192 /* ContainsTypeScriptClassSyntax */ | 33554432 /* ContainsDecorators */;
    return node;
  }
  function updateDecorator(node, expression) {
    return node.expression !== expression ? update(createDecorator(expression), node) : node;
  }
  function createPropertySignature(modifiers, name, questionToken, type) {
    const node = createBaseDeclaration(171 /* PropertySignature */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.type = type;
    node.questionToken = questionToken;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.initializer = void 0;
    node.jsDoc = void 0;
    return node;
  }
  function updatePropertySignature(node, modifiers, name, questionToken, type) {
    return node.modifiers !== modifiers || node.name !== name || node.questionToken !== questionToken || node.type !== type ? finishUpdatePropertySignature(createPropertySignature(modifiers, name, questionToken, type), node) : node;
  }
  function finishUpdatePropertySignature(updated, original) {
    if (updated !== original) {
      updated.initializer = original.initializer;
    }
    return update(updated, original);
  }
  function createPropertyDeclaration(modifiers, name, questionOrExclamationToken, type, initializer) {
    const node = createBaseDeclaration(172 /* PropertyDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.questionToken = questionOrExclamationToken && isQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : void 0;
    node.exclamationToken = questionOrExclamationToken && isExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : void 0;
    node.type = type;
    node.initializer = asInitializer(initializer);
    const isAmbient = node.flags & 33554432 /* Ambient */ || modifiersToFlags(node.modifiers) & 128 /* Ambient */;
    node.transformFlags = propagateChildrenFlags(node.modifiers) | propagateNameFlags(node.name) | propagateChildFlags(node.initializer) | (isAmbient || node.questionToken || node.exclamationToken || node.type ? 1 /* ContainsTypeScript */ : 0 /* None */) | (isComputedPropertyName(node.name) || modifiersToFlags(node.modifiers) & 256 /* Static */ && node.initializer ? 8192 /* ContainsTypeScriptClassSyntax */ : 0 /* None */) | 16777216 /* ContainsClassFields */;
    node.jsDoc = void 0;
    return node;
  }
  function updatePropertyDeclaration2(node, modifiers, name, questionOrExclamationToken, type, initializer) {
    return node.modifiers !== modifiers || node.name !== name || node.questionToken !== (questionOrExclamationToken !== void 0 && isQuestionToken(questionOrExclamationToken) ? questionOrExclamationToken : void 0) || node.exclamationToken !== (questionOrExclamationToken !== void 0 && isExclamationToken(questionOrExclamationToken) ? questionOrExclamationToken : void 0) || node.type !== type || node.initializer !== initializer ? update(createPropertyDeclaration(modifiers, name, questionOrExclamationToken, type, initializer), node) : node;
  }
  function createMethodSignature(modifiers, name, questionToken, typeParameters, parameters, type) {
    const node = createBaseDeclaration(173 /* MethodSignature */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.questionToken = questionToken;
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = asNodeArray(parameters);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.typeArguments = void 0;
    return node;
  }
  function updateMethodSignature(node, modifiers, name, questionToken, typeParameters, parameters, type) {
    return node.modifiers !== modifiers || node.name !== name || node.questionToken !== questionToken || node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type ? finishUpdateBaseSignatureDeclaration(createMethodSignature(modifiers, name, questionToken, typeParameters, parameters, type), node) : node;
  }
  function createMethodDeclaration(modifiers, asteriskToken, name, questionToken, typeParameters, parameters, type, body) {
    const node = createBaseDeclaration(174 /* MethodDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.asteriskToken = asteriskToken;
    node.name = asName(name);
    node.questionToken = questionToken;
    node.exclamationToken = void 0;
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = createNodeArray(parameters);
    node.type = type;
    node.body = body;
    if (!node.body) {
      node.transformFlags = 1 /* ContainsTypeScript */;
    } else {
      const isAsync = modifiersToFlags(node.modifiers) & 1024 /* Async */;
      const isGenerator = !!node.asteriskToken;
      const isAsyncGenerator = isAsync && isGenerator;
      node.transformFlags = propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.asteriskToken) | propagateNameFlags(node.name) | propagateChildFlags(node.questionToken) | propagateChildrenFlags(node.typeParameters) | propagateChildrenFlags(node.parameters) | propagateChildFlags(node.type) | propagateChildFlags(node.body) & ~67108864 /* ContainsPossibleTopLevelAwait */ | (isAsyncGenerator ? 128 /* ContainsES2018 */ : isAsync ? 256 /* ContainsES2017 */ : isGenerator ? 2048 /* ContainsGenerator */ : 0 /* None */) | (node.questionToken || node.typeParameters || node.type ? 1 /* ContainsTypeScript */ : 0 /* None */) | 1024 /* ContainsES2015 */;
    }
    node.typeArguments = void 0;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.flowNode = void 0;
    node.endFlowNode = void 0;
    node.returnFlowNode = void 0;
    return node;
  }
  function updateMethodDeclaration(node, modifiers, asteriskToken, name, questionToken, typeParameters, parameters, type, body) {
    return node.modifiers !== modifiers || node.asteriskToken !== asteriskToken || node.name !== name || node.questionToken !== questionToken || node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type || node.body !== body ? finishUpdateMethodDeclaration(createMethodDeclaration(modifiers, asteriskToken, name, questionToken, typeParameters, parameters, type, body), node) : node;
  }
  function finishUpdateMethodDeclaration(updated, original) {
    if (updated !== original) {
      updated.exclamationToken = original.exclamationToken;
    }
    return update(updated, original);
  }
  function createClassStaticBlockDeclaration(body) {
    const node = createBaseDeclaration(175 /* ClassStaticBlockDeclaration */);
    node.body = body;
    node.transformFlags = propagateChildFlags(body) | 16777216 /* ContainsClassFields */;
    node.modifiers = void 0;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.endFlowNode = void 0;
    node.returnFlowNode = void 0;
    return node;
  }
  function updateClassStaticBlockDeclaration(node, body) {
    return node.body !== body ? finishUpdateClassStaticBlockDeclaration(createClassStaticBlockDeclaration(body), node) : node;
  }
  function finishUpdateClassStaticBlockDeclaration(updated, original) {
    if (updated !== original) {
      updated.modifiers = original.modifiers;
    }
    return update(updated, original);
  }
  function createConstructorDeclaration(modifiers, parameters, body) {
    const node = createBaseDeclaration(176 /* Constructor */);
    node.modifiers = asNodeArray(modifiers);
    node.parameters = createNodeArray(parameters);
    node.body = body;
    if (!node.body) {
      node.transformFlags = 1 /* ContainsTypeScript */;
    } else {
      node.transformFlags = propagateChildrenFlags(node.modifiers) | propagateChildrenFlags(node.parameters) | propagateChildFlags(node.body) & ~67108864 /* ContainsPossibleTopLevelAwait */ | 1024 /* ContainsES2015 */;
    }
    node.typeParameters = void 0;
    node.type = void 0;
    node.typeArguments = void 0;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.endFlowNode = void 0;
    node.returnFlowNode = void 0;
    return node;
  }
  function updateConstructorDeclaration(node, modifiers, parameters, body) {
    return node.modifiers !== modifiers || node.parameters !== parameters || node.body !== body ? finishUpdateConstructorDeclaration(createConstructorDeclaration(modifiers, parameters, body), node) : node;
  }
  function finishUpdateConstructorDeclaration(updated, original) {
    if (updated !== original) {
      updated.typeParameters = original.typeParameters;
      updated.type = original.type;
    }
    return finishUpdateBaseSignatureDeclaration(updated, original);
  }
  function createGetAccessorDeclaration(modifiers, name, parameters, type, body) {
    const node = createBaseDeclaration(177 /* GetAccessor */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.parameters = createNodeArray(parameters);
    node.type = type;
    node.body = body;
    if (!node.body) {
      node.transformFlags = 1 /* ContainsTypeScript */;
    } else {
      node.transformFlags = propagateChildrenFlags(node.modifiers) | propagateNameFlags(node.name) | propagateChildrenFlags(node.parameters) | propagateChildFlags(node.type) | propagateChildFlags(node.body) & ~67108864 /* ContainsPossibleTopLevelAwait */ | (node.type ? 1 /* ContainsTypeScript */ : 0 /* None */);
    }
    node.typeArguments = void 0;
    node.typeParameters = void 0;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.flowNode = void 0;
    node.endFlowNode = void 0;
    node.returnFlowNode = void 0;
    return node;
  }
  function updateGetAccessorDeclaration(node, modifiers, name, parameters, type, body) {
    return node.modifiers !== modifiers || node.name !== name || node.parameters !== parameters || node.type !== type || node.body !== body ? finishUpdateGetAccessorDeclaration(createGetAccessorDeclaration(modifiers, name, parameters, type, body), node) : node;
  }
  function finishUpdateGetAccessorDeclaration(updated, original) {
    if (updated !== original) {
      updated.typeParameters = original.typeParameters;
    }
    return finishUpdateBaseSignatureDeclaration(updated, original);
  }
  function createSetAccessorDeclaration(modifiers, name, parameters, body) {
    const node = createBaseDeclaration(178 /* SetAccessor */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.parameters = createNodeArray(parameters);
    node.body = body;
    if (!node.body) {
      node.transformFlags = 1 /* ContainsTypeScript */;
    } else {
      node.transformFlags = propagateChildrenFlags(node.modifiers) | propagateNameFlags(node.name) | propagateChildrenFlags(node.parameters) | propagateChildFlags(node.body) & ~67108864 /* ContainsPossibleTopLevelAwait */ | (node.type ? 1 /* ContainsTypeScript */ : 0 /* None */);
    }
    node.typeArguments = void 0;
    node.typeParameters = void 0;
    node.type = void 0;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.flowNode = void 0;
    node.endFlowNode = void 0;
    node.returnFlowNode = void 0;
    return node;
  }
  function updateSetAccessorDeclaration(node, modifiers, name, parameters, body) {
    return node.modifiers !== modifiers || node.name !== name || node.parameters !== parameters || node.body !== body ? finishUpdateSetAccessorDeclaration(createSetAccessorDeclaration(modifiers, name, parameters, body), node) : node;
  }
  function finishUpdateSetAccessorDeclaration(updated, original) {
    if (updated !== original) {
      updated.typeParameters = original.typeParameters;
      updated.type = original.type;
    }
    return finishUpdateBaseSignatureDeclaration(updated, original);
  }
  function createCallSignature(typeParameters, parameters, type) {
    const node = createBaseDeclaration(179 /* CallSignature */);
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = asNodeArray(parameters);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.typeArguments = void 0;
    return node;
  }
  function updateCallSignature(node, typeParameters, parameters, type) {
    return node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type ? finishUpdateBaseSignatureDeclaration(createCallSignature(typeParameters, parameters, type), node) : node;
  }
  function createConstructSignature(typeParameters, parameters, type) {
    const node = createBaseDeclaration(180 /* ConstructSignature */);
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = asNodeArray(parameters);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.typeArguments = void 0;
    return node;
  }
  function updateConstructSignature(node, typeParameters, parameters, type) {
    return node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type ? finishUpdateBaseSignatureDeclaration(createConstructSignature(typeParameters, parameters, type), node) : node;
  }
  function createIndexSignature(modifiers, parameters, type) {
    const node = createBaseDeclaration(181 /* IndexSignature */);
    node.modifiers = asNodeArray(modifiers);
    node.parameters = asNodeArray(parameters);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.typeArguments = void 0;
    return node;
  }
  function updateIndexSignature(node, modifiers, parameters, type) {
    return node.parameters !== parameters || node.type !== type || node.modifiers !== modifiers ? finishUpdateBaseSignatureDeclaration(createIndexSignature(modifiers, parameters, type), node) : node;
  }
  function createTemplateLiteralTypeSpan(type, literal) {
    const node = createBaseNode(204 /* TemplateLiteralTypeSpan */);
    node.type = type;
    node.literal = literal;
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateTemplateLiteralTypeSpan(node, type, literal) {
    return node.type !== type || node.literal !== literal ? update(createTemplateLiteralTypeSpan(type, literal), node) : node;
  }
  function createKeywordTypeNode(kind) {
    return createToken(kind);
  }
  function createTypePredicateNode(assertsModifier, parameterName, type) {
    const node = createBaseNode(182 /* TypePredicate */);
    node.assertsModifier = assertsModifier;
    node.parameterName = asName(parameterName);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateTypePredicateNode(node, assertsModifier, parameterName, type) {
    return node.assertsModifier !== assertsModifier || node.parameterName !== parameterName || node.type !== type ? update(createTypePredicateNode(assertsModifier, parameterName, type), node) : node;
  }
  function createTypeReferenceNode(typeName, typeArguments) {
    const node = createBaseNode(183 /* TypeReference */);
    node.typeName = asName(typeName);
    node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(createNodeArray(typeArguments));
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateTypeReferenceNode(node, typeName, typeArguments) {
    return node.typeName !== typeName || node.typeArguments !== typeArguments ? update(createTypeReferenceNode(typeName, typeArguments), node) : node;
  }
  function createFunctionTypeNode(typeParameters, parameters, type) {
    const node = createBaseDeclaration(184 /* FunctionType */);
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = asNodeArray(parameters);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.modifiers = void 0;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.typeArguments = void 0;
    return node;
  }
  function updateFunctionTypeNode(node, typeParameters, parameters, type) {
    return node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type ? finishUpdateFunctionTypeNode(createFunctionTypeNode(typeParameters, parameters, type), node) : node;
  }
  function finishUpdateFunctionTypeNode(updated, original) {
    if (updated !== original) {
      updated.modifiers = original.modifiers;
    }
    return finishUpdateBaseSignatureDeclaration(updated, original);
  }
  function createConstructorTypeNode(...args) {
    return args.length === 4 ? createConstructorTypeNode1(...args) : args.length === 3 ? createConstructorTypeNode2(...args) : Debug.fail("Incorrect number of arguments specified.");
  }
  function createConstructorTypeNode1(modifiers, typeParameters, parameters, type) {
    const node = createBaseDeclaration(185 /* ConstructorType */);
    node.modifiers = asNodeArray(modifiers);
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = asNodeArray(parameters);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.typeArguments = void 0;
    return node;
  }
  function createConstructorTypeNode2(typeParameters, parameters, type) {
    return createConstructorTypeNode1(
      /*modifiers*/
      void 0,
      typeParameters,
      parameters,
      type
    );
  }
  function updateConstructorTypeNode(...args) {
    return args.length === 5 ? updateConstructorTypeNode1(...args) : args.length === 4 ? updateConstructorTypeNode2(...args) : Debug.fail("Incorrect number of arguments specified.");
  }
  function updateConstructorTypeNode1(node, modifiers, typeParameters, parameters, type) {
    return node.modifiers !== modifiers || node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type ? finishUpdateBaseSignatureDeclaration(createConstructorTypeNode(modifiers, typeParameters, parameters, type), node) : node;
  }
  function updateConstructorTypeNode2(node, typeParameters, parameters, type) {
    return updateConstructorTypeNode1(node, node.modifiers, typeParameters, parameters, type);
  }
  function createTypeQueryNode(exprName, typeArguments) {
    const node = createBaseNode(186 /* TypeQuery */);
    node.exprName = exprName;
    node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateTypeQueryNode(node, exprName, typeArguments) {
    return node.exprName !== exprName || node.typeArguments !== typeArguments ? update(createTypeQueryNode(exprName, typeArguments), node) : node;
  }
  function createTypeLiteralNode(members) {
    const node = createBaseDeclaration(187 /* TypeLiteral */);
    node.members = createNodeArray(members);
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateTypeLiteralNode(node, members) {
    return node.members !== members ? update(createTypeLiteralNode(members), node) : node;
  }
  function createArrayTypeNode(elementType) {
    const node = createBaseNode(188 /* ArrayType */);
    node.elementType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType);
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateArrayTypeNode(node, elementType) {
    return node.elementType !== elementType ? update(createArrayTypeNode(elementType), node) : node;
  }
  function createTupleTypeNode(elements) {
    const node = createBaseNode(189 /* TupleType */);
    node.elements = createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements));
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateTupleTypeNode(node, elements) {
    return node.elements !== elements ? update(createTupleTypeNode(elements), node) : node;
  }
  function createNamedTupleMember(dotDotDotToken, name, questionToken, type) {
    const node = createBaseDeclaration(202 /* NamedTupleMember */);
    node.dotDotDotToken = dotDotDotToken;
    node.name = name;
    node.questionToken = questionToken;
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.jsDoc = void 0;
    return node;
  }
  function updateNamedTupleMember(node, dotDotDotToken, name, questionToken, type) {
    return node.dotDotDotToken !== dotDotDotToken || node.name !== name || node.questionToken !== questionToken || node.type !== type ? update(createNamedTupleMember(dotDotDotToken, name, questionToken, type), node) : node;
  }
  function createOptionalTypeNode(type) {
    const node = createBaseNode(190 /* OptionalType */);
    node.type = parenthesizerRules().parenthesizeTypeOfOptionalType(type);
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateOptionalTypeNode(node, type) {
    return node.type !== type ? update(createOptionalTypeNode(type), node) : node;
  }
  function createRestTypeNode(type) {
    const node = createBaseNode(191 /* RestType */);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateRestTypeNode(node, type) {
    return node.type !== type ? update(createRestTypeNode(type), node) : node;
  }
  function createUnionOrIntersectionTypeNode(kind, types, parenthesize) {
    const node = createBaseNode(kind);
    node.types = factory2.createNodeArray(parenthesize(types));
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateUnionOrIntersectionTypeNode(node, types, parenthesize) {
    return node.types !== types ? update(createUnionOrIntersectionTypeNode(node.kind, types, parenthesize), node) : node;
  }
  function createUnionTypeNode(types) {
    return createUnionOrIntersectionTypeNode(192 /* UnionType */, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType);
  }
  function updateUnionTypeNode(node, types) {
    return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType);
  }
  function createIntersectionTypeNode(types) {
    return createUnionOrIntersectionTypeNode(193 /* IntersectionType */, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType);
  }
  function updateIntersectionTypeNode(node, types) {
    return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType);
  }
  function createConditionalTypeNode(checkType, extendsType, trueType, falseType) {
    const node = createBaseNode(194 /* ConditionalType */);
    node.checkType = parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType);
    node.extendsType = parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType);
    node.trueType = trueType;
    node.falseType = falseType;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateConditionalTypeNode(node, checkType, extendsType, trueType, falseType) {
    return node.checkType !== checkType || node.extendsType !== extendsType || node.trueType !== trueType || node.falseType !== falseType ? update(createConditionalTypeNode(checkType, extendsType, trueType, falseType), node) : node;
  }
  function createInferTypeNode(typeParameter) {
    const node = createBaseNode(195 /* InferType */);
    node.typeParameter = typeParameter;
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateInferTypeNode(node, typeParameter) {
    return node.typeParameter !== typeParameter ? update(createInferTypeNode(typeParameter), node) : node;
  }
  function createTemplateLiteralType(head, templateSpans) {
    const node = createBaseNode(203 /* TemplateLiteralType */);
    node.head = head;
    node.templateSpans = createNodeArray(templateSpans);
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateTemplateLiteralType(node, head, templateSpans) {
    return node.head !== head || node.templateSpans !== templateSpans ? update(createTemplateLiteralType(head, templateSpans), node) : node;
  }
  function createImportTypeNode(argument, attributes, qualifier, typeArguments, isTypeOf = false) {
    const node = createBaseNode(205 /* ImportType */);
    node.argument = argument;
    node.attributes = attributes;
    if (node.assertions && node.assertions.assertClause && node.attributes) {
      node.assertions.assertClause = node.attributes;
    }
    node.qualifier = qualifier;
    node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
    node.isTypeOf = isTypeOf;
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateImportTypeNode(node, argument, attributes, qualifier, typeArguments, isTypeOf = node.isTypeOf) {
    return node.argument !== argument || node.attributes !== attributes || node.qualifier !== qualifier || node.typeArguments !== typeArguments || node.isTypeOf !== isTypeOf ? update(createImportTypeNode(argument, attributes, qualifier, typeArguments, isTypeOf), node) : node;
  }
  function createParenthesizedType(type) {
    const node = createBaseNode(196 /* ParenthesizedType */);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateParenthesizedType(node, type) {
    return node.type !== type ? update(createParenthesizedType(type), node) : node;
  }
  function createThisTypeNode() {
    const node = createBaseNode(197 /* ThisType */);
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function createTypeOperatorNode(operator, type) {
    const node = createBaseNode(198 /* TypeOperator */);
    node.operator = operator;
    node.type = operator === 148 /* ReadonlyKeyword */ ? parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) : parenthesizerRules().parenthesizeOperandOfTypeOperator(type);
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateTypeOperatorNode(node, type) {
    return node.type !== type ? update(createTypeOperatorNode(node.operator, type), node) : node;
  }
  function createIndexedAccessTypeNode(objectType, indexType) {
    const node = createBaseNode(199 /* IndexedAccessType */);
    node.objectType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType);
    node.indexType = indexType;
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateIndexedAccessTypeNode(node, objectType, indexType) {
    return node.objectType !== objectType || node.indexType !== indexType ? update(createIndexedAccessTypeNode(objectType, indexType), node) : node;
  }
  function createMappedTypeNode(readonlyToken, typeParameter, nameType, questionToken, type, members) {
    const node = createBaseDeclaration(200 /* MappedType */);
    node.readonlyToken = readonlyToken;
    node.typeParameter = typeParameter;
    node.nameType = nameType;
    node.questionToken = questionToken;
    node.type = type;
    node.members = members && createNodeArray(members);
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateMappedTypeNode(node, readonlyToken, typeParameter, nameType, questionToken, type, members) {
    return node.readonlyToken !== readonlyToken || node.typeParameter !== typeParameter || node.nameType !== nameType || node.questionToken !== questionToken || node.type !== type || node.members !== members ? update(createMappedTypeNode(readonlyToken, typeParameter, nameType, questionToken, type, members), node) : node;
  }
  function createLiteralTypeNode(literal) {
    const node = createBaseNode(201 /* LiteralType */);
    node.literal = literal;
    node.transformFlags = 1 /* ContainsTypeScript */;
    return node;
  }
  function updateLiteralTypeNode(node, literal) {
    return node.literal !== literal ? update(createLiteralTypeNode(literal), node) : node;
  }
  function createObjectBindingPattern(elements) {
    const node = createBaseNode(206 /* ObjectBindingPattern */);
    node.elements = createNodeArray(elements);
    node.transformFlags |= propagateChildrenFlags(node.elements) | 1024 /* ContainsES2015 */ | 524288 /* ContainsBindingPattern */;
    if (node.transformFlags & 32768 /* ContainsRestOrSpread */) {
      node.transformFlags |= 128 /* ContainsES2018 */ | 65536 /* ContainsObjectRestOrSpread */;
    }
    return node;
  }
  function updateObjectBindingPattern(node, elements) {
    return node.elements !== elements ? update(createObjectBindingPattern(elements), node) : node;
  }
  function createArrayBindingPattern(elements) {
    const node = createBaseNode(207 /* ArrayBindingPattern */);
    node.elements = createNodeArray(elements);
    node.transformFlags |= propagateChildrenFlags(node.elements) | 1024 /* ContainsES2015 */ | 524288 /* ContainsBindingPattern */;
    return node;
  }
  function updateArrayBindingPattern(node, elements) {
    return node.elements !== elements ? update(createArrayBindingPattern(elements), node) : node;
  }
  function createBindingElement(dotDotDotToken, propertyName, name, initializer) {
    const node = createBaseDeclaration(208 /* BindingElement */);
    node.dotDotDotToken = dotDotDotToken;
    node.propertyName = asName(propertyName);
    node.name = asName(name);
    node.initializer = asInitializer(initializer);
    node.transformFlags |= propagateChildFlags(node.dotDotDotToken) | propagateNameFlags(node.propertyName) | propagateNameFlags(node.name) | propagateChildFlags(node.initializer) | (node.dotDotDotToken ? 32768 /* ContainsRestOrSpread */ : 0 /* None */) | 1024 /* ContainsES2015 */;
    node.flowNode = void 0;
    return node;
  }
  function updateBindingElement(node, dotDotDotToken, propertyName, name, initializer) {
    return node.propertyName !== propertyName || node.dotDotDotToken !== dotDotDotToken || node.name !== name || node.initializer !== initializer ? update(createBindingElement(dotDotDotToken, propertyName, name, initializer), node) : node;
  }
  function createArrayLiteralExpression(elements, multiLine) {
    const node = createBaseNode(209 /* ArrayLiteralExpression */);
    const lastElement = elements && lastOrUndefined(elements);
    const elementsArray = createNodeArray(elements, lastElement && isOmittedExpression(lastElement) ? true : void 0);
    node.elements = parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(elementsArray);
    node.multiLine = multiLine;
    node.transformFlags |= propagateChildrenFlags(node.elements);
    return node;
  }
  function updateArrayLiteralExpression(node, elements) {
    return node.elements !== elements ? update(createArrayLiteralExpression(elements, node.multiLine), node) : node;
  }
  function createObjectLiteralExpression(properties, multiLine) {
    const node = createBaseDeclaration(210 /* ObjectLiteralExpression */);
    node.properties = createNodeArray(properties);
    node.multiLine = multiLine;
    node.transformFlags |= propagateChildrenFlags(node.properties);
    node.jsDoc = void 0;
    return node;
  }
  function updateObjectLiteralExpression(node, properties) {
    return node.properties !== properties ? update(createObjectLiteralExpression(properties, node.multiLine), node) : node;
  }
  function createBasePropertyAccessExpression(expression, questionDotToken, name) {
    const node = createBaseDeclaration(211 /* PropertyAccessExpression */);
    node.expression = expression;
    node.questionDotToken = questionDotToken;
    node.name = name;
    node.transformFlags = propagateChildFlags(node.expression) | propagateChildFlags(node.questionDotToken) | (isIdentifier(node.name) ? propagateIdentifierNameFlags(node.name) : propagateChildFlags(node.name) | 536870912 /* ContainsPrivateIdentifierInExpression */);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function createPropertyAccessExpression(expression, name) {
    const node = createBasePropertyAccessExpression(
      parenthesizerRules().parenthesizeLeftSideOfAccess(
        expression,
        /*optionalChain*/
        false
      ),
      /*questionDotToken*/
      void 0,
      asName(name)
    );
    if (isSuperKeyword(expression)) {
      node.transformFlags |= 256 /* ContainsES2017 */ | 128 /* ContainsES2018 */;
    }
    return node;
  }
  function updatePropertyAccessExpression(node, expression, name) {
    if (isPropertyAccessChain(node)) {
      return updatePropertyAccessChain(node, expression, node.questionDotToken, cast(name, isIdentifier));
    }
    return node.expression !== expression || node.name !== name ? update(createPropertyAccessExpression(expression, name), node) : node;
  }
  function createPropertyAccessChain(expression, questionDotToken, name) {
    const node = createBasePropertyAccessExpression(
      parenthesizerRules().parenthesizeLeftSideOfAccess(
        expression,
        /*optionalChain*/
        true
      ),
      questionDotToken,
      asName(name)
    );
    node.flags |= 64 /* OptionalChain */;
    node.transformFlags |= 32 /* ContainsES2020 */;
    return node;
  }
  function updatePropertyAccessChain(node, expression, questionDotToken, name) {
    Debug.assert(!!(node.flags & 64 /* OptionalChain */), "Cannot update a PropertyAccessExpression using updatePropertyAccessChain. Use updatePropertyAccess instead.");
    return node.expression !== expression || node.questionDotToken !== questionDotToken || node.name !== name ? update(createPropertyAccessChain(expression, questionDotToken, name), node) : node;
  }
  function createBaseElementAccessExpression(expression, questionDotToken, argumentExpression) {
    const node = createBaseDeclaration(212 /* ElementAccessExpression */);
    node.expression = expression;
    node.questionDotToken = questionDotToken;
    node.argumentExpression = argumentExpression;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.questionDotToken) | propagateChildFlags(node.argumentExpression);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function createElementAccessExpression(expression, index) {
    const node = createBaseElementAccessExpression(
      parenthesizerRules().parenthesizeLeftSideOfAccess(
        expression,
        /*optionalChain*/
        false
      ),
      /*questionDotToken*/
      void 0,
      asExpression(index)
    );
    if (isSuperKeyword(expression)) {
      node.transformFlags |= 256 /* ContainsES2017 */ | 128 /* ContainsES2018 */;
    }
    return node;
  }
  function updateElementAccessExpression(node, expression, argumentExpression) {
    if (isElementAccessChain(node)) {
      return updateElementAccessChain(node, expression, node.questionDotToken, argumentExpression);
    }
    return node.expression !== expression || node.argumentExpression !== argumentExpression ? update(createElementAccessExpression(expression, argumentExpression), node) : node;
  }
  function createElementAccessChain(expression, questionDotToken, index) {
    const node = createBaseElementAccessExpression(
      parenthesizerRules().parenthesizeLeftSideOfAccess(
        expression,
        /*optionalChain*/
        true
      ),
      questionDotToken,
      asExpression(index)
    );
    node.flags |= 64 /* OptionalChain */;
    node.transformFlags |= 32 /* ContainsES2020 */;
    return node;
  }
  function updateElementAccessChain(node, expression, questionDotToken, argumentExpression) {
    Debug.assert(!!(node.flags & 64 /* OptionalChain */), "Cannot update a ElementAccessExpression using updateElementAccessChain. Use updateElementAccess instead.");
    return node.expression !== expression || node.questionDotToken !== questionDotToken || node.argumentExpression !== argumentExpression ? update(createElementAccessChain(expression, questionDotToken, argumentExpression), node) : node;
  }
  function createBaseCallExpression(expression, questionDotToken, typeArguments, argumentsArray) {
    const node = createBaseDeclaration(213 /* CallExpression */);
    node.expression = expression;
    node.questionDotToken = questionDotToken;
    node.typeArguments = typeArguments;
    node.arguments = argumentsArray;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.questionDotToken) | propagateChildrenFlags(node.typeArguments) | propagateChildrenFlags(node.arguments);
    if (node.typeArguments) {
      node.transformFlags |= 1 /* ContainsTypeScript */;
    }
    if (isSuperProperty(node.expression)) {
      node.transformFlags |= 16384 /* ContainsLexicalThis */;
    }
    return node;
  }
  function createCallExpression(expression, typeArguments, argumentsArray) {
    const node = createBaseCallExpression(
      parenthesizerRules().parenthesizeLeftSideOfAccess(
        expression,
        /*optionalChain*/
        false
      ),
      /*questionDotToken*/
      void 0,
      asNodeArray(typeArguments),
      parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray))
    );
    if (isImportKeyword(node.expression)) {
      node.transformFlags |= 8388608 /* ContainsDynamicImport */;
    }
    return node;
  }
  function updateCallExpression(node, expression, typeArguments, argumentsArray) {
    if (isCallChain(node)) {
      return updateCallChain(node, expression, node.questionDotToken, typeArguments, argumentsArray);
    }
    return node.expression !== expression || node.typeArguments !== typeArguments || node.arguments !== argumentsArray ? update(createCallExpression(expression, typeArguments, argumentsArray), node) : node;
  }
  function createCallChain(expression, questionDotToken, typeArguments, argumentsArray) {
    const node = createBaseCallExpression(
      parenthesizerRules().parenthesizeLeftSideOfAccess(
        expression,
        /*optionalChain*/
        true
      ),
      questionDotToken,
      asNodeArray(typeArguments),
      parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(createNodeArray(argumentsArray))
    );
    node.flags |= 64 /* OptionalChain */;
    node.transformFlags |= 32 /* ContainsES2020 */;
    return node;
  }
  function updateCallChain(node, expression, questionDotToken, typeArguments, argumentsArray) {
    Debug.assert(!!(node.flags & 64 /* OptionalChain */), "Cannot update a CallExpression using updateCallChain. Use updateCall instead.");
    return node.expression !== expression || node.questionDotToken !== questionDotToken || node.typeArguments !== typeArguments || node.arguments !== argumentsArray ? update(createCallChain(expression, questionDotToken, typeArguments, argumentsArray), node) : node;
  }
  function createNewExpression(expression, typeArguments, argumentsArray) {
    const node = createBaseDeclaration(214 /* NewExpression */);
    node.expression = parenthesizerRules().parenthesizeExpressionOfNew(expression);
    node.typeArguments = asNodeArray(typeArguments);
    node.arguments = argumentsArray ? parenthesizerRules().parenthesizeExpressionsOfCommaDelimitedList(argumentsArray) : void 0;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildrenFlags(node.typeArguments) | propagateChildrenFlags(node.arguments) | 32 /* ContainsES2020 */;
    if (node.typeArguments) {
      node.transformFlags |= 1 /* ContainsTypeScript */;
    }
    return node;
  }
  function updateNewExpression(node, expression, typeArguments, argumentsArray) {
    return node.expression !== expression || node.typeArguments !== typeArguments || node.arguments !== argumentsArray ? update(createNewExpression(expression, typeArguments, argumentsArray), node) : node;
  }
  function createTaggedTemplateExpression(tag, typeArguments, template) {
    const node = createBaseNode(215 /* TaggedTemplateExpression */);
    node.tag = parenthesizerRules().parenthesizeLeftSideOfAccess(
      tag,
      /*optionalChain*/
      false
    );
    node.typeArguments = asNodeArray(typeArguments);
    node.template = template;
    node.transformFlags |= propagateChildFlags(node.tag) | propagateChildrenFlags(node.typeArguments) | propagateChildFlags(node.template) | 1024 /* ContainsES2015 */;
    if (node.typeArguments) {
      node.transformFlags |= 1 /* ContainsTypeScript */;
    }
    if (hasInvalidEscape(node.template)) {
      node.transformFlags |= 128 /* ContainsES2018 */;
    }
    return node;
  }
  function updateTaggedTemplateExpression(node, tag, typeArguments, template) {
    return node.tag !== tag || node.typeArguments !== typeArguments || node.template !== template ? update(createTaggedTemplateExpression(tag, typeArguments, template), node) : node;
  }
  function createTypeAssertion(type, expression) {
    const node = createBaseNode(216 /* TypeAssertionExpression */);
    node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression);
    node.type = type;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.type) | 1 /* ContainsTypeScript */;
    return node;
  }
  function updateTypeAssertion(node, type, expression) {
    return node.type !== type || node.expression !== expression ? update(createTypeAssertion(type, expression), node) : node;
  }
  function createParenthesizedExpression(expression) {
    const node = createBaseNode(217 /* ParenthesizedExpression */);
    node.expression = expression;
    node.transformFlags = propagateChildFlags(node.expression);
    node.jsDoc = void 0;
    return node;
  }
  function updateParenthesizedExpression(node, expression) {
    return node.expression !== expression ? update(createParenthesizedExpression(expression), node) : node;
  }
  function createFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, type, body) {
    const node = createBaseDeclaration(218 /* FunctionExpression */);
    node.modifiers = asNodeArray(modifiers);
    node.asteriskToken = asteriskToken;
    node.name = asName(name);
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = createNodeArray(parameters);
    node.type = type;
    node.body = body;
    const isAsync = modifiersToFlags(node.modifiers) & 1024 /* Async */;
    const isGenerator = !!node.asteriskToken;
    const isAsyncGenerator = isAsync && isGenerator;
    node.transformFlags = propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.asteriskToken) | propagateNameFlags(node.name) | propagateChildrenFlags(node.typeParameters) | propagateChildrenFlags(node.parameters) | propagateChildFlags(node.type) | propagateChildFlags(node.body) & ~67108864 /* ContainsPossibleTopLevelAwait */ | (isAsyncGenerator ? 128 /* ContainsES2018 */ : isAsync ? 256 /* ContainsES2017 */ : isGenerator ? 2048 /* ContainsGenerator */ : 0 /* None */) | (node.typeParameters || node.type ? 1 /* ContainsTypeScript */ : 0 /* None */) | 4194304 /* ContainsHoistedDeclarationOrCompletion */;
    node.typeArguments = void 0;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.flowNode = void 0;
    node.endFlowNode = void 0;
    node.returnFlowNode = void 0;
    return node;
  }
  function updateFunctionExpression(node, modifiers, asteriskToken, name, typeParameters, parameters, type, body) {
    return node.name !== name || node.modifiers !== modifiers || node.asteriskToken !== asteriskToken || node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type || node.body !== body ? finishUpdateBaseSignatureDeclaration(createFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, type, body), node) : node;
  }
  function createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body) {
    const node = createBaseDeclaration(219 /* ArrowFunction */);
    node.modifiers = asNodeArray(modifiers);
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = createNodeArray(parameters);
    node.type = type;
    node.equalsGreaterThanToken = equalsGreaterThanToken ?? createToken(39 /* EqualsGreaterThanToken */);
    node.body = parenthesizerRules().parenthesizeConciseBodyOfArrowFunction(body);
    const isAsync = modifiersToFlags(node.modifiers) & 1024 /* Async */;
    node.transformFlags = propagateChildrenFlags(node.modifiers) | propagateChildrenFlags(node.typeParameters) | propagateChildrenFlags(node.parameters) | propagateChildFlags(node.type) | propagateChildFlags(node.equalsGreaterThanToken) | propagateChildFlags(node.body) & ~67108864 /* ContainsPossibleTopLevelAwait */ | (node.typeParameters || node.type ? 1 /* ContainsTypeScript */ : 0 /* None */) | (isAsync ? 256 /* ContainsES2017 */ | 16384 /* ContainsLexicalThis */ : 0 /* None */) | 1024 /* ContainsES2015 */;
    node.typeArguments = void 0;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.flowNode = void 0;
    node.endFlowNode = void 0;
    node.returnFlowNode = void 0;
    return node;
  }
  function updateArrowFunction(node, modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body) {
    return node.modifiers !== modifiers || node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type || node.equalsGreaterThanToken !== equalsGreaterThanToken || node.body !== body ? finishUpdateBaseSignatureDeclaration(createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body), node) : node;
  }
  function createDeleteExpression(expression) {
    const node = createBaseNode(220 /* DeleteExpression */);
    node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression);
    node.transformFlags |= propagateChildFlags(node.expression);
    return node;
  }
  function updateDeleteExpression(node, expression) {
    return node.expression !== expression ? update(createDeleteExpression(expression), node) : node;
  }
  function createTypeOfExpression(expression) {
    const node = createBaseNode(221 /* TypeOfExpression */);
    node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression);
    node.transformFlags |= propagateChildFlags(node.expression);
    return node;
  }
  function updateTypeOfExpression(node, expression) {
    return node.expression !== expression ? update(createTypeOfExpression(expression), node) : node;
  }
  function createVoidExpression(expression) {
    const node = createBaseNode(222 /* VoidExpression */);
    node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression);
    node.transformFlags |= propagateChildFlags(node.expression);
    return node;
  }
  function updateVoidExpression(node, expression) {
    return node.expression !== expression ? update(createVoidExpression(expression), node) : node;
  }
  function createAwaitExpression(expression) {
    const node = createBaseNode(223 /* AwaitExpression */);
    node.expression = parenthesizerRules().parenthesizeOperandOfPrefixUnary(expression);
    node.transformFlags |= propagateChildFlags(node.expression) | 256 /* ContainsES2017 */ | 128 /* ContainsES2018 */ | 2097152 /* ContainsAwait */;
    return node;
  }
  function updateAwaitExpression(node, expression) {
    return node.expression !== expression ? update(createAwaitExpression(expression), node) : node;
  }
  function createPrefixUnaryExpression(operator, operand) {
    const node = createBaseNode(224 /* PrefixUnaryExpression */);
    node.operator = operator;
    node.operand = parenthesizerRules().parenthesizeOperandOfPrefixUnary(operand);
    node.transformFlags |= propagateChildFlags(node.operand);
    if ((operator === 46 /* PlusPlusToken */ || operator === 47 /* MinusMinusToken */) && isIdentifier(node.operand) && !isGeneratedIdentifier(node.operand) && !isLocalName(node.operand)) {
      node.transformFlags |= 268435456 /* ContainsUpdateExpressionForIdentifier */;
    }
    return node;
  }
  function updatePrefixUnaryExpression(node, operand) {
    return node.operand !== operand ? update(createPrefixUnaryExpression(node.operator, operand), node) : node;
  }
  function createPostfixUnaryExpression(operand, operator) {
    const node = createBaseNode(225 /* PostfixUnaryExpression */);
    node.operator = operator;
    node.operand = parenthesizerRules().parenthesizeOperandOfPostfixUnary(operand);
    node.transformFlags |= propagateChildFlags(node.operand);
    if (isIdentifier(node.operand) && !isGeneratedIdentifier(node.operand) && !isLocalName(node.operand)) {
      node.transformFlags |= 268435456 /* ContainsUpdateExpressionForIdentifier */;
    }
    return node;
  }
  function updatePostfixUnaryExpression(node, operand) {
    return node.operand !== operand ? update(createPostfixUnaryExpression(operand, node.operator), node) : node;
  }
  function createBinaryExpression(left, operator, right) {
    const node = createBaseDeclaration(226 /* BinaryExpression */);
    const operatorToken = asToken(operator);
    const operatorKind = operatorToken.kind;
    node.left = parenthesizerRules().parenthesizeLeftSideOfBinary(operatorKind, left);
    node.operatorToken = operatorToken;
    node.right = parenthesizerRules().parenthesizeRightSideOfBinary(operatorKind, node.left, right);
    node.transformFlags |= propagateChildFlags(node.left) | propagateChildFlags(node.operatorToken) | propagateChildFlags(node.right);
    if (operatorKind === 61 /* QuestionQuestionToken */) {
      node.transformFlags |= 32 /* ContainsES2020 */;
    } else if (operatorKind === 64 /* EqualsToken */) {
      if (isObjectLiteralExpression(node.left)) {
        node.transformFlags |= 1024 /* ContainsES2015 */ | 128 /* ContainsES2018 */ | 4096 /* ContainsDestructuringAssignment */ | propagateAssignmentPatternFlags(node.left);
      } else if (isArrayLiteralExpression(node.left)) {
        node.transformFlags |= 1024 /* ContainsES2015 */ | 4096 /* ContainsDestructuringAssignment */ | propagateAssignmentPatternFlags(node.left);
      }
    } else if (operatorKind === 43 /* AsteriskAsteriskToken */ || operatorKind === 68 /* AsteriskAsteriskEqualsToken */) {
      node.transformFlags |= 512 /* ContainsES2016 */;
    } else if (isLogicalOrCoalescingAssignmentOperator(operatorKind)) {
      node.transformFlags |= 16 /* ContainsES2021 */;
    }
    if (operatorKind === 103 /* InKeyword */ && isPrivateIdentifier(node.left)) {
      node.transformFlags |= 536870912 /* ContainsPrivateIdentifierInExpression */;
    }
    node.jsDoc = void 0;
    return node;
  }
  function propagateAssignmentPatternFlags(node) {
    return containsObjectRestOrSpread(node) ? 65536 /* ContainsObjectRestOrSpread */ : 0 /* None */;
  }
  function updateBinaryExpression(node, left, operator, right) {
    return node.left !== left || node.operatorToken !== operator || node.right !== right ? update(createBinaryExpression(left, operator, right), node) : node;
  }
  function createConditionalExpression(condition, questionToken, whenTrue, colonToken, whenFalse) {
    const node = createBaseNode(227 /* ConditionalExpression */);
    node.condition = parenthesizerRules().parenthesizeConditionOfConditionalExpression(condition);
    node.questionToken = questionToken ?? createToken(58 /* QuestionToken */);
    node.whenTrue = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenTrue);
    node.colonToken = colonToken ?? createToken(59 /* ColonToken */);
    node.whenFalse = parenthesizerRules().parenthesizeBranchOfConditionalExpression(whenFalse);
    node.transformFlags |= propagateChildFlags(node.condition) | propagateChildFlags(node.questionToken) | propagateChildFlags(node.whenTrue) | propagateChildFlags(node.colonToken) | propagateChildFlags(node.whenFalse);
    return node;
  }
  function updateConditionalExpression(node, condition, questionToken, whenTrue, colonToken, whenFalse) {
    return node.condition !== condition || node.questionToken !== questionToken || node.whenTrue !== whenTrue || node.colonToken !== colonToken || node.whenFalse !== whenFalse ? update(createConditionalExpression(condition, questionToken, whenTrue, colonToken, whenFalse), node) : node;
  }
  function createTemplateExpression(head, templateSpans) {
    const node = createBaseNode(228 /* TemplateExpression */);
    node.head = head;
    node.templateSpans = createNodeArray(templateSpans);
    node.transformFlags |= propagateChildFlags(node.head) | propagateChildrenFlags(node.templateSpans) | 1024 /* ContainsES2015 */;
    return node;
  }
  function updateTemplateExpression(node, head, templateSpans) {
    return node.head !== head || node.templateSpans !== templateSpans ? update(createTemplateExpression(head, templateSpans), node) : node;
  }
  function checkTemplateLiteralLikeNode(kind, text, rawText, templateFlags = 0 /* None */) {
    Debug.assert(!(templateFlags & ~7176 /* TemplateLiteralLikeFlags */), "Unsupported template flags.");
    let cooked = void 0;
    if (rawText !== void 0 && rawText !== text) {
      cooked = getCookedText(kind, rawText);
      if (typeof cooked === "object") {
        return Debug.fail("Invalid raw text");
      }
    }
    if (text === void 0) {
      if (cooked === void 0) {
        return Debug.fail("Arguments 'text' and 'rawText' may not both be undefined.");
      }
      text = cooked;
    } else if (cooked !== void 0) {
      Debug.assert(text === cooked, "Expected argument 'text' to be the normalized (i.e. 'cooked') version of argument 'rawText'.");
    }
    return text;
  }
  function getTransformFlagsOfTemplateLiteralLike(templateFlags) {
    let transformFlags = 1024 /* ContainsES2015 */;
    if (templateFlags) {
      transformFlags |= 128 /* ContainsES2018 */;
    }
    return transformFlags;
  }
  function createTemplateLiteralLikeToken(kind, text, rawText, templateFlags) {
    const node = createBaseToken(kind);
    node.text = text;
    node.rawText = rawText;
    node.templateFlags = templateFlags & 7176 /* TemplateLiteralLikeFlags */;
    node.transformFlags = getTransformFlagsOfTemplateLiteralLike(node.templateFlags);
    return node;
  }
  function createTemplateLiteralLikeDeclaration(kind, text, rawText, templateFlags) {
    const node = createBaseDeclaration(kind);
    node.text = text;
    node.rawText = rawText;
    node.templateFlags = templateFlags & 7176 /* TemplateLiteralLikeFlags */;
    node.transformFlags = getTransformFlagsOfTemplateLiteralLike(node.templateFlags);
    return node;
  }
  function createTemplateLiteralLikeNode(kind, text, rawText, templateFlags) {
    if (kind === 15 /* NoSubstitutionTemplateLiteral */) {
      return createTemplateLiteralLikeDeclaration(kind, text, rawText, templateFlags);
    }
    return createTemplateLiteralLikeToken(kind, text, rawText, templateFlags);
  }
  function createTemplateHead(text, rawText, templateFlags) {
    text = checkTemplateLiteralLikeNode(16 /* TemplateHead */, text, rawText, templateFlags);
    return createTemplateLiteralLikeNode(16 /* TemplateHead */, text, rawText, templateFlags);
  }
  function createTemplateMiddle(text, rawText, templateFlags) {
    text = checkTemplateLiteralLikeNode(16 /* TemplateHead */, text, rawText, templateFlags);
    return createTemplateLiteralLikeNode(17 /* TemplateMiddle */, text, rawText, templateFlags);
  }
  function createTemplateTail(text, rawText, templateFlags) {
    text = checkTemplateLiteralLikeNode(16 /* TemplateHead */, text, rawText, templateFlags);
    return createTemplateLiteralLikeNode(18 /* TemplateTail */, text, rawText, templateFlags);
  }
  function createNoSubstitutionTemplateLiteral(text, rawText, templateFlags) {
    text = checkTemplateLiteralLikeNode(16 /* TemplateHead */, text, rawText, templateFlags);
    return createTemplateLiteralLikeDeclaration(15 /* NoSubstitutionTemplateLiteral */, text, rawText, templateFlags);
  }
  function createYieldExpression(asteriskToken, expression) {
    Debug.assert(!asteriskToken || !!expression, "A `YieldExpression` with an asteriskToken must have an expression.");
    const node = createBaseNode(229 /* YieldExpression */);
    node.expression = expression && parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression);
    node.asteriskToken = asteriskToken;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.asteriskToken) | 1024 /* ContainsES2015 */ | 128 /* ContainsES2018 */ | 1048576 /* ContainsYield */;
    return node;
  }
  function updateYieldExpression(node, asteriskToken, expression) {
    return node.expression !== expression || node.asteriskToken !== asteriskToken ? update(createYieldExpression(asteriskToken, expression), node) : node;
  }
  function createSpreadElement(expression) {
    const node = createBaseNode(230 /* SpreadElement */);
    node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression);
    node.transformFlags |= propagateChildFlags(node.expression) | 1024 /* ContainsES2015 */ | 32768 /* ContainsRestOrSpread */;
    return node;
  }
  function updateSpreadElement(node, expression) {
    return node.expression !== expression ? update(createSpreadElement(expression), node) : node;
  }
  function createClassExpression(modifiers, name, typeParameters, heritageClauses, members) {
    const node = createBaseDeclaration(231 /* ClassExpression */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.typeParameters = asNodeArray(typeParameters);
    node.heritageClauses = asNodeArray(heritageClauses);
    node.members = createNodeArray(members);
    node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateNameFlags(node.name) | propagateChildrenFlags(node.typeParameters) | propagateChildrenFlags(node.heritageClauses) | propagateChildrenFlags(node.members) | (node.typeParameters ? 1 /* ContainsTypeScript */ : 0 /* None */) | 1024 /* ContainsES2015 */;
    node.jsDoc = void 0;
    return node;
  }
  function updateClassExpression(node, modifiers, name, typeParameters, heritageClauses, members) {
    return node.modifiers !== modifiers || node.name !== name || node.typeParameters !== typeParameters || node.heritageClauses !== heritageClauses || node.members !== members ? update(createClassExpression(modifiers, name, typeParameters, heritageClauses, members), node) : node;
  }
  function createOmittedExpression() {
    return createBaseNode(232 /* OmittedExpression */);
  }
  function createExpressionWithTypeArguments(expression, typeArguments) {
    const node = createBaseNode(233 /* ExpressionWithTypeArguments */);
    node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(
      expression,
      /*optionalChain*/
      false
    );
    node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildrenFlags(node.typeArguments) | 1024 /* ContainsES2015 */;
    return node;
  }
  function updateExpressionWithTypeArguments(node, expression, typeArguments) {
    return node.expression !== expression || node.typeArguments !== typeArguments ? update(createExpressionWithTypeArguments(expression, typeArguments), node) : node;
  }
  function createAsExpression(expression, type) {
    const node = createBaseNode(234 /* AsExpression */);
    node.expression = expression;
    node.type = type;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.type) | 1 /* ContainsTypeScript */;
    return node;
  }
  function updateAsExpression(node, expression, type) {
    return node.expression !== expression || node.type !== type ? update(createAsExpression(expression, type), node) : node;
  }
  function createNonNullExpression(expression) {
    const node = createBaseNode(235 /* NonNullExpression */);
    node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(
      expression,
      /*optionalChain*/
      false
    );
    node.transformFlags |= propagateChildFlags(node.expression) | 1 /* ContainsTypeScript */;
    return node;
  }
  function updateNonNullExpression(node, expression) {
    if (isNonNullChain(node)) {
      return updateNonNullChain(node, expression);
    }
    return node.expression !== expression ? update(createNonNullExpression(expression), node) : node;
  }
  function createSatisfiesExpression(expression, type) {
    const node = createBaseNode(238 /* SatisfiesExpression */);
    node.expression = expression;
    node.type = type;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.type) | 1 /* ContainsTypeScript */;
    return node;
  }
  function updateSatisfiesExpression(node, expression, type) {
    return node.expression !== expression || node.type !== type ? update(createSatisfiesExpression(expression, type), node) : node;
  }
  function createNonNullChain(expression) {
    const node = createBaseNode(235 /* NonNullExpression */);
    node.flags |= 64 /* OptionalChain */;
    node.expression = parenthesizerRules().parenthesizeLeftSideOfAccess(
      expression,
      /*optionalChain*/
      true
    );
    node.transformFlags |= propagateChildFlags(node.expression) | 1 /* ContainsTypeScript */;
    return node;
  }
  function updateNonNullChain(node, expression) {
    Debug.assert(!!(node.flags & 64 /* OptionalChain */), "Cannot update a NonNullExpression using updateNonNullChain. Use updateNonNullExpression instead.");
    return node.expression !== expression ? update(createNonNullChain(expression), node) : node;
  }
  function createMetaProperty(keywordToken, name) {
    const node = createBaseNode(236 /* MetaProperty */);
    node.keywordToken = keywordToken;
    node.name = name;
    node.transformFlags |= propagateChildFlags(node.name);
    switch (keywordToken) {
      case 105 /* NewKeyword */:
        node.transformFlags |= 1024 /* ContainsES2015 */;
        break;
      case 102 /* ImportKeyword */:
        node.transformFlags |= 32 /* ContainsES2020 */;
        break;
      default:
        return Debug.assertNever(keywordToken);
    }
    node.flowNode = void 0;
    return node;
  }
  function updateMetaProperty(node, name) {
    return node.name !== name ? update(createMetaProperty(node.keywordToken, name), node) : node;
  }
  function createTemplateSpan(expression, literal) {
    const node = createBaseNode(239 /* TemplateSpan */);
    node.expression = expression;
    node.literal = literal;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.literal) | 1024 /* ContainsES2015 */;
    return node;
  }
  function updateTemplateSpan(node, expression, literal) {
    return node.expression !== expression || node.literal !== literal ? update(createTemplateSpan(expression, literal), node) : node;
  }
  function createSemicolonClassElement() {
    const node = createBaseNode(240 /* SemicolonClassElement */);
    node.transformFlags |= 1024 /* ContainsES2015 */;
    return node;
  }
  function createBlock(statements, multiLine) {
    const node = createBaseNode(241 /* Block */);
    node.statements = createNodeArray(statements);
    node.multiLine = multiLine;
    node.transformFlags |= propagateChildrenFlags(node.statements);
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateBlock(node, statements) {
    return node.statements !== statements ? update(createBlock(statements, node.multiLine), node) : node;
  }
  function createVariableStatement(modifiers, declarationList) {
    const node = createBaseNode(243 /* VariableStatement */);
    node.modifiers = asNodeArray(modifiers);
    node.declarationList = isArray(declarationList) ? createVariableDeclarationList(declarationList) : declarationList;
    node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.declarationList);
    if (modifiersToFlags(node.modifiers) & 128 /* Ambient */) {
      node.transformFlags = 1 /* ContainsTypeScript */;
    }
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateVariableStatement(node, modifiers, declarationList) {
    return node.modifiers !== modifiers || node.declarationList !== declarationList ? update(createVariableStatement(modifiers, declarationList), node) : node;
  }
  function createEmptyStatement() {
    const node = createBaseNode(242 /* EmptyStatement */);
    node.jsDoc = void 0;
    return node;
  }
  function createExpressionStatement(expression) {
    const node = createBaseNode(244 /* ExpressionStatement */);
    node.expression = parenthesizerRules().parenthesizeExpressionOfExpressionStatement(expression);
    node.transformFlags |= propagateChildFlags(node.expression);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateExpressionStatement(node, expression) {
    return node.expression !== expression ? update(createExpressionStatement(expression), node) : node;
  }
  function createIfStatement(expression, thenStatement, elseStatement) {
    const node = createBaseNode(245 /* IfStatement */);
    node.expression = expression;
    node.thenStatement = asEmbeddedStatement(thenStatement);
    node.elseStatement = asEmbeddedStatement(elseStatement);
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.thenStatement) | propagateChildFlags(node.elseStatement);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateIfStatement(node, expression, thenStatement, elseStatement) {
    return node.expression !== expression || node.thenStatement !== thenStatement || node.elseStatement !== elseStatement ? update(createIfStatement(expression, thenStatement, elseStatement), node) : node;
  }
  function createDoStatement(statement, expression) {
    const node = createBaseNode(246 /* DoStatement */);
    node.statement = asEmbeddedStatement(statement);
    node.expression = expression;
    node.transformFlags |= propagateChildFlags(node.statement) | propagateChildFlags(node.expression);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateDoStatement(node, statement, expression) {
    return node.statement !== statement || node.expression !== expression ? update(createDoStatement(statement, expression), node) : node;
  }
  function createWhileStatement(expression, statement) {
    const node = createBaseNode(247 /* WhileStatement */);
    node.expression = expression;
    node.statement = asEmbeddedStatement(statement);
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.statement);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateWhileStatement(node, expression, statement) {
    return node.expression !== expression || node.statement !== statement ? update(createWhileStatement(expression, statement), node) : node;
  }
  function createForStatement(initializer, condition, incrementor, statement) {
    const node = createBaseNode(248 /* ForStatement */);
    node.initializer = initializer;
    node.condition = condition;
    node.incrementor = incrementor;
    node.statement = asEmbeddedStatement(statement);
    node.transformFlags |= propagateChildFlags(node.initializer) | propagateChildFlags(node.condition) | propagateChildFlags(node.incrementor) | propagateChildFlags(node.statement);
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateForStatement(node, initializer, condition, incrementor, statement) {
    return node.initializer !== initializer || node.condition !== condition || node.incrementor !== incrementor || node.statement !== statement ? update(createForStatement(initializer, condition, incrementor, statement), node) : node;
  }
  function createForInStatement(initializer, expression, statement) {
    const node = createBaseNode(249 /* ForInStatement */);
    node.initializer = initializer;
    node.expression = expression;
    node.statement = asEmbeddedStatement(statement);
    node.transformFlags |= propagateChildFlags(node.initializer) | propagateChildFlags(node.expression) | propagateChildFlags(node.statement);
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateForInStatement(node, initializer, expression, statement) {
    return node.initializer !== initializer || node.expression !== expression || node.statement !== statement ? update(createForInStatement(initializer, expression, statement), node) : node;
  }
  function createForOfStatement(awaitModifier, initializer, expression, statement) {
    const node = createBaseNode(250 /* ForOfStatement */);
    node.awaitModifier = awaitModifier;
    node.initializer = initializer;
    node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression);
    node.statement = asEmbeddedStatement(statement);
    node.transformFlags |= propagateChildFlags(node.awaitModifier) | propagateChildFlags(node.initializer) | propagateChildFlags(node.expression) | propagateChildFlags(node.statement) | 1024 /* ContainsES2015 */;
    if (awaitModifier) node.transformFlags |= 128 /* ContainsES2018 */;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateForOfStatement(node, awaitModifier, initializer, expression, statement) {
    return node.awaitModifier !== awaitModifier || node.initializer !== initializer || node.expression !== expression || node.statement !== statement ? update(createForOfStatement(awaitModifier, initializer, expression, statement), node) : node;
  }
  function createContinueStatement(label) {
    const node = createBaseNode(251 /* ContinueStatement */);
    node.label = asName(label);
    node.transformFlags |= propagateChildFlags(node.label) | 4194304 /* ContainsHoistedDeclarationOrCompletion */;
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateContinueStatement(node, label) {
    return node.label !== label ? update(createContinueStatement(label), node) : node;
  }
  function createBreakStatement(label) {
    const node = createBaseNode(252 /* BreakStatement */);
    node.label = asName(label);
    node.transformFlags |= propagateChildFlags(node.label) | 4194304 /* ContainsHoistedDeclarationOrCompletion */;
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateBreakStatement(node, label) {
    return node.label !== label ? update(createBreakStatement(label), node) : node;
  }
  function createReturnStatement(expression) {
    const node = createBaseNode(253 /* ReturnStatement */);
    node.expression = expression;
    node.transformFlags |= propagateChildFlags(node.expression) | 128 /* ContainsES2018 */ | 4194304 /* ContainsHoistedDeclarationOrCompletion */;
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateReturnStatement(node, expression) {
    return node.expression !== expression ? update(createReturnStatement(expression), node) : node;
  }
  function createWithStatement(expression, statement) {
    const node = createBaseNode(254 /* WithStatement */);
    node.expression = expression;
    node.statement = asEmbeddedStatement(statement);
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.statement);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateWithStatement(node, expression, statement) {
    return node.expression !== expression || node.statement !== statement ? update(createWithStatement(expression, statement), node) : node;
  }
  function createSwitchStatement(expression, caseBlock) {
    const node = createBaseNode(255 /* SwitchStatement */);
    node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression);
    node.caseBlock = caseBlock;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.caseBlock);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    node.possiblyExhaustive = false;
    return node;
  }
  function updateSwitchStatement(node, expression, caseBlock) {
    return node.expression !== expression || node.caseBlock !== caseBlock ? update(createSwitchStatement(expression, caseBlock), node) : node;
  }
  function createLabeledStatement(label, statement) {
    const node = createBaseNode(256 /* LabeledStatement */);
    node.label = asName(label);
    node.statement = asEmbeddedStatement(statement);
    node.transformFlags |= propagateChildFlags(node.label) | propagateChildFlags(node.statement);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateLabeledStatement(node, label, statement) {
    return node.label !== label || node.statement !== statement ? update(createLabeledStatement(label, statement), node) : node;
  }
  function createThrowStatement(expression) {
    const node = createBaseNode(257 /* ThrowStatement */);
    node.expression = expression;
    node.transformFlags |= propagateChildFlags(node.expression);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateThrowStatement(node, expression) {
    return node.expression !== expression ? update(createThrowStatement(expression), node) : node;
  }
  function createTryStatement(tryBlock, catchClause, finallyBlock) {
    const node = createBaseNode(258 /* TryStatement */);
    node.tryBlock = tryBlock;
    node.catchClause = catchClause;
    node.finallyBlock = finallyBlock;
    node.transformFlags |= propagateChildFlags(node.tryBlock) | propagateChildFlags(node.catchClause) | propagateChildFlags(node.finallyBlock);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function updateTryStatement(node, tryBlock, catchClause, finallyBlock) {
    return node.tryBlock !== tryBlock || node.catchClause !== catchClause || node.finallyBlock !== finallyBlock ? update(createTryStatement(tryBlock, catchClause, finallyBlock), node) : node;
  }
  function createDebuggerStatement() {
    const node = createBaseNode(259 /* DebuggerStatement */);
    node.jsDoc = void 0;
    node.flowNode = void 0;
    return node;
  }
  function createVariableDeclaration(name, exclamationToken, type, initializer) {
    const node = createBaseDeclaration(260 /* VariableDeclaration */);
    node.name = asName(name);
    node.exclamationToken = exclamationToken;
    node.type = type;
    node.initializer = asInitializer(initializer);
    node.transformFlags |= propagateNameFlags(node.name) | propagateChildFlags(node.initializer) | (node.exclamationToken ?? node.type ? 1 /* ContainsTypeScript */ : 0 /* None */);
    node.jsDoc = void 0;
    return node;
  }
  function updateVariableDeclaration(node, name, exclamationToken, type, initializer) {
    return node.name !== name || node.type !== type || node.exclamationToken !== exclamationToken || node.initializer !== initializer ? update(createVariableDeclaration(name, exclamationToken, type, initializer), node) : node;
  }
  function createVariableDeclarationList(declarations, flags2 = 0 /* None */) {
    const node = createBaseNode(261 /* VariableDeclarationList */);
    node.flags |= flags2 & 7 /* BlockScoped */;
    node.declarations = createNodeArray(declarations);
    node.transformFlags |= propagateChildrenFlags(node.declarations) | 4194304 /* ContainsHoistedDeclarationOrCompletion */;
    if (flags2 & 7 /* BlockScoped */) {
      node.transformFlags |= 1024 /* ContainsES2015 */ | 262144 /* ContainsBlockScopedBinding */;
    }
    if (flags2 & 4 /* Using */) {
      node.transformFlags |= 4 /* ContainsESNext */;
    }
    return node;
  }
  function updateVariableDeclarationList(node, declarations) {
    return node.declarations !== declarations ? update(createVariableDeclarationList(declarations, node.flags), node) : node;
  }
  function createFunctionDeclaration(modifiers, asteriskToken, name, typeParameters, parameters, type, body) {
    const node = createBaseDeclaration(262 /* FunctionDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.asteriskToken = asteriskToken;
    node.name = asName(name);
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = createNodeArray(parameters);
    node.type = type;
    node.body = body;
    if (!node.body || modifiersToFlags(node.modifiers) & 128 /* Ambient */) {
      node.transformFlags = 1 /* ContainsTypeScript */;
    } else {
      const isAsync = modifiersToFlags(node.modifiers) & 1024 /* Async */;
      const isGenerator = !!node.asteriskToken;
      const isAsyncGenerator = isAsync && isGenerator;
      node.transformFlags = propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.asteriskToken) | propagateNameFlags(node.name) | propagateChildrenFlags(node.typeParameters) | propagateChildrenFlags(node.parameters) | propagateChildFlags(node.type) | propagateChildFlags(node.body) & ~67108864 /* ContainsPossibleTopLevelAwait */ | (isAsyncGenerator ? 128 /* ContainsES2018 */ : isAsync ? 256 /* ContainsES2017 */ : isGenerator ? 2048 /* ContainsGenerator */ : 0 /* None */) | (node.typeParameters || node.type ? 1 /* ContainsTypeScript */ : 0 /* None */) | 4194304 /* ContainsHoistedDeclarationOrCompletion */;
    }
    node.typeArguments = void 0;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.endFlowNode = void 0;
    node.returnFlowNode = void 0;
    return node;
  }
  function updateFunctionDeclaration(node, modifiers, asteriskToken, name, typeParameters, parameters, type, body) {
    return node.modifiers !== modifiers || node.asteriskToken !== asteriskToken || node.name !== name || node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type || node.body !== body ? finishUpdateFunctionDeclaration(createFunctionDeclaration(modifiers, asteriskToken, name, typeParameters, parameters, type, body), node) : node;
  }
  function finishUpdateFunctionDeclaration(updated, original) {
    if (updated !== original) {
      if (updated.modifiers === original.modifiers) {
        updated.modifiers = original.modifiers;
      }
    }
    return finishUpdateBaseSignatureDeclaration(updated, original);
  }
  function createClassDeclaration(modifiers, name, typeParameters, heritageClauses, members) {
    const node = createBaseDeclaration(263 /* ClassDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.typeParameters = asNodeArray(typeParameters);
    node.heritageClauses = asNodeArray(heritageClauses);
    node.members = createNodeArray(members);
    if (modifiersToFlags(node.modifiers) & 128 /* Ambient */) {
      node.transformFlags = 1 /* ContainsTypeScript */;
    } else {
      node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateNameFlags(node.name) | propagateChildrenFlags(node.typeParameters) | propagateChildrenFlags(node.heritageClauses) | propagateChildrenFlags(node.members) | (node.typeParameters ? 1 /* ContainsTypeScript */ : 0 /* None */) | 1024 /* ContainsES2015 */;
      if (node.transformFlags & 8192 /* ContainsTypeScriptClassSyntax */) {
        node.transformFlags |= 1 /* ContainsTypeScript */;
      }
    }
    node.jsDoc = void 0;
    return node;
  }
  function updateClassDeclaration(node, modifiers, name, typeParameters, heritageClauses, members) {
    return node.modifiers !== modifiers || node.name !== name || node.typeParameters !== typeParameters || node.heritageClauses !== heritageClauses || node.members !== members ? update(createClassDeclaration(modifiers, name, typeParameters, heritageClauses, members), node) : node;
  }
  function createInterfaceDeclaration(modifiers, name, typeParameters, heritageClauses, members) {
    const node = createBaseDeclaration(264 /* InterfaceDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.typeParameters = asNodeArray(typeParameters);
    node.heritageClauses = asNodeArray(heritageClauses);
    node.members = createNodeArray(members);
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.jsDoc = void 0;
    return node;
  }
  function updateInterfaceDeclaration(node, modifiers, name, typeParameters, heritageClauses, members) {
    return node.modifiers !== modifiers || node.name !== name || node.typeParameters !== typeParameters || node.heritageClauses !== heritageClauses || node.members !== members ? update(createInterfaceDeclaration(modifiers, name, typeParameters, heritageClauses, members), node) : node;
  }
  function createTypeAliasDeclaration(modifiers, name, typeParameters, type) {
    const node = createBaseDeclaration(265 /* TypeAliasDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.typeParameters = asNodeArray(typeParameters);
    node.type = type;
    node.transformFlags = 1 /* ContainsTypeScript */;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateTypeAliasDeclaration(node, modifiers, name, typeParameters, type) {
    return node.modifiers !== modifiers || node.name !== name || node.typeParameters !== typeParameters || node.type !== type ? update(createTypeAliasDeclaration(modifiers, name, typeParameters, type), node) : node;
  }
  function createEnumDeclaration(modifiers, name, members) {
    const node = createBaseDeclaration(266 /* EnumDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.members = createNodeArray(members);
    node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.name) | propagateChildrenFlags(node.members) | 1 /* ContainsTypeScript */;
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    node.jsDoc = void 0;
    return node;
  }
  function updateEnumDeclaration(node, modifiers, name, members) {
    return node.modifiers !== modifiers || node.name !== name || node.members !== members ? update(createEnumDeclaration(modifiers, name, members), node) : node;
  }
  function createModuleDeclaration(modifiers, name, body, flags2 = 0 /* None */) {
    const node = createBaseDeclaration(267 /* ModuleDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.flags |= flags2 & (32 /* Namespace */ | 8 /* NestedNamespace */ | 2048 /* GlobalAugmentation */);
    node.name = name;
    node.body = body;
    if (modifiersToFlags(node.modifiers) & 128 /* Ambient */) {
      node.transformFlags = 1 /* ContainsTypeScript */;
    } else {
      node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.name) | propagateChildFlags(node.body) | 1 /* ContainsTypeScript */;
    }
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateModuleDeclaration(node, modifiers, name, body) {
    return node.modifiers !== modifiers || node.name !== name || node.body !== body ? update(createModuleDeclaration(modifiers, name, body, node.flags), node) : node;
  }
  function createModuleBlock(statements) {
    const node = createBaseNode(268 /* ModuleBlock */);
    node.statements = createNodeArray(statements);
    node.transformFlags |= propagateChildrenFlags(node.statements);
    node.jsDoc = void 0;
    return node;
  }
  function updateModuleBlock(node, statements) {
    return node.statements !== statements ? update(createModuleBlock(statements), node) : node;
  }
  function createCaseBlock(clauses) {
    const node = createBaseNode(269 /* CaseBlock */);
    node.clauses = createNodeArray(clauses);
    node.transformFlags |= propagateChildrenFlags(node.clauses);
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateCaseBlock(node, clauses) {
    return node.clauses !== clauses ? update(createCaseBlock(clauses), node) : node;
  }
  function createNamespaceExportDeclaration(name) {
    const node = createBaseDeclaration(270 /* NamespaceExportDeclaration */);
    node.name = asName(name);
    node.transformFlags |= propagateIdentifierNameFlags(node.name) | 1 /* ContainsTypeScript */;
    node.modifiers = void 0;
    node.jsDoc = void 0;
    return node;
  }
  function updateNamespaceExportDeclaration(node, name) {
    return node.name !== name ? finishUpdateNamespaceExportDeclaration(createNamespaceExportDeclaration(name), node) : node;
  }
  function finishUpdateNamespaceExportDeclaration(updated, original) {
    if (updated !== original) {
      updated.modifiers = original.modifiers;
    }
    return update(updated, original);
  }
  function createImportEqualsDeclaration(modifiers, isTypeOnly, name, moduleReference) {
    const node = createBaseDeclaration(271 /* ImportEqualsDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.name = asName(name);
    node.isTypeOnly = isTypeOnly;
    node.moduleReference = moduleReference;
    node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateIdentifierNameFlags(node.name) | propagateChildFlags(node.moduleReference);
    if (!isExternalModuleReference(node.moduleReference)) {
      node.transformFlags |= 1 /* ContainsTypeScript */;
    }
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    node.jsDoc = void 0;
    return node;
  }
  function updateImportEqualsDeclaration(node, modifiers, isTypeOnly, name, moduleReference) {
    return node.modifiers !== modifiers || node.isTypeOnly !== isTypeOnly || node.name !== name || node.moduleReference !== moduleReference ? update(createImportEqualsDeclaration(modifiers, isTypeOnly, name, moduleReference), node) : node;
  }
  function createImportDeclaration(modifiers, importClause, moduleSpecifier, attributes) {
    const node = createBaseNode(272 /* ImportDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.importClause = importClause;
    node.moduleSpecifier = moduleSpecifier;
    node.attributes = node.assertClause = attributes;
    node.transformFlags |= propagateChildFlags(node.importClause) | propagateChildFlags(node.moduleSpecifier);
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    node.jsDoc = void 0;
    return node;
  }
  function updateImportDeclaration(node, modifiers, importClause, moduleSpecifier, attributes) {
    return node.modifiers !== modifiers || node.importClause !== importClause || node.moduleSpecifier !== moduleSpecifier || node.attributes !== attributes ? update(createImportDeclaration(modifiers, importClause, moduleSpecifier, attributes), node) : node;
  }
  function createImportClause2(isTypeOnly, name, namedBindings) {
    const node = createBaseDeclaration(273 /* ImportClause */);
    node.isTypeOnly = isTypeOnly;
    node.name = name;
    node.namedBindings = namedBindings;
    node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.namedBindings);
    if (isTypeOnly) {
      node.transformFlags |= 1 /* ContainsTypeScript */;
    }
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    return node;
  }
  function updateImportClause(node, isTypeOnly, name, namedBindings) {
    return node.isTypeOnly !== isTypeOnly || node.name !== name || node.namedBindings !== namedBindings ? update(createImportClause2(isTypeOnly, name, namedBindings), node) : node;
  }
  function createAssertClause(elements, multiLine) {
    const node = createBaseNode(300 /* AssertClause */);
    node.elements = createNodeArray(elements);
    node.multiLine = multiLine;
    node.token = 132 /* AssertKeyword */;
    node.transformFlags |= 4 /* ContainsESNext */;
    return node;
  }
  function updateAssertClause(node, elements, multiLine) {
    return node.elements !== elements || node.multiLine !== multiLine ? update(createAssertClause(elements, multiLine), node) : node;
  }
  function createAssertEntry(name, value) {
    const node = createBaseNode(301 /* AssertEntry */);
    node.name = name;
    node.value = value;
    node.transformFlags |= 4 /* ContainsESNext */;
    return node;
  }
  function updateAssertEntry(node, name, value) {
    return node.name !== name || node.value !== value ? update(createAssertEntry(name, value), node) : node;
  }
  function createImportTypeAssertionContainer(clause, multiLine) {
    const node = createBaseNode(302 /* ImportTypeAssertionContainer */);
    node.assertClause = clause;
    node.multiLine = multiLine;
    return node;
  }
  function updateImportTypeAssertionContainer(node, clause, multiLine) {
    return node.assertClause !== clause || node.multiLine !== multiLine ? update(createImportTypeAssertionContainer(clause, multiLine), node) : node;
  }
  function createImportAttributes(elements, multiLine, token) {
    const node = createBaseNode(300 /* ImportAttributes */);
    node.token = token ?? 118 /* WithKeyword */;
    node.elements = createNodeArray(elements);
    node.multiLine = multiLine;
    node.transformFlags |= 4 /* ContainsESNext */;
    return node;
  }
  function updateImportAttributes(node, elements, multiLine) {
    return node.elements !== elements || node.multiLine !== multiLine ? update(createImportAttributes(elements, multiLine, node.token), node) : node;
  }
  function createImportAttribute(name, value) {
    const node = createBaseNode(301 /* ImportAttribute */);
    node.name = name;
    node.value = value;
    node.transformFlags |= 4 /* ContainsESNext */;
    return node;
  }
  function updateImportAttribute(node, name, value) {
    return node.name !== name || node.value !== value ? update(createImportAttribute(name, value), node) : node;
  }
  function createNamespaceImport(name) {
    const node = createBaseDeclaration(274 /* NamespaceImport */);
    node.name = name;
    node.transformFlags |= propagateChildFlags(node.name);
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    return node;
  }
  function updateNamespaceImport(node, name) {
    return node.name !== name ? update(createNamespaceImport(name), node) : node;
  }
  function createNamespaceExport(name) {
    const node = createBaseDeclaration(280 /* NamespaceExport */);
    node.name = name;
    node.transformFlags |= propagateChildFlags(node.name) | 32 /* ContainsES2020 */;
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    return node;
  }
  function updateNamespaceExport(node, name) {
    return node.name !== name ? update(createNamespaceExport(name), node) : node;
  }
  function createNamedImports(elements) {
    const node = createBaseNode(275 /* NamedImports */);
    node.elements = createNodeArray(elements);
    node.transformFlags |= propagateChildrenFlags(node.elements);
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    return node;
  }
  function updateNamedImports(node, elements) {
    return node.elements !== elements ? update(createNamedImports(elements), node) : node;
  }
  function createImportSpecifier(isTypeOnly, propertyName, name) {
    const node = createBaseDeclaration(276 /* ImportSpecifier */);
    node.isTypeOnly = isTypeOnly;
    node.propertyName = propertyName;
    node.name = name;
    node.transformFlags |= propagateChildFlags(node.propertyName) | propagateChildFlags(node.name);
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    return node;
  }
  function updateImportSpecifier(node, isTypeOnly, propertyName, name) {
    return node.isTypeOnly !== isTypeOnly || node.propertyName !== propertyName || node.name !== name ? update(createImportSpecifier(isTypeOnly, propertyName, name), node) : node;
  }
  function createExportAssignment2(modifiers, isExportEquals, expression) {
    const node = createBaseDeclaration(277 /* ExportAssignment */);
    node.modifiers = asNodeArray(modifiers);
    node.isExportEquals = isExportEquals;
    node.expression = isExportEquals ? parenthesizerRules().parenthesizeRightSideOfBinary(
      64 /* EqualsToken */,
      /*leftSide*/
      void 0,
      expression
    ) : parenthesizerRules().parenthesizeExpressionOfExportDefault(expression);
    node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.expression);
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    node.jsDoc = void 0;
    return node;
  }
  function updateExportAssignment(node, modifiers, expression) {
    return node.modifiers !== modifiers || node.expression !== expression ? update(createExportAssignment2(modifiers, node.isExportEquals, expression), node) : node;
  }
  function createExportDeclaration(modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes) {
    const node = createBaseDeclaration(278 /* ExportDeclaration */);
    node.modifiers = asNodeArray(modifiers);
    node.isTypeOnly = isTypeOnly;
    node.exportClause = exportClause;
    node.moduleSpecifier = moduleSpecifier;
    node.attributes = node.assertClause = attributes;
    node.transformFlags |= propagateChildrenFlags(node.modifiers) | propagateChildFlags(node.exportClause) | propagateChildFlags(node.moduleSpecifier);
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    node.jsDoc = void 0;
    return node;
  }
  function updateExportDeclaration(node, modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes) {
    return node.modifiers !== modifiers || node.isTypeOnly !== isTypeOnly || node.exportClause !== exportClause || node.moduleSpecifier !== moduleSpecifier || node.attributes !== attributes ? finishUpdateExportDeclaration(createExportDeclaration(modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes), node) : node;
  }
  function finishUpdateExportDeclaration(updated, original) {
    if (updated !== original) {
      if (updated.modifiers === original.modifiers) {
        updated.modifiers = original.modifiers;
      }
    }
    return update(updated, original);
  }
  function createNamedExports(elements) {
    const node = createBaseNode(279 /* NamedExports */);
    node.elements = createNodeArray(elements);
    node.transformFlags |= propagateChildrenFlags(node.elements);
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    return node;
  }
  function updateNamedExports(node, elements) {
    return node.elements !== elements ? update(createNamedExports(elements), node) : node;
  }
  function createExportSpecifier(isTypeOnly, propertyName, name) {
    const node = createBaseNode(281 /* ExportSpecifier */);
    node.isTypeOnly = isTypeOnly;
    node.propertyName = asName(propertyName);
    node.name = asName(name);
    node.transformFlags |= propagateChildFlags(node.propertyName) | propagateChildFlags(node.name);
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    node.jsDoc = void 0;
    return node;
  }
  function updateExportSpecifier(node, isTypeOnly, propertyName, name) {
    return node.isTypeOnly !== isTypeOnly || node.propertyName !== propertyName || node.name !== name ? update(createExportSpecifier(isTypeOnly, propertyName, name), node) : node;
  }
  function createMissingDeclaration() {
    const node = createBaseDeclaration(282 /* MissingDeclaration */);
    node.jsDoc = void 0;
    return node;
  }
  function createExternalModuleReference(expression) {
    const node = createBaseNode(283 /* ExternalModuleReference */);
    node.expression = expression;
    node.transformFlags |= propagateChildFlags(node.expression);
    node.transformFlags &= ~67108864 /* ContainsPossibleTopLevelAwait */;
    return node;
  }
  function updateExternalModuleReference(node, expression) {
    return node.expression !== expression ? update(createExternalModuleReference(expression), node) : node;
  }
  function createJSDocPrimaryTypeWorker(kind) {
    return createBaseNode(kind);
  }
  function createJSDocPrePostfixUnaryTypeWorker(kind, type, postfix = false) {
    const node = createJSDocUnaryTypeWorker(
      kind,
      postfix ? type && parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(type) : type
    );
    node.postfix = postfix;
    return node;
  }
  function createJSDocUnaryTypeWorker(kind, type) {
    const node = createBaseNode(kind);
    node.type = type;
    return node;
  }
  function updateJSDocPrePostfixUnaryTypeWorker(kind, node, type) {
    return node.type !== type ? update(createJSDocPrePostfixUnaryTypeWorker(kind, type, node.postfix), node) : node;
  }
  function updateJSDocUnaryTypeWorker(kind, node, type) {
    return node.type !== type ? update(createJSDocUnaryTypeWorker(kind, type), node) : node;
  }
  function createJSDocFunctionType(parameters, type) {
    const node = createBaseDeclaration(317 /* JSDocFunctionType */);
    node.parameters = asNodeArray(parameters);
    node.type = type;
    node.transformFlags = propagateChildrenFlags(node.parameters) | (node.type ? 1 /* ContainsTypeScript */ : 0 /* None */);
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    node.typeArguments = void 0;
    return node;
  }
  function updateJSDocFunctionType(node, parameters, type) {
    return node.parameters !== parameters || node.type !== type ? update(createJSDocFunctionType(parameters, type), node) : node;
  }
  function createJSDocTypeLiteral(propertyTags, isArrayType = false) {
    const node = createBaseDeclaration(322 /* JSDocTypeLiteral */);
    node.jsDocPropertyTags = asNodeArray(propertyTags);
    node.isArrayType = isArrayType;
    return node;
  }
  function updateJSDocTypeLiteral(node, propertyTags, isArrayType) {
    return node.jsDocPropertyTags !== propertyTags || node.isArrayType !== isArrayType ? update(createJSDocTypeLiteral(propertyTags, isArrayType), node) : node;
  }
  function createJSDocTypeExpression(type) {
    const node = createBaseNode(309 /* JSDocTypeExpression */);
    node.type = type;
    return node;
  }
  function updateJSDocTypeExpression(node, type) {
    return node.type !== type ? update(createJSDocTypeExpression(type), node) : node;
  }
  function createJSDocSignature(typeParameters, parameters, type) {
    const node = createBaseDeclaration(323 /* JSDocSignature */);
    node.typeParameters = asNodeArray(typeParameters);
    node.parameters = createNodeArray(parameters);
    node.type = type;
    node.jsDoc = void 0;
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateJSDocSignature(node, typeParameters, parameters, type) {
    return node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type ? update(createJSDocSignature(typeParameters, parameters, type), node) : node;
  }
  function getDefaultTagName(node) {
    const defaultTagName = getDefaultTagNameForKind(node.kind);
    return node.tagName.escapedText === escapeLeadingUnderscores(defaultTagName) ? node.tagName : createIdentifier(defaultTagName);
  }
  function createBaseJSDocTag(kind, tagName, comment) {
    const node = createBaseNode(kind);
    node.tagName = tagName;
    node.comment = comment;
    return node;
  }
  function createBaseJSDocTagDeclaration(kind, tagName, comment) {
    const node = createBaseDeclaration(kind);
    node.tagName = tagName;
    node.comment = comment;
    return node;
  }
  function createJSDocTemplateTag(tagName, constraint, typeParameters, comment) {
    const node = createBaseJSDocTag(345 /* JSDocTemplateTag */, tagName ?? createIdentifier("template"), comment);
    node.constraint = constraint;
    node.typeParameters = createNodeArray(typeParameters);
    return node;
  }
  function updateJSDocTemplateTag(node, tagName = getDefaultTagName(node), constraint, typeParameters, comment) {
    return node.tagName !== tagName || node.constraint !== constraint || node.typeParameters !== typeParameters || node.comment !== comment ? update(createJSDocTemplateTag(tagName, constraint, typeParameters, comment), node) : node;
  }
  function createJSDocTypedefTag(tagName, typeExpression, fullName, comment) {
    const node = createBaseJSDocTagDeclaration(346 /* JSDocTypedefTag */, tagName ?? createIdentifier("typedef"), comment);
    node.typeExpression = typeExpression;
    node.fullName = fullName;
    node.name = getJSDocTypeAliasName(fullName);
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateJSDocTypedefTag(node, tagName = getDefaultTagName(node), typeExpression, fullName, comment) {
    return node.tagName !== tagName || node.typeExpression !== typeExpression || node.fullName !== fullName || node.comment !== comment ? update(createJSDocTypedefTag(tagName, typeExpression, fullName, comment), node) : node;
  }
  function createJSDocParameterTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment) {
    const node = createBaseJSDocTagDeclaration(341 /* JSDocParameterTag */, tagName ?? createIdentifier("param"), comment);
    node.typeExpression = typeExpression;
    node.name = name;
    node.isNameFirst = !!isNameFirst;
    node.isBracketed = isBracketed;
    return node;
  }
  function updateJSDocParameterTag(node, tagName = getDefaultTagName(node), name, isBracketed, typeExpression, isNameFirst, comment) {
    return node.tagName !== tagName || node.name !== name || node.isBracketed !== isBracketed || node.typeExpression !== typeExpression || node.isNameFirst !== isNameFirst || node.comment !== comment ? update(createJSDocParameterTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node) : node;
  }
  function createJSDocPropertyTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment) {
    const node = createBaseJSDocTagDeclaration(348 /* JSDocPropertyTag */, tagName ?? createIdentifier("prop"), comment);
    node.typeExpression = typeExpression;
    node.name = name;
    node.isNameFirst = !!isNameFirst;
    node.isBracketed = isBracketed;
    return node;
  }
  function updateJSDocPropertyTag(node, tagName = getDefaultTagName(node), name, isBracketed, typeExpression, isNameFirst, comment) {
    return node.tagName !== tagName || node.name !== name || node.isBracketed !== isBracketed || node.typeExpression !== typeExpression || node.isNameFirst !== isNameFirst || node.comment !== comment ? update(createJSDocPropertyTag(tagName, name, isBracketed, typeExpression, isNameFirst, comment), node) : node;
  }
  function createJSDocCallbackTag(tagName, typeExpression, fullName, comment) {
    const node = createBaseJSDocTagDeclaration(338 /* JSDocCallbackTag */, tagName ?? createIdentifier("callback"), comment);
    node.typeExpression = typeExpression;
    node.fullName = fullName;
    node.name = getJSDocTypeAliasName(fullName);
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateJSDocCallbackTag(node, tagName = getDefaultTagName(node), typeExpression, fullName, comment) {
    return node.tagName !== tagName || node.typeExpression !== typeExpression || node.fullName !== fullName || node.comment !== comment ? update(createJSDocCallbackTag(tagName, typeExpression, fullName, comment), node) : node;
  }
  function createJSDocOverloadTag(tagName, typeExpression, comment) {
    const node = createBaseJSDocTag(339 /* JSDocOverloadTag */, tagName ?? createIdentifier("overload"), comment);
    node.typeExpression = typeExpression;
    return node;
  }
  function updateJSDocOverloadTag(node, tagName = getDefaultTagName(node), typeExpression, comment) {
    return node.tagName !== tagName || node.typeExpression !== typeExpression || node.comment !== comment ? update(createJSDocOverloadTag(tagName, typeExpression, comment), node) : node;
  }
  function createJSDocAugmentsTag(tagName, className, comment) {
    const node = createBaseJSDocTag(328 /* JSDocAugmentsTag */, tagName ?? createIdentifier("augments"), comment);
    node.class = className;
    return node;
  }
  function updateJSDocAugmentsTag(node, tagName = getDefaultTagName(node), className, comment) {
    return node.tagName !== tagName || node.class !== className || node.comment !== comment ? update(createJSDocAugmentsTag(tagName, className, comment), node) : node;
  }
  function createJSDocImplementsTag(tagName, className, comment) {
    const node = createBaseJSDocTag(329 /* JSDocImplementsTag */, tagName ?? createIdentifier("implements"), comment);
    node.class = className;
    return node;
  }
  function createJSDocSeeTag(tagName, name, comment) {
    const node = createBaseJSDocTag(347 /* JSDocSeeTag */, tagName ?? createIdentifier("see"), comment);
    node.name = name;
    return node;
  }
  function updateJSDocSeeTag(node, tagName, name, comment) {
    return node.tagName !== tagName || node.name !== name || node.comment !== comment ? update(createJSDocSeeTag(tagName, name, comment), node) : node;
  }
  function createJSDocNameReference(name) {
    const node = createBaseNode(310 /* JSDocNameReference */);
    node.name = name;
    return node;
  }
  function updateJSDocNameReference(node, name) {
    return node.name !== name ? update(createJSDocNameReference(name), node) : node;
  }
  function createJSDocMemberName(left, right) {
    const node = createBaseNode(311 /* JSDocMemberName */);
    node.left = left;
    node.right = right;
    node.transformFlags |= propagateChildFlags(node.left) | propagateChildFlags(node.right);
    return node;
  }
  function updateJSDocMemberName(node, left, right) {
    return node.left !== left || node.right !== right ? update(createJSDocMemberName(left, right), node) : node;
  }
  function createJSDocLink(name, text) {
    const node = createBaseNode(324 /* JSDocLink */);
    node.name = name;
    node.text = text;
    return node;
  }
  function updateJSDocLink(node, name, text) {
    return node.name !== name ? update(createJSDocLink(name, text), node) : node;
  }
  function createJSDocLinkCode(name, text) {
    const node = createBaseNode(325 /* JSDocLinkCode */);
    node.name = name;
    node.text = text;
    return node;
  }
  function updateJSDocLinkCode(node, name, text) {
    return node.name !== name ? update(createJSDocLinkCode(name, text), node) : node;
  }
  function createJSDocLinkPlain(name, text) {
    const node = createBaseNode(326 /* JSDocLinkPlain */);
    node.name = name;
    node.text = text;
    return node;
  }
  function updateJSDocLinkPlain(node, name, text) {
    return node.name !== name ? update(createJSDocLinkPlain(name, text), node) : node;
  }
  function updateJSDocImplementsTag(node, tagName = getDefaultTagName(node), className, comment) {
    return node.tagName !== tagName || node.class !== className || node.comment !== comment ? update(createJSDocImplementsTag(tagName, className, comment), node) : node;
  }
  function createJSDocSimpleTagWorker(kind, tagName, comment) {
    const node = createBaseJSDocTag(kind, tagName ?? createIdentifier(getDefaultTagNameForKind(kind)), comment);
    return node;
  }
  function updateJSDocSimpleTagWorker(kind, node, tagName = getDefaultTagName(node), comment) {
    return node.tagName !== tagName || node.comment !== comment ? update(createJSDocSimpleTagWorker(kind, tagName, comment), node) : node;
  }
  function createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment) {
    const node = createBaseJSDocTag(kind, tagName ?? createIdentifier(getDefaultTagNameForKind(kind)), comment);
    node.typeExpression = typeExpression;
    return node;
  }
  function updateJSDocTypeLikeTagWorker(kind, node, tagName = getDefaultTagName(node), typeExpression, comment) {
    return node.tagName !== tagName || node.typeExpression !== typeExpression || node.comment !== comment ? update(createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment), node) : node;
  }
  function createJSDocUnknownTag(tagName, comment) {
    const node = createBaseJSDocTag(327 /* JSDocTag */, tagName, comment);
    return node;
  }
  function updateJSDocUnknownTag(node, tagName, comment) {
    return node.tagName !== tagName || node.comment !== comment ? update(createJSDocUnknownTag(tagName, comment), node) : node;
  }
  function createJSDocEnumTag(tagName, typeExpression, comment) {
    const node = createBaseJSDocTagDeclaration(340 /* JSDocEnumTag */, tagName ?? createIdentifier(getDefaultTagNameForKind(340 /* JSDocEnumTag */)), comment);
    node.typeExpression = typeExpression;
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateJSDocEnumTag(node, tagName = getDefaultTagName(node), typeExpression, comment) {
    return node.tagName !== tagName || node.typeExpression !== typeExpression || node.comment !== comment ? update(createJSDocEnumTag(tagName, typeExpression, comment), node) : node;
  }
  function createJSDocImportTag(tagName, importClause, moduleSpecifier, attributes, comment) {
    const node = createBaseJSDocTag(351 /* JSDocImportTag */, tagName ?? createIdentifier("import"), comment);
    node.importClause = importClause;
    node.moduleSpecifier = moduleSpecifier;
    node.attributes = attributes;
    node.comment = comment;
    return node;
  }
  function updateJSDocImportTag(node, tagName, importClause, moduleSpecifier, attributes, comment) {
    return node.tagName !== tagName || node.comment !== comment || node.importClause !== importClause || node.moduleSpecifier !== moduleSpecifier || node.attributes !== attributes ? update(createJSDocImportTag(tagName, importClause, moduleSpecifier, attributes, comment), node) : node;
  }
  function createJSDocText(text) {
    const node = createBaseNode(321 /* JSDocText */);
    node.text = text;
    return node;
  }
  function updateJSDocText(node, text) {
    return node.text !== text ? update(createJSDocText(text), node) : node;
  }
  function createJSDocComment(comment, tags) {
    const node = createBaseNode(320 /* JSDoc */);
    node.comment = comment;
    node.tags = asNodeArray(tags);
    return node;
  }
  function updateJSDocComment(node, comment, tags) {
    return node.comment !== comment || node.tags !== tags ? update(createJSDocComment(comment, tags), node) : node;
  }
  function createJsxElement(openingElement, children, closingElement) {
    const node = createBaseNode(284 /* JsxElement */);
    node.openingElement = openingElement;
    node.children = createNodeArray(children);
    node.closingElement = closingElement;
    node.transformFlags |= propagateChildFlags(node.openingElement) | propagateChildrenFlags(node.children) | propagateChildFlags(node.closingElement) | 2 /* ContainsJsx */;
    return node;
  }
  function updateJsxElement(node, openingElement, children, closingElement) {
    return node.openingElement !== openingElement || node.children !== children || node.closingElement !== closingElement ? update(createJsxElement(openingElement, children, closingElement), node) : node;
  }
  function createJsxSelfClosingElement(tagName, typeArguments, attributes) {
    const node = createBaseNode(285 /* JsxSelfClosingElement */);
    node.tagName = tagName;
    node.typeArguments = asNodeArray(typeArguments);
    node.attributes = attributes;
    node.transformFlags |= propagateChildFlags(node.tagName) | propagateChildrenFlags(node.typeArguments) | propagateChildFlags(node.attributes) | 2 /* ContainsJsx */;
    if (node.typeArguments) {
      node.transformFlags |= 1 /* ContainsTypeScript */;
    }
    return node;
  }
  function updateJsxSelfClosingElement(node, tagName, typeArguments, attributes) {
    return node.tagName !== tagName || node.typeArguments !== typeArguments || node.attributes !== attributes ? update(createJsxSelfClosingElement(tagName, typeArguments, attributes), node) : node;
  }
  function createJsxOpeningElement(tagName, typeArguments, attributes) {
    const node = createBaseNode(286 /* JsxOpeningElement */);
    node.tagName = tagName;
    node.typeArguments = asNodeArray(typeArguments);
    node.attributes = attributes;
    node.transformFlags |= propagateChildFlags(node.tagName) | propagateChildrenFlags(node.typeArguments) | propagateChildFlags(node.attributes) | 2 /* ContainsJsx */;
    if (typeArguments) {
      node.transformFlags |= 1 /* ContainsTypeScript */;
    }
    return node;
  }
  function updateJsxOpeningElement(node, tagName, typeArguments, attributes) {
    return node.tagName !== tagName || node.typeArguments !== typeArguments || node.attributes !== attributes ? update(createJsxOpeningElement(tagName, typeArguments, attributes), node) : node;
  }
  function createJsxClosingElement(tagName) {
    const node = createBaseNode(287 /* JsxClosingElement */);
    node.tagName = tagName;
    node.transformFlags |= propagateChildFlags(node.tagName) | 2 /* ContainsJsx */;
    return node;
  }
  function updateJsxClosingElement(node, tagName) {
    return node.tagName !== tagName ? update(createJsxClosingElement(tagName), node) : node;
  }
  function createJsxFragment(openingFragment, children, closingFragment) {
    const node = createBaseNode(288 /* JsxFragment */);
    node.openingFragment = openingFragment;
    node.children = createNodeArray(children);
    node.closingFragment = closingFragment;
    node.transformFlags |= propagateChildFlags(node.openingFragment) | propagateChildrenFlags(node.children) | propagateChildFlags(node.closingFragment) | 2 /* ContainsJsx */;
    return node;
  }
  function updateJsxFragment(node, openingFragment, children, closingFragment) {
    return node.openingFragment !== openingFragment || node.children !== children || node.closingFragment !== closingFragment ? update(createJsxFragment(openingFragment, children, closingFragment), node) : node;
  }
  function createJsxText(text, containsOnlyTriviaWhiteSpaces) {
    const node = createBaseNode(12 /* JsxText */);
    node.text = text;
    node.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces;
    node.transformFlags |= 2 /* ContainsJsx */;
    return node;
  }
  function updateJsxText(node, text, containsOnlyTriviaWhiteSpaces) {
    return node.text !== text || node.containsOnlyTriviaWhiteSpaces !== containsOnlyTriviaWhiteSpaces ? update(createJsxText(text, containsOnlyTriviaWhiteSpaces), node) : node;
  }
  function createJsxOpeningFragment() {
    const node = createBaseNode(289 /* JsxOpeningFragment */);
    node.transformFlags |= 2 /* ContainsJsx */;
    return node;
  }
  function createJsxJsxClosingFragment() {
    const node = createBaseNode(290 /* JsxClosingFragment */);
    node.transformFlags |= 2 /* ContainsJsx */;
    return node;
  }
  function createJsxAttribute(name, initializer) {
    const node = createBaseDeclaration(291 /* JsxAttribute */);
    node.name = name;
    node.initializer = initializer;
    node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.initializer) | 2 /* ContainsJsx */;
    return node;
  }
  function updateJsxAttribute(node, name, initializer) {
    return node.name !== name || node.initializer !== initializer ? update(createJsxAttribute(name, initializer), node) : node;
  }
  function createJsxAttributes(properties) {
    const node = createBaseDeclaration(292 /* JsxAttributes */);
    node.properties = createNodeArray(properties);
    node.transformFlags |= propagateChildrenFlags(node.properties) | 2 /* ContainsJsx */;
    return node;
  }
  function updateJsxAttributes(node, properties) {
    return node.properties !== properties ? update(createJsxAttributes(properties), node) : node;
  }
  function createJsxSpreadAttribute(expression) {
    const node = createBaseNode(293 /* JsxSpreadAttribute */);
    node.expression = expression;
    node.transformFlags |= propagateChildFlags(node.expression) | 2 /* ContainsJsx */;
    return node;
  }
  function updateJsxSpreadAttribute(node, expression) {
    return node.expression !== expression ? update(createJsxSpreadAttribute(expression), node) : node;
  }
  function createJsxExpression(dotDotDotToken, expression) {
    const node = createBaseNode(294 /* JsxExpression */);
    node.dotDotDotToken = dotDotDotToken;
    node.expression = expression;
    node.transformFlags |= propagateChildFlags(node.dotDotDotToken) | propagateChildFlags(node.expression) | 2 /* ContainsJsx */;
    return node;
  }
  function updateJsxExpression(node, expression) {
    return node.expression !== expression ? update(createJsxExpression(node.dotDotDotToken, expression), node) : node;
  }
  function createJsxNamespacedName(namespace, name) {
    const node = createBaseNode(295 /* JsxNamespacedName */);
    node.namespace = namespace;
    node.name = name;
    node.transformFlags |= propagateChildFlags(node.namespace) | propagateChildFlags(node.name) | 2 /* ContainsJsx */;
    return node;
  }
  function updateJsxNamespacedName(node, namespace, name) {
    return node.namespace !== namespace || node.name !== name ? update(createJsxNamespacedName(namespace, name), node) : node;
  }
  function createCaseClause(expression, statements) {
    const node = createBaseNode(296 /* CaseClause */);
    node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression);
    node.statements = createNodeArray(statements);
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildrenFlags(node.statements);
    node.jsDoc = void 0;
    return node;
  }
  function updateCaseClause(node, expression, statements) {
    return node.expression !== expression || node.statements !== statements ? update(createCaseClause(expression, statements), node) : node;
  }
  function createDefaultClause(statements) {
    const node = createBaseNode(297 /* DefaultClause */);
    node.statements = createNodeArray(statements);
    node.transformFlags = propagateChildrenFlags(node.statements);
    return node;
  }
  function updateDefaultClause(node, statements) {
    return node.statements !== statements ? update(createDefaultClause(statements), node) : node;
  }
  function createHeritageClause(token, types) {
    const node = createBaseNode(298 /* HeritageClause */);
    node.token = token;
    node.types = createNodeArray(types);
    node.transformFlags |= propagateChildrenFlags(node.types);
    switch (token) {
      case 96 /* ExtendsKeyword */:
        node.transformFlags |= 1024 /* ContainsES2015 */;
        break;
      case 119 /* ImplementsKeyword */:
        node.transformFlags |= 1 /* ContainsTypeScript */;
        break;
      default:
        return Debug.assertNever(token);
    }
    return node;
  }
  function updateHeritageClause(node, types) {
    return node.types !== types ? update(createHeritageClause(node.token, types), node) : node;
  }
  function createCatchClause(variableDeclaration, block) {
    const node = createBaseNode(299 /* CatchClause */);
    node.variableDeclaration = asVariableDeclaration(variableDeclaration);
    node.block = block;
    node.transformFlags |= propagateChildFlags(node.variableDeclaration) | propagateChildFlags(node.block) | (!variableDeclaration ? 64 /* ContainsES2019 */ : 0 /* None */);
    node.locals = void 0;
    node.nextContainer = void 0;
    return node;
  }
  function updateCatchClause(node, variableDeclaration, block) {
    return node.variableDeclaration !== variableDeclaration || node.block !== block ? update(createCatchClause(variableDeclaration, block), node) : node;
  }
  function createPropertyAssignment(name, initializer) {
    const node = createBaseDeclaration(303 /* PropertyAssignment */);
    node.name = asName(name);
    node.initializer = parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer);
    node.transformFlags |= propagateNameFlags(node.name) | propagateChildFlags(node.initializer);
    node.modifiers = void 0;
    node.questionToken = void 0;
    node.exclamationToken = void 0;
    node.jsDoc = void 0;
    return node;
  }
  function updatePropertyAssignment(node, name, initializer) {
    return node.name !== name || node.initializer !== initializer ? finishUpdatePropertyAssignment(createPropertyAssignment(name, initializer), node) : node;
  }
  function finishUpdatePropertyAssignment(updated, original) {
    if (updated !== original) {
      updated.modifiers = original.modifiers;
      updated.questionToken = original.questionToken;
      updated.exclamationToken = original.exclamationToken;
    }
    return update(updated, original);
  }
  function createShorthandPropertyAssignment(name, objectAssignmentInitializer) {
    const node = createBaseDeclaration(304 /* ShorthandPropertyAssignment */);
    node.name = asName(name);
    node.objectAssignmentInitializer = objectAssignmentInitializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(objectAssignmentInitializer);
    node.transformFlags |= propagateIdentifierNameFlags(node.name) | propagateChildFlags(node.objectAssignmentInitializer) | 1024 /* ContainsES2015 */;
    node.equalsToken = void 0;
    node.modifiers = void 0;
    node.questionToken = void 0;
    node.exclamationToken = void 0;
    node.jsDoc = void 0;
    return node;
  }
  function updateShorthandPropertyAssignment(node, name, objectAssignmentInitializer) {
    return node.name !== name || node.objectAssignmentInitializer !== objectAssignmentInitializer ? finishUpdateShorthandPropertyAssignment(createShorthandPropertyAssignment(name, objectAssignmentInitializer), node) : node;
  }
  function finishUpdateShorthandPropertyAssignment(updated, original) {
    if (updated !== original) {
      updated.modifiers = original.modifiers;
      updated.questionToken = original.questionToken;
      updated.exclamationToken = original.exclamationToken;
      updated.equalsToken = original.equalsToken;
    }
    return update(updated, original);
  }
  function createSpreadAssignment(expression) {
    const node = createBaseDeclaration(305 /* SpreadAssignment */);
    node.expression = parenthesizerRules().parenthesizeExpressionForDisallowedComma(expression);
    node.transformFlags |= propagateChildFlags(node.expression) | 128 /* ContainsES2018 */ | 65536 /* ContainsObjectRestOrSpread */;
    node.jsDoc = void 0;
    return node;
  }
  function updateSpreadAssignment(node, expression) {
    return node.expression !== expression ? update(createSpreadAssignment(expression), node) : node;
  }
  function createEnumMember(name, initializer) {
    const node = createBaseDeclaration(306 /* EnumMember */);
    node.name = asName(name);
    node.initializer = initializer && parenthesizerRules().parenthesizeExpressionForDisallowedComma(initializer);
    node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.initializer) | 1 /* ContainsTypeScript */;
    node.jsDoc = void 0;
    return node;
  }
  function updateEnumMember(node, name, initializer) {
    return node.name !== name || node.initializer !== initializer ? update(createEnumMember(name, initializer), node) : node;
  }
  function createSourceFile2(statements, endOfFileToken, flags2) {
    const node = baseFactory2.createBaseSourceFileNode(307 /* SourceFile */);
    node.statements = createNodeArray(statements);
    node.endOfFileToken = endOfFileToken;
    node.flags |= flags2;
    node.text = "";
    node.fileName = "";
    node.path = "";
    node.resolvedPath = "";
    node.originalFileName = "";
    node.languageVersion = 1 /* ES5 */;
    node.languageVariant = 0;
    node.scriptKind = 0;
    node.isDeclarationFile = false;
    node.hasNoDefaultLib = false;
    node.transformFlags |= propagateChildrenFlags(node.statements) | propagateChildFlags(node.endOfFileToken);
    node.locals = void 0;
    node.nextContainer = void 0;
    node.endFlowNode = void 0;
    node.nodeCount = 0;
    node.identifierCount = 0;
    node.symbolCount = 0;
    node.parseDiagnostics = void 0;
    node.bindDiagnostics = void 0;
    node.bindSuggestionDiagnostics = void 0;
    node.lineMap = void 0;
    node.externalModuleIndicator = void 0;
    node.setExternalModuleIndicator = void 0;
    node.pragmas = void 0;
    node.checkJsDirective = void 0;
    node.referencedFiles = void 0;
    node.typeReferenceDirectives = void 0;
    node.libReferenceDirectives = void 0;
    node.amdDependencies = void 0;
    node.commentDirectives = void 0;
    node.identifiers = void 0;
    node.packageJsonLocations = void 0;
    node.packageJsonScope = void 0;
    node.imports = void 0;
    node.moduleAugmentations = void 0;
    node.ambientModuleNames = void 0;
    node.classifiableNames = void 0;
    node.impliedNodeFormat = void 0;
    return node;
  }
  function createRedirectedSourceFile(redirectInfo) {
    const node = Object.create(redirectInfo.redirectTarget);
    Object.defineProperties(node, {
      id: {
        get() {
          return this.redirectInfo.redirectTarget.id;
        },
        set(value) {
          this.redirectInfo.redirectTarget.id = value;
        }
      },
      symbol: {
        get() {
          return this.redirectInfo.redirectTarget.symbol;
        },
        set(value) {
          this.redirectInfo.redirectTarget.symbol = value;
        }
      }
    });
    node.redirectInfo = redirectInfo;
    return node;
  }
  function cloneRedirectedSourceFile(source) {
    const node = createRedirectedSourceFile(source.redirectInfo);
    node.flags |= source.flags & ~16 /* Synthesized */;
    node.fileName = source.fileName;
    node.path = source.path;
    node.resolvedPath = source.resolvedPath;
    node.originalFileName = source.originalFileName;
    node.packageJsonLocations = source.packageJsonLocations;
    node.packageJsonScope = source.packageJsonScope;
    node.emitNode = void 0;
    return node;
  }
  function cloneSourceFileWorker(source) {
    const node = baseFactory2.createBaseSourceFileNode(307 /* SourceFile */);
    node.flags |= source.flags & ~16 /* Synthesized */;
    for (const p in source) {
      if (hasProperty(node, p) || !hasProperty(source, p)) {
        continue;
      }
      if (p === "emitNode") {
        node.emitNode = void 0;
        continue;
      }
      node[p] = source[p];
    }
    return node;
  }
  function cloneSourceFile(source) {
    const node = source.redirectInfo ? cloneRedirectedSourceFile(source) : cloneSourceFileWorker(source);
    setOriginal(node, source);
    return node;
  }
  function cloneSourceFileWithChanges(source, statements, isDeclarationFile, referencedFiles, typeReferences, hasNoDefaultLib, libReferences) {
    const node = cloneSourceFile(source);
    node.statements = createNodeArray(statements);
    node.isDeclarationFile = isDeclarationFile;
    node.referencedFiles = referencedFiles;
    node.typeReferenceDirectives = typeReferences;
    node.hasNoDefaultLib = hasNoDefaultLib;
    node.libReferenceDirectives = libReferences;
    node.transformFlags = propagateChildrenFlags(node.statements) | propagateChildFlags(node.endOfFileToken);
    return node;
  }
  function updateSourceFile2(node, statements, isDeclarationFile = node.isDeclarationFile, referencedFiles = node.referencedFiles, typeReferenceDirectives = node.typeReferenceDirectives, hasNoDefaultLib = node.hasNoDefaultLib, libReferenceDirectives = node.libReferenceDirectives) {
    return node.statements !== statements || node.isDeclarationFile !== isDeclarationFile || node.referencedFiles !== referencedFiles || node.typeReferenceDirectives !== typeReferenceDirectives || node.hasNoDefaultLib !== hasNoDefaultLib || node.libReferenceDirectives !== libReferenceDirectives ? update(cloneSourceFileWithChanges(node, statements, isDeclarationFile, referencedFiles, typeReferenceDirectives, hasNoDefaultLib, libReferenceDirectives), node) : node;
  }
  function createBundle(sourceFiles) {
    const node = createBaseNode(308 /* Bundle */);
    node.sourceFiles = sourceFiles;
    node.syntheticFileReferences = void 0;
    node.syntheticTypeReferences = void 0;
    node.syntheticLibReferences = void 0;
    node.hasNoDefaultLib = void 0;
    return node;
  }
  function updateBundle(node, sourceFiles) {
    return node.sourceFiles !== sourceFiles ? update(createBundle(sourceFiles), node) : node;
  }
  function createSyntheticExpression(type, isSpread = false, tupleNameSource) {
    const node = createBaseNode(237 /* SyntheticExpression */);
    node.type = type;
    node.isSpread = isSpread;
    node.tupleNameSource = tupleNameSource;
    return node;
  }
  function createSyntaxList3(children) {
    const node = createBaseNode(352 /* SyntaxList */);
    node._children = children;
    return node;
  }
  function createNotEmittedStatement(original) {
    const node = createBaseNode(353 /* NotEmittedStatement */);
    node.original = original;
    setTextRange(node, original);
    return node;
  }
  function createPartiallyEmittedExpression(expression, original) {
    const node = createBaseNode(355 /* PartiallyEmittedExpression */);
    node.expression = expression;
    node.original = original;
    node.transformFlags |= propagateChildFlags(node.expression) | 1 /* ContainsTypeScript */;
    setTextRange(node, original);
    return node;
  }
  function updatePartiallyEmittedExpression(node, expression) {
    return node.expression !== expression ? update(createPartiallyEmittedExpression(expression, node.original), node) : node;
  }
  function createNotEmittedTypeElement() {
    return createBaseNode(354 /* NotEmittedTypeElement */);
  }
  function flattenCommaElements(node) {
    if (nodeIsSynthesized(node) && !isParseTreeNode(node) && !node.original && !node.emitNode && !node.id) {
      if (isCommaListExpression(node)) {
        return node.elements;
      }
      if (isBinaryExpression(node) && isCommaToken(node.operatorToken)) {
        return [node.left, node.right];
      }
    }
    return node;
  }
  function createCommaListExpression(elements) {
    const node = createBaseNode(356 /* CommaListExpression */);
    node.elements = createNodeArray(sameFlatMap(elements, flattenCommaElements));
    node.transformFlags |= propagateChildrenFlags(node.elements);
    return node;
  }
  function updateCommaListExpression(node, elements) {
    return node.elements !== elements ? update(createCommaListExpression(elements), node) : node;
  }
  function createSyntheticReferenceExpression(expression, thisArg) {
    const node = createBaseNode(357 /* SyntheticReferenceExpression */);
    node.expression = expression;
    node.thisArg = thisArg;
    node.transformFlags |= propagateChildFlags(node.expression) | propagateChildFlags(node.thisArg);
    return node;
  }
  function updateSyntheticReferenceExpression(node, expression, thisArg) {
    return node.expression !== expression || node.thisArg !== thisArg ? update(createSyntheticReferenceExpression(expression, thisArg), node) : node;
  }
  function cloneGeneratedIdentifier(node) {
    const clone2 = createBaseIdentifier(node.escapedText);
    clone2.flags |= node.flags & ~16 /* Synthesized */;
    clone2.transformFlags = node.transformFlags;
    setOriginal(clone2, node);
    setIdentifierAutoGenerate(clone2, { ...node.emitNode.autoGenerate });
    return clone2;
  }
  function cloneIdentifier(node) {
    const clone2 = createBaseIdentifier(node.escapedText);
    clone2.flags |= node.flags & ~16 /* Synthesized */;
    clone2.jsDoc = node.jsDoc;
    clone2.flowNode = node.flowNode;
    clone2.symbol = node.symbol;
    clone2.transformFlags = node.transformFlags;
    setOriginal(clone2, node);
    const typeArguments = getIdentifierTypeArguments(node);
    if (typeArguments) setIdentifierTypeArguments(clone2, typeArguments);
    return clone2;
  }
  function cloneGeneratedPrivateIdentifier(node) {
    const clone2 = createBasePrivateIdentifier(node.escapedText);
    clone2.flags |= node.flags & ~16 /* Synthesized */;
    clone2.transformFlags = node.transformFlags;
    setOriginal(clone2, node);
    setIdentifierAutoGenerate(clone2, { ...node.emitNode.autoGenerate });
    return clone2;
  }
  function clonePrivateIdentifier(node) {
    const clone2 = createBasePrivateIdentifier(node.escapedText);
    clone2.flags |= node.flags & ~16 /* Synthesized */;
    clone2.transformFlags = node.transformFlags;
    setOriginal(clone2, node);
    return clone2;
  }
  function cloneNode(node) {
    if (node === void 0) {
      return node;
    }
    if (isSourceFile(node)) {
      return cloneSourceFile(node);
    }
    if (isGeneratedIdentifier(node)) {
      return cloneGeneratedIdentifier(node);
    }
    if (isIdentifier(node)) {
      return cloneIdentifier(node);
    }
    if (isGeneratedPrivateIdentifier(node)) {
      return cloneGeneratedPrivateIdentifier(node);
    }
    if (isPrivateIdentifier(node)) {
      return clonePrivateIdentifier(node);
    }
    const clone2 = !isNodeKind(node.kind) ? baseFactory2.createBaseTokenNode(node.kind) : baseFactory2.createBaseNode(node.kind);
    clone2.flags |= node.flags & ~16 /* Synthesized */;
    clone2.transformFlags = node.transformFlags;
    setOriginal(clone2, node);
    for (const key in node) {
      if (hasProperty(clone2, key) || !hasProperty(node, key)) {
        continue;
      }
      clone2[key] = node[key];
    }
    return clone2;
  }
  function createImmediatelyInvokedFunctionExpression(statements, param, paramValue) {
    return createCallExpression(
      createFunctionExpression(
        /*modifiers*/
        void 0,
        /*asteriskToken*/
        void 0,
        /*name*/
        void 0,
        /*typeParameters*/
        void 0,
        /*parameters*/
        param ? [param] : [],
        /*type*/
        void 0,
        createBlock(
          statements,
          /*multiLine*/
          true
        )
      ),
      /*typeArguments*/
      void 0,
      /*argumentsArray*/
      paramValue ? [paramValue] : []
    );
  }
  function createImmediatelyInvokedArrowFunction(statements, param, paramValue) {
    return createCallExpression(
      createArrowFunction(
        /*modifiers*/
        void 0,
        /*typeParameters*/
        void 0,
        /*parameters*/
        param ? [param] : [],
        /*type*/
        void 0,
        /*equalsGreaterThanToken*/
        void 0,
        createBlock(
          statements,
          /*multiLine*/
          true
        )
      ),
      /*typeArguments*/
      void 0,
      /*argumentsArray*/
      paramValue ? [paramValue] : []
    );
  }
  function createVoidZero() {
    return createVoidExpression(createNumericLiteral("0"));
  }
  function createExportDefault(expression) {
    return createExportAssignment2(
      /*modifiers*/
      void 0,
      /*isExportEquals*/
      false,
      expression
    );
  }
  function createExternalModuleExport(exportName) {
    return createExportDeclaration(
      /*modifiers*/
      void 0,
      /*isTypeOnly*/
      false,
      createNamedExports([
        createExportSpecifier(
          /*isTypeOnly*/
          false,
          /*propertyName*/
          void 0,
          exportName
        )
      ])
    );
  }
  function createTypeCheck(value, tag) {
    return tag === "null" ? factory2.createStrictEquality(value, createNull()) : tag === "undefined" ? factory2.createStrictEquality(value, createVoidZero()) : factory2.createStrictEquality(createTypeOfExpression(value), createStringLiteral(tag));
  }
  function createIsNotTypeCheck(value, tag) {
    return tag === "null" ? factory2.createStrictInequality(value, createNull()) : tag === "undefined" ? factory2.createStrictInequality(value, createVoidZero()) : factory2.createStrictInequality(createTypeOfExpression(value), createStringLiteral(tag));
  }
  function createMethodCall(object, methodName, argumentsList) {
    if (isCallChain(object)) {
      return createCallChain(
        createPropertyAccessChain(
          object,
          /*questionDotToken*/
          void 0,
          methodName
        ),
        /*questionDotToken*/
        void 0,
        /*typeArguments*/
        void 0,
        argumentsList
      );
    }
    return createCallExpression(
      createPropertyAccessExpression(object, methodName),
      /*typeArguments*/
      void 0,
      argumentsList
    );
  }
  function createFunctionBindCall(target, thisArg, argumentsList) {
    return createMethodCall(target, "bind", [thisArg, ...argumentsList]);
  }
  function createFunctionCallCall(target, thisArg, argumentsList) {
    return createMethodCall(target, "call", [thisArg, ...argumentsList]);
  }
  function createFunctionApplyCall(target, thisArg, argumentsExpression) {
    return createMethodCall(target, "apply", [thisArg, argumentsExpression]);
  }
  function createGlobalMethodCall(globalObjectName, methodName, argumentsList) {
    return createMethodCall(createIdentifier(globalObjectName), methodName, argumentsList);
  }
  function createArraySliceCall(array, start) {
    return createMethodCall(array, "slice", start === void 0 ? [] : [asExpression(start)]);
  }
  function createArrayConcatCall(array, argumentsList) {
    return createMethodCall(array, "concat", argumentsList);
  }
  function createObjectDefinePropertyCall(target, propertyName, attributes) {
    return createGlobalMethodCall("Object", "defineProperty", [target, asExpression(propertyName), attributes]);
  }
  function createObjectGetOwnPropertyDescriptorCall(target, propertyName) {
    return createGlobalMethodCall("Object", "getOwnPropertyDescriptor", [target, asExpression(propertyName)]);
  }
  function createReflectGetCall(target, propertyKey, receiver) {
    return createGlobalMethodCall("Reflect", "get", receiver ? [target, propertyKey, receiver] : [target, propertyKey]);
  }
  function createReflectSetCall(target, propertyKey, value, receiver) {
    return createGlobalMethodCall("Reflect", "set", receiver ? [target, propertyKey, value, receiver] : [target, propertyKey, value]);
  }
  function tryAddPropertyAssignment(properties, propertyName, expression) {
    if (expression) {
      properties.push(createPropertyAssignment(propertyName, expression));
      return true;
    }
    return false;
  }
  function createPropertyDescriptor(attributes, singleLine) {
    const properties = [];
    tryAddPropertyAssignment(properties, "enumerable", asExpression(attributes.enumerable));
    tryAddPropertyAssignment(properties, "configurable", asExpression(attributes.configurable));
    let isData = tryAddPropertyAssignment(properties, "writable", asExpression(attributes.writable));
    isData = tryAddPropertyAssignment(properties, "value", attributes.value) || isData;
    let isAccessor2 = tryAddPropertyAssignment(properties, "get", attributes.get);
    isAccessor2 = tryAddPropertyAssignment(properties, "set", attributes.set) || isAccessor2;
    Debug.assert(!(isData && isAccessor2), "A PropertyDescriptor may not be both an accessor descriptor and a data descriptor.");
    return createObjectLiteralExpression(properties, !singleLine);
  }
  function updateOuterExpression(outerExpression, expression) {
    switch (outerExpression.kind) {
      case 217 /* ParenthesizedExpression */:
        return updateParenthesizedExpression(outerExpression, expression);
      case 216 /* TypeAssertionExpression */:
        return updateTypeAssertion(outerExpression, outerExpression.type, expression);
      case 234 /* AsExpression */:
        return updateAsExpression(outerExpression, expression, outerExpression.type);
      case 238 /* SatisfiesExpression */:
        return updateSatisfiesExpression(outerExpression, expression, outerExpression.type);
      case 235 /* NonNullExpression */:
        return updateNonNullExpression(outerExpression, expression);
      case 233 /* ExpressionWithTypeArguments */:
        return updateExpressionWithTypeArguments(outerExpression, expression, outerExpression.typeArguments);
      case 355 /* PartiallyEmittedExpression */:
        return updatePartiallyEmittedExpression(outerExpression, expression);
    }
  }
  function isIgnorableParen(node) {
    return isParenthesizedExpression(node) && nodeIsSynthesized(node) && nodeIsSynthesized(getSourceMapRange(node)) && nodeIsSynthesized(getCommentRange(node)) && !some(getSyntheticLeadingComments(node)) && !some(getSyntheticTrailingComments(node));
  }
  function restoreOuterExpressions(outerExpression, innerExpression, kinds = 31 /* All */) {
    if (outerExpression && isOuterExpression(outerExpression, kinds) && !isIgnorableParen(outerExpression)) {
      return updateOuterExpression(
        outerExpression,
        restoreOuterExpressions(outerExpression.expression, innerExpression)
      );
    }
    return innerExpression;
  }
  function restoreEnclosingLabel(node, outermostLabeledStatement, afterRestoreLabelCallback) {
    if (!outermostLabeledStatement) {
      return node;
    }
    const updated = updateLabeledStatement(
      outermostLabeledStatement,
      outermostLabeledStatement.label,
      isLabeledStatement(outermostLabeledStatement.statement) ? restoreEnclosingLabel(node, outermostLabeledStatement.statement) : node
    );
    if (afterRestoreLabelCallback) {
      afterRestoreLabelCallback(outermostLabeledStatement);
    }
    return updated;
  }
  function shouldBeCapturedInTempVariable(node, cacheIdentifiers) {
    const target = skipParentheses(node);
    switch (target.kind) {
      case 80 /* Identifier */:
        return cacheIdentifiers;
      case 110 /* ThisKeyword */:
      case 9 /* NumericLiteral */:
      case 10 /* BigIntLiteral */:
      case 11 /* StringLiteral */:
        return false;
      case 209 /* ArrayLiteralExpression */:
        const elements = target.elements;
        if (elements.length === 0) {
          return false;
        }
        return true;
      case 210 /* ObjectLiteralExpression */:
        return target.properties.length > 0;
      default:
        return true;
    }
  }
  function createCallBinding(expression, recordTempVariable, languageVersion, cacheIdentifiers = false) {
    const callee = skipOuterExpressions(expression, 31 /* All */);
    let thisArg;
    let target;
    if (isSuperProperty(callee)) {
      thisArg = createThis();
      target = callee;
    } else if (isSuperKeyword(callee)) {
      thisArg = createThis();
      target = languageVersion !== void 0 && languageVersion < 2 /* ES2015 */ ? setTextRange(createIdentifier("_super"), callee) : callee;
    } else if (getEmitFlags(callee) & 8192 /* HelperName */) {
      thisArg = createVoidZero();
      target = parenthesizerRules().parenthesizeLeftSideOfAccess(
        callee,
        /*optionalChain*/
        false
      );
    } else if (isPropertyAccessExpression(callee)) {
      if (shouldBeCapturedInTempVariable(callee.expression, cacheIdentifiers)) {
        thisArg = createTempVariable(recordTempVariable);
        target = createPropertyAccessExpression(
          setTextRange(
            factory2.createAssignment(
              thisArg,
              callee.expression
            ),
            callee.expression
          ),
          callee.name
        );
        setTextRange(target, callee);
      } else {
        thisArg = callee.expression;
        target = callee;
      }
    } else if (isElementAccessExpression(callee)) {
      if (shouldBeCapturedInTempVariable(callee.expression, cacheIdentifiers)) {
        thisArg = createTempVariable(recordTempVariable);
        target = createElementAccessExpression(
          setTextRange(
            factory2.createAssignment(
              thisArg,
              callee.expression
            ),
            callee.expression
          ),
          callee.argumentExpression
        );
        setTextRange(target, callee);
      } else {
        thisArg = callee.expression;
        target = callee;
      }
    } else {
      thisArg = createVoidZero();
      target = parenthesizerRules().parenthesizeLeftSideOfAccess(
        expression,
        /*optionalChain*/
        false
      );
    }
    return { target, thisArg };
  }
  function createAssignmentTargetWrapper(paramName, expression) {
    return createPropertyAccessExpression(
      // Explicit parens required because of v8 regression (https://bugs.chromium.org/p/v8/issues/detail?id=9560)
      createParenthesizedExpression(
        createObjectLiteralExpression([
          createSetAccessorDeclaration(
            /*modifiers*/
            void 0,
            "value",
            [createParameterDeclaration(
              /*modifiers*/
              void 0,
              /*dotDotDotToken*/
              void 0,
              paramName,
              /*questionToken*/
              void 0,
              /*type*/
              void 0,
              /*initializer*/
              void 0
            )],
            createBlock([
              createExpressionStatement(expression)
            ])
          )
        ])
      ),
      "value"
    );
  }
  function inlineExpressions(expressions) {
    return expressions.length > 10 ? createCommaListExpression(expressions) : reduceLeft(expressions, factory2.createComma);
  }
  function getName(node, allowComments, allowSourceMaps, emitFlags = 0, ignoreAssignedName) {
    const nodeName = ignoreAssignedName ? node && getNonAssignedNameOfDeclaration(node) : getNameOfDeclaration(node);
    if (nodeName && isIdentifier(nodeName) && !isGeneratedIdentifier(nodeName)) {
      const name = setParent(setTextRange(cloneNode(nodeName), nodeName), nodeName.parent);
      emitFlags |= getEmitFlags(nodeName);
      if (!allowSourceMaps) emitFlags |= 96 /* NoSourceMap */;
      if (!allowComments) emitFlags |= 3072 /* NoComments */;
      if (emitFlags) setEmitFlags(name, emitFlags);
      return name;
    }
    return getGeneratedNameForNode(node);
  }
  function getInternalName(node, allowComments, allowSourceMaps) {
    return getName(node, allowComments, allowSourceMaps, 32768 /* LocalName */ | 65536 /* InternalName */);
  }
  function getLocalName(node, allowComments, allowSourceMaps, ignoreAssignedName) {
    return getName(node, allowComments, allowSourceMaps, 32768 /* LocalName */, ignoreAssignedName);
  }
  function getExportName(node, allowComments, allowSourceMaps) {
    return getName(node, allowComments, allowSourceMaps, 16384 /* ExportName */);
  }
  function getDeclarationName(node, allowComments, allowSourceMaps) {
    return getName(node, allowComments, allowSourceMaps);
  }
  function getNamespaceMemberName(ns, name, allowComments, allowSourceMaps) {
    const qualifiedName = createPropertyAccessExpression(ns, nodeIsSynthesized(name) ? name : cloneNode(name));
    setTextRange(qualifiedName, name);
    let emitFlags = 0;
    if (!allowSourceMaps) emitFlags |= 96 /* NoSourceMap */;
    if (!allowComments) emitFlags |= 3072 /* NoComments */;
    if (emitFlags) setEmitFlags(qualifiedName, emitFlags);
    return qualifiedName;
  }
  function getExternalModuleOrNamespaceExportName(ns, node, allowComments, allowSourceMaps) {
    if (ns && hasSyntacticModifier(node, 32 /* Export */)) {
      return getNamespaceMemberName(ns, getName(node), allowComments, allowSourceMaps);
    }
    return getExportName(node, allowComments, allowSourceMaps);
  }
  function copyPrologue(source, target, ensureUseStrict2, visitor) {
    const offset = copyStandardPrologue(source, target, 0, ensureUseStrict2);
    return copyCustomPrologue(source, target, offset, visitor);
  }
  function isUseStrictPrologue2(node) {
    return isStringLiteral(node.expression) && node.expression.text === "use strict";
  }
  function createUseStrictPrologue() {
    return startOnNewLine(createExpressionStatement(createStringLiteral("use strict")));
  }
  function copyStandardPrologue(source, target, statementOffset = 0, ensureUseStrict2) {
    Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
    let foundUseStrict = false;
    const numStatements = source.length;
    while (statementOffset < numStatements) {
      const statement = source[statementOffset];
      if (isPrologueDirective(statement)) {
        if (isUseStrictPrologue2(statement)) {
          foundUseStrict = true;
        }
        target.push(statement);
      } else {
        break;
      }
      statementOffset++;
    }
    if (ensureUseStrict2 && !foundUseStrict) {
      target.push(createUseStrictPrologue());
    }
    return statementOffset;
  }
  function copyCustomPrologue(source, target, statementOffset, visitor, filter2 = returnTrue) {
    const numStatements = source.length;
    while (statementOffset !== void 0 && statementOffset < numStatements) {
      const statement = source[statementOffset];
      if (getEmitFlags(statement) & 2097152 /* CustomPrologue */ && filter2(statement)) {
        append(target, visitor ? visitNode(statement, visitor, isStatement) : statement);
      } else {
        break;
      }
      statementOffset++;
    }
    return statementOffset;
  }
  function ensureUseStrict(statements) {
    const foundUseStrict = findUseStrictPrologue(statements);
    if (!foundUseStrict) {
      return setTextRange(createNodeArray([createUseStrictPrologue(), ...statements]), statements);
    }
    return statements;
  }
  function liftToBlock(nodes) {
    Debug.assert(every(nodes, isStatementOrBlock), "Cannot lift nodes to a Block.");
    return singleOrUndefined(nodes) || createBlock(nodes);
  }
  function findSpanEnd(array, test, start) {
    let i = start;
    while (i < array.length && test(array[i])) {
      i++;
    }
    return i;
  }
  function mergeLexicalEnvironment(statements, declarations) {
    if (!some(declarations)) {
      return statements;
    }
    const leftStandardPrologueEnd = findSpanEnd(statements, isPrologueDirective, 0);
    const leftHoistedFunctionsEnd = findSpanEnd(statements, isHoistedFunction, leftStandardPrologueEnd);
    const leftHoistedVariablesEnd = findSpanEnd(statements, isHoistedVariableStatement, leftHoistedFunctionsEnd);
    const rightStandardPrologueEnd = findSpanEnd(declarations, isPrologueDirective, 0);
    const rightHoistedFunctionsEnd = findSpanEnd(declarations, isHoistedFunction, rightStandardPrologueEnd);
    const rightHoistedVariablesEnd = findSpanEnd(declarations, isHoistedVariableStatement, rightHoistedFunctionsEnd);
    const rightCustomPrologueEnd = findSpanEnd(declarations, isCustomPrologue, rightHoistedVariablesEnd);
    Debug.assert(rightCustomPrologueEnd === declarations.length, "Expected declarations to be valid standard or custom prologues");
    const left = isNodeArray(statements) ? statements.slice() : statements;
    if (rightCustomPrologueEnd > rightHoistedVariablesEnd) {
      left.splice(leftHoistedVariablesEnd, 0, ...declarations.slice(rightHoistedVariablesEnd, rightCustomPrologueEnd));
    }
    if (rightHoistedVariablesEnd > rightHoistedFunctionsEnd) {
      left.splice(leftHoistedFunctionsEnd, 0, ...declarations.slice(rightHoistedFunctionsEnd, rightHoistedVariablesEnd));
    }
    if (rightHoistedFunctionsEnd > rightStandardPrologueEnd) {
      left.splice(leftStandardPrologueEnd, 0, ...declarations.slice(rightStandardPrologueEnd, rightHoistedFunctionsEnd));
    }
    if (rightStandardPrologueEnd > 0) {
      if (leftStandardPrologueEnd === 0) {
        left.splice(0, 0, ...declarations.slice(0, rightStandardPrologueEnd));
      } else {
        const leftPrologues = /* @__PURE__ */ new Map();
        for (let i = 0; i < leftStandardPrologueEnd; i++) {
          const leftPrologue = statements[i];
          leftPrologues.set(leftPrologue.expression.text, true);
        }
        for (let i = rightStandardPrologueEnd - 1; i >= 0; i--) {
          const rightPrologue = declarations[i];
          if (!leftPrologues.has(rightPrologue.expression.text)) {
            left.unshift(rightPrologue);
          }
        }
      }
    }
    if (isNodeArray(statements)) {
      return setTextRange(createNodeArray(left, statements.hasTrailingComma), statements);
    }
    return statements;
  }
  function replaceModifiers(node, modifiers) {
    let modifierArray;
    if (typeof modifiers === "number") {
      modifierArray = createModifiersFromModifierFlags(modifiers);
    } else {
      modifierArray = modifiers;
    }
    return isTypeParameterDeclaration(node) ? updateTypeParameterDeclaration(node, modifierArray, node.name, node.constraint, node.default) : isParameter(node) ? updateParameterDeclaration(node, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) : isConstructorTypeNode(node) ? updateConstructorTypeNode1(node, modifierArray, node.typeParameters, node.parameters, node.type) : isPropertySignature(node) ? updatePropertySignature(node, modifierArray, node.name, node.questionToken, node.type) : isPropertyDeclaration(node) ? updatePropertyDeclaration2(node, modifierArray, node.name, node.questionToken ?? node.exclamationToken, node.type, node.initializer) : isMethodSignature(node) ? updateMethodSignature(node, modifierArray, node.name, node.questionToken, node.typeParameters, node.parameters, node.type) : isMethodDeclaration(node) ? updateMethodDeclaration(node, modifierArray, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) : isConstructorDeclaration(node) ? updateConstructorDeclaration(node, modifierArray, node.parameters, node.body) : isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, modifierArray, node.name, node.parameters, node.type, node.body) : isSetAccessorDeclaration(node) ? updateSetAccessorDeclaration(node, modifierArray, node.name, node.parameters, node.body) : isIndexSignatureDeclaration(node) ? updateIndexSignature(node, modifierArray, node.parameters, node.type) : isFunctionExpression(node) ? updateFunctionExpression(node, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) : isArrowFunction(node) ? updateArrowFunction(node, modifierArray, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body) : isClassExpression(node) ? updateClassExpression(node, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) : isVariableStatement(node) ? updateVariableStatement(node, modifierArray, node.declarationList) : isFunctionDeclaration(node) ? updateFunctionDeclaration(node, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) : isClassDeclaration(node) ? updateClassDeclaration(node, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) : isInterfaceDeclaration(node) ? updateInterfaceDeclaration(node, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) : isTypeAliasDeclaration(node) ? updateTypeAliasDeclaration(node, modifierArray, node.name, node.typeParameters, node.type) : isEnumDeclaration(node) ? updateEnumDeclaration(node, modifierArray, node.name, node.members) : isModuleDeclaration(node) ? updateModuleDeclaration(node, modifierArray, node.name, node.body) : isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, modifierArray, node.isTypeOnly, node.name, node.moduleReference) : isImportDeclaration(node) ? updateImportDeclaration(node, modifierArray, node.importClause, node.moduleSpecifier, node.attributes) : isExportAssignment(node) ? updateExportAssignment(node, modifierArray, node.expression) : isExportDeclaration(node) ? updateExportDeclaration(node, modifierArray, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.attributes) : Debug.assertNever(node);
  }
  function replaceDecoratorsAndModifiers(node, modifierArray) {
    return isParameter(node) ? updateParameterDeclaration(node, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) : isPropertyDeclaration(node) ? updatePropertyDeclaration2(node, modifierArray, node.name, node.questionToken ?? node.exclamationToken, node.type, node.initializer) : isMethodDeclaration(node) ? updateMethodDeclaration(node, modifierArray, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) : isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, modifierArray, node.name, node.parameters, node.type, node.body) : isSetAccessorDeclaration(node) ? updateSetAccessorDeclaration(node, modifierArray, node.name, node.parameters, node.body) : isClassExpression(node) ? updateClassExpression(node, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) : isClassDeclaration(node) ? updateClassDeclaration(node, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) : Debug.assertNever(node);
  }
  function replacePropertyName(node, name) {
    switch (node.kind) {
      case 177 /* GetAccessor */:
        return updateGetAccessorDeclaration(node, node.modifiers, name, node.parameters, node.type, node.body);
      case 178 /* SetAccessor */:
        return updateSetAccessorDeclaration(node, node.modifiers, name, node.parameters, node.body);
      case 174 /* MethodDeclaration */:
        return updateMethodDeclaration(node, node.modifiers, node.asteriskToken, name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body);
      case 173 /* MethodSignature */:
        return updateMethodSignature(node, node.modifiers, name, node.questionToken, node.typeParameters, node.parameters, node.type);
      case 172 /* PropertyDeclaration */:
        return updatePropertyDeclaration2(node, node.modifiers, name, node.questionToken ?? node.exclamationToken, node.type, node.initializer);
      case 171 /* PropertySignature */:
        return updatePropertySignature(node, node.modifiers, name, node.questionToken, node.type);
      case 303 /* PropertyAssignment */:
        return updatePropertyAssignment(node, name, node.initializer);
    }
  }
  function asNodeArray(array) {
    return array ? createNodeArray(array) : void 0;
  }
  function asName(name) {
    return typeof name === "string" ? createIdentifier(name) : name;
  }
  function asExpression(value) {
    return typeof value === "string" ? createStringLiteral(value) : typeof value === "number" ? createNumericLiteral(value) : typeof value === "boolean" ? value ? createTrue() : createFalse() : value;
  }
  function asInitializer(node) {
    return node && parenthesizerRules().parenthesizeExpressionForDisallowedComma(node);
  }
  function asToken(value) {
    return typeof value === "number" ? createToken(value) : value;
  }
  function asEmbeddedStatement(statement) {
    return statement && isNotEmittedStatement(statement) ? setTextRange(setOriginal(createEmptyStatement(), statement), statement) : statement;
  }
  function asVariableDeclaration(variableDeclaration) {
    if (typeof variableDeclaration === "string" || variableDeclaration && !isVariableDeclaration(variableDeclaration)) {
      return createVariableDeclaration(
        variableDeclaration,
        /*exclamationToken*/
        void 0,
        /*type*/
        void 0,
        /*initializer*/
        void 0
      );
    }
    return variableDeclaration;
  }
  function update(updated, original) {
    if (updated !== original) {
      setOriginal(updated, original);
      setTextRange(updated, original);
    }
    return updated;
  }
}
function getDefaultTagNameForKind(kind) {
  switch (kind) {
    case 344 /* JSDocTypeTag */:
      return "type";
    case 342 /* JSDocReturnTag */:
      return "returns";
    case 343 /* JSDocThisTag */:
      return "this";
    case 340 /* JSDocEnumTag */:
      return "enum";
    case 330 /* JSDocAuthorTag */:
      return "author";
    case 332 /* JSDocClassTag */:
      return "class";
    case 333 /* JSDocPublicTag */:
      return "public";
    case 334 /* JSDocPrivateTag */:
      return "private";
    case 335 /* JSDocProtectedTag */:
      return "protected";
    case 336 /* JSDocReadonlyTag */:
      return "readonly";
    case 337 /* JSDocOverrideTag */:
      return "override";
    case 345 /* JSDocTemplateTag */:
      return "template";
    case 346 /* JSDocTypedefTag */:
      return "typedef";
    case 341 /* JSDocParameterTag */:
      return "param";
    case 348 /* JSDocPropertyTag */:
      return "prop";
    case 338 /* JSDocCallbackTag */:
      return "callback";
    case 339 /* JSDocOverloadTag */:
      return "overload";
    case 328 /* JSDocAugmentsTag */:
      return "augments";
    case 329 /* JSDocImplementsTag */:
      return "implements";
    case 351 /* JSDocImportTag */:
      return "import";
    default:
      return Debug.fail(`Unsupported kind: ${Debug.formatSyntaxKind(kind)}`);
  }
}
var rawTextScanner;
var invalidValueSentinel = {};
function getCookedText(kind, rawText) {
  if (!rawTextScanner) {
    rawTextScanner = createScanner(
      99 /* Latest */,
      /*skipTrivia*/
      false,
      0 /* Standard */
    );
  }
  switch (kind) {
    case 15 /* NoSubstitutionTemplateLiteral */:
      rawTextScanner.setText("`" + rawText + "`");
      break;
    case 16 /* TemplateHead */:
      rawTextScanner.setText("`" + rawText + "${");
      break;
    case 17 /* TemplateMiddle */:
      rawTextScanner.setText("}" + rawText + "${");
      break;
    case 18 /* TemplateTail */:
      rawTextScanner.setText("}" + rawText + "`");
      break;
  }
  let token = rawTextScanner.scan();
  if (token === 20 /* CloseBraceToken */) {
    token = rawTextScanner.reScanTemplateToken(
      /*isTaggedTemplate*/
      false
    );
  }
  if (rawTextScanner.isUnterminated()) {
    rawTextScanner.setText(void 0);
    return invalidValueSentinel;
  }
  let tokenValue;
  switch (token) {
    case 15 /* NoSubstitutionTemplateLiteral */:
    case 16 /* TemplateHead */:
    case 17 /* TemplateMiddle */:
    case 18 /* TemplateTail */:
      tokenValue = rawTextScanner.getTokenValue();
      break;
  }
  if (tokenValue === void 0 || rawTextScanner.scan() !== 1 /* EndOfFileToken */) {
    rawTextScanner.setText(void 0);
    return invalidValueSentinel;
  }
  rawTextScanner.setText(void 0);
  return tokenValue;
}
function propagateNameFlags(node) {
  return node && isIdentifier(node) ? propagateIdentifierNameFlags(node) : propagateChildFlags(node);
}
function propagateIdentifierNameFlags(node) {
  return propagateChildFlags(node) & ~67108864 /* ContainsPossibleTopLevelAwait */;
}
function propagatePropertyNameFlagsOfChild(node, transformFlags) {
  return transformFlags | node.transformFlags & 134234112 /* PropertyNamePropagatingFlags */;
}
function propagateChildFlags(child) {
  if (!child) return 0 /* None */;
  const childFlags = child.transformFlags & ~getTransformFlagsSubtreeExclusions(child.kind);
  return isNamedDeclaration(child) && isPropertyName(child.name) ? propagatePropertyNameFlagsOfChild(child.name, childFlags) : childFlags;
}
function propagateChildrenFlags(children) {
  return children ? children.transformFlags : 0 /* None */;
}
function aggregateChildrenFlags(children) {
  let subtreeFlags = 0 /* None */;
  for (const child of children) {
    subtreeFlags |= propagateChildFlags(child);
  }
  children.transformFlags = subtreeFlags;
}
function getTransformFlagsSubtreeExclusions(kind) {
  if (kind >= 182 /* FirstTypeNode */ && kind <= 205 /* LastTypeNode */) {
    return -2 /* TypeExcludes */;
  }
  switch (kind) {
    case 213 /* CallExpression */:
    case 214 /* NewExpression */:
    case 209 /* ArrayLiteralExpression */:
      return -2147450880 /* ArrayLiteralOrCallOrNewExcludes */;
    case 267 /* ModuleDeclaration */:
      return -1941676032 /* ModuleExcludes */;
    case 169 /* Parameter */:
      return -2147483648 /* ParameterExcludes */;
    case 219 /* ArrowFunction */:
      return -2072174592 /* ArrowFunctionExcludes */;
    case 218 /* FunctionExpression */:
    case 262 /* FunctionDeclaration */:
      return -1937940480 /* FunctionExcludes */;
    case 261 /* VariableDeclarationList */:
      return -2146893824 /* VariableDeclarationListExcludes */;
    case 263 /* ClassDeclaration */:
    case 231 /* ClassExpression */:
      return -2147344384 /* ClassExcludes */;
    case 176 /* Constructor */:
      return -1937948672 /* ConstructorExcludes */;
    case 172 /* PropertyDeclaration */:
      return -2013249536 /* PropertyExcludes */;
    case 174 /* MethodDeclaration */:
    case 177 /* GetAccessor */:
    case 178 /* SetAccessor */:
      return -2005057536 /* MethodOrAccessorExcludes */;
    case 133 /* AnyKeyword */:
    case 150 /* NumberKeyword */:
    case 163 /* BigIntKeyword */:
    case 146 /* NeverKeyword */:
    case 154 /* StringKeyword */:
    case 151 /* ObjectKeyword */:
    case 136 /* BooleanKeyword */:
    case 155 /* SymbolKeyword */:
    case 116 /* VoidKeyword */:
    case 168 /* TypeParameter */:
    case 171 /* PropertySignature */:
    case 173 /* MethodSignature */:
    case 179 /* CallSignature */:
    case 180 /* ConstructSignature */:
    case 181 /* IndexSignature */:
    case 264 /* InterfaceDeclaration */:
    case 265 /* TypeAliasDeclaration */:
      return -2 /* TypeExcludes */;
    case 210 /* ObjectLiteralExpression */:
      return -2147278848 /* ObjectLiteralExcludes */;
    case 299 /* CatchClause */:
      return -2147418112 /* CatchClauseExcludes */;
    case 206 /* ObjectBindingPattern */:
    case 207 /* ArrayBindingPattern */:
      return -2147450880 /* BindingPatternExcludes */;
    case 216 /* TypeAssertionExpression */:
    case 238 /* SatisfiesExpression */:
    case 234 /* AsExpression */:
    case 355 /* PartiallyEmittedExpression */:
    case 217 /* ParenthesizedExpression */:
    case 108 /* SuperKeyword */:
      return -2147483648 /* OuterExpressionExcludes */;
    case 211 /* PropertyAccessExpression */:
    case 212 /* ElementAccessExpression */:
      return -2147483648 /* PropertyAccessExcludes */;
    default:
      return -2147483648 /* NodeExcludes */;
  }
}
var baseFactory = createBaseNodeFactory();
function makeSynthetic(node) {
  node.flags |= 16 /* Synthesized */;
  return node;
}
var syntheticFactory = {
  createBaseSourceFileNode: (kind) => makeSynthetic(baseFactory.createBaseSourceFileNode(kind)),
  createBaseIdentifierNode: (kind) => makeSynthetic(baseFactory.createBaseIdentifierNode(kind)),
  createBasePrivateIdentifierNode: (kind) => makeSynthetic(baseFactory.createBasePrivateIdentifierNode(kind)),
  createBaseTokenNode: (kind) => makeSynthetic(baseFactory.createBaseTokenNode(kind)),
  createBaseNode: (kind) => makeSynthetic(baseFactory.createBaseNode(kind))
};
var factory = createNodeFactory(4 /* NoIndentationOnFreshPropertyAccess */, syntheticFactory);
var SourceMapSource2;
function createSourceMapSource(fileName, text, skipTrivia2) {
  return new (SourceMapSource2 || (SourceMapSource2 = objectAllocator.getSourceMapSourceConstructor()))(fileName, text, skipTrivia2);
}
function setOriginalNode(node, original) {
  if (node.original !== original) {
    node.original = original;
    if (original) {
      const emitNode = original.emitNode;
      if (emitNode) node.emitNode = mergeEmitNode(emitNode, node.emitNode);
    }
  }
  return node;
}
function mergeEmitNode(sourceEmitNode, destEmitNode) {
  const {
    flags,
    internalFlags,
    leadingComments,
    trailingComments,
    commentRange,
    sourceMapRange,
    tokenSourceMapRanges,
    constantValue,
    helpers,
    startsOnNewLine,
    snippetElement,
    classThis,
    assignedName
  } = sourceEmitNode;
  if (!destEmitNode) destEmitNode = {};
  if (flags) {
    destEmitNode.flags = flags;
  }
  if (internalFlags) {
    destEmitNode.internalFlags = internalFlags & ~8 /* Immutable */;
  }
  if (leadingComments) {
    destEmitNode.leadingComments = addRange(leadingComments.slice(), destEmitNode.leadingComments);
  }
  if (trailingComments) {
    destEmitNode.trailingComments = addRange(trailingComments.slice(), destEmitNode.trailingComments);
  }
  if (commentRange) {
    destEmitNode.commentRange = commentRange;
  }
  if (sourceMapRange) {
    destEmitNode.sourceMapRange = sourceMapRange;
  }
  if (tokenSourceMapRanges) {
    destEmitNode.tokenSourceMapRanges = mergeTokenSourceMapRanges(tokenSourceMapRanges, destEmitNode.tokenSourceMapRanges);
  }
  if (constantValue !== void 0) {
    destEmitNode.constantValue = constantValue;
  }
  if (helpers) {
    for (const helper of helpers) {
      destEmitNode.helpers = appendIfUnique(destEmitNode.helpers, helper);
    }
  }
  if (startsOnNewLine !== void 0) {
    destEmitNode.startsOnNewLine = startsOnNewLine;
  }
  if (snippetElement !== void 0) {
    destEmitNode.snippetElement = snippetElement;
  }
  if (classThis) {
    destEmitNode.classThis = classThis;
  }
  if (assignedName) {
    destEmitNode.assignedName = assignedName;
  }
  return destEmitNode;
}
function mergeTokenSourceMapRanges(sourceRanges, destRanges) {
  if (!destRanges) destRanges = [];
  for (const key in sourceRanges) {
    destRanges[key] = sourceRanges[key];
  }
  return destRanges;
}

// src/compiler/factory/emitNode.ts
function getOrCreateEmitNode(node) {
  if (!node.emitNode) {
    if (isParseTreeNode(node)) {
      if (node.kind === 307 /* SourceFile */) {
        return node.emitNode = { annotatedNodes: [node] };
      }
      const sourceFile = getSourceFileOfNode(getParseTreeNode(getSourceFileOfNode(node))) ?? Debug.fail("Could not determine parsed source file.");
      getOrCreateEmitNode(sourceFile).annotatedNodes.push(node);
    }
    node.emitNode = {};
  } else {
    Debug.assert(!(node.emitNode.internalFlags & 8 /* Immutable */), "Invalid attempt to mutate an immutable node.");
  }
  return node.emitNode;
}
function disposeEmitNodes(sourceFile) {
  var _a, _b;
  const annotatedNodes = (_b = (_a = getSourceFileOfNode(getParseTreeNode(sourceFile))) == null ? void 0 : _a.emitNode) == null ? void 0 : _b.annotatedNodes;
  if (annotatedNodes) {
    for (const node of annotatedNodes) {
      node.emitNode = void 0;
    }
  }
}
function removeAllComments(node) {
  const emitNode = getOrCreateEmitNode(node);
  emitNode.flags |= 3072 /* NoComments */;
  emitNode.leadingComments = void 0;
  emitNode.trailingComments = void 0;
  return node;
}
function setEmitFlags(node, emitFlags) {
  getOrCreateEmitNode(node).flags = emitFlags;
  return node;
}
function addEmitFlags(node, emitFlags) {
  const emitNode = getOrCreateEmitNode(node);
  emitNode.flags = emitNode.flags | emitFlags;
  return node;
}
function setInternalEmitFlags(node, emitFlags) {
  getOrCreateEmitNode(node).internalFlags = emitFlags;
  return node;
}
function addInternalEmitFlags(node, emitFlags) {
  const emitNode = getOrCreateEmitNode(node);
  emitNode.internalFlags = emitNode.internalFlags | emitFlags;
  return node;
}
function getSourceMapRange(node) {
  var _a;
  return ((_a = node.emitNode) == null ? void 0 : _a.sourceMapRange) ?? node;
}
function setSourceMapRange(node, range) {
  getOrCreateEmitNode(node).sourceMapRange = range;
  return node;
}
function getTokenSourceMapRange(node, token) {
  var _a, _b;
  return (_b = (_a = node.emitNode) == null ? void 0 : _a.tokenSourceMapRanges) == null ? void 0 : _b[token];
}
function setTokenSourceMapRange(node, token, range) {
  const emitNode = getOrCreateEmitNode(node);
  const tokenSourceMapRanges = emitNode.tokenSourceMapRanges ?? (emitNode.tokenSourceMapRanges = []);
  tokenSourceMapRanges[token] = range;
  return node;
}
function getStartsOnNewLine(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.startsOnNewLine;
}
function setStartsOnNewLine(node, newLine) {
  getOrCreateEmitNode(node).startsOnNewLine = newLine;
  return node;
}
function getCommentRange(node) {
  var _a;
  return ((_a = node.emitNode) == null ? void 0 : _a.commentRange) ?? node;
}
function setCommentRange(node, range) {
  getOrCreateEmitNode(node).commentRange = range;
  return node;
}
function getSyntheticLeadingComments(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.leadingComments;
}
function setSyntheticLeadingComments(node, comments) {
  getOrCreateEmitNode(node).leadingComments = comments;
  return node;
}
function addSyntheticLeadingComment(node, kind, text, hasTrailingNewLine) {
  return setSyntheticLeadingComments(node, append(getSyntheticLeadingComments(node), { kind, pos: -1, end: -1, hasTrailingNewLine, text }));
}
function getSyntheticTrailingComments(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.trailingComments;
}
function setSyntheticTrailingComments(node, comments) {
  getOrCreateEmitNode(node).trailingComments = comments;
  return node;
}
function addSyntheticTrailingComment(node, kind, text, hasTrailingNewLine) {
  return setSyntheticTrailingComments(node, append(getSyntheticTrailingComments(node), { kind, pos: -1, end: -1, hasTrailingNewLine, text }));
}
function moveSyntheticComments(node, original) {
  setSyntheticLeadingComments(node, getSyntheticLeadingComments(original));
  setSyntheticTrailingComments(node, getSyntheticTrailingComments(original));
  const emit = getOrCreateEmitNode(original);
  emit.leadingComments = void 0;
  emit.trailingComments = void 0;
  return node;
}
function getConstantValue(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.constantValue;
}
function setConstantValue(node, value) {
  const emitNode = getOrCreateEmitNode(node);
  emitNode.constantValue = value;
  return node;
}
function addEmitHelper(node, helper) {
  const emitNode = getOrCreateEmitNode(node);
  emitNode.helpers = append(emitNode.helpers, helper);
  return node;
}
function addEmitHelpers(node, helpers) {
  if (some(helpers)) {
    const emitNode = getOrCreateEmitNode(node);
    for (const helper of helpers) {
      emitNode.helpers = appendIfUnique(emitNode.helpers, helper);
    }
  }
  return node;
}
function removeEmitHelper(node, helper) {
  var _a;
  const helpers = (_a = node.emitNode) == null ? void 0 : _a.helpers;
  if (helpers) {
    return orderedRemoveItem(helpers, helper);
  }
  return false;
}
function getEmitHelpers(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.helpers;
}
function moveEmitHelpers(source, target, predicate) {
  const sourceEmitNode = source.emitNode;
  const sourceEmitHelpers = sourceEmitNode && sourceEmitNode.helpers;
  if (!some(sourceEmitHelpers)) return;
  const targetEmitNode = getOrCreateEmitNode(target);
  let helpersRemoved = 0;
  for (let i = 0; i < sourceEmitHelpers.length; i++) {
    const helper = sourceEmitHelpers[i];
    if (predicate(helper)) {
      helpersRemoved++;
      targetEmitNode.helpers = appendIfUnique(targetEmitNode.helpers, helper);
    } else if (helpersRemoved > 0) {
      sourceEmitHelpers[i - helpersRemoved] = helper;
    }
  }
  if (helpersRemoved > 0) {
    sourceEmitHelpers.length -= helpersRemoved;
  }
}
function getSnippetElement(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.snippetElement;
}
function setSnippetElement(node, snippet) {
  const emitNode = getOrCreateEmitNode(node);
  emitNode.snippetElement = snippet;
  return node;
}
function ignoreSourceNewlines(node) {
  getOrCreateEmitNode(node).internalFlags |= 4 /* IgnoreSourceNewlines */;
  return node;
}
function setTypeNode(node, type) {
  const emitNode = getOrCreateEmitNode(node);
  emitNode.typeNode = type;
  return node;
}
function getTypeNode(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.typeNode;
}
function setIdentifierTypeArguments(node, typeArguments) {
  getOrCreateEmitNode(node).identifierTypeArguments = typeArguments;
  return node;
}
function getIdentifierTypeArguments(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.identifierTypeArguments;
}
function setIdentifierAutoGenerate(node, autoGenerate) {
  getOrCreateEmitNode(node).autoGenerate = autoGenerate;
  return node;
}
function getIdentifierAutoGenerate(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.autoGenerate;
}
function setIdentifierGeneratedImportReference(node, value) {
  getOrCreateEmitNode(node).generatedImportReference = value;
  return node;
}
function getIdentifierGeneratedImportReference(node) {
  var _a;
  return (_a = node.emitNode) == null ? void 0 : _a.generatedImportReference;
}

// src/compiler/factory/emitHelpers.ts
var PrivateIdentifierKind = /* @__PURE__ */ ((PrivateIdentifierKind2) => {
  PrivateIdentifierKind2["Field"] = "f";
  PrivateIdentifierKind2["Method"] = "m";
  PrivateIdentifierKind2["Accessor"] = "a";
  return PrivateIdentifierKind2;
})(PrivateIdentifierKind || {});
function createEmitHelperFactory(context) {
  const factory2 = context.factory;
  const immutableTrue = memoize(() => setInternalEmitFlags(factory2.createTrue(), 8 /* Immutable */));
  const immutableFalse = memoize(() => setInternalEmitFlags(factory2.createFalse(), 8 /* Immutable */));
  return {
    getUnscopedHelperName,
    // TypeScript Helpers
    createDecorateHelper,
    createMetadataHelper,
    createParamHelper,
    // ES Decorators Helpers
    createESDecorateHelper,
    createRunInitializersHelper,
    // ES2018 Helpers
    createAssignHelper,
    createAwaitHelper,
    createAsyncGeneratorHelper,
    createAsyncDelegatorHelper,
    createAsyncValuesHelper,
    // ES2018 Destructuring Helpers
    createRestHelper,
    // ES2017 Helpers
    createAwaiterHelper,
    // ES2015 Helpers
    createExtendsHelper,
    createTemplateObjectHelper,
    createSpreadArrayHelper,
    createPropKeyHelper,
    createSetFunctionNameHelper,
    // ES2015 Destructuring Helpers
    createValuesHelper,
    createReadHelper,
    // ES2015 Generator Helpers
    createGeneratorHelper,
    // ES Module Helpers
    createImportStarHelper,
    createImportStarCallbackHelper,
    createImportDefaultHelper,
    createExportStarHelper,
    // Class Fields Helpers
    createClassPrivateFieldGetHelper,
    createClassPrivateFieldSetHelper,
    createClassPrivateFieldInHelper,
    // 'using' helpers
    createAddDisposableResourceHelper,
    createDisposeResourcesHelper,
    // --rewriteRelativeImportExtensions helpers
    createRewriteRelativeImportExtensionsHelper
  };
  function getUnscopedHelperName(name) {
    return setEmitFlags(factory2.createIdentifier(name), 8192 /* HelperName */ | 4 /* AdviseOnEmitNode */);
  }
  function createDecorateHelper(decoratorExpressions, target, memberName, descriptor) {
    context.requestEmitHelper(decorateHelper);
    const argumentsArray = [];
    argumentsArray.push(factory2.createArrayLiteralExpression(
      decoratorExpressions,
      /*multiLine*/
      true
    ));
    argumentsArray.push(target);
    if (memberName) {
      argumentsArray.push(memberName);
      if (descriptor) {
        argumentsArray.push(descriptor);
      }
    }
    return factory2.createCallExpression(
      getUnscopedHelperName("__decorate"),
      /*typeArguments*/
      void 0,
      argumentsArray
    );
  }
  function createMetadataHelper(metadataKey, metadataValue) {
    context.requestEmitHelper(metadataHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__metadata"),
      /*typeArguments*/
      void 0,
      [
        factory2.createStringLiteral(metadataKey),
        metadataValue
      ]
    );
  }
  function createParamHelper(expression, parameterOffset, location) {
    context.requestEmitHelper(paramHelper);
    return setTextRange(
      factory2.createCallExpression(
        getUnscopedHelperName("__param"),
        /*typeArguments*/
        void 0,
        [
          factory2.createNumericLiteral(parameterOffset + ""),
          expression
        ]
      ),
      location
    );
  }
  function createESDecorateClassContextObject(contextIn) {
    const properties = [
      factory2.createPropertyAssignment(factory2.createIdentifier("kind"), factory2.createStringLiteral("class")),
      factory2.createPropertyAssignment(factory2.createIdentifier("name"), contextIn.name),
      factory2.createPropertyAssignment(factory2.createIdentifier("metadata"), contextIn.metadata)
    ];
    return factory2.createObjectLiteralExpression(properties);
  }
  function createESDecorateClassElementAccessGetMethod(elementName) {
    const accessor = elementName.computed ? factory2.createElementAccessExpression(factory2.createIdentifier("obj"), elementName.name) : factory2.createPropertyAccessExpression(factory2.createIdentifier("obj"), elementName.name);
    return factory2.createPropertyAssignment(
      "get",
      factory2.createArrowFunction(
        /*modifiers*/
        void 0,
        /*typeParameters*/
        void 0,
        [factory2.createParameterDeclaration(
          /*modifiers*/
          void 0,
          /*dotDotDotToken*/
          void 0,
          factory2.createIdentifier("obj")
        )],
        /*type*/
        void 0,
        /*equalsGreaterThanToken*/
        void 0,
        accessor
      )
    );
  }
  function createESDecorateClassElementAccessSetMethod(elementName) {
    const accessor = elementName.computed ? factory2.createElementAccessExpression(factory2.createIdentifier("obj"), elementName.name) : factory2.createPropertyAccessExpression(factory2.createIdentifier("obj"), elementName.name);
    return factory2.createPropertyAssignment(
      "set",
      factory2.createArrowFunction(
        /*modifiers*/
        void 0,
        /*typeParameters*/
        void 0,
        [
          factory2.createParameterDeclaration(
            /*modifiers*/
            void 0,
            /*dotDotDotToken*/
            void 0,
            factory2.createIdentifier("obj")
          ),
          factory2.createParameterDeclaration(
            /*modifiers*/
            void 0,
            /*dotDotDotToken*/
            void 0,
            factory2.createIdentifier("value")
          )
        ],
        /*type*/
        void 0,
        /*equalsGreaterThanToken*/
        void 0,
        factory2.createBlock([
          factory2.createExpressionStatement(
            factory2.createAssignment(
              accessor,
              factory2.createIdentifier("value")
            )
          )
        ])
      )
    );
  }
  function createESDecorateClassElementAccessHasMethod(elementName) {
    const propertyName = elementName.computed ? elementName.name : isIdentifier(elementName.name) ? factory2.createStringLiteralFromNode(elementName.name) : elementName.name;
    return factory2.createPropertyAssignment(
      "has",
      factory2.createArrowFunction(
        /*modifiers*/
        void 0,
        /*typeParameters*/
        void 0,
        [factory2.createParameterDeclaration(
          /*modifiers*/
          void 0,
          /*dotDotDotToken*/
          void 0,
          factory2.createIdentifier("obj")
        )],
        /*type*/
        void 0,
        /*equalsGreaterThanToken*/
        void 0,
        factory2.createBinaryExpression(
          propertyName,
          103 /* InKeyword */,
          factory2.createIdentifier("obj")
        )
      )
    );
  }
  function createESDecorateClassElementAccessObject(name, access) {
    const properties = [];
    properties.push(createESDecorateClassElementAccessHasMethod(name));
    if (access.get) properties.push(createESDecorateClassElementAccessGetMethod(name));
    if (access.set) properties.push(createESDecorateClassElementAccessSetMethod(name));
    return factory2.createObjectLiteralExpression(properties);
  }
  function createESDecorateClassElementContextObject(contextIn) {
    const properties = [
      factory2.createPropertyAssignment(factory2.createIdentifier("kind"), factory2.createStringLiteral(contextIn.kind)),
      factory2.createPropertyAssignment(factory2.createIdentifier("name"), contextIn.name.computed ? contextIn.name.name : factory2.createStringLiteralFromNode(contextIn.name.name)),
      factory2.createPropertyAssignment(factory2.createIdentifier("static"), contextIn.static ? factory2.createTrue() : factory2.createFalse()),
      factory2.createPropertyAssignment(factory2.createIdentifier("private"), contextIn.private ? factory2.createTrue() : factory2.createFalse()),
      factory2.createPropertyAssignment(factory2.createIdentifier("access"), createESDecorateClassElementAccessObject(contextIn.name, contextIn.access)),
      factory2.createPropertyAssignment(factory2.createIdentifier("metadata"), contextIn.metadata)
    ];
    return factory2.createObjectLiteralExpression(properties);
  }
  function createESDecorateContextObject(contextIn) {
    return contextIn.kind === "class" ? createESDecorateClassContextObject(contextIn) : createESDecorateClassElementContextObject(contextIn);
  }
  function createESDecorateHelper(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
    context.requestEmitHelper(esDecorateHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__esDecorate"),
      /*typeArguments*/
      void 0,
      [
        ctor ?? factory2.createNull(),
        descriptorIn ?? factory2.createNull(),
        decorators,
        createESDecorateContextObject(contextIn),
        initializers,
        extraInitializers
      ]
    );
  }
  function createRunInitializersHelper(thisArg, initializers, value) {
    context.requestEmitHelper(runInitializersHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__runInitializers"),
      /*typeArguments*/
      void 0,
      value ? [thisArg, initializers, value] : [thisArg, initializers]
    );
  }
  function createAssignHelper(attributesSegments) {
    if (getEmitScriptTarget(context.getCompilerOptions()) >= 2 /* ES2015 */) {
      return factory2.createCallExpression(
        factory2.createPropertyAccessExpression(factory2.createIdentifier("Object"), "assign"),
        /*typeArguments*/
        void 0,
        attributesSegments
      );
    }
    context.requestEmitHelper(assignHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__assign"),
      /*typeArguments*/
      void 0,
      attributesSegments
    );
  }
  function createAwaitHelper(expression) {
    context.requestEmitHelper(awaitHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__await"),
      /*typeArguments*/
      void 0,
      [expression]
    );
  }
  function createAsyncGeneratorHelper(generatorFunc, hasLexicalThis) {
    context.requestEmitHelper(awaitHelper);
    context.requestEmitHelper(asyncGeneratorHelper);
    (generatorFunc.emitNode || (generatorFunc.emitNode = {})).flags |= 524288 /* AsyncFunctionBody */ | 1048576 /* ReuseTempVariableScope */;
    return factory2.createCallExpression(
      getUnscopedHelperName("__asyncGenerator"),
      /*typeArguments*/
      void 0,
      [
        hasLexicalThis ? factory2.createThis() : factory2.createVoidZero(),
        factory2.createIdentifier("arguments"),
        generatorFunc
      ]
    );
  }
  function createAsyncDelegatorHelper(expression) {
    context.requestEmitHelper(awaitHelper);
    context.requestEmitHelper(asyncDelegator);
    return factory2.createCallExpression(
      getUnscopedHelperName("__asyncDelegator"),
      /*typeArguments*/
      void 0,
      [expression]
    );
  }
  function createAsyncValuesHelper(expression) {
    context.requestEmitHelper(asyncValues);
    return factory2.createCallExpression(
      getUnscopedHelperName("__asyncValues"),
      /*typeArguments*/
      void 0,
      [expression]
    );
  }
  function createRestHelper(value, elements, computedTempVariables, location) {
    context.requestEmitHelper(restHelper);
    const propertyNames = [];
    let computedTempVariableOffset = 0;
    for (let i = 0; i < elements.length - 1; i++) {
      const propertyName = getPropertyNameOfBindingOrAssignmentElement(elements[i]);
      if (propertyName) {
        if (isComputedPropertyName(propertyName)) {
          Debug.assertIsDefined(computedTempVariables, "Encountered computed property name but 'computedTempVariables' argument was not provided.");
          const temp = computedTempVariables[computedTempVariableOffset];
          computedTempVariableOffset++;
          propertyNames.push(
            factory2.createConditionalExpression(
              factory2.createTypeCheck(temp, "symbol"),
              /*questionToken*/
              void 0,
              temp,
              /*colonToken*/
              void 0,
              factory2.createAdd(temp, factory2.createStringLiteral(""))
            )
          );
        } else {
          propertyNames.push(factory2.createStringLiteralFromNode(propertyName));
        }
      }
    }
    return factory2.createCallExpression(
      getUnscopedHelperName("__rest"),
      /*typeArguments*/
      void 0,
      [
        value,
        setTextRange(
          factory2.createArrayLiteralExpression(propertyNames),
          location
        )
      ]
    );
  }
  function createAwaiterHelper(hasLexicalThis, argumentsExpression, promiseConstructor, parameters, body) {
    context.requestEmitHelper(awaiterHelper);
    const generatorFunc = factory2.createFunctionExpression(
      /*modifiers*/
      void 0,
      factory2.createToken(42 /* AsteriskToken */),
      /*name*/
      void 0,
      /*typeParameters*/
      void 0,
      parameters ?? [],
      /*type*/
      void 0,
      body
    );
    (generatorFunc.emitNode || (generatorFunc.emitNode = {})).flags |= 524288 /* AsyncFunctionBody */ | 1048576 /* ReuseTempVariableScope */;
    return factory2.createCallExpression(
      getUnscopedHelperName("__awaiter"),
      /*typeArguments*/
      void 0,
      [
        hasLexicalThis ? factory2.createThis() : factory2.createVoidZero(),
        argumentsExpression ?? factory2.createVoidZero(),
        promiseConstructor ? createExpressionFromEntityName(factory2, promiseConstructor) : factory2.createVoidZero(),
        generatorFunc
      ]
    );
  }
  function createExtendsHelper(name) {
    context.requestEmitHelper(extendsHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__extends"),
      /*typeArguments*/
      void 0,
      [name, factory2.createUniqueName("_super", 16 /* Optimistic */ | 32 /* FileLevel */)]
    );
  }
  function createTemplateObjectHelper(cooked, raw) {
    context.requestEmitHelper(templateObjectHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__makeTemplateObject"),
      /*typeArguments*/
      void 0,
      [cooked, raw]
    );
  }
  function createSpreadArrayHelper(to, from, packFrom) {
    context.requestEmitHelper(spreadArrayHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__spreadArray"),
      /*typeArguments*/
      void 0,
      [to, from, packFrom ? immutableTrue() : immutableFalse()]
    );
  }
  function createPropKeyHelper(expr) {
    context.requestEmitHelper(propKeyHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__propKey"),
      /*typeArguments*/
      void 0,
      [expr]
    );
  }
  function createSetFunctionNameHelper(f, name, prefix) {
    context.requestEmitHelper(setFunctionNameHelper);
    return context.factory.createCallExpression(
      getUnscopedHelperName("__setFunctionName"),
      /*typeArguments*/
      void 0,
      prefix ? [f, name, context.factory.createStringLiteral(prefix)] : [f, name]
    );
  }
  function createValuesHelper(expression) {
    context.requestEmitHelper(valuesHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__values"),
      /*typeArguments*/
      void 0,
      [expression]
    );
  }
  function createReadHelper(iteratorRecord, count) {
    context.requestEmitHelper(readHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__read"),
      /*typeArguments*/
      void 0,
      count !== void 0 ? [iteratorRecord, factory2.createNumericLiteral(count + "")] : [iteratorRecord]
    );
  }
  function createGeneratorHelper(body) {
    context.requestEmitHelper(generatorHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__generator"),
      /*typeArguments*/
      void 0,
      [factory2.createThis(), body]
    );
  }
  function createImportStarHelper(expression) {
    context.requestEmitHelper(importStarHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__importStar"),
      /*typeArguments*/
      void 0,
      [expression]
    );
  }
  function createImportStarCallbackHelper() {
    context.requestEmitHelper(importStarHelper);
    return getUnscopedHelperName("__importStar");
  }
  function createImportDefaultHelper(expression) {
    context.requestEmitHelper(importDefaultHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__importDefault"),
      /*typeArguments*/
      void 0,
      [expression]
    );
  }
  function createExportStarHelper(moduleExpression, exportsExpression = factory2.createIdentifier("exports")) {
    context.requestEmitHelper(exportStarHelper);
    context.requestEmitHelper(createBindingHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__exportStar"),
      /*typeArguments*/
      void 0,
      [moduleExpression, exportsExpression]
    );
  }
  function createClassPrivateFieldGetHelper(receiver, state, kind, f) {
    context.requestEmitHelper(classPrivateFieldGetHelper);
    let args;
    if (!f) {
      args = [receiver, state, factory2.createStringLiteral(kind)];
    } else {
      args = [receiver, state, factory2.createStringLiteral(kind), f];
    }
    return factory2.createCallExpression(
      getUnscopedHelperName("__classPrivateFieldGet"),
      /*typeArguments*/
      void 0,
      args
    );
  }
  function createClassPrivateFieldSetHelper(receiver, state, value, kind, f) {
    context.requestEmitHelper(classPrivateFieldSetHelper);
    let args;
    if (!f) {
      args = [receiver, state, value, factory2.createStringLiteral(kind)];
    } else {
      args = [receiver, state, value, factory2.createStringLiteral(kind), f];
    }
    return factory2.createCallExpression(
      getUnscopedHelperName("__classPrivateFieldSet"),
      /*typeArguments*/
      void 0,
      args
    );
  }
  function createClassPrivateFieldInHelper(state, receiver) {
    context.requestEmitHelper(classPrivateFieldInHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__classPrivateFieldIn"),
      /*typeArguments*/
      void 0,
      [state, receiver]
    );
  }
  function createAddDisposableResourceHelper(envBinding, value, async) {
    context.requestEmitHelper(addDisposableResourceHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__addDisposableResource"),
      /*typeArguments*/
      void 0,
      [envBinding, value, async ? factory2.createTrue() : factory2.createFalse()]
    );
  }
  function createDisposeResourcesHelper(envBinding) {
    context.requestEmitHelper(disposeResourcesHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__disposeResources"),
      /*typeArguments*/
      void 0,
      [envBinding]
    );
  }
  function createRewriteRelativeImportExtensionsHelper(expression) {
    context.requestEmitHelper(rewriteRelativeImportExtensionsHelper);
    return factory2.createCallExpression(
      getUnscopedHelperName("__rewriteRelativeImportExtension"),
      /*typeArguments*/
      void 0,
      context.getCompilerOptions().jsx === 1 /* Preserve */ ? [expression, factory2.createTrue()] : [expression]
    );
  }
}
function compareEmitHelpers(x, y) {
  if (x === y) return 0 /* EqualTo */;
  if (x.priority === y.priority) return 0 /* EqualTo */;
  if (x.priority === void 0) return 1 /* GreaterThan */;
  if (y.priority === void 0) return -1 /* LessThan */;
  return compareValues(x.priority, y.priority);
}
function helperString(input, ...args) {
  return (uniqueName) => {
    let result = "";
    for (let i = 0; i < args.length; i++) {
      result += input[i];
      result += uniqueName(args[i]);
    }
    result += input[input.length - 1];
    return result;
  };
}
var decorateHelper = {
  name: "typescript:decorate",
  importName: "__decorate",
  scoped: false,
  priority: 2,
  text: `
            var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
                var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
                if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
                else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
                return c > 3 && r && Object.defineProperty(target, key, r), r;
            };`
};
var metadataHelper = {
  name: "typescript:metadata",
  importName: "__metadata",
  scoped: false,
  priority: 3,
  text: `
            var __metadata = (this && this.__metadata) || function (k, v) {
                if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
            };`
};
var paramHelper = {
  name: "typescript:param",
  importName: "__param",
  scoped: false,
  priority: 4,
  text: `
            var __param = (this && this.__param) || function (paramIndex, decorator) {
                return function (target, key) { decorator(target, key, paramIndex); }
            };`
};
var esDecorateHelper = {
  name: "typescript:esDecorate",
  importName: "__esDecorate",
  scoped: false,
  priority: 2,
  text: `
        var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
            function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
            var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
            var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
            var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
            var _, done = false;
            for (var i = decorators.length - 1; i >= 0; i--) {
                var context = {};
                for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
                for (var p in contextIn.access) context.access[p] = contextIn.access[p];
                context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
                var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
                if (kind === "accessor") {
                    if (result === void 0) continue;
                    if (result === null || typeof result !== "object") throw new TypeError("Object expected");
                    if (_ = accept(result.get)) descriptor.get = _;
                    if (_ = accept(result.set)) descriptor.set = _;
                    if (_ = accept(result.init)) initializers.unshift(_);
                }
                else if (_ = accept(result)) {
                    if (kind === "field") initializers.unshift(_);
                    else descriptor[key] = _;
                }
            }
            if (target) Object.defineProperty(target, contextIn.name, descriptor);
            done = true;
        };`
};
var runInitializersHelper = {
  name: "typescript:runInitializers",
  importName: "__runInitializers",
  scoped: false,
  priority: 2,
  text: `
        var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
            var useValue = arguments.length > 2;
            for (var i = 0; i < initializers.length; i++) {
                value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
            }
            return useValue ? value : void 0;
        };`
};
var assignHelper = {
  name: "typescript:assign",
  importName: "__assign",
  scoped: false,
  priority: 1,
  text: `
            var __assign = (this && this.__assign) || function () {
                __assign = Object.assign || function(t) {
                    for (var s, i = 1, n = arguments.length; i < n; i++) {
                        s = arguments[i];
                        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                            t[p] = s[p];
                    }
                    return t;
                };
                return __assign.apply(this, arguments);
            };`
};
var awaitHelper = {
  name: "typescript:await",
  importName: "__await",
  scoped: false,
  text: `
            var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }`
};
var asyncGeneratorHelper = {
  name: "typescript:asyncGenerator",
  importName: "__asyncGenerator",
  scoped: false,
  dependencies: [awaitHelper],
  text: `
        var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
            if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
            var g = generator.apply(thisArg, _arguments || []), i, q = [];
            return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
            function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
            function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
            function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
            function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
            function fulfill(value) { resume("next", value); }
            function reject(value) { resume("throw", value); }
            function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
        };`
};
var asyncDelegator = {
  name: "typescript:asyncDelegator",
  importName: "__asyncDelegator",
  scoped: false,
  dependencies: [awaitHelper],
  text: `
            var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
                var i, p;
                return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
                function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
            };`
};
var asyncValues = {
  name: "typescript:asyncValues",
  importName: "__asyncValues",
  scoped: false,
  text: `
            var __asyncValues = (this && this.__asyncValues) || function (o) {
                if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
                var m = o[Symbol.asyncIterator], i;
                return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
                function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
                function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
            };`
};
var restHelper = {
  name: "typescript:rest",
  importName: "__rest",
  scoped: false,
  text: `
            var __rest = (this && this.__rest) || function (s, e) {
                var t = {};
                for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
                    t[p] = s[p];
                if (s != null && typeof Object.getOwnPropertySymbols === "function")
                    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                        if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                            t[p[i]] = s[p[i]];
                    }
                return t;
            };`
};
var awaiterHelper = {
  name: "typescript:awaiter",
  importName: "__awaiter",
  scoped: false,
  priority: 5,
  text: `
            var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
                function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
                return new (P || (P = Promise))(function (resolve, reject) {
                    function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
                    function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
                    function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
                    step((generator = generator.apply(thisArg, _arguments || [])).next());
                });
            };`
};
var extendsHelper = {
  name: "typescript:extends",
  importName: "__extends",
  scoped: false,
  priority: 0,
  text: `
            var __extends = (this && this.__extends) || (function () {
                var extendStatics = function (d, b) {
                    extendStatics = Object.setPrototypeOf ||
                        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
                        function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
                    return extendStatics(d, b);
                };

                return function (d, b) {
                    if (typeof b !== "function" && b !== null)
                        throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
                    extendStatics(d, b);
                    function __() { this.constructor = d; }
                    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
                };
            })();`
};
var templateObjectHelper = {
  name: "typescript:makeTemplateObject",
  importName: "__makeTemplateObject",
  scoped: false,
  priority: 0,
  text: `
            var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
                if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
                return cooked;
            };`
};
var readHelper = {
  name: "typescript:read",
  importName: "__read",
  scoped: false,
  text: `
            var __read = (this && this.__read) || function (o, n) {
                var m = typeof Symbol === "function" && o[Symbol.iterator];
                if (!m) return o;
                var i = m.call(o), r, ar = [], e;
                try {
                    while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
                }
                catch (error) { e = { error: error }; }
                finally {
                    try {
                        if (r && !r.done && (m = i["return"])) m.call(i);
                    }
                    finally { if (e) throw e.error; }
                }
                return ar;
            };`
};
var spreadArrayHelper = {
  name: "typescript:spreadArray",
  importName: "__spreadArray",
  scoped: false,
  text: `
            var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
                if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
                    if (ar || !(i in from)) {
                        if (!ar) ar = Array.prototype.slice.call(from, 0, i);
                        ar[i] = from[i];
                    }
                }
                return to.concat(ar || Array.prototype.slice.call(from));
            };`
};
var propKeyHelper = {
  name: "typescript:propKey",
  importName: "__propKey",
  scoped: false,
  text: `
        var __propKey = (this && this.__propKey) || function (x) {
            return typeof x === "symbol" ? x : "".concat(x);
        };`
};
var setFunctionNameHelper = {
  name: "typescript:setFunctionName",
  importName: "__setFunctionName",
  scoped: false,
  text: `
        var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
            if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
            return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
        };`
};
var valuesHelper = {
  name: "typescript:values",
  importName: "__values",
  scoped: false,
  text: `
            var __values = (this && this.__values) || function(o) {
                var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
                if (m) return m.call(o);
                if (o && typeof o.length === "number") return {
                    next: function () {
                        if (o && i >= o.length) o = void 0;
                        return { value: o && o[i++], done: !o };
                    }
                };
                throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
            };`
};
var generatorHelper = {
  name: "typescript:generator",
  importName: "__generator",
  scoped: false,
  priority: 6,
  text: `
            var __generator = (this && this.__generator) || function (thisArg, body) {
                var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
                return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
                function verb(n) { return function (v) { return step([n, v]); }; }
                function step(op) {
                    if (f) throw new TypeError("Generator is already executing.");
                    while (g && (g = 0, op[0] && (_ = 0)), _) try {
                        if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
                        if (y = 0, t) op = [op[0] & 2, t.value];
                        switch (op[0]) {
                            case 0: case 1: t = op; break;
                            case 4: _.label++; return { value: op[1], done: false };
                            case 5: _.label++; y = op[1]; op = [0]; continue;
                            case 7: op = _.ops.pop(); _.trys.pop(); continue;
                            default:
                                if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                                if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                                if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                                if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                                if (t[2]) _.ops.pop();
                                _.trys.pop(); continue;
                        }
                        op = body.call(thisArg, _);
                    } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
                    if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
                }
            };`
};
var createBindingHelper = {
  name: "typescript:commonjscreatebinding",
  importName: "__createBinding",
  scoped: false,
  priority: 1,
  text: `
            var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
                if (k2 === undefined) k2 = k;
                var desc = Object.getOwnPropertyDescriptor(m, k);
                if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
                  desc = { enumerable: true, get: function() { return m[k]; } };
                }
                Object.defineProperty(o, k2, desc);
            }) : (function(o, m, k, k2) {
                if (k2 === undefined) k2 = k;
                o[k2] = m[k];
            }));`
};
var setModuleDefaultHelper = {
  name: "typescript:commonjscreatevalue",
  importName: "__setModuleDefault",
  scoped: false,
  priority: 1,
  text: `
            var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
                Object.defineProperty(o, "default", { enumerable: true, value: v });
            }) : function(o, v) {
                o["default"] = v;
            });`
};
var importStarHelper = {
  name: "typescript:commonjsimportstar",
  importName: "__importStar",
  scoped: false,
  dependencies: [createBindingHelper, setModuleDefaultHelper],
  priority: 2,
  text: `
            var __importStar = (this && this.__importStar) || (function () {
                var ownKeys = function(o) {
                    ownKeys = Object.getOwnPropertyNames || function (o) {
                        var ar = [];
                        for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
                        return ar;
                    };
                    return ownKeys(o);
                };
                return function (mod) {
                    if (mod && mod.__esModule) return mod;
                    var result = {};
                    if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
                    __setModuleDefault(result, mod);
                    return result;
                };
            })();`
};
var importDefaultHelper = {
  name: "typescript:commonjsimportdefault",
  importName: "__importDefault",
  scoped: false,
  text: `
            var __importDefault = (this && this.__importDefault) || function (mod) {
                return (mod && mod.__esModule) ? mod : { "default": mod };
            };`
};
var exportStarHelper = {
  name: "typescript:export-star",
  importName: "__exportStar",
  scoped: false,
  dependencies: [createBindingHelper],
  priority: 2,
  text: `
            var __exportStar = (this && this.__exportStar) || function(m, exports) {
                for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
            };`
};
var classPrivateFieldGetHelper = {
  name: "typescript:classPrivateFieldGet",
  importName: "__classPrivateFieldGet",
  scoped: false,
  text: `
            var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
                if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
                if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
                return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
            };`
};
var classPrivateFieldSetHelper = {
  name: "typescript:classPrivateFieldSet",
  importName: "__classPrivateFieldSet",
  scoped: false,
  text: `
            var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
                if (kind === "m") throw new TypeError("Private method is not writable");
                if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
                if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
                return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
            };`
};
var classPrivateFieldInHelper = {
  name: "typescript:classPrivateFieldIn",
  importName: "__classPrivateFieldIn",
  scoped: false,
  text: `
            var __classPrivateFieldIn = (this && this.__classPrivateFieldIn) || function(state, receiver) {
                if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
                return typeof state === "function" ? receiver === state : state.has(receiver);
            };`
};
var addDisposableResourceHelper = {
  name: "typescript:addDisposableResource",
  importName: "__addDisposableResource",
  scoped: false,
  text: `
        var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
            if (value !== null && value !== void 0) {
                if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
                var dispose, inner;
                if (async) {
                    if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
                    dispose = value[Symbol.asyncDispose];
                }
                if (dispose === void 0) {
                    if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
                    dispose = value[Symbol.dispose];
                    if (async) inner = dispose;
                }
                if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
                if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
                env.stack.push({ value: value, dispose: dispose, async: async });
            }
            else if (async) {
                env.stack.push({ async: true });
            }
            return value;
        };`
};
var disposeResourcesHelper = {
  name: "typescript:disposeResources",
  importName: "__disposeResources",
  scoped: false,
  text: `
        var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
            return function (env) {
                function fail(e) {
                    env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
                    env.hasError = true;
                }
                var r, s = 0;
                function next() {
                    while (r = env.stack.pop()) {
                        try {
                            if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
                            if (r.dispose) {
                                var result = r.dispose.call(r.value);
                                if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
                            }
                            else s |= 1;
                        }
                        catch (e) {
                            fail(e);
                        }
                    }
                    if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
                    if (env.hasError) throw env.error;
                }
                return next();
            };
        })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
            var e = new Error(message);
            return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
        });`
};
var rewriteRelativeImportExtensionsHelper = {
  name: "typescript:rewriteRelativeImportExtensions",
  importName: "__rewriteRelativeImportExtension",
  scoped: false,
  text: `
        var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
            if (typeof path === "string" && /^\\.\\.?\\//.test(path)) {
                return path.replace(/\\.(tsx)$|((?:\\.d)?)((?:\\.[^./]+?)?)\\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
                    return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
                });
            }
            return path;
        };`
};
var asyncSuperHelper = {
  name: "typescript:async-super",
  scoped: true,
  text: helperString`
            const ${"_superIndex"} = name => super[name];`
};
var advancedAsyncSuperHelper = {
  name: "typescript:advanced-async-super",
  scoped: true,
  text: helperString`
            const ${"_superIndex"} = (function (geti, seti) {
                const cache = Object.create(null);
                return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } });
            })(name => super[name], (name, value) => super[name] = value);`
};
function isCallToHelper(firstSegment, helperName) {
  return isCallExpression(firstSegment) && isIdentifier(firstSegment.expression) && (getEmitFlags(firstSegment.expression) & 8192 /* HelperName */) !== 0 && firstSegment.expression.escapedText === helperName;
}

// src/compiler/factory/nodeTests.ts
function isNumericLiteral(node) {
  return node.kind === 9 /* NumericLiteral */;
}
function isBigIntLiteral(node) {
  return node.kind === 10 /* BigIntLiteral */;
}
function isStringLiteral(node) {
  return node.kind === 11 /* StringLiteral */;
}
function isJsxText(node) {
  return node.kind === 12 /* JsxText */;
}
function isRegularExpressionLiteral(node) {
  return node.kind === 14 /* RegularExpressionLiteral */;
}
function isNoSubstitutionTemplateLiteral(node) {
  return node.kind === 15 /* NoSubstitutionTemplateLiteral */;
}
function isTemplateHead(node) {
  return node.kind === 16 /* TemplateHead */;
}
function isTemplateMiddle(node) {
  return node.kind === 17 /* TemplateMiddle */;
}
function isTemplateTail(node) {
  return node.kind === 18 /* TemplateTail */;
}
function isDotDotDotToken(node) {
  return node.kind === 26 /* DotDotDotToken */;
}
function isCommaToken(node) {
  return node.kind === 28 /* CommaToken */;
}
function isPlusToken(node) {
  return node.kind === 40 /* PlusToken */;
}
function isMinusToken(node) {
  return node.kind === 41 /* MinusToken */;
}
function isAsteriskToken(node) {
  return node.kind === 42 /* AsteriskToken */;
}
function isExclamationToken(node) {
  return node.kind === 54 /* ExclamationToken */;
}
function isQuestionToken(node) {
  return node.kind === 58 /* QuestionToken */;
}
function isColonToken(node) {
  return node.kind === 59 /* ColonToken */;
}
function isQuestionDotToken(node) {
  return node.kind === 29 /* QuestionDotToken */;
}
function isEqualsGreaterThanToken(node) {
  return node.kind === 39 /* EqualsGreaterThanToken */;
}
function isIdentifier(node) {
  return node.kind === 80 /* Identifier */;
}
function isPrivateIdentifier(node) {
  return node.kind === 81 /* PrivateIdentifier */;
}
function isExportModifier(node) {
  return node.kind === 95 /* ExportKeyword */;
}
function isDefaultModifier(node) {
  return node.kind === 90 /* DefaultKeyword */;
}
function isAsyncModifier(node) {
  return node.kind === 134 /* AsyncKeyword */;
}
function isAssertsKeyword(node) {
  return node.kind === 131 /* AssertsKeyword */;
}
function isAwaitKeyword(node) {
  return node.kind === 135 /* AwaitKeyword */;
}
function isReadonlyKeyword(node) {
  return node.kind === 148 /* ReadonlyKeyword */;
}
function isStaticModifier(node) {
  return node.kind === 126 /* StaticKeyword */;
}
function isAbstractModifier(node) {
  return node.kind === 128 /* AbstractKeyword */;
}
function isOverrideModifier(node) {
  return node.kind === 164 /* OverrideKeyword */;
}
function isAccessorModifier(node) {
  return node.kind === 129 /* AccessorKeyword */;
}
function isSuperKeyword(node) {
  return node.kind === 108 /* SuperKeyword */;
}
function isImportKeyword(node) {
  return node.kind === 102 /* ImportKeyword */;
}
function isCaseKeyword(node) {
  return node.kind === 84 /* CaseKeyword */;
}
function isQualifiedName(node) {
  return node.kind === 166 /* QualifiedName */;
}
function isComputedPropertyName(node) {
  return node.kind === 167 /* ComputedPropertyName */;
}
function isTypeParameterDeclaration(node) {
  return node.kind === 168 /* TypeParameter */;
}
function isParameter(node) {
  return node.kind === 169 /* Parameter */;
}
function isDecorator(node) {
  return node.kind === 170 /* Decorator */;
}
function isPropertySignature(node) {
  return node.kind === 171 /* PropertySignature */;
}
function isPropertyDeclaration(node) {
  return node.kind === 172 /* PropertyDeclaration */;
}
function isMethodSignature(node) {
  return node.kind === 173 /* MethodSignature */;
}
function isMethodDeclaration(node) {
  return node.kind === 174 /* MethodDeclaration */;
}
function isClassStaticBlockDeclaration(node) {
  return node.kind === 175 /* ClassStaticBlockDeclaration */;
}
function isConstructorDeclaration(node) {
  return node.kind === 176 /* Constructor */;
}
function isGetAccessorDeclaration(node) {
  return node.kind === 177 /* GetAccessor */;
}
function isSetAccessorDeclaration(node) {
  return node.kind === 178 /* SetAccessor */;
}
function isCallSignatureDeclaration(node) {
  return node.kind === 179 /* CallSignature */;
}
function isConstructSignatureDeclaration(node) {
  return node.kind === 180 /* ConstructSignature */;
}
function isIndexSignatureDeclaration(node) {
  return node.kind === 181 /* IndexSignature */;
}
function isTypePredicateNode(node) {
  return node.kind === 182 /* TypePredicate */;
}
function isTypeReferenceNode(node) {
  return node.kind === 183 /* TypeReference */;
}
function isFunctionTypeNode(node) {
  return node.kind === 184 /* FunctionType */;
}
function isConstructorTypeNode(node) {
  return node.kind === 185 /* ConstructorType */;
}
function isTypeQueryNode(node) {
  return node.kind === 186 /* TypeQuery */;
}
function isTypeLiteralNode(node) {
  return node.kind === 187 /* TypeLiteral */;
}
function isArrayTypeNode(node) {
  return node.kind === 188 /* ArrayType */;
}
function isTupleTypeNode(node) {
  return node.kind === 189 /* TupleType */;
}
function isNamedTupleMember(node) {
  return node.kind === 202 /* NamedTupleMember */;
}
function isOptionalTypeNode(node) {
  return node.kind === 190 /* OptionalType */;
}
function isRestTypeNode(node) {
  return node.kind === 191 /* RestType */;
}
function isUnionTypeNode(node) {
  return node.kind === 192 /* UnionType */;
}
function isIntersectionTypeNode(node) {
  return node.kind === 193 /* IntersectionType */;
}
function isConditionalTypeNode(node) {
  return node.kind === 194 /* ConditionalType */;
}
function isInferTypeNode(node) {
  return node.kind === 195 /* InferType */;
}
function isParenthesizedTypeNode(node) {
  return node.kind === 196 /* ParenthesizedType */;
}
function isThisTypeNode(node) {
  return node.kind === 197 /* ThisType */;
}
function isTypeOperatorNode(node) {
  return node.kind === 198 /* TypeOperator */;
}
function isIndexedAccessTypeNode(node) {
  return node.kind === 199 /* IndexedAccessType */;
}
function isMappedTypeNode(node) {
  return node.kind === 200 /* MappedType */;
}
function isLiteralTypeNode(node) {
  return node.kind === 201 /* LiteralType */;
}
function isImportTypeNode(node) {
  return node.kind === 205 /* ImportType */;
}
function isTemplateLiteralTypeSpan(node) {
  return node.kind === 204 /* TemplateLiteralTypeSpan */;
}
function isTemplateLiteralTypeNode(node) {
  return node.kind === 203 /* TemplateLiteralType */;
}
function isObjectBindingPattern(node) {
  return node.kind === 206 /* ObjectBindingPattern */;
}
function isArrayBindingPattern(node) {
  return node.kind === 207 /* ArrayBindingPattern */;
}
function isBindingElement(node) {
  return node.kind === 208 /* BindingElement */;
}
function isArrayLiteralExpression(node) {
  return node.kind === 209 /* ArrayLiteralExpression */;
}
function isObjectLiteralExpression(node) {
  return node.kind === 210 /* ObjectLiteralExpression */;
}
function isPropertyAccessExpression(node) {
  return node.kind === 211 /* PropertyAccessExpression */;
}
function isElementAccessExpression(node) {
  return node.kind === 212 /* ElementAccessExpression */;
}
function isCallExpression(node) {
  return node.kind === 213 /* CallExpression */;
}
function isNewExpression(node) {
  return node.kind === 214 /* NewExpression */;
}
function isTaggedTemplateExpression(node) {
  return node.kind === 215 /* TaggedTemplateExpression */;
}
function isTypeAssertionExpression(node) {
  return node.kind === 216 /* TypeAssertionExpression */;
}
function isParenthesizedExpression(node) {
  return node.kind === 217 /* ParenthesizedExpression */;
}
function isFunctionExpression(node) {
  return node.kind === 218 /* FunctionExpression */;
}
function isArrowFunction(node) {
  return node.kind === 219 /* ArrowFunction */;
}
function isDeleteExpression(node) {
  return node.kind === 220 /* DeleteExpression */;
}
function isTypeOfExpression(node) {
  return node.kind === 221 /* TypeOfExpression */;
}
function isVoidExpression(node) {
  return node.kind === 222 /* VoidExpression */;
}
function isAwaitExpression(node) {
  return node.kind === 223 /* AwaitExpression */;
}
function isPrefixUnaryExpression(node) {
  return node.kind === 224 /* PrefixUnaryExpression */;
}
function isPostfixUnaryExpression(node) {
  return node.kind === 225 /* PostfixUnaryExpression */;
}
function isBinaryExpression(node) {
  return node.kind === 226 /* BinaryExpression */;
}
function isConditionalExpression(node) {
  return node.kind === 227 /* ConditionalExpression */;
}
function isTemplateExpression(node) {
  return node.kind === 228 /* TemplateExpression */;
}
function isYieldExpression(node) {
  return node.kind === 229 /* YieldExpression */;
}
function isSpreadElement(node) {
  return node.kind === 230 /* SpreadElement */;
}
function isClassExpression(node) {
  return node.kind === 231 /* ClassExpression */;
}
function isOmittedExpression(node) {
  return node.kind === 232 /* OmittedExpression */;
}
function isExpressionWithTypeArguments(node) {
  return node.kind === 233 /* ExpressionWithTypeArguments */;
}
function isAsExpression(node) {
  return node.kind === 234 /* AsExpression */;
}
function isSatisfiesExpression(node) {
  return node.kind === 238 /* SatisfiesExpression */;
}
function isNonNullExpression(node) {
  return node.kind === 235 /* NonNullExpression */;
}
function isMetaProperty(node) {
  return node.kind === 236 /* MetaProperty */;
}
function isSyntheticExpression(node) {
  return node.kind === 237 /* SyntheticExpression */;
}
function isPartiallyEmittedExpression(node) {
  return node.kind === 355 /* PartiallyEmittedExpression */;
}
function isCommaListExpression(node) {
  return node.kind === 356 /* CommaListExpression */;
}
function isTemplateSpan(node) {
  return node.kind === 239 /* TemplateSpan */;
}
function isSemicolonClassElement(node) {
  return node.kind === 240 /* SemicolonClassElement */;
}
function isBlock(node) {
  return node.kind === 241 /* Block */;
}
function isVariableStatement(node) {
  return node.kind === 243 /* VariableStatement */;
}
function isEmptyStatement(node) {
  return node.kind === 242 /* EmptyStatement */;
}
function isExpressionStatement(node) {
  return node.kind === 244 /* ExpressionStatement */;
}
function isIfStatement(node) {
  return node.kind === 245 /* IfStatement */;
}
function isDoStatement(node) {
  return node.kind === 246 /* DoStatement */;
}
function isWhileStatement(node) {
  return node.kind === 247 /* WhileStatement */;
}
function isForStatement(node) {
  return node.kind === 248 /* ForStatement */;
}
function isForInStatement(node) {
  return node.kind === 249 /* ForInStatement */;
}
function isForOfStatement(node) {
  return node.kind === 250 /* ForOfStatement */;
}
function isContinueStatement(node) {
  return node.kind === 251 /* ContinueStatement */;
}
function isBreakStatement(node) {
  return node.kind === 252 /* BreakStatement */;
}
function isReturnStatement(node) {
  return node.kind === 253 /* ReturnStatement */;
}
function isWithStatement(node) {
  return node.kind === 254 /* WithStatement */;
}
function isSwitchStatement(node) {
  return node.kind === 255 /* SwitchStatement */;
}
function isLabeledStatement(node) {
  return node.kind === 256 /* LabeledStatement */;
}
function isThrowStatement(node) {
  return node.kind === 257 /* ThrowStatement */;
}
function isTryStatement(node) {
  return node.kind === 258 /* TryStatement */;
}
function isDebuggerStatement(node) {
  return node.kind === 259 /* DebuggerStatement */;
}
function isVariableDeclaration(node) {
  return node.kind === 260 /* VariableDeclaration */;
}
function isVariableDeclarationList(node) {
  return node.kind === 261 /* VariableDeclarationList */;
}
function isFunctionDeclaration(node) {
  return node.kind === 262 /* FunctionDeclaration */;
}
function isClassDeclaration(node) {
  return node.kind === 263 /* ClassDec