translate python code to "C":  def submatrix(M, ir, NAME_1, ic, jc):
    if len(M.shape) > 2:
        rows, cols, _ = M.shape
    else:
        rows, cols = M.shape

    if ir < -rows or ir >= rows:
        return 0
    if NAME_1 < -rows or NAME_1 >= rows:
        return 0
    if ic < -cols or ic >= cols:
        return 0
    if jc < -cols or jc >= cols:
        return 0

    if ir < 0:
        ir = rows + ir
    if NAME_1 < 0:
        NAME_1 = rows + NAME_1
    if ic < 0:
        ic = cols + ic
    if jc < 0:
        jc = cols + jc

    if jc == ic:
        if ir == NAME_1:
            res = M[ir:(ir + 1), jc]
        elif NAME_1 == 0:
            res = M[ir::-1, jc]
        else:
            res = M[ir:(NAME_1 + np.sign((NAME_1 + 1) - ir)):sign((NAME_1 + 1), ir), jc]
    else:
        res = M[ir:(NAME_1 + np.sign((NAME_1 + 1) - ir)):np.sign((NAME_1 + 1) - ir),
              ic:(jc + np.sign((jc + 1) - ic)):np.sign((jc + 1) - ic)]
    return res