[TIMOB-18027] Cherry Pick PR 6343 into 3_5_0_64-bit

Resolving merge conflicts here itself so it can be merged back into
master easily
[TIMOB-18027] Address comments
[TIMOB-18027] Remove other dead store warnings