Repository: Konstantin8105/c4go
Pull request #499 (2021-04-23 14:14:56)

Simplification of result

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/499?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin) Report
> Merging [#499](https://codecov.io/gh/Konstantin8105/c4go/pull/499?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin) (7e3df2b) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/a668ca54f8eda007c956f8d111f7fd719c1a454f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin) (a668ca5) will **decrease** coverage by `0.13%`.
> The diff coverage is `53.84%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/499/graphs/tree.svg?width=650&height=150&src=pr&token=esH2rHXlZ2&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin)](https://codecov.io/gh/Konstantin8105/c4go/pull/499?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin)

```diff
@@            Coverage Diff             @@
##           master     #499      +/-   ##
==========================================
- Coverage   82.75%   82.61%   -0.14%     
==========================================
  Files         193      193              
  Lines       10857    10909      +52     
==========================================
+ Hits         8985     9013      +28     
- Misses       1360     1372      +12     
- Partials      512      524      +12     
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/499?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin) | Coverage Δ | |
|---|---|---|
| [program/program.go](https://codecov.io/gh/Konstantin8105/c4go/pull/499/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin#diff-cHJvZ3JhbS9wcm9ncmFtLmdv) | `65.68% <53.84%> (-4.06%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/499?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/499?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin). Last update [0dd7f7c...7e3df2b](https://codecov.io/gh/Konstantin8105/c4go/pull/499?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Konstantin).


Patch:
diff --git a/program/program.go b/program/program.go
index 2a4c9c0..c67f814 100644
--- a/program/program.go
+++ b/program/program.go
@@ -364,6 +364,178 @@ type simpleDefer struct {
 }
 
 func (s simpleDefer) Visit(node goast.Node) (w goast.Visitor) {
+	// 	var s int32 = func() int32 {
+	// 		if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
+	// 			return 1
+	// 		}
+	// 		return 0
+	// 	}()
+
+	// from :
+	//		{
+	//			...
+	//			li = func() int32 {
+	//				if booled {
+	//					return result1
+	//				}
+	//				return result2
+	//			}()
+	//			...
+	//		}
+	// to   :
+	//		{
+	//			...
+	//			if booled {
+	//				li = result1
+	//			} else {
+	//				li = result2
+	//			}
+	//			...
+	//		}
+	if eb, ok := node.(*goast.BlockStmt); ok && 0 < len(eb.List) {
+		for i := range eb.List {
+			if eb.List[i] == nil {
+				continue
+			}
+			es, ok := eb.List[i].(*goast.ExprStmt)
+			if !ok {
+				continue
+			}
+			be, ok := es.X.(*goast.BinaryExpr)
+			if !ok {
+				continue
+			}
+
+			valueName := be.X
+			if be.Op != token.ASSIGN {
+				continue
+			}
+			cl, ok := be.Y.(*goast.CallExpr)
+			if !ok {
+				continue
+			}
+			fl, ok := cl.Fun.(*goast.FuncLit)
+			if !ok {
+				continue
+			}
+			b := fl.Body
+			if 2 != len(b.List) {
+				continue
+			}
+			ifd, ok := b.List[0].(*goast.IfStmt)
+			if !ok {
+				continue
+			}
+
+			condition := ifd.Cond
+
+			ifbod := ifd.Body
+			if 1 != len(ifbod.List) {
+				continue
+			}
+
+			ret1, ok := ifbod.List[0].(*goast.ReturnStmt)
+			if !ok {
+				continue
+			}
+
+			result1 := ret1.Results
+
+			ret2, ok := b.List[1].(*goast.ReturnStmt)
+			if !ok {
+				continue
+			}
+
+			result2 := ret2.Results
+
+			eb.List[i] = &goast.IfStmt{
+				Cond: condition,
+				Body: &goast.BlockStmt{
+					List: []goast.Stmt{
+						&goast.AssignStmt{
+							Lhs: []goast.Expr{valueName},
+							Tok: token.ASSIGN,
+							Rhs: result1,
+						},
+					},
+				},
+				Else: &goast.BlockStmt{
+					List: []goast.Stmt{
+						&goast.AssignStmt{
+							Lhs: []goast.Expr{valueName},
+							Tok: token.ASSIGN,
+							Rhs: result2,
+						},
+					},
+				},
+			}
+		}
+	}
+
+	// from :
+	//		if ... {
+	//			{
+	//				...
+	//			}
+	//		} else {
+	//			{
+	//				...
+	//			}
+	//		}
+	// to   :
+	//		if ... {
+	//				...
+	//		} else {
+	//				...
+	//		}
+	if fb, ok := node.(*goast.IfStmt); ok {
+		if len(fb.Body.List) == 1 {
+			if ib, ok := fb.Body.List[0].(*goast.BlockStmt); ok {
+				fb.Body = ib
+			}
+		}
+		if fb.Else != nil {
+			if b1, ok := fb.Else.(*goast.BlockStmt); ok && 1 == len(b1.List) {
+				if b2, ok := b1.List[0].(*goast.BlockStmt); ok {
+					fb.Else = b2
+				}
+			}
+		}
+	}
+
+	// from :
+	//		return func() int32 {
+	//			if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
+	//				return 1
+	//			}
+	//			return 0
+	//		}()
+	// or   :
+	//		return func() int32 {
+	//			...
+	//		}()
+	// to   :
+	//		if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
+	//			return 1
+	//		}
+	//		return 0
+	// or   :
+	//		...
+	if eb, ok := node.(*goast.BlockStmt); ok && 0 < len(eb.List) {
+		if ret, ok := eb.List[len(eb.List)-1].(*goast.ReturnStmt); ok && 1 == len(ret.Results) {
+			if c, ok := ret.Results[0].(*goast.CallExpr); ok {
+				if fl, ok := c.Fun.(*goast.FuncLit); ok {
+					if 1 < len(eb.List) {
+						eb.List = eb.List[:len(eb.List)-1]
+					} else {
+						eb.List = []goast.Stmt{}
+					}
+					eb.List = append(eb.List, fl.Body.List...)
+				}
+			}
+		}
+	}
+
 	// from :
 	//		{
 	//			.....
@@ -376,102 +548,85 @@ func (s simpleDefer) Visit(node goast.Node) (w goast.Visitor) {
 	//			}()
 	//			.....
 	//		}
-	//		0: *ast.ExprStmt {
-	//		.  X: *ast.CallExpr {
-	//		.  .  Fun: *ast.FuncLit {
-	//		.  .  .  Type: *ast.FuncType {
-	//		.  .  .  .  Func: 4:2
-	//		.  .  .  .  Params: *ast.FieldList {
-	//		.  .  .  .  }
-	//		.  .  .  .  Results: *ast.FieldList {
-	//		.  .  .  .  .  Opening: -
-	//		.  .  .  .  .  List: []*ast.Field (len = 1) {
-	//		.  .  .  .  .  .  0: *ast.Field {
-	//		.  .  .  .  .  .  .  Type: *ast.ArrayType {
-	//		.  .  .  .  .  .  .  .  Elt: *ast.Ident {
-	//		.  .  .  .  .  .  .  .  .  Name: "byte"
-	//		.  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  }
-	//		.  .  .  .  .  }
-	//		.  .  .  .  .  Closing: -
-	//		.  .  .  .  }
-	//		.  .  .  }
-	//		.  .  .  Body: *ast.BlockStmt {
-	//		.  .  .  .  Lbrace: 4:16
-	//		.  .  .  .  List: []ast.Stmt (len = 3) {
-	//		.  .  .  .  .  0: *ast.AssignStmt {
-	//		.  .  .  .  .  .  Lhs: []ast.Expr (len = 1) {
-	//		.  .  .  .  .  .  .  0: *ast.Ident {
-	//		.  .  .  .  .  .  .  .  NamePos: 5:3
-	//		.  .  .  .  .  .  .  .  Name: "tempVarUnary"
-	//		.  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  }
-	//		.  .  .  .  .  .  TokPos: 5:16
-	//		.  .  .  .  .  .  Tok: :=
-	//		.  .  .  .  .  .  Rhs: []ast.Expr (len = 1) {
-	//		.  .  .  .  .  .  .  0: *ast.Ident {
-	//		.  .  .  .  .  .  .  .  Name: "sstr_s"
-	//		.  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  }
-	//		.  .  .  .  .  }
-	//		.  .  .  .  .  1: *ast.DeferStmt {
-	//		.  .  .  .  .  .  Defer: 6:3
-	//		.  .  .  .  .  .  Call: *ast.CallExpr {
-	//		.  .  .  .  .  .  .  Fun: *ast.FuncLit {
-	//		.  .  .  .  .  .  .  .  Type: *ast.FuncType {
-	//		.  .  .  .  .  .  .  .  .  Func: 6:9
-	//		.  .  .  .  .  .  .  .  .  Params: *ast.FieldList {
-	//		.  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  Body: *ast.BlockStmt {
-	//		.  .  .  .  .  .  .  .  .  Lbrace: 6:16
-	//		.  .  .  .  .  .  .  .  .  List: []ast.Stmt (len = 1) {
-	//		.  .  .  .  .  .  .  .  .  .  0: *ast.AssignStmt {
-	//		.  .  .  .  .  .  .  .  .  .  .  Lhs: []ast.Expr (len = 1) {
-	//		.  .  .  .  .  .  .  .  .  .  .  .  0: *ast.Ident {
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  Name: "sstr_s"
-	//		.  .  .  .  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  .  .  .  TokPos: 7:11
-	//		.  .  .  .  .  .  .  .  .  .  .  Tok: =
-	//		.  .  .  .  .  .  .  .  .  .  .  Rhs: []ast.Expr (len = 1) {
-	//		.  .  .  .  .  .  .  .  .  .  .  .  0: *ast.CallExpr {
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  Fun: *ast.Ident {
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  .  Name: "f"
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  Lparen: 7:14
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  Args: []ast.Expr (len = 1) {
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  .  0: *ast.Ident {
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  Name: "sstr_s"
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  }
-	//		.  .  .  .  .  }
-	//		.  .  .  .  .  2: *ast.ReturnStmt {
-	//		.  .  .  .  .  .  Return: 9:3
-	//		.  .  .  .  .  .  Results: []ast.Expr (len = 1) {
-	//		.  .  .  .  .  .  .  0: *ast.Ident {
-	//		.  .  .  .  .  .  .  .  Name: "tempVarUnary"
-	//		.  .  .  .  .  .  .  }
-	//		.  .  .  .  .  .  }
-	//		.  .  .  .  .  }
-	//		.  .  .  .  }
-	//		.  .  .  }
-	//		.  .  }
-	//		.  }
 	// to   :
 	//		{
 	//			.....
-	//			sstr_s = c4goPointerArithByteSlice(sstr_s, int(-1))
+	//			sstr_s = f(sstr_s, int(-1))
 	//			.....
 	//		}
+	if eb, ok := node.(*goast.BlockStmt); ok {
+		for i := range eb.List {
+			es, ok := eb.List[i].(*goast.ExprStmt)
+			if !ok {
+				continue
+			}
+			cl, ok := es.X.(*goast.CallExpr)
+			if !ok {
+				continue
+			}
+			fl, ok := cl.Fun.(*goast.FuncLit)
+			if !ok {
+				continue
+			}
+			ft := fl.Type // .(*goast.FuncType)
+			if 1 != len(ft.Results.List) {
+				continue
+			}
+
+			if 3 != len(fl.Body.List) {
+				continue
+			}
+
+			body := fl.Body.List
+
+			as, ok := body[0].(*goast.AssignStmt)
+			if !ok {
+				continue
+			}
+			if 1 != len(as.Lhs) {
+				continue
+			}
+			in, ok := as.Lhs[0].(*goast.Ident)
+			if !ok {
+				continue
+			}
+			if in.Name != "tempVarUnary" {
+				continue
+			}
+
+			rt, ok := body[2].(*goast.ReturnStmt)
+			if !ok {
+				continue
+			}
+			if 1 != len(rt.Results) {
+				continue
+			}
+			id, ok := rt.Results[0].(*goast.Ident)
+			if !ok {
+				continue
+			}
+			if id.Name != "tempVarUnary" {
+				continue
+			}
+
+			def, ok := body[1].(*goast.DeferStmt)
+			if !ok {
+				continue
+			}
+
+			fl, ok = def.Call.Fun.(*goast.FuncLit)
+			if !ok {
+				continue
+			}
+
+			body = fl.Body.List
+			if 1 != len(body) {
+				continue
+			}
+
+			eb.List[i] = body[0]
+		}
+	}
 
 	// 	from:
 	//		func f4() {
diff --git a/scripts/9wm.sh b/scripts/9wm.sh
index 3914816..f806740 100755
--- a/scripts/9wm.sh
+++ b/scripts/9wm.sh
@@ -46,6 +46,9 @@ echo "Calculate warnings : $TEMP_FOLDER"
 # amount Go code lines
 	LINES=`wc $FILE`
 	echo "(lines,words,bytes)	 : $LINES"
+# defers
+	DEFER=`cat $FILE | grep "defer func" | wc -l`
+	echo "defer func           	 : $DEFER"
 
 # Arguments menu
 echo "    -s for show detail of Go build errors"
diff --git a/scripts/brainfuck.sh b/scripts/brainfuck.sh
index 9274b41..18cc39e 100755
--- a/scripts/brainfuck.sh
+++ b/scripts/brainfuck.sh
@@ -54,6 +54,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/easymesh.sh b/scripts/easymesh.sh
index 85996db..b729eaa 100755
--- a/scripts/easymesh.sh
+++ b/scripts/easymesh.sh
@@ -85,6 +85,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 # debugging
 if [ "$1" == "-d" ]; then
diff --git a/scripts/ed.sh b/scripts/ed.sh
index f398d20..51ad67d 100755
--- a/scripts/ed.sh
+++ b/scripts/ed.sh
@@ -49,6 +49,9 @@ echo "Calculate warnings : $TEMP_FOLDER"
 # amount Go code lines
 	LINES=`wc $TEMP_FOLDER/$VERSION.go`
 	echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $TEMP_FOLDER/$VERSION.go | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 # Arguments menu
 echo "    -s for show detail of Go build errors"
diff --git a/scripts/kilo.sh b/scripts/kilo.sh
index 7725138..b6fae10 100755
--- a/scripts/kilo.sh
+++ b/scripts/kilo.sh
@@ -53,6 +53,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 # debugging
 if [ "$1" == "-d" ]; then
diff --git a/scripts/minmad.sh b/scripts/minmad.sh
index a1724df..32d17eb 100755
--- a/scripts/minmad.sh
+++ b/scripts/minmad.sh
@@ -53,6 +53,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/neateqn.sh b/scripts/neateqn.sh
index adbf351..d48f300 100755
--- a/scripts/neateqn.sh
+++ b/scripts/neateqn.sh
@@ -56,6 +56,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/neatmail.sh b/scripts/neatmail.sh
index 444c9e7..5adf474 100755
--- a/scripts/neatmail.sh
+++ b/scripts/neatmail.sh
@@ -56,6 +56,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/neatmkfn.sh b/scripts/neatmkfn.sh
index fc9fef4..f2ec751 100755
--- a/scripts/neatmkfn.sh
+++ b/scripts/neatmkfn.sh
@@ -56,6 +56,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/neatpost.sh b/scripts/neatpost.sh
index fa4d84f..f001c10 100755
--- a/scripts/neatpost.sh
+++ b/scripts/neatpost.sh
@@ -80,6 +80,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/neatrefer.sh b/scripts/neatrefer.sh
index 1e60322..a4a229e 100755
--- a/scripts/neatrefer.sh
+++ b/scripts/neatrefer.sh
@@ -54,6 +54,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/neatroff.sh b/scripts/neatroff.sh
index 499ca89..1355484 100755
--- a/scripts/neatroff.sh
+++ b/scripts/neatroff.sh
@@ -67,6 +67,9 @@ fi
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/neatvi.sh b/scripts/neatvi.sh
index 4f54be5..cde30b6 100755
--- a/scripts/neatvi.sh
+++ b/scripts/neatvi.sh
@@ -57,6 +57,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/progress.sh b/scripts/progress.sh
index f5c0cdf..fe7372c 100755
--- a/scripts/progress.sh
+++ b/scripts/progress.sh
@@ -55,6 +55,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/scripts.sh b/scripts/scripts.sh
index cbc31a1..4092fff 100755
--- a/scripts/scripts.sh
+++ b/scripts/scripts.sh
@@ -9,67 +9,67 @@ export VERIFICATION_FILE="./scripts/scripts.txt"
 
 echo "" > $OUTPUT_FILE
 
-./scripts/brainfuck.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/brainfuck.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/9wm.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/9wm.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-# ./scripts/cis71.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+# ./scripts/cis71.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 # echo "" >> $OUTPUT_FILE
 
-./scripts/ed.sh			2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/ed.sh			2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/kilo.sh			2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/kilo.sh			2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/minmad.sh			2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/minmad.sh			2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/neateqn.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/neateqn.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/neatmkfn.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/neatmkfn.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/neatmail.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/neatmail.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/neatpost.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/neatpost.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/neatrefer.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/neatrefer.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/nuklear.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/nuklear.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/neatroff.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/neatroff.sh	2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/redis.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/redis.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/neatvi.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/neatvi.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/triangle.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/triangle.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/progress.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/progress.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/sqlite.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/sqlite.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/tiny_web_server.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/tiny_web_server.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/vorbis.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/vorbis.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
-./scripts/easymesh.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines' | tee -a $OUTPUT_FILE
+./scripts/easymesh.sh		2>&1 | grep -E 'warning|unsafe|Unsafe|lines|defer' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
 # Arguments menu
diff --git a/scripts/scripts.txt b/scripts/scripts.txt
index e6cb2dd..a626e02 100644
--- a/scripts/scripts.txt
+++ b/scripts/scripts.txt
@@ -3,51 +3,59 @@ Calculate warnings in file: ./testdata/brainfuck/brainfuck.go
 		After transpiling : 0 warnings.
 		Go build : 0 warnings
 		Unsafe   : 0
-(lines,words,bytes)	 :  186  639 4528 ./testdata/brainfuck/brainfuck.go
+(lines,words,bytes)	 :  184  634 4496 ./testdata/brainfuck/brainfuck.go
+defer func           	 : 2
 
 Calculate warnings : ./testdata/9wm
 		After transpiling : 3 warnings.
 		Go build : 4 warnings
 		Unsafe   : 415
-(lines,words,bytes)	 :  10078  31716 346498 ./testdata/9wm/9wm.go
+(lines,words,bytes)	 :  10077  31715 346477 ./testdata/9wm/9wm.go
+defer func           	 : 1
 
 Calculate warnings : ./testdata/ed
 		After transpiling : 0 warnings.
 		Go build : 7 warnings
 		Unsafe   : 165
-(lines,words,bytes)	 :   7023  23684 233822 ./testdata/ed/ed-1.15.go
+(lines,words,bytes)	 :   6831  23269 230438 ./testdata/ed/ed-1.15.go
+defer func           	 : 50
 
 Calculate warnings in file: ./testdata/kilo/kilo.go
 		After transpiling : 0 warnings.
 		Go build : 0 warnings
 		Unsafe   : 17
-(lines,words,bytes)	 :  1772  7132 52429 ./testdata/kilo/kilo.go
+(lines,words,bytes)	 :  1722  7026 51585 ./testdata/kilo/kilo.go
+defer func           	 : 7
 
 
 Calculate warnings in file: ./testdata/neateqn/neateqn.go
 		After transpiling : 0 warnings.
 		Go build : 0 warnings
 		Unsafe   : 75
-(lines,words,bytes)	 :   4772  17456 200976 ./testdata/neateqn/neateqn.go
+(lines,words,bytes)	 :   4714  17332 200001 ./testdata/neateqn/neateqn.go
+defer func           	 : 33
 
 Calculate warnings in file: ./testdata/neatmkfn/neatmkfn.go
 		After transpiling : 0 warnings.
 		Go build : 271 warnings
 		Unsafe   : 141
-(lines,words,bytes)	 :   4844  29510 444311 ./testdata/neatmkfn/neatmkfn.go
+(lines,words,bytes)	 :   4818  29454 443878 ./testdata/neatmkfn/neatmkfn.go
+defer func           	 : 24
 
 
 Calculate warnings in file: ./testdata/neatpost/neatpost.go
 		After transpiling : 2 warnings.
 		Go build : 5 warnings
 		Unsafe   : 47
-(lines,words,bytes)	 :   4299  15821 390186 ./testdata/neatpost/neatpost.go
+(lines,words,bytes)	 :   4215  15638 388710 ./testdata/neatpost/neatpost.go
+defer func           	 : 25
 
 Calculate warnings in file: ./testdata/neatrefer/neatrefer.go
 		After transpiling : 0 warnings.
 		Go build : 0 warnings
 		Unsafe   : 17
-(lines,words,bytes)	 :  1047  3640 27194 ./testdata/neatrefer/neatrefer.go
+(lines,words,bytes)	 :   989  3513 26175 ./testdata/neatrefer/neatrefer.go
+defer func           	 : 26
 
 Calculate warnings : ./testdata/nuklear/x11.go
 		After transpiling : 9 warnings.
@@ -62,7 +70,8 @@ Calculate warnings in file: ./testdata/neatroff/neatroff.go
 		After transpiling : 2 warnings.
 		Go build : 5 warnings
 		Unsafe   : 247
-(lines,words,bytes)	 :  12720  49874 410282 ./testdata/neatroff/neatroff.go
+(lines,words,bytes)	 :  12441  49333 406177 ./testdata/neatroff/neatroff.go
+defer func           	 : 88
 
 Calculate warnings : ./testdata/redis/dict.go
 		After transpiling : 0 warnings.
@@ -85,35 +94,42 @@ Calculate warnings : ./testdata/redis/sds.go
 Calculate warnings in file: ./testdata/triangle/triangle.go
 		After transpiling : 2 warnings.
 		Go build : 585 warnings
-		Unsafe   : 1414
-(lines,words,bytes)	 :  16553  83432 743181 ./testdata/triangle/triangle.go
+		Unsafe   : 1415
+(lines,words,bytes)	 :  16524  83384 742768 ./testdata/triangle/triangle.go
+defer func           	 : 12
 
 Calculate warnings in file: ./testdata/progress/progress.go
 		After transpiling : 0 warnings.
 		Go build : 16 warnings
 		Unsafe   : 6
 (lines,words,bytes)	 :  242  675 7463 ./testdata/progress/progress.go
+defer func           	 : 0
 
 Calculate warnings in file: ./testdata/SQLITE/sqlite.go
 		After transpiling : 1 warnings.
 		Go build : 1 warnings
 		Unsafe   : 2351
+(lines,words,bytes)	 :  144490  731676 5541654 ./testdata/SQLITE/sqlite.go
+defer func           	 : 339
 
 Calculate warnings in file: ./testdata/tiny-web-server/tiny-web-server.go
 		After transpiling : 0 warnings.
 		Go build : 2 warnings
 		Unsafe   : 151
-(lines,words,bytes)	 :   3619  11276 133612 ./testdata/tiny-web-server/tiny-web-server.go
+(lines,words,bytes)	 :   3611  11261 133487 ./testdata/tiny-web-server/tiny-web-server.go
+defer func           	 : 5
 
 Calculate warnings in file: testdata/vorbis/vorbis.go
 		After transpiling : 0 warnings.
 		Go build : 19 warnings
 		Unsafe   : 127
-(lines,words,bytes)	 :   7126  30221 270224 testdata/vorbis/vorbis.go
+(lines,words,bytes)	 :   7103  30176 269763 testdata/vorbis/vorbis.go
+defer func           	 : 12
 
 Calculate warnings in file: ./testdata/easymesh/easymesh.go
 		After transpiling : 0 warnings.
 		Go build : 0 warnings
 		Unsafe   : 10
-(lines,words,bytes)	 :  2599  9101 73376 ./testdata/easymesh/easymesh.go
+(lines,words,bytes)	 :  2582  9084 72957 ./testdata/easymesh/easymesh.go
+defer func           	 : 0
 
diff --git a/scripts/sqlite.sh b/scripts/sqlite.sh
index 69d2239..5bb3251 100755
--- a/scripts/sqlite.sh
+++ b/scripts/sqlite.sh
@@ -52,6 +52,13 @@ echo "		Go build : $SQLITE_WARNINGS_GO warnings"
 SQLITE_UNSAFE=`cat $SQLITE_TEMP_FOLDER/sqlite.go | grep "unsafe\." | wc -l`
 echo "		Unsafe   : $SQLITE_UNSAFE"
 
+# amount Go code lines
+	LINES=`wc $SQLITE_TEMP_FOLDER/sqlite.go`
+	echo "(lines,words,bytes)	 : $LINES"
+# defers
+	DEFER=`cat $SQLITE_TEMP_FOLDER/sqlite.go| grep "defer func" | wc -l`
+	echo "defer func           	 : $DEFER"
+
 # Arguments menu
 echo "    -s for show detail of Go build errors"
 if [ "$1" == "-s" ]; then
diff --git a/scripts/tiny_web_server.sh b/scripts/tiny_web_server.sh
index abe1daf..387770b 100755
--- a/scripts/tiny_web_server.sh
+++ b/scripts/tiny_web_server.sh
@@ -55,6 +55,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/triangle.sh b/scripts/triangle.sh
index bb834fb..5484610 100755
--- a/scripts/triangle.sh
+++ b/scripts/triangle.sh
@@ -49,6 +49,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu
diff --git a/scripts/vorbis.sh b/scripts/vorbis.sh
index 1e990b0..b543ede 100755
--- a/scripts/vorbis.sh
+++ b/scripts/vorbis.sh
@@ -54,6 +54,9 @@ mkdir -p ./testdata/
 	# amount Go code lines
 		LINES=`wc $GO_FILE`
 		echo "(lines,words,bytes)	 : $LINES"
+	# defers
+		DEFER=`cat $GO_FILE | grep "defer func" | wc -l`
+		echo "defer func           	 : $DEFER"
 
 
 # Arguments menu


Test patch:
diff --git a/tests/code_quality/function.c b/tests/code_quality/function.c
index 5033f1a..54913c6 100644
--- a/tests/code_quality/function.c
+++ b/tests/code_quality/function.c
@@ -5,7 +5,7 @@ int sstr_n;
 char *sstr_pop(void)
 {
 	char *ret = sstr_s;
-	sstr_s = sstr_bufs[--sstr_n];
+	sstr_s = &sstr_bufs[--sstr_n];
 	return ret;
 }
 
@@ -18,3 +18,34 @@ void sstr_back(int c)
 {
 	sstr_s--;
 }
+
+int sf1() {
+	sstr_n++;
+	return *sstr_s == sstr_bufs[sstr_n] ? 1: 0;
+}
+
+int st2() {
+	sstr_n++;
+	int s = *sstr_s == sstr_bufs[sstr_n] ? 1: 0;
+	sstr_n--;
+	return s;
+}
+
+int st2a() {
+	sstr_n++;
+	int s;
+	s = *sstr_s == sstr_bufs[sstr_n] ? 1: 0;
+	sstr_n--;
+	return s;
+}
+
+int st3() {
+	sstr_n++;
+	int s = (*sstr_s == sstr_bufs[sstr_n] ? sstr_n+1: sstr_n-1);
+	sstr_n--;
+	return s;
+}
+
+int st4() {
+	return (*sstr_s == sstr_bufs[sstr_n] ? sstr_n+1: sstr_n-1);
+}
diff --git a/tests/code_quality/function.go.expected b/tests/code_quality/function.go.expected
index b2ed4cb..68fcf9b 100644
--- a/tests/code_quality/function.go.expected
+++ b/tests/code_quality/function.go.expected
@@ -32,28 +32,76 @@ func sstr_pop() []byte {
 
 // sstr_next - transpiled function from  C4GO/tests/code_quality/function.c:12
 func sstr_next() int32 {
-	return func() int32 {
-		if int32(sstr_s[0]) != 0 {
-			return int32(uint8((func() []byte {
-				defer func() {
-					sstr_s = sstr_s[0+1:]
-				}()
-				return sstr_s
-			}())[0]))
-		}
-		return -1
-	}()
+	if int32(sstr_s[0]) != 0 {
+		return int32(uint8((func() []byte {
+			defer func() {
+				sstr_s = sstr_s[0+1:]
+			}()
+			return sstr_s
+		}())[0]))
+	}
+	return -1
 }
 
 // sstr_back - transpiled function from  C4GO/tests/code_quality/function.c:17
 func sstr_back(c int32) {
-	func() []byte {
-		tempVarUnary := sstr_s
-		defer func() {
-			sstr_s = c4goPointerArithByteSlice(sstr_s, int(-1))
-		}()
-		return tempVarUnary
+	sstr_s = c4goPointerArithByteSlice(sstr_s, int(-1))
+}
+
+// sf1 - transpiled function from  C4GO/tests/code_quality/function.c:22
+func sf1() int32 {
+	sstr_n++
+	if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
+		return 1
+	}
+	return 0
+}
+
+// st2 - transpiled function from  C4GO/tests/code_quality/function.c:27
+func st2() int32 {
+	sstr_n++
+	var s int32 = func() int32 {
+		if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
+			return 1
+		}
+		return 0
 	}()
+	sstr_n--
+	return s
+}
+
+// st2a - transpiled function from  C4GO/tests/code_quality/function.c:34
+func st2a() int32 {
+	sstr_n++
+	var s int32
+	if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
+		s = 1
+	} else {
+		s = 0
+	}
+	sstr_n--
+	return s
+}
+
+// st3 - transpiled function from  C4GO/tests/code_quality/function.c:42
+func st3() int32 {
+	sstr_n++
+	var s int32 = func() int32 {
+		if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
+			return sstr_n + 1
+		}
+		return sstr_n - 1
+	}()
+	sstr_n--
+	return s
+}
+
+// st4 - transpiled function from  C4GO/tests/code_quality/function.c:49
+func st4() int32 {
+	if int32(sstr_s[0]) == int32(sstr_bufs[sstr_n]) {
+		return sstr_n + 1
+	}
+	return sstr_n - 1
 }
 
 // c4goPointerArithByteSlice - function of pointer arithmetic. generated by c4go
diff --git a/tests/code_quality/if.go.expected b/tests/code_quality/if.go.expected
index 5317a28..c2fe8db 100644
--- a/tests/code_quality/if.go.expected
+++ b/tests/code_quality/if.go.expected
@@ -29,36 +29,31 @@ func if_1() {
 		return 5
 	}()
 	var r int32
-	r = func() int32 {
-		if 2 > 1 {
-			return -1
-		}
-		return 5
-	}()
-	r = func() int32 {
-		if 2 > 1 {
-			return -1
-		}
-		return 5
-	}()
-	r = func() int32 {
-		if w > 1 {
-			return -1
-		}
-		return 5
-	}()
-	r = func() int32 {
-		if w > 1 {
-			return -1
-		}
-		return 5
-	}()
-	r = func() int32 {
-		if noarch.BoolToInt(w > 1)+noarch.BoolToInt(r == 4) != 0 {
-			return -1
-		}
-		return 5
-	}()
+	if 2 > 1 {
+		r = -1
+	} else {
+		r = 5
+	}
+	if 2 > 1 {
+		r = -1
+	} else {
+		r = 5
+	}
+	if w > 1 {
+		r = -1
+	} else {
+		r = 5
+	}
+	if w > 1 {
+		r = -1
+	} else {
+		r = 5
+	}
+	if noarch.BoolToInt(w > 1)+noarch.BoolToInt(r == 4) != 0 {
+		r = -1
+	} else {
+		r = 5
+	}
 	if w > 0 {
 		r = 3
 	}