I have a simple function that takes two variables by reference:

```
void foo(int*& it2,
         bit_reader<big_endian_tag>& reader2)
{
    for(/* ... */)
    {
        *it2++ = boo(reader2.next());
        // it2++ => 0x14001d890 add qword ptr [r12], 0x4
    }
}

```

The problem here is that for `it2` and `reader2` the optimizer makes the computer write to memory instead of registers during the loop.

However, the following code puts the variables properly into registers during the loop, but has an extra overhead in the form of unnecessary copies, before and after the loop:

```
void foo2(int*& it2,
         bit_reader<big_endian_tag>& reader2)
{
    auto reader = reader2;
    auto it     = it2;

    for(/* ... */)
    {
        *it++ = boo(reader.next());
        // it++ => 0x14001d890 add r15, 0x4
    }

    reader2 = reader;
    it2 = it;
}

```

e.g.

How can I make the first example generate the same code as the second example but without the extra copies?