Let $M$ denote a message.
Choose (arbitrarily or randomly) five different sequences of bits (their lengths are allowed to be arbitrary, assuming that our HMAC construction will not exceed the maximum input length for SHA-256). Denote them by $S_i$. For example, we can simply choose “0”, “00”, “000”, “0000” and “00000”.
Consider the following function: $$\begin{array}{l} H(M) = H_5 \mathbin\Vert H_6,\\ \end{array}$$
where $$\begin{array}{l} H_1 = \text{SHA-256}(M),\\ H_2 = \text{HMAC-SHA-256}(M, H_1 \mathbin\Vert S_1),\\ H_3 = \text{HMAC-SHA-256}(M, H_2 \mathbin\Vert S_2),\\ H_4 = \text{HMAC-SHA-256}(M, H_3 \mathbin\Vert S_3),\\ H_5 = \text{HMAC-SHA-256}(M, H_1 \mathbin\Vert H_3 \mathbin\Vert S_4),\\ H_6 = \text{HMAC-SHA-256}(M, H_2 \mathbin\Vert H_4 \mathbin\Vert S_5)\\ \end{array}$$
(assuming that $M$ is the message for HMAC, and the part that ends with $S_i$ is the key).
Is $H(M)$ weaker than $\text{SHA-512}(M)$? If yes, in what aspects?