The real answer is that each unit or type of unit had a Table of Organization and Equipment (TO&E). That stated the number of men in the unit, their ranks and their weapons, as well as any other equipment, such as radios, that the unit was responsible for. As a rule, the company was the basic unit, and its TO&E included its platoons and squads.
Were those Tables always followed? No, but the Army tried to keep things straight because support, such as ammo supply, was based on the TO&E, not on what some GI got somewhere and decided to carry.
Carbines were intended to replace pistols, but prior to their development, many more people carried pistols than did in WWII or today. In WWI, pistols were carried by machinegunners and assistants, BAR men and assistants, mortar men, artillerymen, horse handlers, messengers, and platoon and squad leaders, as well as by company grade officers. In WWII, most of those folks were issued carbines, so there were a fair number of carbines issued in an infantry unit. They were NOT "rear echelon" or issued to "cooks and bakers" as they usual saying goes. (Cooks and bakers usually carried rifles; they were expected to fight as infantry if necessary.)
SMGs were also issued per the unit TO&E, but were sometimes issued "ILO" (in lieu of) a carbine or M1 rifle. SMGs were the standard weapons of tankers. (The "tanker M1 rifle" was never a military weapon; it was a postwar civilian invention and the name was an advertising gimmick.)
Other units commonly issued carbines were signal troops, military police, and others whose primary job was something other than fighting.
P.S. In a movie, a "TO&E" weapon is whatever the director thinks looks good, even if it hasn't been invented yet.
Jim