steps: Search for the first time the variable is defined (write access). In this case it is "" (l.7) Search for the first time the variable is read. In this case it is "" Write down this information in the following style: [name of the variable you are creating a def-use-chain for, the concrete write access, the concrete read access] In this case it is: Repeat these steps in the following style: combine each write access with each read access (but NOT the other way round). The result should be: [d, d=b, return d] [d, d=b, while(d!=0)] [d, d=b, if(c>d)] [d, d=b, c=c-d] [d, d=b, d=d-c] [d, d=d-c, while(d!=0)] [d, d=d-c, if(c>d)] [d, d=d-c, c=c-d] [d, d=d-c, d=d-c] You have to take care, if the variable is changed by the time. For example: From line 7 down to line 13 in the source code, is not redefined / changed. At line 14, could be redefined. This is why you have to recombine this write access on with all possible read accesses which could be reached. In this case, only the code beyond line 10 is relevant. Line 7, for example, cannot be reached again. For your understanding, you can imagine 2 different variables : [d1, d1=b, return d1] [d1, d1=b, while(d1!=0)] [d1, d1=b, if(c>d1)] [d1, d1=b, c=c-d1] [d1, d1=b, d1=d1-c] [d2, d2=d2-c, while(d2!=0)] [d2, d2=d2-c, if(c>d2)] [d2, d2=d2-c, c=c-d2] [d2, d2=d2-c, d2=d2-c] As a result, you could get something like this. The variable would be replaced by /** * @param(a, b) The values used to calculate the divisor. * @return The greatest common divisor of a and b. **/ int gcd(int a, int b) { int c = a; int d; if (c == 0) return b; if (b != 0) { if (c > b) { c = c - b; d = b; } else d = b - c; while (d != 0) { if (c > d) c = c - d; else d = d - c; } } return c; } Method of building a use-def (or ud) chain Set definitions in statement For each in , find live definitions that have use in statement Make a link among definitions and uses Set the statement , as definition statement Kill previous definitions With this algorithm, two things are accomplished: A directed acyclic graph (DAG) is created on the variable uses and definitions. The DAG