<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/94060>94060</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc] add `at_quick_exit`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            michaelrj-google
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          michaelrj-google
      </td>
    </tr>
</table>

<pre>
    Followup to #93581

The `at_quick_exit` function is defined in the C standard on page 381 of this PDF: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf

It's used to register callbacks to be run when `quick_exit` is called, so changes to `quick_exit` will be necessary. Additionally it's similar in design to [`atexit`](https://github.com/llvm/llvm-project/blob/main/libc/src/stdlib/atexit.cpp) so refactoring to reuse that code is recommended.

### Build System

In [entrypoints.txt](https://github.com/llvm/llvm-project/blob/main/libc/config/linux/x86_64/entrypoints.txt)
- [ ] Add the new function to the list of entrypoints for stdlib.h (you need to do this before it will build)

In [stdlib/CMakeLists.txt](https://github.com/llvm/llvm-project/blob/main/libc/src/stdlib/CMakeLists.txt)
- [ ] Add new entrypoint objects to the list

In [stdc.td](https://github.com/llvm/llvm-project/blob/main/libc/spec/stdc.td)
- [ ] Add the functions to the list of functions for stdlib.h.

### Code

- [ ] Refactor [`atexit`](https://github.com/llvm/llvm-project/blob/main/libc/src/stdlib/atexit.cpp)
The existing implementation of `atexit` defines a system for storing and calling functions similar to what should be used for `at_quick_exit`, so it should be moved to a shared file. From there, both `atexit` and `at_quick_exit` should maintain separate lists of functions to call.

- [ ] Create `stdlib/at_quick_exit.h`
- [ ] Create `stdlib/at_quick_exit.cpp`

### Testing

- [ ] Create `test/src/stdlib/at_quick_exit_test.cpp`

- [ ] Add your test to [test/src/stdlib/CMakeLists.txt](https://github.com/llvm/llvm-project/blob/main/libc/test/src/stdlib/CMakeLists.txt)
</pre>
<img width="1px" height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