Double template invocation causes bad codegen (duplicate gensym)
### Description

While working with some embedded code I noticed compilation errors from liberal use of templates. The minimal repro below shows the issue. The `double` template causes the `value` template to generate the exact same C code, with the same variable names. This causes the C compiler to error out.

```nim
template value(): uint =
  var res: uint
  res

template double(x: uint): untyped =
  x + x

proc main() =
  echo double(value())

main()
```

### Nim Version

Tested on 2.0.8 and latest devel:
```
Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-08-28
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 540b414c861c44be9011336ee5fb1cd6f0d6da44
active boot switches: -d:release
```

### Current Output

```text
/home/peter/.cache/nim/test_d/@mtest.nim.c:90:12: error: redeclaration of ‘resX60gensym0_’ with no linkage
   90 |         NU resX60gensym0_;
      |            ^~~~~~~~~~~~~~
/home/peter/.cache/nim/test_d/@mtest.nim.c:89:12: note: previous declaration of ‘resX60gensym0_’ with type ‘NU’ {aka ‘long unsigned int’}
   89 |         NU resX60gensym0_;
      |            ^~~~~~~~~~~~~~
```

### Expected Output
No compilation error, minimal repro outputs `0`