you may either need to use the local variables or compile with optimizations disabled 

I assume you are using msvc on windows ??
shown below is a snippet that was compiled on x64 for x64 in win 10 where you can clearly see the local vars being initialized and used


    f:\git\usr\bin\ls -lg
    total 1
    -rw-r--r-- 1 197121 61 Sep 25 15:24 local.cpp
    
    f:\git\usr\bin\cat *
    int main (void)
    {
            int x = 1;
            int y = 2;
            return x+y;
    }
    cl /Zi /W4 -GS /analyze /Od /nologo local.cpp /link /release /ENTRY:main /SUBSYSTEM:windows /FIXED
    local.cpp
    
    f:\git\usr\bin\ls -lg *.exe
    -rwxr-xr-x 1 197121 2560 Sep 25 15:32 local.exe

description of options given to compiler and linker

    /Zi = build with debug info embedded in pdbfile 
    /w4 build with highest possible warning level
    -GS disable stack cookie
    /analyze run code analysis on the src files 
    /Od disable optimization
    /entry:main (no crt libs are sued so you need to set the entry point
    /subsystem:windows  no cmd or no crt or no input output this is not a console app 
    so you need to specify which subsystem will this program work on
    /fixed disable relocations
    


opening the exe in ghidra and the function main copied as is 


                                 //
                                 // .text 
                                 // ram: 140001000-140001022
                                 //
                                 **************************************************************
                                 *                          FUNCTION                          *
                                 **************************************************************
                                 int __fastcall main(int _Argc, char * * _Argv, char * * 
                 int               EAX:4          <RETURN>
                 int               ECX:4          _Argc
                 char * *          RDX:8          _Argv
                 char * *          R8:8           _Env
                 undefined4        Stack[-0x14]:4 local_14                                XREF[2]:     140001004(W), 
                                                                                                       140001016(R)  
                 undefined4        Stack[-0x18]:4 local_18                                XREF[2]:     14000100c(*), 
                                                                                                       140001013(*)  
                                 
    |||||||||||||||||||| FUNCTION |||||||||||||||||||||||||||||||
                                 Symbol Ref: main
                                 entry                                           XREF[4]:     Entry Point(*), 1400000e0(*), 
                                 .text$mn                                                     1400000e4(*), [more]
                                 main
           140001000 48 83 ec 18     SUB        RSP,0x18
           140001004 c7 44 24        MOV        dword ptr [RSP + local_14],0x1
                     04 01 00 
                     00 00
           14000100c c7 04 24        MOV        dword ptr [RSP]=>local_18,0x2
                     02 00 00 00
           140001013 8b 04 24        MOV        EAX,dword ptr [RSP]=>local_18
           140001016 8b 4c 24 04     MOV        _Argc,dword ptr [RSP + local_14]
           14000101a 03 c8           ADD        _Argc,EAX
           14000101c 8b c1           MOV        EAX,_Argc
           14000101e 48 83 c4 18     ADD        RSP,0x18
           140001022 c3              RET
                                 ********** main Exit ********** 



if you want to disable optimization for specific functions only and not wholesale with /Od  you can use #pragmas see the screen shot below which shows vscode / vsdevcmdprompt / compilation all in one 

replaced the image with a  gif that does a  "show and show" show

[![enter image description here][1]][1]



  [1]: https://i.sstatic.net/GEeRu.gif