Plain C version with attribute((__cleanup)):
int* foo(int bar) {
int* return_value = NULL;
__cleanup__((cleanup_1)) int c1 = 0;
if (!do_something(bar))
return NULL;
__cleanup__((cleanup_2)) int c2 = 0;
if (!init_stuff(bar))
return NULL;
__cleanup__((cleanup_3)) int c3 = 0;
if (!prepare_stuff(bar))
return NULL;
return_value = do_the_thing(bar);
return return_value;
}