int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key)
{
    struct fd_lookup_st *curr, *prev;
    curr = ctx->fds;
    prev = NULL;
    while (curr != NULL) {
        if (curr->del == 1) {
            curr = curr->next;
            continue;
        }
        if (curr->key == key) {
            if (curr->add == 1) {
                if (ctx->fds == curr) {
                    ctx->fds = curr->next;
                } else {
                    prev->next = curr->next;
                }
                OPENSSL_free(curr);
                ctx->numadd--;
                return 1;
            }
            curr->del = 1;
            ctx->numdel++;
            return 1;
        }
        prev = curr;
        curr = curr->next;
    }
    return 0;
}
['static int waitfd(void *args)\n{\n    ASYNC_JOB *job;\n    ASYNC_WAIT_CTX *waitctx;\n    job = ASYNC_get_current_job();\n    if (job == NULL)\n        return 0;\n    waitctx = ASYNC_get_wait_ctx(job);\n    if (waitctx == NULL)\n        return 0;\n    ASYNC_pause_job();\n    if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, waitctx, MAGIC_WAIT_FD, NULL, NULL))\n        return 0;\n    ASYNC_pause_job();\n    if (!ASYNC_WAIT_CTX_clear_fd(waitctx, waitctx))\n        return 0;\n    ASYNC_pause_job();\n    if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, waitctx, MAGIC_WAIT_FD, NULL, NULL))\n        return 0;\n    if (!ASYNC_WAIT_CTX_clear_fd(waitctx, waitctx))\n        return 0;\n    return 1;\n}', 'int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key,\n                               OSSL_ASYNC_FD fd, void *custom_data,\n                               void (*cleanup)(ASYNC_WAIT_CTX *, const void *,\n                                               OSSL_ASYNC_FD, void *))\n{\n    struct fd_lookup_st *fdlookup;\n    fdlookup = OPENSSL_zalloc(sizeof *fdlookup);\n    if (fdlookup == NULL)\n        return 0;\n    fdlookup->key = key;\n    fdlookup->fd = fd;\n    fdlookup->custom_data = custom_data;\n    fdlookup->cleanup = cleanup;\n    fdlookup->add = 1;\n    fdlookup->next = ctx->fds;\n    ctx->fds = fdlookup;\n    ctx->numadd++;\n    return 1;\n}', 'int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key)\n{\n    struct fd_lookup_st *curr, *prev;\n    curr = ctx->fds;\n    prev = NULL;\n    while (curr != NULL) {\n        if (curr->del == 1) {\n            curr = curr->next;\n            continue;\n        }\n        if (curr->key == key) {\n            if (curr->add == 1) {\n                if (ctx->fds == curr) {\n                    ctx->fds = curr->next;\n                } else {\n                    prev->next = curr->next;\n                }\n                OPENSSL_free(curr);\n                ctx->numadd--;\n                return 1;\n            }\n            curr->del = 1;\n            ctx->numdel++;\n            return 1;\n        }\n        prev = curr;\n        curr = curr->next;\n    }\n    return 0;\n}']