 +static long	mem_sortSam1;
 +static long	mem_sortSam2;
 +static long	mem_saveUnmapReads;
++static long	mem_mtMateFinder__;
 +
 +static long md_register_mem_id(const char * mem_id_str);
 +#define REGISTER_MEM_ID(id) id = md_register_mem_id(#id)

+/*  bam_sam2bam.c -- format converter framework
+
+    Author: Takeshi Ogasawara <takeshi@jp.ibm.com>
+	$Rev: 79 $
+	$Date: 2016-10-18 17:33:05 +0900 (Tue, 18 Oct 2016) $
+
+	*/
+

+#endif
+  return ret;
+}
+#endif
+
+static volatile long g_mate_finder_barrier = 0;
+static int qnameid_cmpfunc(const void *p1, const void *p2){
+  bamptr_t * const bp1 = *(bamptr_t**)p1;
+  bamptr_t * const bp2 = *(bamptr_t**)p2;
+  return bamptr_get_qnameid(bp1) - bamptr_get_qnameid(bp2);
+}
+
+static void mt_mate_finder__(int tidx, mt_find_mate_t * fm) {
+
