For the first hour or so of HBO's two-night documentary event, The Zen Diaries of Garry Shandling, you'd be forgiven for assuming the key word in that title is Diaries. In a brief opening, Shandling himself, who died almost exactly two years ago now, shows the diaries he kept all his life to the camera, and reads a particularly banal passage.

He grins. Or maybe he winces. It's a little of both, really. And there it is: That pained smile was the patch of comedy real-estate Shandling staked out for himself, and still owns.

The diaries prove anything but banal, and filmmaker Judd Apatow — to whom Shandling was a lifelong friend and mentor — builds a searching examination of Shandling's life around them. The structure is chronological, as one expects, lingering over a childhood trauma that Apatow treats as the key to Shandling's lifelong neuroses — the death of his brother at age 10. It's the only thing in the documentary that feels less than sure-footed, as — at least at first — it seems like a classic filmmaker idee fixe: the notion that the breadth of a human life can be explained — unlocked — by a single event.

(Apatow waits until the film's conclusion to present a revelation that makes a pretty convincing case that Shandling's life was just exactly as haunted by that trauma as Apatow says it was.)

On the surface — especially at the beginning — it looks and feels like hundreds of other celebrity documentaries: There's footage of very young Garry goofing around with his mom, here's a talking-head recollection from one of his many, many comedian friends, here's a clip from his act, etc.

At first, Apatow uses Shandling's diary entries as connective tissue, like so many other documentaries have before. But it quickly becomes clear that the diaries are much, much more than Shandling's prosaic chronicle of his day-to-day life — they are urgent, searing and shatteringly revelatory cries of the soul.

They're also — at least at first — seemingly anything but Zen. Apatow shows us passages filled self-directed anger and ego, neurosis and vanity. You feel Shandling's drive, his passion for comedy, his thirst for what comedy can do in his life: "I demand truth," he writes, which on its own might seem like the kind of self-help bromide people make inspirational posters out of — but here, in context, it's so plaintive and intimate you find yourself wanting to look away from the screen.

It becomes clear that the diaries were, to Shandling, a daily act of exorcism. As he rose to fame, he filled each page with self-lacerating admonishments and pleas to work harder. Apatow walks us through his comedy career, and the diary entries serve as a kind of neurotic Greek chorus: His stand-up success, his stint as guest host on The Tonight Show, his ground-breaking first series It's Garry Shandling's Show and its even-ground-breaking-er follow-up, The Larry Sanders Show.

We also hear from plenty of his friends about several behind-the-scenes events that led him to, and kept him in, Buddhist practice: the souring of his relationship with his manager, Brad Grey, his participation in a series of lawsuits, some health scares, and the slow-motion car-crash that was his film, What Planet Are You From?

As he nears what we now know will be the end of his life, the diary entries grow more generous — to himself and to others. That's when you realize that the most important word in the title The Zen Diaries of Garry Shandling is Zen after all — we see it in the excerpts, but we also see it in contemporaneous footage of Shandling with friends. In one conversation with Jerry Seinfeld, Shandling is notably warm and effusive, delighted just to be sharing time with his friend. In another conversation with Ricky Gervais, filmed for the Larry Sanders DVD extras, Shandling is the exact opposite — prickly and deliberately (and hilariously) antagonistic. (You'll be on Shandling's side.)

It's important to include that uncomfortable exchange, and not just to watch Gervais squirm (though that is a solid bonus). It's a testament to Apatow's approach, which assiduously keeps the film from becoming the kind of fawning, hagiographic portrait it could easily have been. The Shandling of The Zen Diaries is no comedy legend, no saint, no larger-than-life figure — he's an imperfect man, easily wounded, who perpetually seethes with jealousy, self-doubt, ego and anger.

But to watch The Zen Diaries of Garry Shandling is to watch that imperfect man striving to make himself less so. It's not just Apatow's love letter to a dear friend, it's a love letter to the lifelong effort Shandling undertook, to the grueling work required to heal a damaged soul.

Copyright 2018 NPR. To see more, visit http://www.npr.org/.