code: def random_gamma_grad_impl(a, x, *, dtype):
      is_nan = bitwise_or(_isnan(a), _isnan(x))
      x_is_zero = eq(x, full_like(x, 0))
      domain_error = bitwise_or(
          lt(x, full_like(x, 0)), le(a, full_like(a, 0))
      )
      use_igammac = bitwise_and(gt(x, full_like(x, 1)), gt(x, a))
      ax = a * log(x) - x - lgamma(a)
      underflow = lt(ax, -log(dtypes.finfo(a.dtype).max))
      ax = exp(ax)
      enabled = bitwise_not(
          bitwise_or(
              bitwise_or(
                  bitwise_or(x_is_zero, domain_error), underflow
              ),
              is_nan,
          )
      )
      output = select(
          use_igammac,
          -_igammac_continued_fraction(
              ax,
              x,
              a,
              bitwise_and(enabled, use_igammac),
              dtype,
              IgammaMode.SAMPLE_DERIVATIVE,
          ),
          _igamma_series(
              ax,
              x,
              a,
              bitwise_and(enabled, bitwise_not(use_igammac)),
              dtype,
              IgammaMode.SAMPLE_DERIVATIVE,
          ),
      )
      output = select(x_is_zero, full_like(output, 0), output)
      output = select(
          bitwise_or(domain_error, is_nan),
          full_like(a, float("nan")),
          output,
      )
      return output
  
imports: from enum import Enum
  import numpy
  from functools import partial
  from jax._src.lax.lax import add, bitwise_and, bitwise_not, bitwise_or, broadcast_in_dim, broadcast_shapes, convert_element_type, div, eq, exp, full_like, ge, gt, le, log, log1p, lt, mul, ne, neg, reciprocal, reduce, select, sign, sqrt, square, standard_naryop, standard_unop, sub, _const, _dtype, _float, _nary_lower_hlo, _ones, _isnan, _reduce
  from jax._src.lax.control_flow import while_loop
  from jax._src import dtypes
  from jax._src.interpreters import ad
  from jax._src.interpreters import mlir
  from jax._src.lib.mlir.dialects import chlo
  from jax._src.typing import Array, ArrayLike
label_desc: Use image node_id 31 for calling a global function with example usage: random_gamma_grad_impl(a, x) and returns: output