min_infmachine_lltk 0.1.0

The MinInfMachine Low Level Toolkit.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
use min_infmachine_lltk::builder::*;
use min_infmachine_lltk::handler_builder::*;
use min_infmachine_lltk::*;

#[test]
fn test_handler_builder_1() {
    let mut builder = mi_simple_hbuilder_new_1(Some(1));
    {
        let (func1b, ret) = builder.add_routine("func1", false);
        let mut func1b = func1b.borrow_mut();
        func1b.i(MINF_MR);
        func1b.i(MINF_TBRF);
        func1b.i(MINF_TBB);
        func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
    }
    {
        let (func2b, ret) = builder.add_routine("func2", true);
        let mut func2b = func2b.borrow_mut();
        func2b.i(MINF_MRW0);
        func2b.i(MINF_MAB);
        func2b.i((MINF_MARW0, MINF_MARW1));
        func2b.i((MINF_MR, ret));
    }
    builder.i(MINF_MRW0);
    builder.call_01("func1", MINF_MR);
    builder.i(MINF_TBR);
    builder.call_01("func1", MINF_MAR);
    builder.i(MINF_MRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_TBRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MR, MINF_MR, 9, 9).into(),
                (MINF_TBR, MINF_TBR, 3, 3).into(),
                (MINF_MAR, MINF_MAR, 11, 11).into(),
                (MINF_MRW1, MINF_MRW1, 5, 5).into(),
                (MINF_TBR, MINF_TBR, 16, 16).into(),
                (MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
                (MINF_TBR, MINF_TBR, 18, 18).into(),
                (MINF_STOP, MINF_STOP, 9, 9).into(),
                (MINF_MARW0, MINF_MARW0, 10, 10).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MARW1, MINF_MARW1, 12, 12).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MAB, MINF_MAB, 14, 14).into(),
                (MINF_MARW0, MINF_MARW0, 15, 15).into(),
                (MINF_MR, MINF_MR, 2, 4).into(),
                (MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
                (MINF_TBRF, MINF_TBRF, 27, 27).into(),
                (MINF_TBRW1, MINF_TBRW1, 19, 19).into(),
                (MINF_TBRF, MINF_TBRF, 27, 27).into(),
                (MINF_TBB, MINF_TBB, 21, 21).into(),
                (MINF_TBRW0, MINF_TBRW0, 22, 22).into(),
                (MINF_MR, MINF_MR, 6, 8).into(),
                (MINF_MR, MINF_MR, 24, 24).into(),
                (MINF_TBRF, MINF_TBRF, 25, 25).into(),
                (MINF_TBB, MINF_TBB, 26, 26).into(),
                (MINF_TBRW1, MINF_TBRW0, 13, 13).into(),
                (MINF_MRW0, MINF_MRW0, 28, 28).into(),
                (MINF_MAB, MINF_MAB, 29, 29).into(),
                (MINF_MARW0, MINF_MARW1, 30, 30).into(),
                (MINF_MR, MINF_MR, 20, 20).into()
            ],
            vec![
                ("func1".to_string(), 23),
                ("func1_0_putret_x_0".to_string(), 9),
                ("func1_0_putret_x_1".to_string(), 11),
                ("func1_after_ret_0".to_string(), 2),
                ("func1_after_ret_1".to_string(), 4),
                ("func1_return".to_string(), 13),
                ("func1_return_id_0_0".to_string(), 14),
                ("func2".to_string(), 27),
                ("func2_0_putret_x_0".to_string(), 16),
                ("func2_0_putret_x_1".to_string(), 18),
                ("func2_after_ret_0".to_string(), 6),
                ("func2_after_ret_1".to_string(), 8),
                ("func2_return".to_string(), 20),
                ("func2_return_id_0_0".to_string(), 21)
            ]
        ),
        builder.to_code()
    );
    // add routine in other routine
    let mut builder = mi_simple_hbuilder_new_1(Some(1));
    {
        let (func1b, ret) = builder.add_routine("func1", false);
        let mut func1b = func1b.borrow_mut();
        {
            let (func2b, ret) = func1b.add_routine("func2", true);
            let mut func2b = func2b.borrow_mut();
            func2b.i(MINF_MRW0);
            func2b.i(MINF_MAB);
            func2b.i((MINF_MARW0, MINF_MARW1));
            func2b.i((MINF_MR, ret));
        }
        func1b.i(MINF_MR);
        func1b.i(MINF_TBRF);
        func1b.i(MINF_TBB);
        func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
    }
    builder.i(MINF_MRW0);
    builder.call_01("func1", MINF_MR);
    builder.i(MINF_TBR);
    builder.call_01("func1", MINF_MAR);
    builder.i(MINF_MRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_TBRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MR, MINF_MR, 9, 9).into(),
                (MINF_TBR, MINF_TBR, 3, 3).into(),
                (MINF_MAR, MINF_MAR, 11, 11).into(),
                (MINF_MRW1, MINF_MRW1, 5, 5).into(),
                (MINF_TBR, MINF_TBR, 16, 16).into(),
                (MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
                (MINF_TBR, MINF_TBR, 18, 18).into(),
                (MINF_STOP, MINF_STOP, 9, 9).into(),
                (MINF_MARW0, MINF_MARW0, 10, 10).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MARW1, MINF_MARW1, 12, 12).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MAB, MINF_MAB, 14, 14).into(),
                (MINF_MARW0, MINF_MARW0, 15, 15).into(),
                (MINF_MR, MINF_MR, 2, 4).into(),
                (MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
                (MINF_TBRF, MINF_TBRF, 27, 27).into(),
                (MINF_TBRW1, MINF_TBRW1, 19, 19).into(),
                (MINF_TBRF, MINF_TBRF, 27, 27).into(),
                (MINF_TBB, MINF_TBB, 21, 21).into(),
                (MINF_TBRW0, MINF_TBRW0, 22, 22).into(),
                (MINF_MR, MINF_MR, 6, 8).into(),
                (MINF_MR, MINF_MR, 24, 24).into(),
                (MINF_TBRF, MINF_TBRF, 25, 25).into(),
                (MINF_TBB, MINF_TBB, 26, 26).into(),
                (MINF_TBRW1, MINF_TBRW0, 13, 13).into(),
                (MINF_MRW0, MINF_MRW0, 28, 28).into(),
                (MINF_MAB, MINF_MAB, 29, 29).into(),
                (MINF_MARW0, MINF_MARW1, 30, 30).into(),
                (MINF_MR, MINF_MR, 20, 20).into()
            ],
            vec![
                ("func1".to_string(), 23),
                ("func1_0_putret_x_0".to_string(), 9),
                ("func1_0_putret_x_1".to_string(), 11),
                ("func1_after_ret_0".to_string(), 2),
                ("func1_after_ret_1".to_string(), 4),
                ("func1_return".to_string(), 13),
                ("func1_return_id_0_0".to_string(), 14),
                ("func2".to_string(), 27),
                ("func2_0_putret_x_0".to_string(), 16),
                ("func2_0_putret_x_1".to_string(), 18),
                ("func2_after_ret_0".to_string(), 6),
                ("func2_after_ret_1".to_string(), 8),
                ("func2_return".to_string(), 20),
                ("func2_return_id_0_0".to_string(), 21)
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_1_1() {
    let mut builder = mi_simple_hbuilder_new_1(Some(1));
    {
        let (func1b, ret) = builder.add_routine_l("func1".to_string(), false);
        let mut func1b = func1b.borrow_mut();
        func1b.i(MINF_MR);
        func1b.i(MINF_TBRF);
        func1b.i(MINF_TBB);
        func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
    }
    {
        let (func2b, ret) = builder.add_routine_ll("func2".to_string(), true);
        let mut func2b = func2b.borrow_mut();
        func2b.i(MINF_MRW0);
        func2b.i(MINF_MAB);
        func2b.i((MINF_MARW0, MINF_MARW1));
        func2b.i((MINF_MR, ret));
    }
    builder.i(MINF_MRW0);
    builder.call_01("func1", MINF_MR);
    builder.i(MINF_TBR);
    builder.call_01("func1", MINF_MAR);
    builder.i(MINF_MRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_TBRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MR, MINF_MR, 9, 9).into(),
                (MINF_TBR, MINF_TBR, 3, 3).into(),
                (MINF_MAR, MINF_MAR, 11, 11).into(),
                (MINF_MRW1, MINF_MRW1, 5, 5).into(),
                (MINF_TBR, MINF_TBR, 16, 16).into(),
                (MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
                (MINF_TBR, MINF_TBR, 18, 18).into(),
                (MINF_STOP, MINF_STOP, 9, 9).into(),
                (MINF_MARW0, MINF_MARW0, 10, 10).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MARW1, MINF_MARW1, 12, 12).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MAB, MINF_MAB, 14, 14).into(),
                (MINF_MARW0, MINF_MARW0, 15, 15).into(),
                (MINF_MR, MINF_MR, 2, 4).into(),
                (MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
                (MINF_TBRF, MINF_TBRF, 27, 27).into(),
                (MINF_TBRW1, MINF_TBRW1, 19, 19).into(),
                (MINF_TBRF, MINF_TBRF, 27, 27).into(),
                (MINF_TBB, MINF_TBB, 21, 21).into(),
                (MINF_TBRW0, MINF_TBRW0, 22, 22).into(),
                (MINF_MR, MINF_MR, 6, 8).into(),
                (MINF_MR, MINF_MR, 24, 24).into(),
                (MINF_TBRF, MINF_TBRF, 25, 25).into(),
                (MINF_TBB, MINF_TBB, 26, 26).into(),
                (MINF_TBRW1, MINF_TBRW0, 13, 13).into(),
                (MINF_MRW0, MINF_MRW0, 28, 28).into(),
                (MINF_MAB, MINF_MAB, 29, 29).into(),
                (MINF_MARW0, MINF_MARW1, 30, 30).into(),
                (MINF_MR, MINF_MR, 20, 20).into()
            ],
            vec![
                ("func1".to_string(), 23),
                ("func1_0_putret_x_0".to_string(), 9),
                ("func1_0_putret_x_1".to_string(), 11),
                ("func1_after_ret_0".to_string(), 2),
                ("func1_after_ret_1".to_string(), 4),
                ("func1_return".to_string(), 13),
                ("func1_return_id_0_0".to_string(), 14),
                ("func2".to_string(), 27),
                ("func2_0_putret_x_0".to_string(), 16),
                ("func2_0_putret_x_1".to_string(), 18),
                ("func2_after_ret_0".to_string(), 6),
                ("func2_after_ret_1".to_string(), 8),
                ("func2_return".to_string(), 20),
                ("func2_return_id_0_0".to_string(), 21)
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_2() {
    let mut builder = mi_simple_hbuilder_new_1(Some(3));
    {
        let (func1b, ret) = builder.add_routine("func1", false);
        let mut func1b = func1b.borrow_mut();
        func1b.i(MINF_MR);
        func1b.i(MINF_TBRF);
        func1b.i(MINF_TBB);
        func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
    }
    {
        let (func2b, ret) = builder.add_routine("func2", true);
        let mut func2b = func2b.borrow_mut();
        func2b.i(MINF_MRW0);
        func2b.i(MINF_MAB);
        func2b.i((MINF_MARW0, MINF_MARW1));
        func2b.i((MINF_MR, ret));
    }
    builder.i(MINF_MRW0);
    builder.call_01("func1", MINF_MR);
    builder.i(MINF_TBR);
    builder.call("func1", MINF_MAR, MINF_MARW0);
    builder.i(MINF_MRW1);
    builder.call_fr0_01("func1", MINF_MR, "my_stop");
    builder.i(MINF_TBR);
    builder.call_fr0("func1", MINF_MRW1, MINF_MRW0, "my_stop");
    builder.i(MINF_MRW1);
    builder.call_fr1_01("func2", MINF_MR, "my_stop");
    builder.i(MINF_TBRW1);
    builder.call_fr1("func2", MINF_MRW1, MINF_MRW0, "my_stop");
    builder.i(MINF_MRW1);
    builder.call_2_01("func1", "func2", MINF_MR);
    builder.i(MINF_TBRW1);
    builder.call_2("func1", "func2", MINF_MRW0, MINF_MRW1);
    builder.i(MINF_STOP);
    builder.l("my_stop");
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MR, MINF_MR, 18, 18).into(),
                (MINF_TBR, MINF_TBR, 3, 3).into(),
                (MINF_MAR, MINF_MARW0, 20, 20).into(),
                (MINF_MRW1, MINF_MRW1, 5, 5).into(),
                (MINF_MR, MINF_MR, 22, 17).into(),
                (MINF_TBR, MINF_TBR, 7, 7).into(),
                (MINF_MRW1, MINF_MRW0, 24, 17).into(),
                (MINF_MRW1, MINF_MRW1, 9, 9).into(),
                (MINF_MR, MINF_MR, 17, 53).into(),
                (MINF_TBRW1, MINF_TBRW1, 11, 11).into(),
                (MINF_MRW1, MINF_MRW0, 17, 55).into(),
                (MINF_MRW1, MINF_MRW1, 13, 13).into(),
                (MINF_MR, MINF_MR, 26, 57).into(),
                (MINF_TBRW1, MINF_TBRW1, 15, 15).into(),
                (MINF_MRW0, MINF_MRW1, 28, 59).into(),
                (MINF_STOP, MINF_STOP, 17, 17).into(),
                (MINF_STOP, MINF_STOP, 18, 18).into(),
                (MINF_MARW0, MINF_MARW0, 19, 19).into(),
                (MINF_MARF, MINF_MARF, 30, 30).into(),
                (MINF_MARW1, MINF_MARW1, 21, 21).into(),
                (MINF_MARF, MINF_MARF, 30, 30).into(),
                (MINF_MARW0, MINF_MARW0, 23, 23).into(),
                (MINF_MARF, MINF_MARF, 32, 32).into(),
                (MINF_MARW1, MINF_MARW1, 25, 25).into(),
                (MINF_MARF, MINF_MARF, 32, 32).into(),
                (MINF_MARW0, MINF_MARW0, 27, 27).into(),
                (MINF_MARF, MINF_MARF, 34, 34).into(),
                (MINF_MARW1, MINF_MARW1, 29, 29).into(),
                (MINF_MARF, MINF_MARF, 34, 34).into(),
                (MINF_MARW0, MINF_MARW0, 31, 31).into(),
                (MINF_MARF, MINF_MARF, 36, 36).into(),
                (MINF_MARW1, MINF_MARW1, 33, 33).into(),
                (MINF_MARF, MINF_MARF, 36, 36).into(),
                (MINF_MARW0, MINF_MARW0, 35, 35).into(),
                (MINF_MARF, MINF_MARF, 38, 38).into(),
                (MINF_MARW0, MINF_MARW0, 37, 37).into(),
                (MINF_MARF, MINF_MARF, 76, 76).into(),
                (MINF_MARW1, MINF_MARW1, 39, 39).into(),
                (MINF_MARF, MINF_MARF, 76, 76).into(),
                (MINF_MAB, MINF_MAB, 41, 41).into(),
                (MINF_MARW0, MINF_MARW0, 42, 42).into(),
                (MINF_MAB, MINF_MAB, 43, 45).into(),
                (MINF_MARW0, MINF_MARW0, 44, 44).into(),
                (MINF_MAB, MINF_MAB, 47, 49).into(),
                (MINF_MARW0, MINF_MARW0, 46, 46).into(),
                (MINF_MAB, MINF_MAB, 51, 51).into(),
                (MINF_MARW0, MINF_MARW0, 48, 48).into(),
                (MINF_MR, MINF_MR, 2, 4).into(),
                (MINF_MARW0, MINF_MARW0, 50, 50).into(),
                (MINF_MR, MINF_MR, 6, 8).into(),
                (MINF_MARW0, MINF_MARW0, 52, 52).into(),
                (MINF_MR, MINF_MR, 14, 16).into(),
                (MINF_TBRW0, MINF_TBRW0, 54, 54).into(),
                (MINF_TBRF, MINF_TBRF, 61, 61).into(),
                (MINF_TBRW1, MINF_TBRW1, 56, 56).into(),
                (MINF_TBRF, MINF_TBRF, 61, 61).into(),
                (MINF_TBRW0, MINF_TBRW0, 58, 58).into(),
                (MINF_TBRF, MINF_TBRF, 63, 63).into(),
                (MINF_TBRW1, MINF_TBRW1, 60, 60).into(),
                (MINF_TBRF, MINF_TBRF, 63, 63).into(),
                (MINF_TBRW0, MINF_TBRW0, 62, 62).into(),
                (MINF_TBRF, MINF_TBRF, 65, 65).into(),
                (MINF_TBRW1, MINF_TBRW1, 64, 64).into(),
                (MINF_TBRF, MINF_TBRF, 65, 65).into(),
                (MINF_TBRW0, MINF_TBRW0, 66, 66).into(),
                (MINF_TBRF, MINF_TBRF, 80, 80).into(),
                (MINF_TBB, MINF_TBB, 68, 68).into(),
                (MINF_TBRW0, MINF_TBRW0, 69, 69).into(),
                (MINF_TBB, MINF_TBB, 70, 70).into(),
                (MINF_TBRW0, MINF_TBRW0, 71, 71).into(),
                (MINF_TBB, MINF_TBB, 72, 74).into(),
                (MINF_TBRW0, MINF_TBRW0, 73, 73).into(),
                (MINF_MR, MINF_MR, 10, 12).into(),
                (MINF_TBRW0, MINF_TBRW0, 75, 75).into(),
                (MINF_MR, MINF_MR, 14, 16).into(),
                (MINF_MR, MINF_MR, 77, 77).into(),
                (MINF_TBRF, MINF_TBRF, 78, 78).into(),
                (MINF_TBB, MINF_TBB, 79, 79).into(),
                (MINF_TBRW1, MINF_TBRW0, 40, 40).into(),
                (MINF_MRW0, MINF_MRW0, 81, 81).into(),
                (MINF_MAB, MINF_MAB, 82, 82).into(),
                (MINF_MARW0, MINF_MARW1, 83, 83).into(),
                (MINF_MR, MINF_MR, 67, 67).into(),
            ],
            vec![
                ("func1".to_string(), 76),
                ("func1_0_putret_1_0".to_string(), 36),
                ("func1_0_putret_1_1".to_string(), 38),
                ("func1_0_putret_2_00".to_string(), 30),
                ("func1_0_putret_2_01".to_string(), 32),
                ("func1_0_putret_2_10".to_string(), 34),
                ("func1_0_putret_x_0".to_string(), 18),
                ("func1_0_putret_x_1".to_string(), 20),
                ("func1_0_putret_x_10".to_string(), 22),
                ("func1_0_putret_x_100".to_string(), 26),
                ("func1_0_putret_x_101".to_string(), 28),
                ("func1_0_putret_x_11".to_string(), 24),
                ("func1_after_ret_0".to_string(), 2),
                ("func1_after_ret_1".to_string(), 4),
                ("func1_after_ret_2".to_string(), 6),
                ("func1_after_ret_3".to_string(), 8),
                ("func1_after_ret_4".to_string(), 14),
                ("func1_after_ret_5".to_string(), 16),
                ("func1_return".to_string(), 40),
                ("func1_return_id_0_0".to_string(), 41),
                ("func1_return_id_1_0".to_string(), 43),
                ("func1_return_id_1_1".to_string(), 45),
                ("func1_return_id_2_00".to_string(), 47),
                ("func1_return_id_2_01".to_string(), 49),
                ("func1_return_id_2_10".to_string(), 51),
                ("func2".to_string(), 80),
                ("func2_0_putret_1_0".to_string(), 65),
                ("func2_0_putret_2_00".to_string(), 61),
                ("func2_0_putret_2_01".to_string(), 63),
                ("func2_0_putret_x_0".to_string(), 53),
                ("func2_0_putret_x_1".to_string(), 55),
                ("func2_0_putret_x_10".to_string(), 57),
                ("func2_0_putret_x_11".to_string(), 59),
                ("func2_after_ret_0".to_string(), 10),
                ("func2_after_ret_1".to_string(), 12),
                ("func2_after_ret_2".to_string(), 14),
                ("func2_after_ret_3".to_string(), 16),
                ("func2_return".to_string(), 67),
                ("func2_return_id_0_0".to_string(), 68),
                ("func2_return_id_1_0".to_string(), 70),
                ("func2_return_id_2_00".to_string(), 72),
                ("func2_return_id_2_01".to_string(), 74),
                ("my_stop".to_string(), 17),
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_skip_ret() {
    let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
    builder.i(MINF_MRW0);
    builder.skip_ret(false);
    builder.skip_ret(true);
    builder.back_ret(false);
    builder.back_ret(true);
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MARF, MINF_MARF, 2, 2).into(),
                (MINF_MARF, MINF_MARF, 3, 3).into(),
                (MINF_MARF, MINF_MARF, 4, 4).into(),
                (MINF_TBRF, MINF_TBRF, 5, 5).into(),
                (MINF_TBRF, MINF_TBRF, 6, 6).into(),
                (MINF_TBRF, MINF_TBRF, 7, 7).into(),
                (MINF_TBRF, MINF_TBRF, 8, 8).into(),
                (MINF_TBRF, MINF_TBRF, 9, 9).into(),
                (MINF_MAB, MINF_MAB, 10, 10).into(),
                (MINF_MAB, MINF_MAB, 11, 11).into(),
                (MINF_MAB, MINF_MAB, 12, 12).into(),
                (MINF_TBB, MINF_TBB, 13, 13).into(),
                (MINF_TBB, MINF_TBB, 14, 14).into(),
                (MINF_TBB, MINF_TBB, 15, 15).into(),
                (MINF_TBB, MINF_TBB, 16, 16).into(),
                (MINF_TBB, MINF_TBB, 17, 17).into(),
                (MINF_STOP, MINF_STOP, 0, 0).into(),
            ],
            vec![]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_routine_with_multiple_entries() {
    let mut builder = mi_simple_hbuilder_new(Some(3), Some(3));
    let number = 5;
    {
        let (builder, ret) = builder.add_routine_with_labels_l(
            "routine0",
            ["routine0_a", "routine0_b", "routine0_c"],
            true,
        );
        let mut builder = builder.borrow_mut();
        builder.l("routine0_a");
        builder.i((MINF_MR, MinInfRel::from(&ret)));
        builder.l("routine0_b");
        builder.i((MINF_MR, MinInfRel::from(&ret)));
        builder.l("routine0_c");
        builder.i((MINF_MR, MinInfRel::from(&ret)));
    }
    {
        let ret_handler = builder.routine_handler("routine0");
        let mut ret_handler = ret_handler.borrow_mut();
        for i in 0..number {
            let cslabel = format!("code{}s", i);
            let cretlabel = format!("code{}_ret", i);
            ret_handler.add_label(&cslabel, cretlabel);
        }
    }
    let rets = {
        let ret_handler = builder.routine_handler("routine0");
        let ret_handler = ret_handler.borrow();
        (0..number)
            .map(|i| {
                (0..3)
                    .map(|j| {
                        let cslabel = format!("code{}s", i);
                        ret_handler.jump_to_call_rl(&cslabel, j)
                    })
                    .collect::<Vec<_>>()
            })
            .collect::<Vec<_>>()
    };
    for i in 0..number {
        let cretlabel = format!("code{}_ret", i);
        for j in 0..3 {
            let clabel = format!("code{}_{}", i, j);
            builder.l(clabel.clone());
            builder.i(MINF_MR);
            builder.i((MINF_MR, MinInfRel::from(&rets[i][j])));
        }
        builder.l(cretlabel.clone());
        builder.i(MINF_MR);
    }
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MR, MINF_MR, 1, 1),
                (MINF_MR, MINF_MR, 35, 35).into(),
                (MINF_MR, MINF_MR, 3, 3).into(),
                (MINF_MR, MINF_MR, 55, 55).into(),
                (MINF_MR, MINF_MR, 5, 5).into(),
                (MINF_MR, MINF_MR, 75, 75).into(),
                (MINF_MR, MINF_MR, 7, 7).into(),
                (MINF_MR, MINF_MR, 8, 8).into(),
                (MINF_MR, MINF_MR, 37, 37).into(),
                (MINF_MR, MINF_MR, 10, 10).into(),
                (MINF_MR, MINF_MR, 57, 57).into(),
                (MINF_MR, MINF_MR, 12, 12).into(),
                (MINF_MR, MINF_MR, 77, 77).into(),
                (MINF_MR, MINF_MR, 14, 14).into(),
                (MINF_MR, MINF_MR, 15, 15).into(),
                (MINF_MR, MINF_MR, 39, 39).into(),
                (MINF_MR, MINF_MR, 17, 17).into(),
                (MINF_MR, MINF_MR, 59, 59).into(),
                (MINF_MR, MINF_MR, 19, 19).into(),
                (MINF_MR, MINF_MR, 79, 79).into(),
                (MINF_MR, MINF_MR, 21, 21).into(),
                (MINF_MR, MINF_MR, 22, 22).into(),
                (MINF_MR, MINF_MR, 41, 41).into(),
                (MINF_MR, MINF_MR, 24, 24).into(),
                (MINF_MR, MINF_MR, 61, 61).into(),
                (MINF_MR, MINF_MR, 26, 26).into(),
                (MINF_MR, MINF_MR, 81, 81).into(),
                (MINF_MR, MINF_MR, 28, 28).into(),
                (MINF_MR, MINF_MR, 29, 29).into(),
                (MINF_MR, MINF_MR, 43, 43).into(),
                (MINF_MR, MINF_MR, 31, 31).into(),
                (MINF_MR, MINF_MR, 63, 63).into(),
                (MINF_MR, MINF_MR, 33, 33).into(),
                (MINF_MR, MINF_MR, 83, 83).into(),
                (MINF_MR, MINF_MR, 35, 35).into(),
                (MINF_TBRW0, MINF_TBRW0, 36, 36).into(),
                (MINF_TBRF, MINF_TBRF, 45, 45).into(),
                (MINF_TBRW1, MINF_TBRW1, 38, 38).into(),
                (MINF_TBRF, MINF_TBRF, 45, 45).into(),
                (MINF_TBRW0, MINF_TBRW0, 40, 40).into(),
                (MINF_TBRF, MINF_TBRF, 47, 47).into(),
                (MINF_TBRW1, MINF_TBRW1, 42, 42).into(),
                (MINF_TBRF, MINF_TBRF, 47, 47).into(),
                (MINF_TBRW0, MINF_TBRW0, 44, 44).into(),
                (MINF_TBRF, MINF_TBRF, 49, 49).into(),
                (MINF_TBRW0, MINF_TBRW0, 46, 46).into(),
                (MINF_TBRF, MINF_TBRF, 51, 51).into(),
                (MINF_TBRW1, MINF_TBRW1, 48, 48).into(),
                (MINF_TBRF, MINF_TBRF, 51, 51).into(),
                (MINF_TBRW0, MINF_TBRW0, 50, 50).into(),
                (MINF_TBRF, MINF_TBRF, 53, 53).into(),
                (MINF_TBRW0, MINF_TBRW0, 52, 52).into(),
                (MINF_TBRF, MINF_TBRF, 108, 108).into(),
                (MINF_TBRW1, MINF_TBRW1, 54, 54).into(),
                (MINF_TBRF, MINF_TBRF, 108, 108).into(),
                (MINF_TBRW0, MINF_TBRW0, 56, 56).into(),
                (MINF_TBRF, MINF_TBRF, 65, 65).into(),
                (MINF_TBRW1, MINF_TBRW1, 58, 58).into(),
                (MINF_TBRF, MINF_TBRF, 65, 65).into(),
                (MINF_TBRW0, MINF_TBRW0, 60, 60).into(),
                (MINF_TBRF, MINF_TBRF, 67, 67).into(),
                (MINF_TBRW1, MINF_TBRW1, 62, 62).into(),
                (MINF_TBRF, MINF_TBRF, 67, 67).into(),
                (MINF_TBRW0, MINF_TBRW0, 64, 64).into(),
                (MINF_TBRF, MINF_TBRF, 69, 69).into(),
                (MINF_TBRW0, MINF_TBRW0, 66, 66).into(),
                (MINF_TBRF, MINF_TBRF, 71, 71).into(),
                (MINF_TBRW1, MINF_TBRW1, 68, 68).into(),
                (MINF_TBRF, MINF_TBRF, 71, 71).into(),
                (MINF_TBRW0, MINF_TBRW0, 70, 70).into(),
                (MINF_TBRF, MINF_TBRF, 73, 73).into(),
                (MINF_TBRW0, MINF_TBRW0, 72, 72).into(),
                (MINF_TBRF, MINF_TBRF, 109, 109).into(),
                (MINF_TBRW1, MINF_TBRW1, 74, 74).into(),
                (MINF_TBRF, MINF_TBRF, 109, 109).into(),
                (MINF_TBRW0, MINF_TBRW0, 76, 76).into(),
                (MINF_TBRF, MINF_TBRF, 85, 85).into(),
                (MINF_TBRW1, MINF_TBRW1, 78, 78).into(),
                (MINF_TBRF, MINF_TBRF, 85, 85).into(),
                (MINF_TBRW0, MINF_TBRW0, 80, 80).into(),
                (MINF_TBRF, MINF_TBRF, 87, 87).into(),
                (MINF_TBRW1, MINF_TBRW1, 82, 82).into(),
                (MINF_TBRF, MINF_TBRF, 87, 87).into(),
                (MINF_TBRW0, MINF_TBRW0, 84, 84).into(),
                (MINF_TBRF, MINF_TBRF, 89, 89).into(),
                (MINF_TBRW0, MINF_TBRW0, 86, 86).into(),
                (MINF_TBRF, MINF_TBRF, 91, 91).into(),
                (MINF_TBRW1, MINF_TBRW1, 88, 88).into(),
                (MINF_TBRF, MINF_TBRF, 91, 91).into(),
                (MINF_TBRW0, MINF_TBRW0, 90, 90).into(),
                (MINF_TBRF, MINF_TBRF, 93, 93).into(),
                (MINF_TBRW0, MINF_TBRW0, 92, 92).into(),
                (MINF_TBRF, MINF_TBRF, 110, 110).into(),
                (MINF_TBRW1, MINF_TBRW1, 94, 94).into(),
                (MINF_TBRF, MINF_TBRF, 110, 110).into(),
                (MINF_TBB, MINF_TBB, 96, 96).into(),
                (MINF_TBRW0, MINF_TBRW0, 97, 97).into(),
                (MINF_TBB, MINF_TBB, 98, 100).into(),
                (MINF_TBRW0, MINF_TBRW0, 99, 99).into(),
                (MINF_TBB, MINF_TBB, 102, 104).into(),
                (MINF_TBRW0, MINF_TBRW0, 101, 101).into(),
                (MINF_TBB, MINF_TBB, 106, 106).into(),
                (MINF_TBRW0, MINF_TBRW0, 103, 103).into(),
                (MINF_MR, MINF_MR, 6, 13).into(),
                (MINF_TBRW0, MINF_TBRW0, 105, 105).into(),
                (MINF_MR, MINF_MR, 20, 27).into(),
                (MINF_TBRW0, MINF_TBRW0, 107, 107).into(),
                (MINF_MR, MINF_MR, 34, 34).into(),
                (MINF_MR, MINF_MR, 95, 95).into(),
                (MINF_MR, MINF_MR, 95, 95).into(),
                (MINF_MR, MINF_MR, 95, 95).into(),
            ],
            vec![
                ("code0_0".to_string(), 0),
                ("code0_1".to_string(), 2),
                ("code0_2".to_string(), 4),
                ("code0_ret".to_string(), 6),
                ("code1_0".to_string(), 7),
                ("code1_1".to_string(), 9),
                ("code1_2".to_string(), 11),
                ("code1_ret".to_string(), 13),
                ("code2_0".to_string(), 14),
                ("code2_1".to_string(), 16),
                ("code2_2".to_string(), 18),
                ("code2_ret".to_string(), 20),
                ("code3_0".to_string(), 21),
                ("code3_1".to_string(), 23),
                ("code3_2".to_string(), 25),
                ("code3_ret".to_string(), 27),
                ("code4_0".to_string(), 28),
                ("code4_1".to_string(), 30),
                ("code4_2".to_string(), 32),
                ("code4_ret".to_string(), 34),
                ("routine0".to_string(), 108),
                ("routine0_0_putret_1_0".to_string(), 51),
                ("routine0_0_putret_1_1".to_string(), 53),
                ("routine0_0_putret_2_00".to_string(), 45),
                ("routine0_0_putret_2_01".to_string(), 47),
                ("routine0_0_putret_2_10".to_string(), 49),
                ("routine0_0_putret_x_0".to_string(), 35),
                ("routine0_0_putret_x_1".to_string(), 37),
                ("routine0_0_putret_x_10".to_string(), 39),
                ("routine0_0_putret_x_100".to_string(), 43),
                ("routine0_0_putret_x_11".to_string(), 41),
                ("routine0_1_putret_1_0".to_string(), 71),
                ("routine0_1_putret_1_1".to_string(), 73),
                ("routine0_1_putret_2_00".to_string(), 65),
                ("routine0_1_putret_2_01".to_string(), 67),
                ("routine0_1_putret_2_10".to_string(), 69),
                ("routine0_1_putret_x_0".to_string(), 55),
                ("routine0_1_putret_x_1".to_string(), 57),
                ("routine0_1_putret_x_10".to_string(), 59),
                ("routine0_1_putret_x_100".to_string(), 63),
                ("routine0_1_putret_x_11".to_string(), 61),
                ("routine0_2_putret_1_0".to_string(), 91),
                ("routine0_2_putret_1_1".to_string(), 93),
                ("routine0_2_putret_2_00".to_string(), 85),
                ("routine0_2_putret_2_01".to_string(), 87),
                ("routine0_2_putret_2_10".to_string(), 89),
                ("routine0_2_putret_x_0".to_string(), 75),
                ("routine0_2_putret_x_1".to_string(), 77),
                ("routine0_2_putret_x_10".to_string(), 79),
                ("routine0_2_putret_x_100".to_string(), 83),
                ("routine0_2_putret_x_11".to_string(), 81),
                ("routine0_a".to_string(), 108),
                ("routine0_b".to_string(), 109),
                ("routine0_c".to_string(), 110),
                ("routine0_return".to_string(), 95),
                ("routine0_return_id_0_0".to_string(), 96),
                ("routine0_return_id_1_0".to_string(), 98),
                ("routine0_return_id_1_1".to_string(), 100),
                ("routine0_return_id_2_00".to_string(), 102),
                ("routine0_return_id_2_01".to_string(), 104),
                ("routine0_return_id_2_10".to_string(), 106),
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_indjump() {
    let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
    builder.i(MINF_MRW0);
    builder.add_indjump(
        "indjump0",
        [
            "jump0".to_string(),
            "jump1".to_string(),
            "jump2".to_string(),
            "jump3".to_string(),
        ],
        false,
        false,
    );
    builder.add_indjump_l(
        "indjump1",
        [
            "jump0".to_string(),
            "jump1".to_string(),
            "jump2".to_string(),
            "jump3".to_string(),
        ],
        false,
        false,
    );
    builder.add_indjump_ll("indjump2", ["jump0", "jump2", "jump3"], true, false);
    builder.i((MINF_MR, builder.indjump("indjump0")));
    builder.i((MINF_MAR, builder.indjump("indjump1")));
    builder.i((MINF_MRW0, builder.indjump("indjump2")));
    builder.l("jump0");
    builder.i(MINF_TBRF);
    builder.i(MINF_STOP);
    builder.l("jump1");
    builder.i(MINF_MARW0);
    builder.i(MINF_STOP);
    builder.l("jump2");
    builder.i(MINF_TBRW1);
    builder.i(MINF_STOP);
    builder.l("jump3");
    builder.i(MINF_MRW0);
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MR, MINF_MR, 12, 12).into(),
                (MINF_MAR, MINF_MAR, 19, 19).into(),
                (MINF_MRW0, MINF_MRW0, 26, 26).into(),
                (MINF_TBRF, MINF_TBRF, 5, 5).into(),
                (MINF_STOP, MINF_STOP, 6, 6).into(),
                (MINF_MARW0, MINF_MARW0, 7, 7).into(),
                (MINF_STOP, MINF_STOP, 8, 8).into(),
                (MINF_TBRW1, MINF_TBRW1, 9, 9).into(),
                (MINF_STOP, MINF_STOP, 10, 10).into(),
                (MINF_MRW0, MINF_MRW0, 11, 11).into(),
                (MINF_STOP, MINF_STOP, 12, 12).into(),
                (MINF_MAB, MINF_MAB, 13, 13).into(),
                (MINF_MARW0, MINF_MARW0, 14, 14).into(),
                (MINF_MAB, MINF_MAB, 15, 17).into(),
                (MINF_MARW0, MINF_MARW0, 16, 16).into(),
                (MINF_MR, MINF_MR, 4, 6).into(),
                (MINF_MARW0, MINF_MARW0, 18, 18).into(),
                (MINF_MR, MINF_MR, 8, 10).into(),
                (MINF_MAB, MINF_MAB, 20, 20).into(),
                (MINF_MARW0, MINF_MARW0, 21, 21).into(),
                (MINF_MAB, MINF_MAB, 22, 24).into(),
                (MINF_MARW0, MINF_MARW0, 23, 23).into(),
                (MINF_MR, MINF_MR, 4, 6).into(),
                (MINF_MARW0, MINF_MARW0, 25, 25).into(),
                (MINF_MR, MINF_MR, 8, 10).into(),
                (MINF_TBB, MINF_TBB, 27, 27).into(),
                (MINF_TBRW0, MINF_TBRW0, 28, 28).into(),
                (MINF_TBB, MINF_TBB, 29, 31).into(),
                (MINF_TBRW0, MINF_TBRW0, 30, 30).into(),
                (MINF_MR, MINF_MR, 4, 8).into(),
                (MINF_TBRW0, MINF_TBRW0, 32, 32).into(),
                (MINF_MR, MINF_MR, 10, 10).into(),
            ],
            vec![
                ("indjump0_indjump".to_string(), 12),
                ("indjump0_indjump_id_0_0".to_string(), 13),
                ("indjump0_indjump_id_1_0".to_string(), 15),
                ("indjump0_indjump_id_1_1".to_string(), 17),
                ("indjump1_indjump".to_string(), 19),
                ("indjump1_indjump_id_0_0".to_string(), 20),
                ("indjump1_indjump_id_1_0".to_string(), 22),
                ("indjump1_indjump_id_1_1".to_string(), 24),
                ("indjump2_indjump".to_string(), 26),
                ("indjump2_indjump_id_0_0".to_string(), 27),
                ("indjump2_indjump_id_1_0".to_string(), 29),
                ("indjump2_indjump_id_1_1".to_string(), 31),
                ("jump0".to_string(), 4),
                ("jump1".to_string(), 6),
                ("jump2".to_string(), 8),
                ("jump3".to_string(), 10),
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_once_indjump() {
    let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
    builder.i(MINF_MRW0);
    builder.once_indjump(
        [
            "jump0".to_string(),
            "jump1".to_string(),
            "jump2".to_string(),
            "jump3".to_string(),
        ],
        false,
        false,
    );
    builder.once_indjump(
        [
            "jump0".to_string(),
            "jump1".to_string(),
            "jump2".to_string(),
            "jump3".to_string(),
        ],
        false,
        false,
    );
    builder.once_indjump_l(["jump0", "jump2", "jump3"], true, false);
    builder.l("jump0");
    builder.i(MINF_TBRF);
    builder.i(MINF_STOP);
    builder.l("jump1");
    builder.i(MINF_MARW0);
    builder.i(MINF_STOP);
    builder.l("jump2");
    builder.i(MINF_TBRW1);
    builder.i(MINF_STOP);
    builder.l("jump3");
    builder.i(MINF_MRW0);
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MAB, MINF_MAB, 2, 2).into(),
                (MINF_MARW0, MINF_MARW0, 3, 3).into(),
                (MINF_MAB, MINF_MAB, 4, 6).into(),
                (MINF_MARW0, MINF_MARW0, 5, 5).into(),
                (MINF_MR, MINF_MR, 22, 24).into(),
                (MINF_MARW0, MINF_MARW0, 7, 7).into(),
                (MINF_MR, MINF_MR, 26, 28).into(),
                (MINF_MAB, MINF_MAB, 9, 9).into(),
                (MINF_MARW0, MINF_MARW0, 10, 10).into(),
                (MINF_MAB, MINF_MAB, 11, 13).into(),
                (MINF_MARW0, MINF_MARW0, 12, 12).into(),
                (MINF_MR, MINF_MR, 22, 24).into(),
                (MINF_MARW0, MINF_MARW0, 14, 14).into(),
                (MINF_MR, MINF_MR, 26, 28).into(),
                (MINF_TBB, MINF_TBB, 16, 16).into(),
                (MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
                (MINF_TBB, MINF_TBB, 18, 20).into(),
                (MINF_TBRW0, MINF_TBRW0, 19, 19).into(),
                (MINF_MR, MINF_MR, 22, 26).into(),
                (MINF_TBRW0, MINF_TBRW0, 21, 21).into(),
                (MINF_MR, MINF_MR, 28, 28).into(),
                (MINF_TBRF, MINF_TBRF, 23, 23).into(),
                (MINF_STOP, MINF_STOP, 24, 24).into(),
                (MINF_MARW0, MINF_MARW0, 25, 25).into(),
                (MINF_STOP, MINF_STOP, 26, 26).into(),
                (MINF_TBRW1, MINF_TBRW1, 27, 27).into(),
                (MINF_STOP, MINF_STOP, 28, 28).into(),
                (MINF_MRW0, MINF_MRW0, 29, 29).into(),
                (MINF_STOP, MINF_STOP, 0, 0).into(),
            ],
            vec![
                ("__hb_once_indjump_15_indjump".to_string(), 15),
                ("__hb_once_indjump_15_indjump_id_0_0".to_string(), 16),
                ("__hb_once_indjump_15_indjump_id_1_0".to_string(), 18),
                ("__hb_once_indjump_15_indjump_id_1_1".to_string(), 20),
                ("__hb_once_indjump_1_indjump".to_string(), 1),
                ("__hb_once_indjump_1_indjump_id_0_0".to_string(), 2),
                ("__hb_once_indjump_1_indjump_id_1_0".to_string(), 4),
                ("__hb_once_indjump_1_indjump_id_1_1".to_string(), 6),
                ("__hb_once_indjump_8_indjump".to_string(), 8),
                ("__hb_once_indjump_8_indjump_id_0_0".to_string(), 9),
                ("__hb_once_indjump_8_indjump_id_1_0".to_string(), 11),
                ("__hb_once_indjump_8_indjump_id_1_1".to_string(), 13),
                ("jump0".to_string(), 22),
                ("jump1".to_string(), 24),
                ("jump2".to_string(), 26),
                ("jump3".to_string(), 28),
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_once_indjump_jb() {
    // with jump_bits setup
    let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
    builder.i(MINF_MRW0);
    builder.once_indjump_jb(
        [
            "jump0".to_string(),
            "jump1".to_string(),
            "jump2".to_string(),
            "jump3".to_string(),
        ],
        false,
        false,
        Some(3),
    );
    builder.once_indjump_jb(
        [
            "jump0".to_string(),
            "jump1".to_string(),
            "jump2".to_string(),
            "jump3".to_string(),
        ],
        false,
        false,
        Some(4),
    );
    builder.once_indjump_jb_l(["jump0", "jump2", "jump3"], true, false, Some(2));
    builder.l("jump0");
    builder.i(MINF_TBRF);
    builder.i(MINF_STOP);
    builder.l("jump1");
    builder.i(MINF_MARW0);
    builder.i(MINF_STOP);
    builder.l("jump2");
    builder.i(MINF_TBRW1);
    builder.i(MINF_STOP);
    builder.l("jump3");
    builder.i(MINF_MRW0);
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MAB, MINF_MAB, 2, 2).into(),
                (MINF_MARW0, MINF_MARW0, 3, 3).into(),
                (MINF_MAB, MINF_MAB, 4, 4).into(),
                (MINF_MARW0, MINF_MARW0, 5, 5).into(),
                (MINF_MAB, MINF_MAB, 6, 8).into(),
                (MINF_MARW0, MINF_MARW0, 7, 7).into(),
                (MINF_MR, MINF_MR, 28, 30).into(),
                (MINF_MARW0, MINF_MARW0, 9, 9).into(),
                (MINF_MR, MINF_MR, 32, 34).into(),
                (MINF_MAB, MINF_MAB, 11, 11).into(),
                (MINF_MARW0, MINF_MARW0, 12, 12).into(),
                (MINF_MAB, MINF_MAB, 13, 13).into(),
                (MINF_MARW0, MINF_MARW0, 14, 14).into(),
                (MINF_MAB, MINF_MAB, 15, 15).into(),
                (MINF_MARW0, MINF_MARW0, 16, 16).into(),
                (MINF_MAB, MINF_MAB, 17, 19).into(),
                (MINF_MARW0, MINF_MARW0, 18, 18).into(),
                (MINF_MR, MINF_MR, 28, 30).into(),
                (MINF_MARW0, MINF_MARW0, 20, 20).into(),
                (MINF_MR, MINF_MR, 32, 34).into(),
                (MINF_TBB, MINF_TBB, 22, 22).into(),
                (MINF_TBRW0, MINF_TBRW0, 23, 23).into(),
                (MINF_TBB, MINF_TBB, 24, 26).into(),
                (MINF_TBRW0, MINF_TBRW0, 25, 25).into(),
                (MINF_MR, MINF_MR, 28, 32).into(),
                (MINF_TBRW0, MINF_TBRW0, 27, 27).into(),
                (MINF_MR, MINF_MR, 34, 34).into(),
                (MINF_TBRF, MINF_TBRF, 29, 29).into(),
                (MINF_STOP, MINF_STOP, 30, 30).into(),
                (MINF_MARW0, MINF_MARW0, 31, 31).into(),
                (MINF_STOP, MINF_STOP, 32, 32).into(),
                (MINF_TBRW1, MINF_TBRW1, 33, 33).into(),
                (MINF_STOP, MINF_STOP, 34, 34).into(),
                (MINF_MRW0, MINF_MRW0, 35, 35).into(),
                (MINF_STOP, MINF_STOP, 0, 0).into(),
            ],
            vec![
                ("__hb_once_indjump_10_indjump".to_string(), 10),
                ("__hb_once_indjump_10_indjump_id_0_0".to_string(), 11),
                ("__hb_once_indjump_10_indjump_id_1_0".to_string(), 13),
                ("__hb_once_indjump_10_indjump_id_2_00".to_string(), 15),
                ("__hb_once_indjump_10_indjump_id_3_000".to_string(), 17),
                ("__hb_once_indjump_10_indjump_id_3_001".to_string(), 19),
                ("__hb_once_indjump_1_indjump".to_string(), 1),
                ("__hb_once_indjump_1_indjump_id_0_0".to_string(), 2),
                ("__hb_once_indjump_1_indjump_id_1_0".to_string(), 4),
                ("__hb_once_indjump_1_indjump_id_2_00".to_string(), 6),
                ("__hb_once_indjump_1_indjump_id_2_01".to_string(), 8),
                ("__hb_once_indjump_21_indjump".to_string(), 21),
                ("__hb_once_indjump_21_indjump_id_0_0".to_string(), 22),
                ("__hb_once_indjump_21_indjump_id_1_0".to_string(), 24),
                ("__hb_once_indjump_21_indjump_id_1_1".to_string(), 26),
                ("jump0".to_string(), 28),
                ("jump1".to_string(), 30),
                ("jump2".to_string(), 32),
                ("jump3".to_string(), 34),
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_longdata() {
    let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
    builder.add_longdata_handler("md", false, 1);
    builder.add_longdata_handler("td", true, 1);
    let l1 = builder.add_longdata("md", (&[143, 54], 0, 0), "j1");
    let l2 = builder.add_longdata("td", (&[61, 14], 0, 0), "j2");
    builder.i((MINF_MR, l1));
    builder.l("j1");
    builder.i((MINF_MR, l2));
    builder.l("j2");
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MR, MINF_MR, 47, 47),
                (MINF_MR, MINF_MR, 93, 93).into(),
                (MINF_STOP, MINF_STOP, 3, 3).into(),
                (MINF_MARW1, MINF_MARW1, 4, 4).into(),
                (MINF_MARF, MINF_MARF, 5, 5).into(),
                (MINF_MARW1, MINF_MARW1, 6, 6).into(),
                (MINF_MARF, MINF_MARF, 7, 7).into(),
                (MINF_MARW0, MINF_MARW0, 8, 8).into(),
                (MINF_MARF, MINF_MARF, 9, 9).into(),
                (MINF_MARW0, MINF_MARW0, 10, 10).into(),
                (MINF_MARF, MINF_MARF, 12, 12).into(),
                (MINF_MR, MINF_MR, 3, 3).into(),
                (MINF_MR, MINF_MR, 44, 44).into(),
                (MINF_MARW0, MINF_MARW0, 14, 14).into(),
                (MINF_MARF, MINF_MARF, 15, 15).into(),
                (MINF_MARW1, MINF_MARW1, 16, 16).into(),
                (MINF_MARF, MINF_MARF, 17, 17).into(),
                (MINF_MARW1, MINF_MARW1, 18, 18).into(),
                (MINF_MARF, MINF_MARF, 19, 19).into(),
                (MINF_MARW0, MINF_MARW0, 20, 20).into(),
                (MINF_MARF, MINF_MARF, 22, 22).into(),
                (MINF_MR, MINF_MR, 13, 13).into(),
                (MINF_MR, MINF_MR, 11, 11).into(),
                (MINF_MARW0, MINF_MARW0, 24, 24).into(),
                (MINF_MARF, MINF_MARF, 25, 25).into(),
                (MINF_MARW0, MINF_MARW0, 26, 26).into(),
                (MINF_MARF, MINF_MARF, 27, 27).into(),
                (MINF_MARW0, MINF_MARW0, 28, 28).into(),
                (MINF_MARF, MINF_MARF, 29, 29).into(),
                (MINF_MARW1, MINF_MARW1, 30, 30).into(),
                (MINF_MARF, MINF_MARF, 32, 32).into(),
                (MINF_MR, MINF_MR, 23, 23).into(),
                (MINF_MR, MINF_MR, 46, 46).into(),
                (MINF_MARW1, MINF_MARW1, 34, 34).into(),
                (MINF_MARF, MINF_MARF, 35, 35).into(),
                (MINF_MARW1, MINF_MARW1, 36, 36).into(),
                (MINF_MARF, MINF_MARF, 37, 37).into(),
                (MINF_MARW1, MINF_MARW1, 38, 38).into(),
                (MINF_MARF, MINF_MARF, 39, 39).into(),
                (MINF_MARW1, MINF_MARW1, 40, 40).into(),
                (MINF_MARF, MINF_MARF, 42, 42).into(),
                (MINF_MR, MINF_MR, 33, 33).into(),
                (MINF_MR, MINF_MR, 31, 31).into(),
                (MINF_MR, MINF_MR, 21, 21).into(),
                (MINF_MR, MINF_MR, 48, 48).into(),
                (MINF_MR, MINF_MR, 41, 41).into(),
                (MINF_MR, MINF_MR, 43, 43).into(),
                (MINF_MR, MINF_MR, 45, 45).into(),
                (MINF_MR, MINF_MR, 1, 1).into(),
                (MINF_TBRW0, MINF_TBRW0, 50, 50).into(),
                (MINF_TBRF, MINF_TBRF, 51, 51).into(),
                (MINF_TBRW0, MINF_TBRW0, 52, 52).into(),
                (MINF_TBRF, MINF_TBRF, 53, 53).into(),
                (MINF_TBRW0, MINF_TBRW0, 54, 54).into(),
                (MINF_TBRF, MINF_TBRF, 55, 55).into(),
                (MINF_TBRW0, MINF_TBRW0, 56, 56).into(),
                (MINF_TBRF, MINF_TBRF, 58, 58).into(),
                (MINF_MR, MINF_MR, 49, 49).into(),
                (MINF_MR, MINF_MR, 90, 90).into(),
                (MINF_TBRW1, MINF_TBRW1, 60, 60).into(),
                (MINF_TBRF, MINF_TBRF, 61, 61).into(),
                (MINF_TBRW1, MINF_TBRW1, 62, 62).into(),
                (MINF_TBRF, MINF_TBRF, 63, 63).into(),
                (MINF_TBRW0, MINF_TBRW0, 64, 64).into(),
                (MINF_TBRF, MINF_TBRF, 65, 65).into(),
                (MINF_TBRW0, MINF_TBRW0, 66, 66).into(),
                (MINF_TBRF, MINF_TBRF, 68, 68).into(),
                (MINF_MR, MINF_MR, 59, 59).into(),
                (MINF_MR, MINF_MR, 92, 92).into(),
                (MINF_TBRW1, MINF_TBRW1, 70, 70).into(),
                (MINF_TBRF, MINF_TBRF, 71, 71).into(),
                (MINF_TBRW0, MINF_TBRW0, 72, 72).into(),
                (MINF_TBRF, MINF_TBRF, 73, 73).into(),
                (MINF_TBRW1, MINF_TBRW1, 74, 74).into(),
                (MINF_TBRF, MINF_TBRF, 75, 75).into(),
                (MINF_TBRW1, MINF_TBRW1, 76, 76).into(),
                (MINF_TBRF, MINF_TBRF, 78, 78).into(),
                (MINF_MR, MINF_MR, 69, 69).into(),
                (MINF_MR, MINF_MR, 67, 67).into(),
                (MINF_TBRW0, MINF_TBRW0, 80, 80).into(),
                (MINF_TBRF, MINF_TBRF, 81, 81).into(),
                (MINF_TBRW1, MINF_TBRW1, 82, 82).into(),
                (MINF_TBRF, MINF_TBRF, 83, 83).into(),
                (MINF_TBRW1, MINF_TBRW1, 84, 84).into(),
                (MINF_TBRF, MINF_TBRF, 85, 85).into(),
                (MINF_TBRW1, MINF_TBRW1, 86, 86).into(),
                (MINF_TBRF, MINF_TBRF, 88, 88).into(),
                (MINF_MR, MINF_MR, 79, 79).into(),
                (MINF_MR, MINF_MR, 57, 57).into(),
                (MINF_MR, MINF_MR, 87, 87).into(),
                (MINF_MR, MINF_MR, 94, 94).into(),
                (MINF_MR, MINF_MR, 77, 77).into(),
                (MINF_MR, MINF_MR, 89, 89).into(),
                (MINF_MR, MINF_MR, 91, 91).into(),
                (MINF_MR, MINF_MR, 2, 2).into(),
            ],
            vec![
                ("j1".to_string(), 1),
                ("j2".to_string(), 2),
                ("md_chunk_368f_16_0_putret_x_0".to_string(), 47),
                ("md_chunk_368f_16_return".to_string(), 48),
                ("md_chunk_36_8_0_putret_x_0".to_string(), 43),
                ("md_chunk_36_8_return".to_string(), 44),
                ("md_chunk_3_4".to_string(), 3),
                ("md_chunk_3_4_0_putret_x_0".to_string(), 11),
                ("md_chunk_3_4_return".to_string(), 12),
                ("md_chunk_6_4".to_string(), 13),
                ("md_chunk_6_4_0_putret_x_0".to_string(), 21),
                ("md_chunk_6_4_return".to_string(), 22),
                ("md_chunk_8_4".to_string(), 23),
                ("md_chunk_8_4_0_putret_x_0".to_string(), 31),
                ("md_chunk_8_4_return".to_string(), 32),
                ("md_chunk_8f_8_0_putret_x_0".to_string(), 45),
                ("md_chunk_8f_8_return".to_string(), 46),
                ("md_chunk_f_4".to_string(), 33),
                ("md_chunk_f_4_0_putret_x_0".to_string(), 41),
                ("md_chunk_f_4_return".to_string(), 42),
                ("td_chunk_0_4".to_string(), 49),
                ("td_chunk_0_4_0_putret_x_0".to_string(), 57),
                ("td_chunk_0_4_return".to_string(), 58),
                ("td_chunk_3_4".to_string(), 59),
                ("td_chunk_3_4_0_putret_x_0".to_string(), 67),
                ("td_chunk_3_4_return".to_string(), 68),
                ("td_chunk_3d_8_0_putret_x_0".to_string(), 91),
                ("td_chunk_3d_8_return".to_string(), 92),
                ("td_chunk_d_4".to_string(), 69),
                ("td_chunk_d_4_0_putret_x_0".to_string(), 77),
                ("td_chunk_d_4_return".to_string(), 78),
                ("td_chunk_e3d_16_0_putret_x_0".to_string(), 93),
                ("td_chunk_e3d_16_return".to_string(), 94),
                ("td_chunk_e_4".to_string(), 79),
                ("td_chunk_e_4_0_putret_x_0".to_string(), 87),
                ("td_chunk_e_4_return".to_string(), 88),
                ("td_chunk_e_8_0_putret_x_0".to_string(), 89),
                ("td_chunk_e_8_return".to_string(), 90),
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_longdata_calls() {
    let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
    builder.add_longdata_handler("md", false, 2);
    builder.add_longdata_handler("td", true, 1);
    builder.ld_call_01("td", (&[], 12, 4), MINF_MR);
    builder.ld_call("td", (&[], 12, 4), MINF_TBR, MINF_MAR);
    builder.ld_call_fr0_01("td", (&[], 13, 4), MINF_MARF, "stop");
    builder.ld_call_fr0("td", (&[], 11, 4), MINF_TBRW0, MINF_MARW1, "stop");
    builder.ld_call_fr1_01("td", (&[], 2, 4), MINF_MARW1, "stop2");
    builder.ld_call_fr1("td", (&[], 7, 4), MINF_TBRF, MINF_MAB, "stop2");
    builder.ld_call_2_01("td", (&[], 9, 4), (&[], 5, 4), MINF_MARW0);
    builder.ld_call_2("td", (&[], 8, 4), (&[], 6, 4), MINF_TBRW0, MINF_TBRF);
    builder.ld_call_2x_01("td", "md", (&[], 7, 4), (&[], 10, 4), MINF_MARW0);
    builder.ld_call_2x("md", "td", (&[], 9, 4), (&[], 5, 4), MINF_TBRW0, MINF_MARW1);
    builder.l("stop");
    builder.i(MINF_STOP);
    builder.l("stop2");
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MR, MINF_MR, 128, 128),
                (MINF_TBR, MINF_MAR, 130, 130).into(),
                (MINF_MARF, MINF_MARF, 143, 10).into(),
                (MINF_TBRW0, MINF_MARW1, 118, 10).into(),
                (MINF_MARW1, MINF_MARW1, 11, 48).into(),
                (MINF_TBRF, MINF_MAB, 11, 83).into(),
                (MINF_MARW0, MINF_MARW0, 108, 58).into(),
                (MINF_TBRW0, MINF_TBRF, 98, 73).into(),
                (MINF_MARW0, MINF_MARW0, 85, 38).into(),
                (MINF_TBRW0, MINF_MARW1, 24, 60).into(),
                (MINF_STOP, MINF_STOP, 11, 11).into(),
                (MINF_STOP, MINF_STOP, 12, 12).into(),
                (MINF_MARW1, MINF_MARW1, 13, 13).into(),
                (MINF_MARF, MINF_MARF, 14, 14).into(),
                (MINF_MARF, MINF_MARF, 15, 15).into(),
                (MINF_MARW0, MINF_MARW0, 16, 16).into(),
                (MINF_MARF, MINF_MARF, 17, 17).into(),
                (MINF_MARF, MINF_MARF, 18, 18).into(),
                (MINF_MARW0, MINF_MARW0, 19, 19).into(),
                (MINF_MARF, MINF_MARF, 20, 20).into(),
                (MINF_MARF, MINF_MARF, 21, 21).into(),
                (MINF_MARW1, MINF_MARW1, 22, 22).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MARF, MINF_MARF, 25, 25).into(),
                (MINF_MR, MINF_MR, 12, 12).into(),
                (MINF_MR, MINF_MR, 10, 10).into(),
                (MINF_MARW0, MINF_MARW0, 27, 27).into(),
                (MINF_MARF, MINF_MARF, 28, 28).into(),
                (MINF_MARF, MINF_MARF, 29, 29).into(),
                (MINF_MARW1, MINF_MARW1, 30, 30).into(),
                (MINF_MARF, MINF_MARF, 31, 31).into(),
                (MINF_MARF, MINF_MARF, 32, 32).into(),
                (MINF_MARW0, MINF_MARW0, 33, 33).into(),
                (MINF_MARF, MINF_MARF, 34, 34).into(),
                (MINF_MARF, MINF_MARF, 35, 35).into(),
                (MINF_MARW1, MINF_MARW1, 36, 36).into(),
                (MINF_MARF, MINF_MARF, 37, 37).into(),
                (MINF_MARF, MINF_MARF, 39, 39).into(),
                (MINF_MR, MINF_MR, 26, 26).into(),
                (MINF_MR, MINF_MR, 9, 9).into(),
                (MINF_TBRW0, MINF_TBRW0, 41, 41).into(),
                (MINF_TBRF, MINF_TBRF, 42, 42).into(),
                (MINF_TBRW1, MINF_TBRW1, 43, 43).into(),
                (MINF_TBRF, MINF_TBRF, 44, 44).into(),
                (MINF_TBRW0, MINF_TBRW0, 45, 45).into(),
                (MINF_TBRF, MINF_TBRF, 46, 46).into(),
                (MINF_TBRW0, MINF_TBRW0, 47, 47).into(),
                (MINF_TBRF, MINF_TBRF, 49, 49).into(),
                (MINF_MR, MINF_MR, 40, 40).into(),
                (MINF_MR, MINF_MR, 5, 5).into(),
                (MINF_TBRW1, MINF_TBRW1, 51, 51).into(),
                (MINF_TBRF, MINF_TBRF, 52, 52).into(),
                (MINF_TBRW0, MINF_TBRW0, 53, 53).into(),
                (MINF_TBRF, MINF_TBRF, 54, 54).into(),
                (MINF_TBRW1, MINF_TBRW1, 55, 55).into(),
                (MINF_TBRF, MINF_TBRF, 56, 56).into(),
                (MINF_TBRW0, MINF_TBRW0, 57, 57).into(),
                (MINF_TBRF, MINF_TBRF, 62, 62).into(),
                (MINF_MARW0, MINF_MARW0, 59, 59).into(),
                (MINF_MARF, MINF_MARF, 50, 50).into(),
                (MINF_MARW1, MINF_MARW1, 61, 61).into(),
                (MINF_MARF, MINF_MARF, 50, 50).into(),
                (MINF_MAB, MINF_MAB, 63, 63).into(),
                (MINF_MARW0, MINF_MARW0, 64, 64).into(),
                (MINF_MR, MINF_MR, 7, 10).into(),
                (MINF_TBRW0, MINF_TBRW0, 66, 66).into(),
                (MINF_TBRF, MINF_TBRF, 67, 67).into(),
                (MINF_TBRW1, MINF_TBRW1, 68, 68).into(),
                (MINF_TBRF, MINF_TBRF, 69, 69).into(),
                (MINF_TBRW1, MINF_TBRW1, 70, 70).into(),
                (MINF_TBRF, MINF_TBRF, 71, 71).into(),
                (MINF_TBRW0, MINF_TBRW0, 72, 72).into(),
                (MINF_TBRF, MINF_TBRF, 74, 74).into(),
                (MINF_MR, MINF_MR, 65, 65).into(),
                (MINF_MR, MINF_MR, 8, 8).into(),
                (MINF_TBRW1, MINF_TBRW1, 76, 76).into(),
                (MINF_TBRF, MINF_TBRF, 77, 77).into(),
                (MINF_TBRW1, MINF_TBRW1, 78, 78).into(),
                (MINF_TBRF, MINF_TBRF, 79, 79).into(),
                (MINF_TBRW1, MINF_TBRW1, 80, 80).into(),
                (MINF_TBRF, MINF_TBRF, 81, 81).into(),
                (MINF_TBRW0, MINF_TBRW0, 82, 82).into(),
                (MINF_TBRF, MINF_TBRF, 87, 87).into(),
                (MINF_MARW0, MINF_MARW0, 84, 84).into(),
                (MINF_MARF, MINF_MARF, 75, 75).into(),
                (MINF_MARW1, MINF_MARW1, 86, 86).into(),
                (MINF_MARF, MINF_MARF, 75, 75).into(),
                (MINF_MAB, MINF_MAB, 88, 88).into(),
                (MINF_MARW0, MINF_MARW0, 89, 89).into(),
                (MINF_MR, MINF_MR, 6, 9).into(),
                (MINF_TBRW0, MINF_TBRW0, 91, 91).into(),
                (MINF_TBRF, MINF_TBRF, 92, 92).into(),
                (MINF_TBRW0, MINF_TBRW0, 93, 93).into(),
                (MINF_TBRF, MINF_TBRF, 94, 94).into(),
                (MINF_TBRW0, MINF_TBRW0, 95, 95).into(),
                (MINF_TBRF, MINF_TBRF, 96, 96).into(),
                (MINF_TBRW1, MINF_TBRW1, 97, 97).into(),
                (MINF_TBRF, MINF_TBRF, 99, 99).into(),
                (MINF_MR, MINF_MR, 90, 90).into(),
                (MINF_MR, MINF_MR, 8, 8).into(),
                (MINF_TBRW1, MINF_TBRW1, 101, 101).into(),
                (MINF_TBRF, MINF_TBRF, 102, 102).into(),
                (MINF_TBRW0, MINF_TBRW0, 103, 103).into(),
                (MINF_TBRF, MINF_TBRF, 104, 104).into(),
                (MINF_TBRW0, MINF_TBRW0, 105, 105).into(),
                (MINF_TBRF, MINF_TBRF, 106, 106).into(),
                (MINF_TBRW1, MINF_TBRW1, 107, 107).into(),
                (MINF_TBRF, MINF_TBRF, 109, 109).into(),
                (MINF_MR, MINF_MR, 100, 100).into(),
                (MINF_MR, MINF_MR, 7, 7).into(),
                (MINF_TBRW1, MINF_TBRW1, 111, 111).into(),
                (MINF_TBRF, MINF_TBRF, 112, 112).into(),
                (MINF_TBRW1, MINF_TBRW1, 113, 113).into(),
                (MINF_TBRF, MINF_TBRF, 114, 114).into(),
                (MINF_TBRW0, MINF_TBRW0, 115, 115).into(),
                (MINF_TBRF, MINF_TBRF, 116, 116).into(),
                (MINF_TBRW1, MINF_TBRW1, 117, 117).into(),
                (MINF_TBRF, MINF_TBRF, 119, 119).into(),
                (MINF_MR, MINF_MR, 110, 110).into(),
                (MINF_MR, MINF_MR, 4, 4).into(),
                (MINF_TBRW0, MINF_TBRW0, 121, 121).into(),
                (MINF_TBRF, MINF_TBRF, 122, 122).into(),
                (MINF_TBRW0, MINF_TBRW0, 123, 123).into(),
                (MINF_TBRF, MINF_TBRF, 124, 124).into(),
                (MINF_TBRW1, MINF_TBRW1, 125, 125).into(),
                (MINF_TBRF, MINF_TBRF, 126, 126).into(),
                (MINF_TBRW1, MINF_TBRW1, 127, 127).into(),
                (MINF_TBRF, MINF_TBRF, 132, 132).into(),
                (MINF_MARW0, MINF_MARW0, 129, 129).into(),
                (MINF_MARF, MINF_MARF, 120, 120).into(),
                (MINF_MARW1, MINF_MARW1, 131, 131).into(),
                (MINF_MARF, MINF_MARF, 120, 120).into(),
                (MINF_MAB, MINF_MAB, 133, 133).into(),
                (MINF_MARW0, MINF_MARW0, 134, 134).into(),
                (MINF_MR, MINF_MR, 1, 2).into(),
                (MINF_TBRW1, MINF_TBRW1, 136, 136).into(),
                (MINF_TBRF, MINF_TBRF, 137, 137).into(),
                (MINF_TBRW0, MINF_TBRW0, 138, 138).into(),
                (MINF_TBRF, MINF_TBRF, 139, 139).into(),
                (MINF_TBRW1, MINF_TBRW1, 140, 140).into(),
                (MINF_TBRF, MINF_TBRF, 141, 141).into(),
                (MINF_TBRW1, MINF_TBRW1, 142, 142).into(),
                (MINF_TBRF, MINF_TBRF, 144, 144).into(),
                (MINF_MR, MINF_MR, 135, 135).into(),
                (MINF_MR, MINF_MR, 3, 3).into(),
            ],
            vec![
                ("md_chunk_9_4".to_string(), 12),
                ("md_chunk_9_4_0_putret_x_0".to_string(), 24),
                ("md_chunk_9_4_return".to_string(), 25),
                ("md_chunk_a_4".to_string(), 26),
                ("md_chunk_a_4_0_putret_x_0".to_string(), 38),
                ("md_chunk_a_4_return".to_string(), 39),
                ("md_next_0".to_string(), 10),
                ("stop".to_string(), 10),
                ("stop2".to_string(), 11),
                ("td_chunk_2_4".to_string(), 40),
                ("td_chunk_2_4_0_putret_x_0".to_string(), 48),
                ("td_chunk_2_4_return".to_string(), 49),
                ("td_chunk_5_4".to_string(), 50),
                ("td_chunk_5_4_0_putret_x_0".to_string(), 58),
                ("td_chunk_5_4_0_putret_x_1".to_string(), 60),
                ("td_chunk_5_4_return".to_string(), 62),
                ("td_chunk_5_4_return_id_0_0".to_string(), 63),
                ("td_chunk_6_4".to_string(), 65),
                ("td_chunk_6_4_0_putret_x_0".to_string(), 73),
                ("td_chunk_6_4_return".to_string(), 74),
                ("td_chunk_7_4".to_string(), 75),
                ("td_chunk_7_4_0_putret_x_0".to_string(), 83),
                ("td_chunk_7_4_0_putret_x_1".to_string(), 85),
                ("td_chunk_7_4_return".to_string(), 87),
                ("td_chunk_7_4_return_id_0_0".to_string(), 88),
                ("td_chunk_8_4".to_string(), 90),
                ("td_chunk_8_4_0_putret_x_0".to_string(), 98),
                ("td_chunk_8_4_return".to_string(), 99),
                ("td_chunk_9_4".to_string(), 100),
                ("td_chunk_9_4_0_putret_x_0".to_string(), 108),
                ("td_chunk_9_4_return".to_string(), 109),
                ("td_chunk_b_4".to_string(), 110),
                ("td_chunk_b_4_0_putret_x_0".to_string(), 118),
                ("td_chunk_b_4_return".to_string(), 119),
                ("td_chunk_c_4".to_string(), 120),
                ("td_chunk_c_4_0_putret_x_0".to_string(), 128),
                ("td_chunk_c_4_0_putret_x_1".to_string(), 130),
                ("td_chunk_c_4_return".to_string(), 132),
                ("td_chunk_c_4_return_id_0_0".to_string(), 133),
                ("td_chunk_d_4".to_string(), 135),
                ("td_chunk_d_4_0_putret_x_0".to_string(), 143),
                ("td_chunk_d_4_return".to_string(), 144),
                ("td_next_0".to_string(), 1),
                ("td_next_1".to_string(), 2),
                ("td_next_2".to_string(), 3),
                ("td_next_3".to_string(), 4),
                ("td_next_4".to_string(), 5),
                ("td_next_5".to_string(), 6),
                ("td_next_6".to_string(), 7),
                ("td_next_7".to_string(), 8),
                ("td_next_8".to_string(), 9),
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_data() {
    let mut builder = mi_simple_hbuilder_new(Some(3), Some(5));
    builder.add_data_handler_ll("dh0", 5, 1, "end", true);
    builder.add_data_handler_ll("dh1", 5, 1, "end2", false);
    let j0 = builder.put_data("dh0", 17);
    let j1 = builder.put_data("dh0", 19);
    let j2 = builder.put_data("dh1", 26);
    let j3 = builder.put_data("dh1", 21);
    builder.i((MINF_MR, "t0", "t1"));
    builder.l("t0");
    builder.i((MINF_MR, j0, j1));
    builder.l("t1");
    builder.i((MINF_MR, j2, j3));
    builder.l("end");
    builder.i(MINF_STOP);
    builder.l("end2");
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MR, MINF_MR, 1, 2),
                (MINF_MR, MINF_MR, 5, 7).into(),
                (MINF_MR, MINF_MR, 21, 19).into(),
                (MINF_STOP, MINF_STOP, 4, 4).into(),
                (MINF_STOP, MINF_STOP, 5, 5).into(),
                (MINF_TBRW1, MINF_TBRW1, 6, 6).into(),
                (MINF_TBRF, MINF_TBRF, 9, 9).into(),
                (MINF_TBRW1, MINF_TBRW1, 8, 8).into(),
                (MINF_TBRF, MINF_TBRF, 11, 11).into(),
                (MINF_TBRW0, MINF_TBRW0, 10, 10).into(),
                (MINF_TBRF, MINF_TBRF, 13, 13).into(),
                (MINF_TBRW1, MINF_TBRW1, 12, 12).into(),
                (MINF_TBRF, MINF_TBRF, 13, 13).into(),
                (MINF_TBRW0, MINF_TBRW0, 14, 14).into(),
                (MINF_TBRF, MINF_TBRF, 15, 15).into(),
                (MINF_TBRW0, MINF_TBRW0, 16, 16).into(),
                (MINF_TBRF, MINF_TBRF, 17, 17).into(),
                (MINF_TBRW1, MINF_TBRW1, 18, 18).into(),
                (MINF_TBRF, MINF_TBRF, 3, 3).into(),
                (MINF_MARW1, MINF_MARW1, 20, 20).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MARW0, MINF_MARW0, 22, 22).into(),
                (MINF_MARF, MINF_MARF, 25, 25).into(),
                (MINF_MARW0, MINF_MARW0, 24, 24).into(),
                (MINF_MARF, MINF_MARF, 27, 27).into(),
                (MINF_MARW1, MINF_MARW1, 26, 26).into(),
                (MINF_MARF, MINF_MARF, 29, 29).into(),
                (MINF_MARW1, MINF_MARW1, 28, 28).into(),
                (MINF_MARF, MINF_MARF, 31, 31).into(),
                (MINF_MARW0, MINF_MARW0, 30, 30).into(),
                (MINF_MARF, MINF_MARF, 33, 33).into(),
                (MINF_MARW0, MINF_MARW0, 32, 32).into(),
                (MINF_MARF, MINF_MARF, 35, 35).into(),
                (MINF_MARW1, MINF_MARW1, 34, 34).into(),
                (MINF_MARF, MINF_MARF, 35, 35).into(),
                (MINF_MARW1, MINF_MARW1, 36, 36).into(),
                (MINF_MARF, MINF_MARF, 4, 4).into(),
            ],
            vec![
                ("dh0_putdata_1_1".to_string(), 17),
                ("dh0_putdata_2_10".to_string(), 15),
                ("dh0_putdata_3_100".to_string(), 13),
                ("dh0_putdata_4_1000".to_string(), 9),
                ("dh0_putdata_4_1001".to_string(), 11),
                ("dh0_putdata_5_10001".to_string(), 5),
                ("dh0_putdata_5_10011".to_string(), 7),
                ("dh1_putdata_1_1".to_string(), 35),
                ("dh1_putdata_2_10".to_string(), 31),
                ("dh1_putdata_2_11".to_string(), 33),
                ("dh1_putdata_3_101".to_string(), 27),
                ("dh1_putdata_3_110".to_string(), 29),
                ("dh1_putdata_4_1010".to_string(), 23),
                ("dh1_putdata_4_1101".to_string(), 25),
                ("dh1_putdata_5_10101".to_string(), 19),
                ("dh1_putdata_5_11010".to_string(), 21),
                ("end".to_string(), 3),
                ("end2".to_string(), 4),
                ("t0".to_string(), 1),
                ("t1".to_string(), 2),
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_sv_1() {
    let mut builder = mi_std_sv_hbuilder_new_1(Some(1), 1);
    {
        let (func1b, ret) = builder.add_routine("func1", false);
        let mut func1b = func1b.borrow_mut();
        func1b.i(MINF_MR);
        func1b.i(MINF_TBRF);
        func1b.i(MINF_TBB);
        func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
    }
    {
        let (func2b, ret) = builder.add_routine("func2", true);
        let mut func2b = func2b.borrow_mut();
        func2b.i(MINF_MRW0);
        func2b.i(MINF_MAB);
        func2b.i((MINF_MARW0, MINF_MARW1));
        func2b.i((MINF_MR, ret));
    }
    builder.i(MINF_MRW0);
    builder.call_01("func1", MINF_MR);
    builder.i(MINF_TBR);
    builder.call_01("func1", MINF_MAR);
    builder.i(MINF_MRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_TBRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_STOP);
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MR, MINF_MR, 9, 9).into(),
                (MINF_TBR, MINF_TBR, 3, 3).into(),
                (MINF_MAR, MINF_MAR, 11, 11).into(),
                (MINF_MRW1, MINF_MRW1, 5, 5).into(),
                (MINF_TBR, MINF_TBR, 16, 16).into(),
                (MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
                (MINF_TBR, MINF_TBR, 18, 18).into(),
                (MINF_STOP, MINF_STOP, 9, 9).into(),
                (MINF_MARW0, MINF_MARW0, 10, 10).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MARW1, MINF_MARW1, 12, 12).into(),
                (MINF_MARF, MINF_MARF, 23, 23).into(),
                (MINF_MAB, MINF_MAB, 14, 14).into(),
                (MINF_MARW0, MINF_MARW0, 15, 15).into(),
                (MINF_MR, MINF_MR, 2, 4).into(),
                (MINF_TBRW0, MINF_TBRW0, 17, 17).into(),
                (MINF_TBRF, MINF_TBRF, 27, 27).into(),
                (MINF_TBRW1, MINF_TBRW1, 19, 19).into(),
                (MINF_TBRF, MINF_TBRF, 27, 27).into(),
                (MINF_TBB, MINF_TBB, 21, 21).into(),
                (MINF_TBRW0, MINF_TBRW0, 22, 22).into(),
                (MINF_MR, MINF_MR, 6, 8).into(),
                (MINF_MR, MINF_MR, 24, 24).into(),
                (MINF_TBRF, MINF_TBRF, 25, 25).into(),
                (MINF_TBB, MINF_TBB, 26, 26).into(),
                (MINF_TBRW1, MINF_TBRW0, 13, 13).into(),
                (MINF_MRW0, MINF_MRW0, 28, 28).into(),
                (MINF_MAB, MINF_MAB, 29, 29).into(),
                (MINF_MARW0, MINF_MARW1, 30, 30).into(),
                (MINF_MR, MINF_MR, 20, 20).into()
            ],
            vec![
                ("func1".to_string(), 23),
                ("func1_0_putret_x_0".to_string(), 9),
                ("func1_0_putret_x_1".to_string(), 11),
                ("func1_after_ret_0".to_string(), 2),
                ("func1_after_ret_1".to_string(), 4),
                ("func1_return".to_string(), 13),
                ("func1_return_id_0_0".to_string(), 14),
                ("func2".to_string(), 27),
                ("func2_0_putret_x_0".to_string(), 16),
                ("func2_0_putret_x_1".to_string(), 18),
                ("func2_after_ret_0".to_string(), 6),
                ("func2_after_ret_1".to_string(), 8),
                ("func2_return".to_string(), 20),
                ("func2_return_id_0_0".to_string(), 21)
            ]
        ),
        builder.to_code()
    );
}

