Mio in the Land of Faraway aka Mio min Mio (1987)
From Wikipedia: Orphaned by 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 one night to seek his father, Bosse meets the 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 there. After Bosse mails the card, the apple turns golden. 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 golden 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. 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.