Repository: conan-io/conan

Issue:
[bug] cpp_info.requires fails when the same replacement is used multiple times in `[replace_requires]`
### Describe the bug

Conan: 2.9.2
OS: Linux

When using the following `[replace_requires]` in the host profile (for cross-compilation, since system libs are not available there):
```
[replace_requires]
opengl/system: libglvnd/1.7.0
egl/system: libglvnd/1.7.0
glu/system: libglvnd/1.7.0
```
[this version](https://github.com/valgur/conan-center-index/blob/e02d2425322355dadec9754c228a0b68617a623a/recipes/libepoxy/all/conanfile.py) of `libepoxy` fails during the `package_info()` step with the following error:
```
ERROR: libepoxy/1.5.10: required component package 'egl::' not in dependencies
```

This only happens when both `opengl/system` and `egl/system` are being used simultaneously. The error disappears when either one of the dependencies is removed from either `self.requires()` or `self.cpp_info.requires`.

The error does not occur when `self.cpp_info.requires` is left unset entirely.

### How to reproduce it

Here's a minimal example:
```python
from conan import ConanFile

class EpoxyConan(ConanFile):
    name = "libepoxy"
    version = "0.1"
    settings = "os", "arch", "compiler", "build_type"

    def requirements(self):
        self.requires("opengl/system")
        self.requires("egl/system")

    def package_info(self):
        self.cpp_info.requires.append("opengl::opengl")
        self.cpp_info.requires.append("egl::egl")
```
and a sample profile:
```
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux

[conf]
tools.build:compiler_executables={"c": "gcc-11", "cpp": "g++-11"}

[replace_requires]
opengl/system: libglvnd/1.7.0
egl/system: libglvnd/1.7.0
glu/system: libglvnd/1.7.0
```


Discussion:

Patch:
diff --git a/conans/model/dependencies.py b/conans/model/dependencies.py
index 44a52125b1d..82e9a0e958a 100644
--- a/conans/model/dependencies.py
+++ b/conans/model/dependencies.py
@@ -91,12 +91,16 @@ class ConanFileDependencies(UserRequirementsDict):
     def from_node(node):
         d = OrderedDict((require, ConanFileInterface(transitive.node.conanfile))
                         for require, transitive in node.transitive_deps.items())
-        for old_req, new_req in node.replaced_requires.items():
-            existing = d.pop(new_req, None)
-            if existing is not None:
+        if node.replaced_requires:
+            for old_req, new_req in node.replaced_requires.items():
+                # Two different replaced_requires can point to the same real requirement
+                existing = d[new_req]
                 added_req = new_req.copy_requirement()
                 added_req.ref = RecipeReference.loads(old_req)
                 d[added_req] = existing
+            # Now remove the replaced from dependencies dict
+            for new_req in node.replaced_requires.values():
+                d.pop(new_req, None)
         return ConanFileDependencies(d)
 
     def filter(self, require_filter, remove_system=True):


Test patch:
diff --git a/test/integration/graph/test_replace_requires.py b/test/integration/graph/test_replace_requires.py
index ae615c9bb90..7f9d4bdd493 100644
--- a/test/integration/graph/test_replace_requires.py
+++ b/test/integration/graph/test_replace_requires.py
@@ -279,3 +279,39 @@ def package_info(self):
     assert "target_link_libraries(... ZLIB::ZLIB)" in c.out
     assert "zlib in deps?: True" in c.out
     assert "zlib-ng in deps?: False" in c.out
+
+
+def test_replace_requires_multiple():
+    conanfile = textwrap.dedent("""
+        from conan import ConanFile
+
+        class EpoxyConan(ConanFile):
+            name = "libepoxy"
+            version = "0.1"
+
+            def requirements(self):
+                self.requires("opengl/system")
+                self.requires("egl/system")
+
+            def generate(self):
+                for r, d in self.dependencies.items():
+                    self.output.info(f"DEP: {r.ref.name}: {d.ref.name}")
+
+            def package_info(self):
+                self.cpp_info.requires.append("opengl::opengl")
+                self.cpp_info.requires.append("egl::egl")
+        """)
+    profile = textwrap.dedent("""
+        [replace_requires]
+        opengl/system: libgl/1.0
+        egl/system: libgl/1.0
+        """)
+    c = TestClient()
+    c.save({"dep/conanfile.py": GenConanfile(),
+            "app/conanfile.py": conanfile,
+            "profile": profile})
+    c.run("create dep --name=libgl --version=1.0")
+    c.run("create app -pr=profile")
+    # There are actually 2 dependencies, pointing to the same node
+    assert "libepoxy/0.1: DEP: opengl: libgl" in c.out
+    assert "libepoxy/0.1: DEP: egl: libgl" in c.out