#[test]
fn test_handler_builder_sv_2() {
    let mut builder = mi_std_sv_hbuilder_new_1(Some(2), 1);
    {
        let (func1b, ret) = builder.add_routine("func1", false);
        let mut func1b = func1b.borrow_mut();
        func1b.i(MINF_MR);
        func1b.i(MINF_TBRF);
        func1b.call_01("func1", MINF_TBR);
        func1b.i(MINF_TBB);
        func1b.i((MINF_TBRW1, MINF_TBRW0, ret));
    }
    {
        let (func2b, ret) = builder.add_routine("func2", true);
        let mut func2b = func2b.borrow_mut();
        func2b.i(MINF_MRW0);
        func2b.i(MINF_MAB);
        func2b.i((MINF_MARW0, MINF_MARW1));
        func2b.call_01("func1", MINF_MAR);
        func2b.i((MINF_MR, ret));
    }
    builder.i(MINF_MRW0);
    builder.call_01("func1", MINF_MR);
    builder.i(MINF_TBR);
    builder.call_01("func1", MINF_MAR);
    builder.i(MINF_MRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_TBRW1);
    builder.call_01("func2", MINF_TBR);
    builder.i(MINF_STOP);
    // let (code, labels) = builder.to_code();
    // for c in code.into_iter() {
    //     println!("{}.into(),", c);
    // }
    // for (l, p) in labels {
    //     println!("({:?}.to_string(), {}),", l, p);
    // }
    assert_eq!(
        (
            vec![
                MinInfInstr::new(MINF_MRW0, MINF_MRW0, 1, 1),
                (MINF_MR, MINF_MR, 13, 13).into(),
                (MINF_TBR, MINF_TBR, 3, 3).into(),
                (MINF_MAR, MINF_MAR, 15, 15).into(),
                (MINF_MRW1, MINF_MRW1, 5, 5).into(),
                (MINF_TBR, MINF_TBR, 28, 28).into(),
                (MINF_TBRW1, MINF_TBRW1, 7, 7).into(),
                (MINF_TBR, MINF_TBR, 30, 30).into(),
                (MINF_STOP, MINF_STOP, 9, 9).into(),
                (MINF_MARW0, MINF_MARW0, 10, 10).into(),
                (MINF_MARF, MINF_MARF, 17, 17).into(),
                (MINF_MARW1, MINF_MARW1, 12, 12).into(),
                (MINF_MARF, MINF_MARF, 17, 17).into(),
                (MINF_MARW0, MINF_MARW0, 14, 14).into(),
                (MINF_MARF, MINF_MARF, 19, 19).into(),
                (MINF_MARW1, MINF_MARW1, 16, 16).into(),
                (MINF_MARF, MINF_MARF, 19, 19).into(),
                (MINF_MARW0, MINF_MARW0, 18, 18).into(),
                (MINF_MARF, MINF_MARF, 39, 39).into(),
                (MINF_MARW1, MINF_MARW1, 20, 20).into(),
                (MINF_MARF, MINF_MARF, 39, 39).into(),
                (MINF_MAB, MINF_MAB, 22, 22).into(),
                (MINF_MARW0, MINF_MARW0, 23, 23).into(),
                (MINF_MAB, MINF_MAB, 24, 26).into(),
                (MINF_MARW0, MINF_MARW0, 25, 25).into(),
                (MINF_MR, MINF_MR, 42, 48).into(),
                (MINF_MARW0, MINF_MARW0, 27, 27).into(),
                (MINF_MR, MINF_MR, 2, 4).into(),
                (MINF_TBRW0, MINF_TBRW0, 29, 29).into(),
                (MINF_TBRF, MINF_TBRF, 32, 32).into(),
                (MINF_TBRW1, MINF_TBRW1, 31, 31).into(),
                (MINF_TBRF, MINF_TBRF, 32, 32).into(),
                (MINF_TBRW0, MINF_TBRW0, 33, 33).into(),
                (MINF_TBRF, MINF_TBRF, 44, 44).into(),
                (MINF_TBB, MINF_TBB, 35, 35).into(),
                (MINF_TBRW0, MINF_TBRW0, 36, 36).into(),
                (MINF_TBB, MINF_TBB, 37, 37).into(),
                (MINF_TBRW0, MINF_TBRW0, 38, 38).into(),
                (MINF_MR, MINF_MR, 6, 8).into(),
                (MINF_MR, MINF_MR, 40, 40).into(),
                (MINF_TBRF, MINF_TBRF, 41, 41).into(),
                (MINF_TBR, MINF_TBR, 9, 9).into(),
                (MINF_TBB, MINF_TBB, 43, 43).into(),
                (MINF_TBRW1, MINF_TBRW0, 21, 21).into(),
                (MINF_MRW0, MINF_MRW0, 45, 45).into(),
                (MINF_MAB, MINF_MAB, 46, 46).into(),
                (MINF_MARW0, MINF_MARW1, 47, 47).into(),
                (MINF_MAR, MINF_MAR, 11, 11).into(),
                (MINF_MR, MINF_MR, 34, 34).into(),
            ],
            vec![
                ("func1".to_string(), 39),
                ("func1_0_putret_1_0".to_string(), 17),
                ("func1_0_putret_1_1".to_string(), 19),
                ("func1_0_putret_x_0".to_string(), 9),
                ("func1_0_putret_x_1".to_string(), 11),
                ("func1_0_putret_x_10".to_string(), 13),
                ("func1_0_putret_x_11".to_string(), 15),
                ("func1_after_ret_0".to_string(), 42),
                ("func1_after_ret_1".to_string(), 48),
                ("func1_after_ret_2".to_string(), 2),
                ("func1_after_ret_3".to_string(), 4),
                ("func1_return".to_string(), 21),
                ("func1_return_id_0_0".to_string(), 22),
                ("func1_return_id_1_0".to_string(), 24),
                ("func1_return_id_1_1".to_string(), 26),
                ("func2".to_string(), 44),
                ("func2_0_putret_1_0".to_string(), 32),
                ("func2_0_putret_x_0".to_string(), 28),
                ("func2_0_putret_x_1".to_string(), 30),
                ("func2_after_ret_0".to_string(), 6),
                ("func2_after_ret_1".to_string(), 8),
                ("func2_return".to_string(), 34),
                ("func2_return_id_0_0".to_string(), 35),
                ("func2_return_id_1_0".to_string(), 37),
            ]
        ),
        builder.to_code()
    );
}