Mio in the Land of Faraway aka Mio min Mio (1987)
Wikipedia synopsis excerpt: After his mother's death and father's disappearance, Bosse (Nicholas Pickard) suffers neglect by his guardians, as well as abuse from bullies. His best friend is Benke (Christian Bale, who plays a dual role). Running away to seek his father, Bosse meets kindly shopkeeper Mrs. Lundin (Linn Stokke), who gives him an apple and asks him to mail a postcard. The card is addressed to the Land of Faraway, informing its king of Bosse's impending journey. After Bosse mails the card, the apple turns gold! Dropping the transfigured apple in shock, Bosse stumbles upon a genie (Geoffrey Staines) trapped in a bottle and frees him. It turns out that this spirit has travelled from the Land of Faraway to seek Bosse and that the apple is Bosse's identifying sign. With the boy clinging to his beard, the genie transports the boy, setting him down on Green Meadow Island, where Bosse discovers that his real name is Mio and that his father is the king (Timothy Bottoms). ... However, not all is well. Mio learns that an iron-clawed knight from the Land Outside, Kato (Christopher Lee), has been kidnapping children and making them his servants by ripping out their hearts and replacing them with stone. Those who refuse to serve him are transformed into birds and are condemned to circle his castle in flight. Mio and friends must end this.