Note that in C an `int` is 32bit and in Nim 64bit on my x86-64 on Linux, so probably on your system as well. Use `int32` instead of `int` in Nim and performance is equal to C on my system with just that change.
The reason is that general purpose division (`mod`) is MUCH slower for 64bit numbers than 32bit (note that division by 2 is fast, just shift the number). See [http://www.agner.org/optimize/instruction_tables.pdf](http://forum.nim-lang.org///www.agner.org/optimize/instruction_tables.pdf) , which tells us that on a Skylake CPU a 32bit DIV operation takes 26 cycles while a 64bit DIV operation takes 35-88 cycles, so it can be nearly four times as slow, fitting well into what you measure. Another common effect is that 64bit numbers fill up the caches more quickly, but this is unlikely to be the case here since you only use very few variables.
