A calamity befell him and he apostatized from Islam; can he repent?
Question

                I used to pray regularly whenever I could, and I was one of the top students which enabled me to enter the school of engineering, and I was one of those who used to praise Allaah. Like all other young men, I hoped to have a house and beautiful wife and respected status, and I used to say a lot of du’aa’, night and day. Then I had some problems in my studies and failed to get the grades that would enable me to continue studying engineering, and I felt that that was unfair, so I said: So and so does not pray but Allaah made it easy for him to become an engineer, whereas I pray but I did not succeed. I could not bear it and I said to myself some things that put me beyond the pale of Islam, such as reviling Allaah and the faith, and reviling the divine decree. I stopped praying for a short while, even though I was uncomfortable about not responding to the adhaan and my heart became attached to the prayer. After my anger dissipated, I realized the enormity of my transgression against the rights of Allaah, and I was afraid that I might die when Allaah was angry with me. I wept and I could not continue with my studies because I was always worried about my sins. I went and looked for a fatwa that might give me peace of mind. Will Allaah forgive my sins? It says: “Verily, Allaah forgives not that partners should be set up with Him (in worship), but He forgives except that (anything else) to whom He wills” [al-Nisa’ 4:48]. I asked about this matter and I rejoiced when I read the verse in which Allaah says: “Say: O ‘Ibaadi (My slaves) who have transgressed against themselves (by committing evil deeds and sins)! Despair not of the Mercy of Allaah, verily, Allaah forgives all sins. Truly, He is Oft‑Forgiving, Most Merciful”[al-Zumar 39:53]. I researched and I found that this verse was revealed concerning people who were not Muslims and they asked the Messenger (peace and blessings of Allaah be upon him) whether they could repent. But I am a Muslim so my joy quickly evaporated. 

I have lost all hope of forgiveness. I no longer pray regularly as I used to do, or pray naafil prayer or fast on Mondays. My questions are as follows: Even if I repent, will I never be with the ummah of Muhammad, because of the report narrated by al-Bukhaari which says that the Messenger said: “On the Day of Resurrection Allaah will seize some people from my right and I will say, ‘My companions!’ but Allaah will say, ‘They are not your companions; they are people who apostatized after you were gone”? Is it true that even if I repent sincerely and am prepared to carry out the hadd punishment, Allaah will never forgive me for what I did, because Allaah  forgives not that partners should be set up with Him (in worship)?.
Praise be to Allah.Firstly: 
If you uttered what you 
    mention of reviling the faith and the divine decree, then undoubtedly what 
    you did was a serious matter, which is apostasy from Islam. By doing that 
    you behaved badly towards Allaah the Almighty Who has blessed you, created 
    you and guided you, and Who is more merciful towards you than anyone else. 
    Perhaps He diverted you from engineering for some good that He wanted to 
    bring to you, or for some evil that He wanted to ward off from you, and you 
    should have accepted that and been content with it. 
But if it is something that 
    you merely thought or said to yourself, and did not utter out loud, and it 
    did not settle in your heart, then you should have hastened to reject it and 
    brought to mind the blessings of Allaah and His bounty towards you. 
Whatever the case, your 
    giving up prayer is another sin, and it is known that with regard to the one 
    who does not pray out of laziness there is a difference of opinion among the 
    scholars, but the most correct view is that he is a kaafir, because the 
    texts indicate that. 
Secondly: 
No matter how great your 
    sin, the forbearance of Allaah is greater. 
No matter what your sin, if 
    you repent from it, then Allaah will accept your repentance and forgive you. 
    He has promised that and He is the most sincere of speakers, may He be 
    glorified and exalted. 
The verse which you 
    mention, in which Allaah says (interpretation of the meaning): 
    “Verily, Allaah forgives not that partners should be set up 
    with Him (in worship), but He forgives except that (anything else) to whom 
    He wills” [al-Nisa’ 4:48] applies to those who 
    meet Him without having repented from shirk; Allaah will not forgive them. 
    But as for those who repent before the death rattle reaches the throat, and 
    before the sun rises from the west, Allaah will accept that from them, and 
    will turn their bad deeds into good, whether they committed kufr and shirk, 
    or major or minor sins. What matters is sincere repentance, regretting what 
    one has done in the past and resolving never to go back to it. 
The evidence for that is 
    the verses in which Allaah says (interpretation of the meaning): 
“And those who invoke 
    not any other ilâh (god) along with Allaah, nor kill such person as Allaah 
    has forbidden, except for just cause, nor commit illegal sexual intercourse
    ___and whoever does this shall receive the punishment.
69. The torment will be 
    doubled to him on the Day of Resurrection, and he will abide therein in 
    disgrace;
70. Except those who 
    repent and believe (in Islamic Monotheism), and do righteous deeds; for 
    those, Allaah will change their sins into good deeds, and Allaah is 
    Oft‑Forgiving, Most Merciful”
[al-Furqaan 25:68-70] 
“And verily, I am indeed 
    forgiving to him who repents, believes (in My Oneness, and associates none 
    in worship with Me) and does righteous good deeds, and then remains constant 
    in doing them (till his death)”
[Ta-Ha 20:82] 
“Know they not that 
    Allaah accepts repentance from His slaves and takes the Sadaqaat (alms, 
    charity), and that Allaah Alone is the One Who forgives and accepts 
    repentance, Most Merciful?”
[al-Tawbah 9:104]
There is no difference 
    between one who was originally a kaafir, then Allaah guided him, and one who 
    was a Muslim and then apostatized – Allaah forbid – then repented and turned 
    back to Allaah. Repentance erases the sins that came before it, and Islam 
    erases that which came before it. 
The verse in which Allaah 
    says (interpretation of the meaning): “Say: O ‘Ibaadi (My slaves) who 
    have transgressed against themselves (by committing evil deeds and sins)! 
    Despair not of the Mercy of Allaah, verily, Allaah forgives all sins. Truly, 
    He is Oft‑Forgiving, Most Merciful”[al-Zumar 39:53], is general in 
    meaning and applies to everyone who sins then repents, whether he was 
    originally a kaafir or he was a Muslim then apostatized. It includes all 
    those who commit sin. 
Ibn Katheer (may Allaah 
    have mercy on him) said: This verse is a call to all sinners, kaafirs and 
    others, to repent and turn back to Allaah. It tells us that Allaah, may He 
    be blessed and exalted, forgives all sins for the one who repents to Him and 
    gives up the sin, no matter what it is, even if his sins are many and like 
    the foam of the sea. It is not correct to interpret this as meaning that all 
    sins will be forgiven without repentance, because shirk can never be  
    forgiven except in the case of one who repents from it. End quote from 
    Tafseer Ibn Katheer (4/75). 
As for those who will be 
    driven away from the Cistern, of whom it will be said: “You do not know what 
    they introduced after you were gone,” this applies to those who did not 
    repent, rather they meet Allaah as sinners and apostates. 
If you have repented to 
    Allaah, then be of good cheer and praise Allaah for having caused you to 
    live until you came back to Islam. Do a lot of righteous deeds and strive to 
    do a lot of acts of worship, so that after you repent you will be better 
    than you were before. Beware of neglecting prayer or delaying prayer until 
    the time for it is over, because prayer is very important and it is the 
    connection between a person and his Lord, and it is the door to happiness 
    and peace of mind. We ask Allaah to accept it from you and to pardon your 
    sin. 
And Allaah knows best.