debug origin lines
diff --git a/asn1c/asn1c.c b/asn1c/asn1c.c
index 7147e29..b67f9e7 100644
--- a/asn1c/asn1c.c
+++ b/asn1c/asn1c.c
@@ -101,6 +101,9 @@
                     strdup(optarg + 17);
                 debug_type_names[debug_type_names_count] = NULL;
                 break;
+            } else if(strcmp(optarg, "ebug-output-origin-lines") == 0) {
+                asn1_compiler_flags |= A1C_DEBUG_OUTPUT_ORIGIN_LINES;
+                break;
             }
             usage(av[0]);
         case 'E':
diff --git a/libasn1compiler/asn1c_C.c b/libasn1compiler/asn1c_C.c
index 01ef50d..53831f9 100644
--- a/libasn1compiler/asn1c_C.c
+++ b/libasn1compiler/asn1c_C.c
@@ -2026,7 +2026,7 @@
 			OUT("{ APC_CONSTRAINED%s,%s% d, % d, ",
 				range->extensible
 					? " | APC_EXTENSIBLE" : "",
-				range->extensible ? " " : "\t", rbits, ebits);
+				range->extensible ? " " : "\t", (int)rbits, (int)ebits);
 
 			if(alphabetsize) {
 				asn1c_integer_t lv = range->left.value;
diff --git a/libasn1compiler/asn1c_ioc.c b/libasn1compiler/asn1c_ioc.c
index bb72f7d..9a5e253 100644
--- a/libasn1compiler/asn1c_ioc.c
+++ b/libasn1compiler/asn1c_ioc.c
@@ -175,10 +175,10 @@
                 asn1c_integer_t v = expr_value->value->value.v_integer;
                 if(v >= 0) {
                     if(v <= 127) {
-                        OUT("\"\\x%02x\", 1", v);
+                        OUT("\"\\x%02x\", 1", (int)v);
                         break;
                     } else if(v <= 32767) {
-                        OUT("\"\\x%02x\\x%02x\", 2", (v >> 8), (v & 0xff));
+                        OUT("\"\\x%02x\\x%02x\", 2", (int)(v >> 8), (int)(v & 0xff));
                         break;
                     }
                 }
diff --git a/libasn1compiler/asn1c_out.c b/libasn1compiler/asn1c_out.c
index 8314bb5..b381e21 100644
--- a/libasn1compiler/asn1c_out.c
+++ b/libasn1compiler/asn1c_out.c
@@ -6,7 +6,8 @@
  * into appropriate output stream.
  */
 int
-asn1c_compiled_output(arg_t *arg, const char *fmt, ...) {
+asn1c_compiled_output(arg_t *arg, const char *source, int lineno, const char *func, const char *fmt,
+                      ...) {
 	struct compiler_stream_destination_s *dst;
 	const char *p;
 	int lf_found;
@@ -45,13 +46,19 @@
 		}
 		dst->indented = 1;
 		while(i--) {
-			ret = asn1c_compiled_output(arg, "\t");
+			ret = asn1c_compiled_output(arg, source, lineno, func, "\t");
 			if(ret == -1) return -1;
 		}
 	}
 	if(lf_found)
 		dst->indented = 0;
 
+    size_t debug_reserve_size = 0;
+    if(lf_found && (arg->flags & A1C_DEBUG_OUTPUT_ORIGIN_LINES)) {
+        debug_reserve_size =
+            sizeof("\t// :100000 ()") + strlen(source) + strlen(func);
+    }
+
 	/*
 	 * Allocate buffer.
 	 */
@@ -62,7 +69,7 @@
 	do {
 		void *tmp;
 		m->len <<= 2;
-		tmp = realloc(m->buf, m->len);
+		tmp = realloc(m->buf, m->len + debug_reserve_size);
 		if(tmp) {
 			m->buf = (char *)tmp;
 		} else {
@@ -77,6 +84,15 @@
 
 	m->len = ret;
 
+    /* Print out the origin of the lines */
+    if(lf_found && (arg->flags & A1C_DEBUG_OUTPUT_ORIGIN_LINES)) {
+        assert(m->buf[m->len - 1] == '\n');
+        ret = snprintf(m->buf + m->len - 1, debug_reserve_size,
+                       "\t// %s:%03d %s()\n", source, lineno, func);
+        assert(ret > 0 && (size_t)ret < debug_reserve_size);
+        m->len = m->len - 1 + ret;
+    }
+
 	if(arg->target->target == OT_INCLUDES
 	|| arg->target->target == OT_FWD_DECLS
 	|| arg->target->target == OT_POST_INCLUDE) {
diff --git a/libasn1compiler/asn1c_out.h b/libasn1compiler/asn1c_out.h
index 47762a8..41077df 100644
--- a/libasn1compiler/asn1c_out.h
+++ b/libasn1compiler/asn1c_out.h
@@ -39,7 +39,9 @@
 static char *_compiler_stream2str[] __attribute__ ((unused))
     = { "IGNORE", "INCLUDES", "DEPS", "FWD-DECLS", "FWD-DEFS", "TYPE-DECLS", "FUNC-DECLS", "POST-INCLUDE", "IOC-TABLES", "CTABLES", "CODE", "CTDEFS", "STAT-DEFS" };
 
-int asn1c_compiled_output(arg_t *arg, const char *fmt, ...);
+int asn1c_compiled_output(arg_t *arg, const char *file, int lineno,
+                          const char *func, const char *fmt, ...)
+    __attribute__((format(printf, 5, 6)));
 
 
 /*****************************************************************
@@ -80,7 +82,8 @@
     } while(0)
 
 /* Output a piece of text into a default stream */
-#define	OUT(fmt, args...)	asn1c_compiled_output(arg, fmt, ##args)
+#define OUT(fmt, args...) \
+    asn1c_compiled_output(arg, __FILE__, __LINE__, __func__, fmt, ##args)
 #define	OUT_NOINDENT(fmt, args...)	do {			\
 	int _saved_indent = INDENT_LEVEL;			\
 	INDENT_LEVEL = 0;					\
diff --git a/libasn1compiler/asn1compiler.h b/libasn1compiler/asn1compiler.h
index 7178282..2901d40 100644
--- a/libasn1compiler/asn1compiler.h
+++ b/libasn1compiler/asn1compiler.h
@@ -92,6 +92,11 @@
 	 * Generate top-level configure.ac and Makefile.am
 	 */
 	A1C_GEN_AUTOTOOLS_EXAMPLE	= 0x200000,
+	/*
+	 * Print the source of generated lines.
+	 * -debug-output-origin-lines
+	 */
+	A1C_DEBUG_OUTPUT_ORIGIN_LINES = 0x400000,
 };
 
 /*