Before we knew about gases in the atmosphere, what did scientists think was the function of breathing?
That air is a substance, which is breathed in, was known already in antiquity. Aristotle even suggests that, unlike fire, it has weight in De Caelo [On the Heavens] Book IV.4:
"Earth, then, and bodies in which earth preponderates, must have weight everywhere, while water is heavy anywhere but in earth, and air is heavy when not in water or earth. In its own place each of these bodies has weight excepting fire, even air. Of this we have evidence in the fact that a bladder when inflated weighs more than when empty".
Given the weighing methods used, the experiment is considered inconclusive today, but, in any case, this view was common. There is also a work Περὶ Πνεύματος (On Breathing) in the Aristotelian corpus, although the attribution is controversial. The etymology gives an idea of what role the pneuma, the "breath of life", the vital spirit, was thought by "the folk" to play in the body. This certainly influenced the ancient natural philosophy. Aristotle (and/or his immediate successors) talked of the "connate" pneuma that transmits the capacity to move and feel to the offspring through the sperm. Nonetheless, the pneuma was distinguished from the psyche (soul, spirit).
The ancient Stoics went much further. Their pneuma, a mixture of air and fire, was the force of growth (a prototype of the later élan vital, postulated by Lamarck and others), and in its most refined form, the material of the soul. Indeed, it was elevated to a cosmic principle that both animates and organizes the universe. The Stoics had a curious mixture of materialism with theology, their God/World Soul was made of pneuma.
In the more empirical Hellenistic science, the Hippocratic tradition ascribed to the pneuma the preservation of bodily heat and the spread of nourishment. When Praxagoras discovered that arteries in the corpses were empty c. 300 BC, it was taken to mean that they were vessels for transporting pneuma from the lungs to different parts of the body. From Russo's Forgotten Revolution:
"Herophilus maintains that pneuma, besides being breathed in, is also present in the arteries. The surviving testimonia unfortunately say nothing about the passage of pneuma from lungs to arteries. It has been said that Herophilus thought that arteries contained only pneuma and no blood, but a closer analysis of the sources reveals that most likely he distinguished between the contents of veins (blood alone) and that of the arteries (blood and pneuma)... According to Galen, Erasistratus believed that the pneuma is communicated from the heart to all parts of the body through the arteries, which are filled with blood. We also know that Herophilus believed that the pulsation of arteries served to spread nourishment."
Pneumatics, the study of machines that used compressed air, such as air pumps, was developed, most notably by Ctesibius (c. 285-222 BC). He was likely the first head of the Alexandrian library, and is known as the "father of pneumatics". The principle of the siphon was known to him, but it is unclear if he linked it to the mechanism of breathing, his works are not extant. Heron (c. 10-70 AD), in a later treatise, describes pneuma without any vitalistic connotations, as simply air in motion, and links suction to the functioning of lungs. According to Russo:
"Heron, most probably drawing from Ctesibius or Strato of Lampsacus, devotes the entire introduction of his Pneumatica to arguing that macroscopic regions of vacuum cannot exist in nature, but can be approximated artificially, as in fact he demonstrates later in the work on several occasions. In particular, Heron explains that the natural distribution of particles and void in air can be changed in both directions under the application of external forces, although the air opposes such changes with an elastic reaction. The elastic properties of air had already been described and used by Ctesibius, as we know from Philo.
[...] Heron also describes a medical device (syringe) based on suction due to expansion (Pneumatica, II, xviii). It does not seem that the idea of suction depending on expansion was clear to Aristotle: he does say that when the lung rises the air comes in, but he also says that when the air comes in the lung rises, so it's not clear whether and in what direction he postulates a causal link. It might be that, following his teleological scheme, he attributed the influx of air to the lung's porousness, which he stresses (De partibus animalium, III, vi, 669a). It may seem that the very early use of bellows should have been enough to suggest the "modern" explanation for suction, but Aristotle's passage shows that this is not so."
In the tratise "De facie quae in orbe Lunae apparet" by Plutarch, from early 2nd century AD it is said regarding the possibility of plant life on the Moon:
Then as to winds and clouds and showers, without which plants can neither receive nor maintain existence, it is out of the question to conceive of their being formed, because the surrounding atmosphere is too hot and too rare.
Thus it was understood that plant life needs air.