static int init_thread_deregister(void *index, int all)
{
    GLOBAL_TEVENT_REGISTER *gtr;
    int i;
    gtr = get_global_tevent_register();
    if (!all)
        CRYPTO_THREAD_write_lock(gtr->lock);
    for (i = 0; i < sk_THREAD_EVENT_HANDLER_PTR_num(gtr->skhands); i++) {
        THREAD_EVENT_HANDLER **hands
            = sk_THREAD_EVENT_HANDLER_PTR_value(gtr->skhands, i);
        THREAD_EVENT_HANDLER *curr = *hands, *prev = NULL, *tmp;
        if (hands == NULL) {
            if (!all)
                CRYPTO_THREAD_unlock(gtr->lock);
            return 0;
        }
        while (curr != NULL) {
            if (all || curr->index == index) {
                if (prev != NULL)
                    prev->next = curr->next;
                else
                    *hands = curr->next;
                tmp = curr;
                curr = curr->next;
                OPENSSL_free(tmp);
                continue;
            }
            prev = curr;
            curr = curr->next;
        }
        if (all)
            OPENSSL_free(hands);
    }
    if (all) {
        CRYPTO_THREAD_lock_free(gtr->lock);
        sk_THREAD_EVENT_HANDLER_PTR_free(gtr->skhands);
        OPENSSL_free(gtr);
    } else {
        CRYPTO_THREAD_unlock(gtr->lock);
    }
    return 1;
}
['static int init_thread_deregister(void *index, int all)\n{\n    GLOBAL_TEVENT_REGISTER *gtr;\n    int i;\n    gtr = get_global_tevent_register();\n    if (!all)\n        CRYPTO_THREAD_write_lock(gtr->lock);\n    for (i = 0; i < sk_THREAD_EVENT_HANDLER_PTR_num(gtr->skhands); i++) {\n        THREAD_EVENT_HANDLER **hands\n            = sk_THREAD_EVENT_HANDLER_PTR_value(gtr->skhands, i);\n        THREAD_EVENT_HANDLER *curr = *hands, *prev = NULL, *tmp;\n        if (hands == NULL) {\n            if (!all)\n                CRYPTO_THREAD_unlock(gtr->lock);\n            return 0;\n        }\n        while (curr != NULL) {\n            if (all || curr->index == index) {\n                if (prev != NULL)\n                    prev->next = curr->next;\n                else\n                    *hands = curr->next;\n                tmp = curr;\n                curr = curr->next;\n                OPENSSL_free(tmp);\n                continue;\n            }\n            prev = curr;\n            curr = curr->next;\n        }\n        if (all)\n            OPENSSL_free(hands);\n    }\n    if (all) {\n        CRYPTO_THREAD_lock_free(gtr->lock);\n        sk_THREAD_EVENT_HANDLER_PTR_free(gtr->skhands);\n        OPENSSL_free(gtr);\n    } else {\n        CRYPTO_THREAD_unlock(gtr->lock);\n    }\n    return 1;\n}', 'static GLOBAL_TEVENT_REGISTER *get_global_tevent_register(void)\n{\n    if (!RUN_ONCE(&tevent_register_runonce, create_global_tevent_register))\n        return NULL;\n    return glob_tevent_reg;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n    if (pthread_once(once, init) != 0)\n        return 0;\n    return 1;\n}']