Index: /trunk/optimizer.c
===================================================================
--- /trunk/optimizer.c	(revision 329)
+++ /trunk/optimizer.c	(revision 330)
@@ -225,6 +225,14 @@
 #endif
 
-#define bbs_get(bbs, n) ((bb_t *) xc_stack_get(bbs, n))
-#define bbs_count(bbs) xc_stack_count(bbs)
+static bb_t *bbs_get(bbs_t *bbs, int n) /* {{{ */
+{
+	return (bb_t *) xc_stack_get(bbs, n);
+}
+/* }}} */
+static int bbs_count(bbs_t *bbs) /* {{{ */
+{
+	return xc_stack_count(bbs);
+}
+/* }}} */
 static void bbs_destroy(bbs_t *bbs) /* {{{ */
 {
@@ -398,7 +406,9 @@
 }
 /* }}} */
-static void bbs_restore_opnum(bbs_t *bbs) /* {{{ */
+static void bbs_restore_opnum(bbs_t *bbs, zend_op_array *op_array) /* {{{ */
 {
 	int i;
+	bbid_t lasttrybbid;
+
 	for (i = 0; i < bbs_count(bbs); i ++) {
 		op_flowinfo_t fi;
@@ -422,5 +432,21 @@
 	}
 
-	/* TODO: rebuild zend_try_catch_element here */
+	lasttrybbid = BBID_INVALID;
+	op_array->last_try_catch = 0;
+	for (i = 0; i < bbs_count(bbs); i ++) {
+		bb_t *bb = bbs_get(bbs, i);
+
+		if (lasttrybbid != bb->catch) {
+			if (lasttrybbid != BBID_INVALID) {
+				int try_catch_offset = op_array->last_try_catch ++;
+
+				op_array->try_catch_array = erealloc(op_array->try_catch_array, sizeof(zend_try_catch_element) * op_array->last_try_catch);
+				op_array->try_catch_array[try_catch_offset].try_op = bbs_get(bbs, lasttrybbid)->opnum;
+				op_array->try_catch_array[try_catch_offset].catch_op = bbs_get(bbs, bb->id)->opnum;
+			}
+			lasttrybbid = bb->catch;
+		}
+	}
+	/* it is impossible to have last bb catched */
 }
 /* }}} */
@@ -456,5 +482,5 @@
 				bb->opnum = bb->opcodes - op_array->opcodes;
 			}
-			bbs_restore_opnum(&bbs);
+			bbs_restore_opnum(&bbs, op_array);
 		}
 		bbs_destroy(&bbs);
