merge from optimization lwt.c