The Compiler does not add any functions
think how printf() can work ?
where can it print ?
does your program know or do you allocate a console for printf() to print ?
do you know where the main returns to?
no you don't and neither you coded those functions
but for proper functioning of your code you need a console window
and after your program finishes and wants to return it needs to know where to return to and how to de allocate all the memory , consoles , handles it uses
all these job are done by CRT code (c run-time initialization code)
most of those code are in the include file stdio.h (this header includes other needed files )
the compiler then compiles all this code into a single executable
you can also write explicit code and remove all these functions and provide an entry point
here is an example of explicit code that allocates and writes to the allocated
Console and Exits using the algo in your query
#include <windows.h>
int f(int a) { return a + 5; }
void main(void) {
if ( !AllocConsole()) { goto door; }
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
if (out == INVALID_HANDLE_VALUE) { goto door; }
char buff[20] = { 0 }; DWORD cwritten = 0;
wsprintf(buff, "Result: %d\n", f(3));
WriteConsole(out, buff, sizeof(buff), &cwritten, NULL);
Sleep(10000);
door:
ExitProcess(0);
}
compiled and linked in vs 2017 cmdprompt
compiled with cl /Zi /W4 /analyze /GS- /Ox
linked with /release /nodefaultlib /subsystem:windows /entry:main kernel32.lib user32.lib
here is a screen shot of function calls from ida free 5
you can double click the exe and it will work no need to run this from cmd.exe