GCC's treatment of asm statements is very simple. It produces assembly instructions to deal with the asm's operands, and it replaces the asm statement with the instruction that you specify. It does not analyze the instruction in any way.
foo and bar each require two words of stack storage on a 32-bit x86
architecture.The register ebp points to data on the stack.
The first two instructions copy foo into registers EDX and ECX on which mycool_asm operates.
The compiler decides to use the same registers to store the answer, which is copied into bar by the final two instructions. It chooses appropriate registers, even reusing the same registers, and copies operands to and from the proper locations automatically.