deepCopy _ (ValueParameter arg1 : ins'@(ValueParameter in1:ins))
  | isArray (typeof arg1)
  = [ initArray (Just arg1) expDstLen, copyFirstSegment ] ++
      flattenCopy (ValueParameter arg1) ins argnLens arg1len
    where expDstLen = foldr ePlus (litI32 0) aLens
          copyFirstSegment = if arg1 == in1
                                then Empty
                                else call "copyArray" [ ValueParameter arg1
                                                      , ValueParameter in1]
          aLens@(arg1len:argnLens) = map (\(ValueParameter src) -> arrayLength src) ins'
deepCopy _ (ValueParameter arg1 : ins'@(ValueParameter in1:ins))
  | isArray (typeof arg1)
  = [ initArray (Just arg1) expDstLen, copyFirstSegment ] ++
      flattenCopy (ValueParameter arg1) ins argnLens arg1len
    where expDstLen = foldr ePlus (litI32 0) aLens
          copyFirstSegment = if arg1 == in1
                                then Empty
                                else call "copyArray" [ ValueParameter arg1
                                                      , ValueParameter in1]
          aLens@(arg1len:argnLens) = map (\(ValueParameter src) -> arrayLength src) ins'
deepCopy _ (ValueParameter arg1 : ins'@(ValueParameter in1:ins))
  | isArray (typeof arg1)
  = [ initArray (Just arg1) expDstLen, copyFirstSegment ] ++
      flattenCopy (ValueParameter arg1) ins argnLens arg1len
    where expDstLen = foldr ePlus (litI32 0) aLens
          copyFirstSegment = if arg1 == in1
                                then Empty
                                else call "copyArray" [ ValueParameter arg1
                                                      , ValueParameter in1]
          aLens@(arg1len:argnLens) = map (\(ValueParameter src) -> arrayLength src) ins'