I have a small C++ program as follows:
#include <iostream>
int add(int a, int b)
{
return a + b;
}
int main()
{
int a = 10;
int b = 20;
std::cout << "add(a + b) = " << add(a, b) << std::endl;
return 0;
}
I'm compiling this code on Windows 10 using the MSVC compiler with the following command:
cl /c /FA main.cpp
I've noticed that the generated assembly code is surprisingly large, consisting of thousands of lines. However, when I use godbolt.com to inspect the assembly output, it shows only a few lines of code.
I would appreciate it if someone could help me understand why MSVC is producing such lengthy assembly code for this seemingly straightforward C++ function. Are there specific compiler flags or settings I should be aware of to reduce the verbosity of the generated assembly? Is this behavior expected, or am I missing something in my compilation process?
Any insights or recommendations would be greatly appreciated. Thank you!