btree.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #include "prescheme.h"
  2. #include "ps-init.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. struct btree_node {
  7. struct btree_node *left;
  8. struct btree_node *right;
  9. long value;
  10. };
  11. static void deallocate_btree(struct btree_node *);
  12. static char btree_equalP(struct btree_node *, struct btree_node *);
  13. long main(void);
  14. static void deallocate_btree(struct btree_node *t_0X) {
  15. struct btree_node *v_2X;
  16. struct btree_node *v_1X;
  17. {
  18. v_1X = t_0X->left;
  19. if ((NULL == v_1X)) {
  20. goto L91;
  21. } else {
  22. deallocate_btree((t_0X->left));
  23. goto L91;
  24. }
  25. }
  26. L91 : {
  27. v_2X = t_0X->right;
  28. if ((NULL == v_2X)) {
  29. goto L105;
  30. } else {
  31. deallocate_btree((t_0X->right));
  32. goto L105;
  33. }
  34. }
  35. L105 : {
  36. free(t_0X);
  37. return;
  38. }
  39. }
  40. static char btree_equalP(struct btree_node *a_3X, struct btree_node *b_4X) {
  41. struct btree_node *arg0K1;
  42. struct btree_node *arg0K0;
  43. char v_8X;
  44. char temp_7X;
  45. struct btree_node *b_6X;
  46. struct btree_node *a_5X;
  47. {
  48. arg0K0 = a_3X;
  49. arg0K1 = b_4X;
  50. goto L358;
  51. }
  52. L358 : {
  53. a_5X = arg0K0;
  54. b_6X = arg0K1;
  55. temp_7X = a_5X == b_6X;
  56. if (temp_7X) {
  57. return temp_7X;
  58. } else {
  59. if (((a_5X->value) == (b_6X->value))) {
  60. v_8X = btree_equalP((a_5X->left), (b_6X->left));
  61. if (v_8X) {
  62. arg0K0 = (a_5X->right);
  63. arg0K1 = (b_6X->right);
  64. goto L358;
  65. } else {
  66. return 0;
  67. }
  68. } else {
  69. return 0;
  70. }
  71. }
  72. }
  73. }
  74. long main(void) {
  75. struct btree_node *arg0K0;
  76. char v_23X;
  77. struct btree_node *c2_22X;
  78. struct btree_node *btree_node_21X;
  79. struct btree_node *b2_20X;
  80. struct btree_node *btree_node_19X;
  81. struct btree_node *a2_18X;
  82. struct btree_node *btree_node_17X;
  83. struct btree_node *c1_16X;
  84. struct btree_node *btree_node_15X;
  85. struct btree_node *b1_14X;
  86. struct btree_node *btree_node_13X;
  87. struct btree_node *a1_12X;
  88. struct btree_node *btree_node_11X;
  89. struct btree_node *null_10X;
  90. FILE *out_9X;
  91. {
  92. out_9X = stdout;
  93. null_10X = NULL;
  94. btree_node_11X = (struct btree_node *)malloc(sizeof(struct btree_node));
  95. if ((NULL == btree_node_11X)) {
  96. arg0K0 = btree_node_11X;
  97. goto L219;
  98. } else {
  99. btree_node_11X->left = null_10X;
  100. btree_node_11X->right = null_10X;
  101. btree_node_11X->value = 6;
  102. arg0K0 = btree_node_11X;
  103. goto L219;
  104. }
  105. }
  106. L219 : {
  107. a1_12X = arg0K0;
  108. btree_node_13X = (struct btree_node *)malloc(sizeof(struct btree_node));
  109. if ((NULL == btree_node_13X)) {
  110. arg0K0 = btree_node_13X;
  111. goto L223;
  112. } else {
  113. btree_node_13X->left = null_10X;
  114. btree_node_13X->right = null_10X;
  115. btree_node_13X->value = 5;
  116. arg0K0 = btree_node_13X;
  117. goto L223;
  118. }
  119. }
  120. L223 : {
  121. b1_14X = arg0K0;
  122. btree_node_15X = (struct btree_node *)malloc(sizeof(struct btree_node));
  123. if ((NULL == btree_node_15X)) {
  124. arg0K0 = btree_node_15X;
  125. goto L227;
  126. } else {
  127. btree_node_15X->left = a1_12X;
  128. btree_node_15X->right = b1_14X;
  129. btree_node_15X->value = 4;
  130. arg0K0 = btree_node_15X;
  131. goto L227;
  132. }
  133. }
  134. L227 : {
  135. c1_16X = arg0K0;
  136. btree_node_17X = (struct btree_node *)malloc(sizeof(struct btree_node));
  137. if ((NULL == btree_node_17X)) {
  138. arg0K0 = btree_node_17X;
  139. goto L231;
  140. } else {
  141. btree_node_17X->left = null_10X;
  142. btree_node_17X->right = null_10X;
  143. btree_node_17X->value = 6;
  144. arg0K0 = btree_node_17X;
  145. goto L231;
  146. }
  147. }
  148. L231 : {
  149. a2_18X = arg0K0;
  150. btree_node_19X = (struct btree_node *)malloc(sizeof(struct btree_node));
  151. if ((NULL == btree_node_19X)) {
  152. arg0K0 = btree_node_19X;
  153. goto L235;
  154. } else {
  155. btree_node_19X->left = null_10X;
  156. btree_node_19X->right = null_10X;
  157. btree_node_19X->value = 5;
  158. arg0K0 = btree_node_19X;
  159. goto L235;
  160. }
  161. }
  162. L235 : {
  163. b2_20X = arg0K0;
  164. btree_node_21X = (struct btree_node *)malloc(sizeof(struct btree_node));
  165. if ((NULL == btree_node_21X)) {
  166. arg0K0 = btree_node_21X;
  167. goto L239;
  168. } else {
  169. btree_node_21X->left = a2_18X;
  170. btree_node_21X->right = b2_20X;
  171. btree_node_21X->value = 4;
  172. arg0K0 = btree_node_21X;
  173. goto L239;
  174. }
  175. }
  176. L239 : {
  177. c2_22X = arg0K0;
  178. v_23X = btree_equalP(c1_16X, c2_22X);
  179. if (v_23X) {
  180. ps_write_string("trees are equal\n", out_9X);
  181. goto L249;
  182. } else {
  183. ps_write_string("trees are not equal\n", out_9X);
  184. goto L249;
  185. }
  186. }
  187. L249 : {
  188. deallocate_btree(c1_16X);
  189. deallocate_btree(c2_22X);
  190. return 0;
  191. }
  192. }