You can start here, registering with the Electronic Copyright Office. This circular describes the process (it's tailored to registering computer programs). You submit the source code in an accepted format (PDF, and others are said to be listed "online"). There is a list of conditions relevant to how much you must provide (for example if the code contains trade secrets. This document covers deposits, i.e. the copies of the work, and §1509.1(C) is specific to computer programs. Read that section to determine what you have to submit. Look at §1507.2 for specification of electronic deposit copies. At some point you will wonder about accepted formats: this is the currently accepted format list.
If you cannot figure it out given this, you do really need a lawyer: but it's not legally required that the application be submitted by a lawyer. There is an increased risk that you will mess up the application if you do it yourself, but the same is also true of paying your income tax, and people do manage on their own. For example, you do need to exploit the "Limitation of Claim" field, so that you do not attempt to claim copyright ownership of third party code.
The situation where two parties A and B both claim copyright ownership is a very complicated matter, briefly summarized here. Most typically, competing claims of ownership involve collaboration and get resolved in court (or by negotiation) after the fact. For example, A may think he owns the copyright because he wrote the code, but he was hired as an employee by B to write that code, and as a work for hire, B may actually own the copyright. But maybe A was an independent contractor who agreed to write some code and license it to B, and A is the copyright holder. If you are just talking about a case of code-poaching (B stole your thumb drive, saw the code, and registered it), when you litigate for infringement, you would present (in court) whatever evidence you have that you are the rightful copyright holder. Registration is a requirement for litigation and provides prima facie evidence – not irrefutable proof – of copyright ownership. The law does not specify a practical means of balancing the evidence in your favor, but surely there are technical ways of permanently encoding your name in the source code.
If I want to sue a person for infringement, I must register the copyright first. 17 USC 411 says that
no civil action for infringement of the copyright in any United States
work shall be instituted until preregistration or registration of the
copyright claim has been made in accordance with this title
"United States work" is defined here – as a US citizen, anything I create is a US work. Anything you create as a non US person and publish in the US is also a US work: basically, if the work involves a US creator or US publisher, it is a US work. If the work is unpublished and you are not a US person, it's not a US work. Once you've determined if the work is a US work, you know whether you have to register before you can sue in US courts.
You would have a separate set of remedies and procedures available to you under Lebanese copyright law (which is a whole other question).