#include <stdio.h>
#include <sys/queue.h>
struct foo {
TAILQ_ENTRY(foo) tailq;
int datum;
};
struct foo foo (int val) {
struct foo x = { { 0, 0 }, val };
return x;
}
TAILQ_HEAD(fooq, foo);
int main ()
{
struct fooq q;
struct foo data[3] = { foo(3), foo(7), foo(1) };
struct foo *p;
TAILQ_INIT(&q);
TAILQ_INSERT_HEAD(&q, &data[0], tailq);
TAILQ_INSERT_AFTER(&q, &data[0], &data[1], tailq);
TAILQ_INSERT_TAIL(&q, &data[2], tailq);
TAILQ_FOREACH(p, &q, tailq) {
}
TAILQ_FOREACH_REVERSE(p, &q, fooq, tailq) {
}
while (!TAILQ_EMPTY(&q)) {
p = TAILQ_FIRST(&q);
TAILQ_REMOVE(&q, p, tailq);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzeXMvcXVldWUuaD4KCnN0cnVjdCBmb28gewogICAgVEFJTFFfRU5UUlkoZm9vKSB0YWlscTsKICAgIGludCBkYXR1bTsKfTsKCnN0cnVjdCBmb28gZm9vIChpbnQgdmFsKSB7CiAgICBzdHJ1Y3QgZm9vIHggPSB7IHsgMCwgMCB9LCB2YWwgfTsKICAgIHJldHVybiB4Owp9CgpUQUlMUV9IRUFEKGZvb3EsIGZvbyk7CgppbnQgbWFpbiAoKQp7CiAgICBzdHJ1Y3QgZm9vcSBxOwogICAgc3RydWN0IGZvbyBkYXRhWzNdID0geyBmb28oMyksIGZvbyg3KSwgZm9vKDEpIH07CiAgICBzdHJ1Y3QgZm9vICpwOwoKICAgIFRBSUxRX0lOSVQoJnEpOwogICAgVEFJTFFfSU5TRVJUX0hFQUQoJnEsICZkYXRhWzBdLCB0YWlscSk7CiAgICBUQUlMUV9JTlNFUlRfQUZURVIoJnEsICZkYXRhWzBdLCAmZGF0YVsxXSwgdGFpbHEpOwogICAgVEFJTFFfSU5TRVJUX1RBSUwoJnEsICZkYXRhWzJdLCB0YWlscSk7CgogICAgVEFJTFFfRk9SRUFDSChw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