Why, Oh, Why?

"Sir, yes, sir!" I don't get it.

I understand that the "yes" affirms the order or question given. And the second "sir" addresses the receiver of the message (whomever asked the question, or gave the order). But ... what's the first "sir" for? Why add that first "sir"?

I mean, heck, keep the first one, and scrap the second one. It doesn't matter which one you keep; the issue is that only one is necessary.