kmp_settings.cpp 192 KB
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 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763
/*
 * kmp_settings.cpp -- Initialize environment variables
 */

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "kmp.h"
#include "kmp_affinity.h"
#include "kmp_atomic.h"
#if KMP_USE_HIER_SCHED
#include "kmp_dispatch_hier.h"
#endif
#include "kmp_environment.h"
#include "kmp_i18n.h"
#include "kmp_io.h"
#include "kmp_itt.h"
#include "kmp_lock.h"
#include "kmp_settings.h"
#include "kmp_str.h"
#include "kmp_wrapper_getpid.h"
#include <ctype.h> // toupper()

static int __kmp_env_toPrint(char const *name, int flag);

bool __kmp_env_format = 0; // 0 - old format; 1 - new format

// -----------------------------------------------------------------------------
// Helper string functions. Subject to move to kmp_str.

#ifdef USE_LOAD_BALANCE
static double __kmp_convert_to_double(char const *s) {
  double result;

  if (KMP_SSCANF(s, "%lf", &result) < 1) {
    result = 0.0;
  }

  return result;
}
#endif

#ifdef KMP_DEBUG
static unsigned int __kmp_readstr_with_sentinel(char *dest, char const *src,
                                                size_t len, char sentinel) {
  unsigned int i;
  for (i = 0; i < len; i++) {
    if ((*src == '\0') || (*src == sentinel)) {
      break;
    }
    *(dest++) = *(src++);
  }
  *dest = '\0';
  return i;
}
#endif

static int __kmp_match_with_sentinel(char const *a, char const *b, size_t len,
                                     char sentinel) {
  size_t l = 0;

  if (a == NULL)
    a = "";
  if (b == NULL)
    b = "";
  while (*a && *b && *b != sentinel) {
    char ca = *a, cb = *b;

    if (ca >= 'a' && ca <= 'z')
      ca -= 'a' - 'A';
    if (cb >= 'a' && cb <= 'z')
      cb -= 'a' - 'A';
    if (ca != cb)
      return FALSE;
    ++l;
    ++a;
    ++b;
  }
  return l >= len;
}

// Expected usage:
//     token is the token to check for.
//     buf is the string being parsed.
//     *end returns the char after the end of the token.
//        it is not modified unless a match occurs.
//
// Example 1:
//
//     if (__kmp_match_str("token", buf, *end) {
//         <do something>
//         buf = end;
//     }
//
//  Example 2:
//
//     if (__kmp_match_str("token", buf, *end) {
//         char *save = **end;
//         **end = sentinel;
//         <use any of the __kmp*_with_sentinel() functions>
//         **end = save;
//         buf = end;
//     }

static int __kmp_match_str(char const *token, char const *buf,
                           const char **end) {

  KMP_ASSERT(token != NULL);
  KMP_ASSERT(buf != NULL);
  KMP_ASSERT(end != NULL);

  while (*token && *buf) {
    char ct = *token, cb = *buf;

    if (ct >= 'a' && ct <= 'z')
      ct -= 'a' - 'A';
    if (cb >= 'a' && cb <= 'z')
      cb -= 'a' - 'A';
    if (ct != cb)
      return FALSE;
    ++token;
    ++buf;
  }
  if (*token) {
    return FALSE;
  }
  *end = buf;
  return TRUE;
}

#if KMP_OS_DARWIN
static size_t __kmp_round4k(size_t size) {
  size_t _4k = 4 * 1024;
  if (size & (_4k - 1)) {
    size &= ~(_4k - 1);
    if (size <= KMP_SIZE_T_MAX - _4k) {
      size += _4k; // Round up if there is no overflow.
    }
  }
  return size;
} // __kmp_round4k
#endif

/* Here, multipliers are like __kmp_convert_to_seconds, but floating-point
   values are allowed, and the return value is in milliseconds.  The default
   multiplier is milliseconds.  Returns INT_MAX only if the value specified
   matches "infinit*".  Returns -1 if specified string is invalid. */
int __kmp_convert_to_milliseconds(char const *data) {
  int ret, nvalues, factor;
  char mult, extra;
  double value;

  if (data == NULL)
    return (-1);
  if (__kmp_str_match("infinit", -1, data))
    return (INT_MAX);
  value = (double)0.0;
  mult = '\0';
  nvalues = KMP_SSCANF(data, "%lf%c%c", &value, &mult, &extra);
  if (nvalues < 1)
    return (-1);
  if (nvalues == 1)
    mult = '\0';
  if (nvalues == 3)
    return (-1);

  if (value < 0)
    return (-1);

  switch (mult) {
  case '\0':
    /*  default is milliseconds  */
    factor = 1;
    break;
  case 's':
  case 'S':
    factor = 1000;
    break;
  case 'm':
  case 'M':
    factor = 1000 * 60;
    break;
  case 'h':
  case 'H':
    factor = 1000 * 60 * 60;
    break;
  case 'd':
  case 'D':
    factor = 1000 * 24 * 60 * 60;
    break;
  default:
    return (-1);
  }

  if (value >= ((INT_MAX - 1) / factor))
    ret = INT_MAX - 1; /* Don't allow infinite value here */
  else
    ret = (int)(value * (double)factor); /* truncate to int  */

  return ret;
}

static int __kmp_strcasecmp_with_sentinel(char const *a, char const *b,
                                          char sentinel) {
  if (a == NULL)
    a = "";
  if (b == NULL)
    b = "";
  while (*a && *b && *b != sentinel) {
    char ca = *a, cb = *b;

    if (ca >= 'a' && ca <= 'z')
      ca -= 'a' - 'A';
    if (cb >= 'a' && cb <= 'z')
      cb -= 'a' - 'A';
    if (ca != cb)
      return (int)(unsigned char)*a - (int)(unsigned char)*b;
    ++a;
    ++b;
  }
  return *a
             ? (*b && *b != sentinel)
                   ? (int)(unsigned char)*a - (int)(unsigned char)*b
                   : 1
             : (*b && *b != sentinel) ? -1 : 0;
}

// =============================================================================
// Table structures and helper functions.

typedef struct __kmp_setting kmp_setting_t;
typedef struct __kmp_stg_ss_data kmp_stg_ss_data_t;
typedef struct __kmp_stg_wp_data kmp_stg_wp_data_t;
typedef struct __kmp_stg_fr_data kmp_stg_fr_data_t;

typedef void (*kmp_stg_parse_func_t)(char const *name, char const *value,
                                     void *data);
typedef void (*kmp_stg_print_func_t)(kmp_str_buf_t *buffer, char const *name,
                                     void *data);

struct __kmp_setting {
  char const *name; // Name of setting (environment variable).
  kmp_stg_parse_func_t parse; // Parser function.
  kmp_stg_print_func_t print; // Print function.
  void *data; // Data passed to parser and printer.
  int set; // Variable set during this "session"
  //     (__kmp_env_initialize() or kmp_set_defaults() call).
  int defined; // Variable set in any "session".
}; // struct __kmp_setting

struct __kmp_stg_ss_data {
  size_t factor; // Default factor: 1 for KMP_STACKSIZE, 1024 for others.
  kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
}; // struct __kmp_stg_ss_data

struct __kmp_stg_wp_data {
  int omp; // 0 -- KMP_LIBRARY, 1 -- OMP_WAIT_POLICY.
  kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
}; // struct __kmp_stg_wp_data

struct __kmp_stg_fr_data {
  int force; // 0 -- KMP_DETERMINISTIC_REDUCTION, 1 -- KMP_FORCE_REDUCTION.
  kmp_setting_t **rivals; // Array of pointers to rivals (including itself).
}; // struct __kmp_stg_fr_data

static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
    char const *name, // Name of variable.
    char const *value, // Value of the variable.
    kmp_setting_t **rivals // List of rival settings (must include current one).
    );

// -----------------------------------------------------------------------------
// Helper parse functions.

static void __kmp_stg_parse_bool(char const *name, char const *value,
                                 int *out) {
  if (__kmp_str_match_true(value)) {
    *out = TRUE;
  } else if (__kmp_str_match_false(value)) {
    *out = FALSE;
  } else {
    __kmp_msg(kmp_ms_warning, KMP_MSG(BadBoolValue, name, value),
              KMP_HNT(ValidBoolValues), __kmp_msg_null);
  }
} // __kmp_stg_parse_bool

// placed here in order to use __kmp_round4k static function
void __kmp_check_stksize(size_t *val) {
  // if system stack size is too big then limit the size for worker threads
  if (*val > KMP_DEFAULT_STKSIZE * 16) // just a heuristics...
    *val = KMP_DEFAULT_STKSIZE * 16;
  if (*val < KMP_MIN_STKSIZE)
    *val = KMP_MIN_STKSIZE;
  if (*val > KMP_MAX_STKSIZE)
    *val = KMP_MAX_STKSIZE; // dead code currently, but may work in future
#if KMP_OS_DARWIN
  *val = __kmp_round4k(*val);
#endif // KMP_OS_DARWIN
}

static void __kmp_stg_parse_size(char const *name, char const *value,
                                 size_t size_min, size_t size_max,
                                 int *is_specified, size_t *out,
                                 size_t factor) {
  char const *msg = NULL;
#if KMP_OS_DARWIN
  size_min = __kmp_round4k(size_min);
  size_max = __kmp_round4k(size_max);
#endif // KMP_OS_DARWIN
  if (value) {
    if (is_specified != NULL) {
      *is_specified = 1;
    }
    __kmp_str_to_size(value, out, factor, &msg);
    if (msg == NULL) {
      if (*out > size_max) {
        *out = size_max;
        msg = KMP_I18N_STR(ValueTooLarge);
      } else if (*out < size_min) {
        *out = size_min;
        msg = KMP_I18N_STR(ValueTooSmall);
      } else {
#if KMP_OS_DARWIN
        size_t round4k = __kmp_round4k(*out);
        if (*out != round4k) {
          *out = round4k;
          msg = KMP_I18N_STR(NotMultiple4K);
        }
#endif
      }
    } else {
      // If integer overflow occurred, * out == KMP_SIZE_T_MAX. Cut it to
      // size_max silently.
      if (*out < size_min) {
        *out = size_max;
      } else if (*out > size_max) {
        *out = size_max;
      }
    }
    if (msg != NULL) {
      // Message is not empty. Print warning.
      kmp_str_buf_t buf;
      __kmp_str_buf_init(&buf);
      __kmp_str_buf_print_size(&buf, *out);
      KMP_WARNING(ParseSizeIntWarn, name, value, msg);
      KMP_INFORM(Using_str_Value, name, buf.str);
      __kmp_str_buf_free(&buf);
    }
  }
} // __kmp_stg_parse_size

static void __kmp_stg_parse_str(char const *name, char const *value,
                                char **out) {
  __kmp_str_free(out);
  *out = __kmp_str_format("%s", value);
} // __kmp_stg_parse_str

static void __kmp_stg_parse_int(
    char const
        *name, // I: Name of environment variable (used in warning messages).
    char const *value, // I: Value of environment variable to parse.
    int min, // I: Minimum allowed value.
    int max, // I: Maximum allowed value.
    int *out // O: Output (parsed) value.
    ) {
  char const *msg = NULL;
  kmp_uint64 uint = *out;
  __kmp_str_to_uint(value, &uint, &msg);
  if (msg == NULL) {
    if (uint < (unsigned int)min) {
      msg = KMP_I18N_STR(ValueTooSmall);
      uint = min;
    } else if (uint > (unsigned int)max) {
      msg = KMP_I18N_STR(ValueTooLarge);
      uint = max;
    }
  } else {
    // If overflow occurred msg contains error message and uint is very big. Cut
    // tmp it to INT_MAX.
    if (uint < (unsigned int)min) {
      uint = min;
    } else if (uint > (unsigned int)max) {
      uint = max;
    }
  }
  if (msg != NULL) {
    // Message is not empty. Print warning.
    kmp_str_buf_t buf;
    KMP_WARNING(ParseSizeIntWarn, name, value, msg);
    __kmp_str_buf_init(&buf);
    __kmp_str_buf_print(&buf, "%" KMP_UINT64_SPEC "", uint);
    KMP_INFORM(Using_uint64_Value, name, buf.str);
    __kmp_str_buf_free(&buf);
  }
  *out = uint;
} // __kmp_stg_parse_int

#if KMP_DEBUG_ADAPTIVE_LOCKS
static void __kmp_stg_parse_file(char const *name, char const *value,
                                 const char *suffix, char **out) {
  char buffer[256];
  char *t;
  int hasSuffix;
  __kmp_str_free(out);
  t = (char *)strrchr(value, '.');
  hasSuffix = t && __kmp_str_eqf(t, suffix);
  t = __kmp_str_format("%s%s", value, hasSuffix ? "" : suffix);
  __kmp_expand_file_name(buffer, sizeof(buffer), t);
  __kmp_str_free(&t);
  *out = __kmp_str_format("%s", buffer);
} // __kmp_stg_parse_file
#endif

#ifdef KMP_DEBUG
static char *par_range_to_print = NULL;

static void __kmp_stg_parse_par_range(char const *name, char const *value,
                                      int *out_range, char *out_routine,
                                      char *out_file, int *out_lb,
                                      int *out_ub) {
  size_t len = KMP_STRLEN(value) + 1;
  par_range_to_print = (char *)KMP_INTERNAL_MALLOC(len + 1);
  KMP_STRNCPY_S(par_range_to_print, len + 1, value, len + 1);
  __kmp_par_range = +1;
  __kmp_par_range_lb = 0;
  __kmp_par_range_ub = INT_MAX;
  for (;;) {
    unsigned int len;
    if (*value == '\0') {
      break;
    }
    if (!__kmp_strcasecmp_with_sentinel("routine", value, '=')) {
      value = strchr(value, '=') + 1;
      len = __kmp_readstr_with_sentinel(out_routine, value,
                                        KMP_PAR_RANGE_ROUTINE_LEN - 1, ',');
      if (len == 0) {
        goto par_range_error;
      }
      value = strchr(value, ',');
      if (value != NULL) {
        value++;
      }
      continue;
    }
    if (!__kmp_strcasecmp_with_sentinel("filename", value, '=')) {
      value = strchr(value, '=') + 1;
      len = __kmp_readstr_with_sentinel(out_file, value,
                                        KMP_PAR_RANGE_FILENAME_LEN - 1, ',');
      if (len == 0) {
        goto par_range_error;
      }
      value = strchr(value, ',');
      if (value != NULL) {
        value++;
      }
      continue;
    }
    if ((!__kmp_strcasecmp_with_sentinel("range", value, '=')) ||
        (!__kmp_strcasecmp_with_sentinel("incl_range", value, '='))) {
      value = strchr(value, '=') + 1;
      if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
        goto par_range_error;
      }
      *out_range = +1;
      value = strchr(value, ',');
      if (value != NULL) {
        value++;
      }
      continue;
    }
    if (!__kmp_strcasecmp_with_sentinel("excl_range", value, '=')) {
      value = strchr(value, '=') + 1;
      if (KMP_SSCANF(value, "%d:%d", out_lb, out_ub) != 2) {
        goto par_range_error;
      }
      *out_range = -1;
      value = strchr(value, ',');
      if (value != NULL) {
        value++;
      }
      continue;
    }
  par_range_error:
    KMP_WARNING(ParRangeSyntax, name);
    __kmp_par_range = 0;
    break;
  }
} // __kmp_stg_parse_par_range
#endif

int __kmp_initial_threads_capacity(int req_nproc) {
  int nth = 32;

  /* MIN( MAX( 32, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
   * __kmp_max_nth) */
  if (nth < (4 * req_nproc))
    nth = (4 * req_nproc);
  if (nth < (4 * __kmp_xproc))
    nth = (4 * __kmp_xproc);

  if (nth > __kmp_max_nth)
    nth = __kmp_max_nth;

  return nth;
}

int __kmp_default_tp_capacity(int req_nproc, int max_nth,
                              int all_threads_specified) {
  int nth = 128;

  if (all_threads_specified)
    return max_nth;
  /* MIN( MAX (128, 4 * $OMP_NUM_THREADS, 4 * omp_get_num_procs() ),
   * __kmp_max_nth ) */
  if (nth < (4 * req_nproc))
    nth = (4 * req_nproc);
  if (nth < (4 * __kmp_xproc))
    nth = (4 * __kmp_xproc);

  if (nth > __kmp_max_nth)
    nth = __kmp_max_nth;

  return nth;
}

// -----------------------------------------------------------------------------
// Helper print functions.

static void __kmp_stg_print_bool(kmp_str_buf_t *buffer, char const *name,
                                 int value) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_BOOL;
  } else {
    __kmp_str_buf_print(buffer, "   %s=%s\n", name, value ? "true" : "false");
  }
} // __kmp_stg_print_bool

static void __kmp_stg_print_int(kmp_str_buf_t *buffer, char const *name,
                                int value) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_INT;
  } else {
    __kmp_str_buf_print(buffer, "   %s=%d\n", name, value);
  }
} // __kmp_stg_print_int

#if USE_ITT_BUILD && USE_ITT_NOTIFY
static void __kmp_stg_print_uint64(kmp_str_buf_t *buffer, char const *name,
                                   kmp_uint64 value) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_UINT64;
  } else {
    __kmp_str_buf_print(buffer, "   %s=%" KMP_UINT64_SPEC "\n", name, value);
  }
} // __kmp_stg_print_uint64
#endif

static void __kmp_stg_print_str(kmp_str_buf_t *buffer, char const *name,
                                char const *value) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_STR;
  } else {
    __kmp_str_buf_print(buffer, "   %s=%s\n", name, value);
  }
} // __kmp_stg_print_str

static void __kmp_stg_print_size(kmp_str_buf_t *buffer, char const *name,
                                 size_t value) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME_EX(name);
    __kmp_str_buf_print_size(buffer, value);
    __kmp_str_buf_print(buffer, "'\n");
  } else {
    __kmp_str_buf_print(buffer, "   %s=", name);
    __kmp_str_buf_print_size(buffer, value);
    __kmp_str_buf_print(buffer, "\n");
    return;
  }
} // __kmp_stg_print_size

// =============================================================================
// Parse and print functions.

// -----------------------------------------------------------------------------
// KMP_DEVICE_THREAD_LIMIT, KMP_ALL_THREADS

static void __kmp_stg_parse_device_thread_limit(char const *name,
                                                char const *value, void *data) {
  kmp_setting_t **rivals = (kmp_setting_t **)data;
  int rc;
  if (strcmp(name, "KMP_ALL_THREADS") == 0) {
    KMP_INFORM(EnvVarDeprecated, name, "KMP_DEVICE_THREAD_LIMIT");
  }
  rc = __kmp_stg_check_rivals(name, value, rivals);
  if (rc) {
    return;
  }
  if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
    __kmp_max_nth = __kmp_xproc;
    __kmp_allThreadsSpecified = 1;
  } else {
    __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_max_nth);
    __kmp_allThreadsSpecified = 0;
  }
  K_DIAG(1, ("__kmp_max_nth == %d\n", __kmp_max_nth));

} // __kmp_stg_parse_device_thread_limit

static void __kmp_stg_print_device_thread_limit(kmp_str_buf_t *buffer,
                                                char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_max_nth);
} // __kmp_stg_print_device_thread_limit

// -----------------------------------------------------------------------------
// OMP_THREAD_LIMIT
static void __kmp_stg_parse_thread_limit(char const *name, char const *value,
                                         void *data) {
  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_cg_max_nth);
  K_DIAG(1, ("__kmp_cg_max_nth == %d\n", __kmp_cg_max_nth));

} // __kmp_stg_parse_thread_limit

static void __kmp_stg_print_thread_limit(kmp_str_buf_t *buffer,
                                         char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_cg_max_nth);
} // __kmp_stg_print_thread_limit

// -----------------------------------------------------------------------------
// KMP_TEAMS_THREAD_LIMIT
static void __kmp_stg_parse_teams_thread_limit(char const *name,
                                               char const *value, void *data) {
  __kmp_stg_parse_int(name, value, 1, __kmp_sys_max_nth, &__kmp_teams_max_nth);
} // __kmp_stg_teams_thread_limit

static void __kmp_stg_print_teams_thread_limit(kmp_str_buf_t *buffer,
                                               char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_teams_max_nth);
} // __kmp_stg_print_teams_thread_limit

// -----------------------------------------------------------------------------
// KMP_USE_YIELD
static void __kmp_stg_parse_use_yield(char const *name, char const *value,
                                      void *data) {
  __kmp_stg_parse_int(name, value, 0, 2, &__kmp_use_yield);
  __kmp_use_yield_exp_set = 1;
} // __kmp_stg_parse_use_yield

static void __kmp_stg_print_use_yield(kmp_str_buf_t *buffer, char const *name,
                                      void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_use_yield);
} // __kmp_stg_print_use_yield

// -----------------------------------------------------------------------------
// KMP_BLOCKTIME

static void __kmp_stg_parse_blocktime(char const *name, char const *value,
                                      void *data) {
  __kmp_dflt_blocktime = __kmp_convert_to_milliseconds(value);
  if (__kmp_dflt_blocktime < 0) {
    __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
    __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidValue, name, value),
              __kmp_msg_null);
    KMP_INFORM(Using_int_Value, name, __kmp_dflt_blocktime);
    __kmp_env_blocktime = FALSE; // Revert to default as if var not set.
  } else {
    if (__kmp_dflt_blocktime < KMP_MIN_BLOCKTIME) {
      __kmp_dflt_blocktime = KMP_MIN_BLOCKTIME;
      __kmp_msg(kmp_ms_warning, KMP_MSG(SmallValue, name, value),
                __kmp_msg_null);
      KMP_INFORM(MinValueUsing, name, __kmp_dflt_blocktime);
    } else if (__kmp_dflt_blocktime > KMP_MAX_BLOCKTIME) {
      __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
      __kmp_msg(kmp_ms_warning, KMP_MSG(LargeValue, name, value),
                __kmp_msg_null);
      KMP_INFORM(MaxValueUsing, name, __kmp_dflt_blocktime);
    }
    __kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
  }
#if KMP_USE_MONITOR
  // calculate number of monitor thread wakeup intervals corresponding to
  // blocktime.
  __kmp_monitor_wakeups =
      KMP_WAKEUPS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
  __kmp_bt_intervals =
      KMP_INTERVALS_FROM_BLOCKTIME(__kmp_dflt_blocktime, __kmp_monitor_wakeups);
#endif
  K_DIAG(1, ("__kmp_env_blocktime == %d\n", __kmp_env_blocktime));
  if (__kmp_env_blocktime) {
    K_DIAG(1, ("__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime));
  }
} // __kmp_stg_parse_blocktime

static void __kmp_stg_print_blocktime(kmp_str_buf_t *buffer, char const *name,
                                      void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_dflt_blocktime);
} // __kmp_stg_print_blocktime

// -----------------------------------------------------------------------------
// KMP_DUPLICATE_LIB_OK

static void __kmp_stg_parse_duplicate_lib_ok(char const *name,
                                             char const *value, void *data) {
  /* actually this variable is not supported, put here for compatibility with
     earlier builds and for static/dynamic combination */
  __kmp_stg_parse_bool(name, value, &__kmp_duplicate_library_ok);
} // __kmp_stg_parse_duplicate_lib_ok

static void __kmp_stg_print_duplicate_lib_ok(kmp_str_buf_t *buffer,
                                             char const *name, void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_duplicate_library_ok);
} // __kmp_stg_print_duplicate_lib_ok

// -----------------------------------------------------------------------------
// KMP_INHERIT_FP_CONTROL

#if KMP_ARCH_X86 || KMP_ARCH_X86_64

static void __kmp_stg_parse_inherit_fp_control(char const *name,
                                               char const *value, void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_inherit_fp_control);
} // __kmp_stg_parse_inherit_fp_control

static void __kmp_stg_print_inherit_fp_control(kmp_str_buf_t *buffer,
                                               char const *name, void *data) {
#if KMP_DEBUG
  __kmp_stg_print_bool(buffer, name, __kmp_inherit_fp_control);
#endif /* KMP_DEBUG */
} // __kmp_stg_print_inherit_fp_control

#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */

// Used for OMP_WAIT_POLICY
static char const *blocktime_str = NULL;

// -----------------------------------------------------------------------------
// KMP_LIBRARY, OMP_WAIT_POLICY

static void __kmp_stg_parse_wait_policy(char const *name, char const *value,
                                        void *data) {

  kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
  int rc;

  rc = __kmp_stg_check_rivals(name, value, wait->rivals);
  if (rc) {
    return;
  }

  if (wait->omp) {
    if (__kmp_str_match("ACTIVE", 1, value)) {
      __kmp_library = library_turnaround;
      if (blocktime_str == NULL) {
        // KMP_BLOCKTIME not specified, so set default to "infinite".
        __kmp_dflt_blocktime = KMP_MAX_BLOCKTIME;
      }
    } else if (__kmp_str_match("PASSIVE", 1, value)) {
      __kmp_library = library_throughput;
      if (blocktime_str == NULL) {
        // KMP_BLOCKTIME not specified, so set default to 0.
        __kmp_dflt_blocktime = 0;
      }
    } else {
      KMP_WARNING(StgInvalidValue, name, value);
    }
  } else {
    if (__kmp_str_match("serial", 1, value)) { /* S */
      __kmp_library = library_serial;
    } else if (__kmp_str_match("throughput", 2, value)) { /* TH */
      __kmp_library = library_throughput;
      if (blocktime_str == NULL) {
        // KMP_BLOCKTIME not specified, so set default to 0.
        __kmp_dflt_blocktime = 0;
      }
    } else if (__kmp_str_match("turnaround", 2, value)) { /* TU */
      __kmp_library = library_turnaround;
    } else if (__kmp_str_match("dedicated", 1, value)) { /* D */
      __kmp_library = library_turnaround;
    } else if (__kmp_str_match("multiuser", 1, value)) { /* M */
      __kmp_library = library_throughput;
      if (blocktime_str == NULL) {
        // KMP_BLOCKTIME not specified, so set default to 0.
        __kmp_dflt_blocktime = 0;
      }
    } else {
      KMP_WARNING(StgInvalidValue, name, value);
    }
  }
} // __kmp_stg_parse_wait_policy

static void __kmp_stg_print_wait_policy(kmp_str_buf_t *buffer, char const *name,
                                        void *data) {

  kmp_stg_wp_data_t *wait = (kmp_stg_wp_data_t *)data;
  char const *value = NULL;

  if (wait->omp) {
    switch (__kmp_library) {
    case library_turnaround: {
      value = "ACTIVE";
    } break;
    case library_throughput: {
      value = "PASSIVE";
    } break;
    }
  } else {
    switch (__kmp_library) {
    case library_serial: {
      value = "serial";
    } break;
    case library_turnaround: {
      value = "turnaround";
    } break;
    case library_throughput: {
      value = "throughput";
    } break;
    }
  }
  if (value != NULL) {
    __kmp_stg_print_str(buffer, name, value);
  }

} // __kmp_stg_print_wait_policy

#if KMP_USE_MONITOR
// -----------------------------------------------------------------------------
// KMP_MONITOR_STACKSIZE

static void __kmp_stg_parse_monitor_stacksize(char const *name,
                                              char const *value, void *data) {
  __kmp_stg_parse_size(name, value, __kmp_sys_min_stksize, KMP_MAX_STKSIZE,
                       NULL, &__kmp_monitor_stksize, 1);
} // __kmp_stg_parse_monitor_stacksize

static void __kmp_stg_print_monitor_stacksize(kmp_str_buf_t *buffer,
                                              char const *name, void *data) {
  if (__kmp_env_format) {
    if (__kmp_monitor_stksize > 0)
      KMP_STR_BUF_PRINT_NAME_EX(name);
    else
      KMP_STR_BUF_PRINT_NAME;
  } else {
    __kmp_str_buf_print(buffer, "   %s", name);
  }
  if (__kmp_monitor_stksize > 0) {
    __kmp_str_buf_print_size(buffer, __kmp_monitor_stksize);
  } else {
    __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
  }
  if (__kmp_env_format && __kmp_monitor_stksize) {
    __kmp_str_buf_print(buffer, "'\n");
  }
} // __kmp_stg_print_monitor_stacksize
#endif // KMP_USE_MONITOR

// -----------------------------------------------------------------------------
// KMP_SETTINGS

static void __kmp_stg_parse_settings(char const *name, char const *value,
                                     void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_settings);
} // __kmp_stg_parse_settings

static void __kmp_stg_print_settings(kmp_str_buf_t *buffer, char const *name,
                                     void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_settings);
} // __kmp_stg_print_settings

// -----------------------------------------------------------------------------
// KMP_STACKPAD

static void __kmp_stg_parse_stackpad(char const *name, char const *value,
                                     void *data) {
  __kmp_stg_parse_int(name, // Env var name
                      value, // Env var value
                      KMP_MIN_STKPADDING, // Min value
                      KMP_MAX_STKPADDING, // Max value
                      &__kmp_stkpadding // Var to initialize
                      );
} // __kmp_stg_parse_stackpad

static void __kmp_stg_print_stackpad(kmp_str_buf_t *buffer, char const *name,
                                     void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_stkpadding);
} // __kmp_stg_print_stackpad

// -----------------------------------------------------------------------------
// KMP_STACKOFFSET

static void __kmp_stg_parse_stackoffset(char const *name, char const *value,
                                        void *data) {
  __kmp_stg_parse_size(name, // Env var name
                       value, // Env var value
                       KMP_MIN_STKOFFSET, // Min value
                       KMP_MAX_STKOFFSET, // Max value
                       NULL, //
                       &__kmp_stkoffset, // Var to initialize
                       1);
} // __kmp_stg_parse_stackoffset

static void __kmp_stg_print_stackoffset(kmp_str_buf_t *buffer, char const *name,
                                        void *data) {
  __kmp_stg_print_size(buffer, name, __kmp_stkoffset);
} // __kmp_stg_print_stackoffset

// -----------------------------------------------------------------------------
// KMP_STACKSIZE, OMP_STACKSIZE, GOMP_STACKSIZE

static void __kmp_stg_parse_stacksize(char const *name, char const *value,
                                      void *data) {

  kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
  int rc;

  rc = __kmp_stg_check_rivals(name, value, stacksize->rivals);
  if (rc) {
    return;
  }
  __kmp_stg_parse_size(name, // Env var name
                       value, // Env var value
                       __kmp_sys_min_stksize, // Min value
                       KMP_MAX_STKSIZE, // Max value
                       &__kmp_env_stksize, //
                       &__kmp_stksize, // Var to initialize
                       stacksize->factor);

} // __kmp_stg_parse_stacksize

// This function is called for printing both KMP_STACKSIZE (factor is 1) and
// OMP_STACKSIZE (factor is 1024). Currently it is not possible to print
// OMP_STACKSIZE value in bytes. We can consider adding this possibility by a
// customer request in future.
static void __kmp_stg_print_stacksize(kmp_str_buf_t *buffer, char const *name,
                                      void *data) {
  kmp_stg_ss_data_t *stacksize = (kmp_stg_ss_data_t *)data;
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME_EX(name);
    __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
                                         ? __kmp_stksize / stacksize->factor
                                         : __kmp_stksize);
    __kmp_str_buf_print(buffer, "'\n");
  } else {
    __kmp_str_buf_print(buffer, "   %s=", name);
    __kmp_str_buf_print_size(buffer, (__kmp_stksize % 1024)
                                         ? __kmp_stksize / stacksize->factor
                                         : __kmp_stksize);
    __kmp_str_buf_print(buffer, "\n");
  }
} // __kmp_stg_print_stacksize

// -----------------------------------------------------------------------------
// KMP_VERSION

static void __kmp_stg_parse_version(char const *name, char const *value,
                                    void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_version);
} // __kmp_stg_parse_version

static void __kmp_stg_print_version(kmp_str_buf_t *buffer, char const *name,
                                    void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_version);
} // __kmp_stg_print_version

// -----------------------------------------------------------------------------
// KMP_WARNINGS

static void __kmp_stg_parse_warnings(char const *name, char const *value,
                                     void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_generate_warnings);
  if (__kmp_generate_warnings != kmp_warnings_off) {
    // AC: only 0/1 values documented, so reset to explicit to distinguish from
    // default setting
    __kmp_generate_warnings = kmp_warnings_explicit;
  }
} // __kmp_stg_parse_warnings

static void __kmp_stg_print_warnings(kmp_str_buf_t *buffer, char const *name,
                                     void *data) {
  // AC: TODO: change to print_int? (needs documentation change)
  __kmp_stg_print_bool(buffer, name, __kmp_generate_warnings);
} // __kmp_stg_print_warnings

// -----------------------------------------------------------------------------
// OMP_NESTED, OMP_NUM_THREADS

static void __kmp_stg_parse_nested(char const *name, char const *value,
                                   void *data) {
  int nested;
  KMP_INFORM(EnvVarDeprecated, name, "OMP_MAX_ACTIVE_LEVELS");
  __kmp_stg_parse_bool(name, value, &nested);
  if (nested) {
    if (!__kmp_dflt_max_active_levels_set)
      __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
  } else { // nesting explicitly turned off
    __kmp_dflt_max_active_levels = 1;
    __kmp_dflt_max_active_levels_set = true;
  }
} // __kmp_stg_parse_nested

static void __kmp_stg_print_nested(kmp_str_buf_t *buffer, char const *name,
                                   void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME;
  } else {
    __kmp_str_buf_print(buffer, "   %s", name);
  }
  __kmp_str_buf_print(buffer, ": deprecated; max-active-levels-var=%d\n",
                      __kmp_dflt_max_active_levels);
} // __kmp_stg_print_nested

static void __kmp_parse_nested_num_threads(const char *var, const char *env,
                                           kmp_nested_nthreads_t *nth_array) {
  const char *next = env;
  const char *scan = next;

  int total = 0; // Count elements that were set. It'll be used as an array size
  int prev_comma = FALSE; // For correct processing sequential commas

  // Count the number of values in the env. var string
  for (;;) {
    SKIP_WS(next);

    if (*next == '\0') {
      break;
    }
    // Next character is not an integer or not a comma => end of list
    if (((*next < '0') || (*next > '9')) && (*next != ',')) {
      KMP_WARNING(NthSyntaxError, var, env);
      return;
    }
    // The next character is ','
    if (*next == ',') {
      // ',' is the first character
      if (total == 0 || prev_comma) {
        total++;
      }
      prev_comma = TRUE;
      next++; // skip ','
      SKIP_WS(next);
    }
    // Next character is a digit
    if (*next >= '0' && *next <= '9') {
      prev_comma = FALSE;
      SKIP_DIGITS(next);
      total++;
      const char *tmp = next;
      SKIP_WS(tmp);
      if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
        KMP_WARNING(NthSpacesNotAllowed, var, env);
        return;
      }
    }
  }
  if (!__kmp_dflt_max_active_levels_set && total > 1)
    __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;
  KMP_DEBUG_ASSERT(total > 0);
  if (total <= 0) {
    KMP_WARNING(NthSyntaxError, var, env);
    return;
  }

  // Check if the nested nthreads array exists
  if (!nth_array->nth) {
    // Allocate an array of double size
    nth_array->nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int) * total * 2);
    if (nth_array->nth == NULL) {
      KMP_FATAL(MemoryAllocFailed);
    }
    nth_array->size = total * 2;
  } else {
    if (nth_array->size < total) {
      // Increase the array size
      do {
        nth_array->size *= 2;
      } while (nth_array->size < total);

      nth_array->nth = (int *)KMP_INTERNAL_REALLOC(
          nth_array->nth, sizeof(int) * nth_array->size);
      if (nth_array->nth == NULL) {
        KMP_FATAL(MemoryAllocFailed);
      }
    }
  }
  nth_array->used = total;
  int i = 0;

  prev_comma = FALSE;
  total = 0;
  // Save values in the array
  for (;;) {
    SKIP_WS(scan);
    if (*scan == '\0') {
      break;
    }
    // The next character is ','
    if (*scan == ',') {
      // ',' in the beginning of the list
      if (total == 0) {
        // The value is supposed to be equal to __kmp_avail_proc but it is
        // unknown at the moment.
        // So let's put a placeholder (#threads = 0) to correct it later.
        nth_array->nth[i++] = 0;
        total++;
      } else if (prev_comma) {
        // Num threads is inherited from the previous level
        nth_array->nth[i] = nth_array->nth[i - 1];
        i++;
        total++;
      }
      prev_comma = TRUE;
      scan++; // skip ','
      SKIP_WS(scan);
    }
    // Next character is a digit
    if (*scan >= '0' && *scan <= '9') {
      int num;
      const char *buf = scan;
      char const *msg = NULL;
      prev_comma = FALSE;
      SKIP_DIGITS(scan);
      total++;

      num = __kmp_str_to_int(buf, *scan);
      if (num < KMP_MIN_NTH) {
        msg = KMP_I18N_STR(ValueTooSmall);
        num = KMP_MIN_NTH;
      } else if (num > __kmp_sys_max_nth) {
        msg = KMP_I18N_STR(ValueTooLarge);
        num = __kmp_sys_max_nth;
      }
      if (msg != NULL) {
        // Message is not empty. Print warning.
        KMP_WARNING(ParseSizeIntWarn, var, env, msg);
        KMP_INFORM(Using_int_Value, var, num);
      }
      nth_array->nth[i++] = num;
    }
  }
}

static void __kmp_stg_parse_num_threads(char const *name, char const *value,
                                        void *data) {
  // TODO: Remove this option. OMP_NUM_THREADS is a list of positive integers!
  if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
    // The array of 1 element
    __kmp_nested_nth.nth = (int *)KMP_INTERNAL_MALLOC(sizeof(int));
    __kmp_nested_nth.size = __kmp_nested_nth.used = 1;
    __kmp_nested_nth.nth[0] = __kmp_dflt_team_nth = __kmp_dflt_team_nth_ub =
        __kmp_xproc;
  } else {
    __kmp_parse_nested_num_threads(name, value, &__kmp_nested_nth);
    if (__kmp_nested_nth.nth) {
      __kmp_dflt_team_nth = __kmp_nested_nth.nth[0];
      if (__kmp_dflt_team_nth_ub < __kmp_dflt_team_nth) {
        __kmp_dflt_team_nth_ub = __kmp_dflt_team_nth;
      }
    }
  }
  K_DIAG(1, ("__kmp_dflt_team_nth == %d\n", __kmp_dflt_team_nth));
} // __kmp_stg_parse_num_threads

static void __kmp_stg_print_num_threads(kmp_str_buf_t *buffer, char const *name,
                                        void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME;
  } else {
    __kmp_str_buf_print(buffer, "   %s", name);
  }
  if (__kmp_nested_nth.used) {
    kmp_str_buf_t buf;
    __kmp_str_buf_init(&buf);
    for (int i = 0; i < __kmp_nested_nth.used; i++) {
      __kmp_str_buf_print(&buf, "%d", __kmp_nested_nth.nth[i]);
      if (i < __kmp_nested_nth.used - 1) {
        __kmp_str_buf_print(&buf, ",");
      }
    }
    __kmp_str_buf_print(buffer, "='%s'\n", buf.str);
    __kmp_str_buf_free(&buf);
  } else {
    __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
  }
} // __kmp_stg_print_num_threads

// -----------------------------------------------------------------------------
// OpenMP 3.0: KMP_TASKING, OMP_MAX_ACTIVE_LEVELS,

static void __kmp_stg_parse_tasking(char const *name, char const *value,
                                    void *data) {
  __kmp_stg_parse_int(name, value, 0, (int)tskm_max,
                      (int *)&__kmp_tasking_mode);
} // __kmp_stg_parse_tasking

static void __kmp_stg_print_tasking(kmp_str_buf_t *buffer, char const *name,
                                    void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_tasking_mode);
} // __kmp_stg_print_tasking

static void __kmp_stg_parse_task_stealing(char const *name, char const *value,
                                          void *data) {
  __kmp_stg_parse_int(name, value, 0, 1,
                      (int *)&__kmp_task_stealing_constraint);
} // __kmp_stg_parse_task_stealing

static void __kmp_stg_print_task_stealing(kmp_str_buf_t *buffer,
                                          char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_task_stealing_constraint);
} // __kmp_stg_print_task_stealing

static void __kmp_stg_parse_max_active_levels(char const *name,
                                              char const *value, void *data) {
  kmp_uint64 tmp_dflt = 0;
  char const *msg = NULL;
  if (!__kmp_dflt_max_active_levels_set) {
    // Don't overwrite __kmp_dflt_max_active_levels if we get an invalid setting
    __kmp_str_to_uint(value, &tmp_dflt, &msg);
    if (msg != NULL) { // invalid setting; print warning and ignore
      KMP_WARNING(ParseSizeIntWarn, name, value, msg);
    } else if (tmp_dflt > KMP_MAX_ACTIVE_LEVELS_LIMIT) {
      // invalid setting; print warning and ignore
      msg = KMP_I18N_STR(ValueTooLarge);
      KMP_WARNING(ParseSizeIntWarn, name, value, msg);
    } else { // valid setting
      __kmp_dflt_max_active_levels = tmp_dflt;
      __kmp_dflt_max_active_levels_set = true;
    }
  }
} // __kmp_stg_parse_max_active_levels

static void __kmp_stg_print_max_active_levels(kmp_str_buf_t *buffer,
                                              char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_dflt_max_active_levels);
} // __kmp_stg_print_max_active_levels

// -----------------------------------------------------------------------------
// OpenMP 4.0: OMP_DEFAULT_DEVICE
static void __kmp_stg_parse_default_device(char const *name, char const *value,
                                           void *data) {
  __kmp_stg_parse_int(name, value, 0, KMP_MAX_DEFAULT_DEVICE_LIMIT,
                      &__kmp_default_device);
} // __kmp_stg_parse_default_device

static void __kmp_stg_print_default_device(kmp_str_buf_t *buffer,
                                           char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_default_device);
} // __kmp_stg_print_default_device

// -----------------------------------------------------------------------------
// OpenMP 5.0: OMP_TARGET_OFFLOAD
static void __kmp_stg_parse_target_offload(char const *name, char const *value,
                                           void *data) {
  const char *next = value;
  const char *scan = next;

  __kmp_target_offload = tgt_default;
  SKIP_WS(next);
  if (*next == '\0')
    return;
  scan = next;
  if (!__kmp_strcasecmp_with_sentinel("mandatory", scan, 0)) {
    __kmp_target_offload = tgt_mandatory;
  } else if (!__kmp_strcasecmp_with_sentinel("disabled", scan, 0)) {
    __kmp_target_offload = tgt_disabled;
  } else if (!__kmp_strcasecmp_with_sentinel("default", scan, 0)) {
    __kmp_target_offload = tgt_default;
  } else {
    KMP_WARNING(SyntaxErrorUsing, name, "DEFAULT");
  }

} // __kmp_stg_parse_target_offload

static void __kmp_stg_print_target_offload(kmp_str_buf_t *buffer,
                                           char const *name, void *data) {
  const char *value = NULL;
  if (__kmp_target_offload == tgt_default)
    value = "DEFAULT";
  else if (__kmp_target_offload == tgt_mandatory)
    value = "MANDATORY";
  else if (__kmp_target_offload == tgt_disabled)
    value = "DISABLED";
  KMP_DEBUG_ASSERT(value);
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME;
  } else {
    __kmp_str_buf_print(buffer, "   %s", name);
  }
  __kmp_str_buf_print(buffer, "=%s\n", value);
} // __kmp_stg_print_target_offload

// -----------------------------------------------------------------------------
// OpenMP 4.5: OMP_MAX_TASK_PRIORITY
static void __kmp_stg_parse_max_task_priority(char const *name,
                                              char const *value, void *data) {
  __kmp_stg_parse_int(name, value, 0, KMP_MAX_TASK_PRIORITY_LIMIT,
                      &__kmp_max_task_priority);
} // __kmp_stg_parse_max_task_priority

static void __kmp_stg_print_max_task_priority(kmp_str_buf_t *buffer,
                                              char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_max_task_priority);
} // __kmp_stg_print_max_task_priority

// KMP_TASKLOOP_MIN_TASKS
// taskloop threshold to switch from recursive to linear tasks creation
static void __kmp_stg_parse_taskloop_min_tasks(char const *name,
                                               char const *value, void *data) {
  int tmp;
  __kmp_stg_parse_int(name, value, 0, INT_MAX, &tmp);
  __kmp_taskloop_min_tasks = tmp;
} // __kmp_stg_parse_taskloop_min_tasks

static void __kmp_stg_print_taskloop_min_tasks(kmp_str_buf_t *buffer,
                                               char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_taskloop_min_tasks);
} // __kmp_stg_print_taskloop_min_tasks

// -----------------------------------------------------------------------------
// KMP_DISP_NUM_BUFFERS
static void __kmp_stg_parse_disp_buffers(char const *name, char const *value,
                                         void *data) {
  if (TCR_4(__kmp_init_serial)) {
    KMP_WARNING(EnvSerialWarn, name);
    return;
  } // read value before serial initialization only
  __kmp_stg_parse_int(name, value, 1, KMP_MAX_NTH, &__kmp_dispatch_num_buffers);
} // __kmp_stg_parse_disp_buffers

static void __kmp_stg_print_disp_buffers(kmp_str_buf_t *buffer,
                                         char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_dispatch_num_buffers);
} // __kmp_stg_print_disp_buffers

#if KMP_NESTED_HOT_TEAMS
// -----------------------------------------------------------------------------
// KMP_HOT_TEAMS_MAX_LEVEL, KMP_HOT_TEAMS_MODE

static void __kmp_stg_parse_hot_teams_level(char const *name, char const *value,
                                            void *data) {
  if (TCR_4(__kmp_init_parallel)) {
    KMP_WARNING(EnvParallelWarn, name);
    return;
  } // read value before first parallel only
  __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
                      &__kmp_hot_teams_max_level);
} // __kmp_stg_parse_hot_teams_level

static void __kmp_stg_print_hot_teams_level(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_hot_teams_max_level);
} // __kmp_stg_print_hot_teams_level

static void __kmp_stg_parse_hot_teams_mode(char const *name, char const *value,
                                           void *data) {
  if (TCR_4(__kmp_init_parallel)) {
    KMP_WARNING(EnvParallelWarn, name);
    return;
  } // read value before first parallel only
  __kmp_stg_parse_int(name, value, 0, KMP_MAX_ACTIVE_LEVELS_LIMIT,
                      &__kmp_hot_teams_mode);
} // __kmp_stg_parse_hot_teams_mode

static void __kmp_stg_print_hot_teams_mode(kmp_str_buf_t *buffer,
                                           char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_hot_teams_mode);
} // __kmp_stg_print_hot_teams_mode

#endif // KMP_NESTED_HOT_TEAMS

// -----------------------------------------------------------------------------
// KMP_HANDLE_SIGNALS

#if KMP_HANDLE_SIGNALS

static void __kmp_stg_parse_handle_signals(char const *name, char const *value,
                                           void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_handle_signals);
} // __kmp_stg_parse_handle_signals

static void __kmp_stg_print_handle_signals(kmp_str_buf_t *buffer,
                                           char const *name, void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_handle_signals);
} // __kmp_stg_print_handle_signals

#endif // KMP_HANDLE_SIGNALS

// -----------------------------------------------------------------------------
// KMP_X_DEBUG, KMP_DEBUG, KMP_DEBUG_BUF_*, KMP_DIAG

#ifdef KMP_DEBUG

#define KMP_STG_X_DEBUG(x)                                                     \
  static void __kmp_stg_parse_##x##_debug(char const *name, char const *value, \
                                          void *data) {                        \
    __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_##x##_debug);            \
  } /* __kmp_stg_parse_x_debug */                                              \
  static void __kmp_stg_print_##x##_debug(kmp_str_buf_t *buffer,               \
                                          char const *name, void *data) {      \
    __kmp_stg_print_int(buffer, name, kmp_##x##_debug);                        \
  } /* __kmp_stg_print_x_debug */

KMP_STG_X_DEBUG(a)
KMP_STG_X_DEBUG(b)
KMP_STG_X_DEBUG(c)
KMP_STG_X_DEBUG(d)
KMP_STG_X_DEBUG(e)
KMP_STG_X_DEBUG(f)

#undef KMP_STG_X_DEBUG

static void __kmp_stg_parse_debug(char const *name, char const *value,
                                  void *data) {
  int debug = 0;
  __kmp_stg_parse_int(name, value, 0, INT_MAX, &debug);
  if (kmp_a_debug < debug) {
    kmp_a_debug = debug;
  }
  if (kmp_b_debug < debug) {
    kmp_b_debug = debug;
  }
  if (kmp_c_debug < debug) {
    kmp_c_debug = debug;
  }
  if (kmp_d_debug < debug) {
    kmp_d_debug = debug;
  }
  if (kmp_e_debug < debug) {
    kmp_e_debug = debug;
  }
  if (kmp_f_debug < debug) {
    kmp_f_debug = debug;
  }
} // __kmp_stg_parse_debug

static void __kmp_stg_parse_debug_buf(char const *name, char const *value,
                                      void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_debug_buf);
  // !!! TODO: Move buffer initialization of of this file! It may works
  // incorrectly if KMP_DEBUG_BUF is parsed before KMP_DEBUG_BUF_LINES or
  // KMP_DEBUG_BUF_CHARS.
  if (__kmp_debug_buf) {
    int i;
    int elements = __kmp_debug_buf_lines * __kmp_debug_buf_chars;

    /* allocate and initialize all entries in debug buffer to empty */
    __kmp_debug_buffer = (char *)__kmp_page_allocate(elements * sizeof(char));
    for (i = 0; i < elements; i += __kmp_debug_buf_chars)
      __kmp_debug_buffer[i] = '\0';

    __kmp_debug_count = 0;
  }
  K_DIAG(1, ("__kmp_debug_buf = %d\n", __kmp_debug_buf));
} // __kmp_stg_parse_debug_buf

static void __kmp_stg_print_debug_buf(kmp_str_buf_t *buffer, char const *name,
                                      void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_debug_buf);
} // __kmp_stg_print_debug_buf

static void __kmp_stg_parse_debug_buf_atomic(char const *name,
                                             char const *value, void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_debug_buf_atomic);
} // __kmp_stg_parse_debug_buf_atomic

static void __kmp_stg_print_debug_buf_atomic(kmp_str_buf_t *buffer,
                                             char const *name, void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_debug_buf_atomic);
} // __kmp_stg_print_debug_buf_atomic

static void __kmp_stg_parse_debug_buf_chars(char const *name, char const *value,
                                            void *data) {
  __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_CHARS_MIN, INT_MAX,
                      &__kmp_debug_buf_chars);
} // __kmp_stg_debug_parse_buf_chars

static void __kmp_stg_print_debug_buf_chars(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_debug_buf_chars);
} // __kmp_stg_print_debug_buf_chars

static void __kmp_stg_parse_debug_buf_lines(char const *name, char const *value,
                                            void *data) {
  __kmp_stg_parse_int(name, value, KMP_DEBUG_BUF_LINES_MIN, INT_MAX,
                      &__kmp_debug_buf_lines);
} // __kmp_stg_parse_debug_buf_lines

static void __kmp_stg_print_debug_buf_lines(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_debug_buf_lines);
} // __kmp_stg_print_debug_buf_lines

static void __kmp_stg_parse_diag(char const *name, char const *value,
                                 void *data) {
  __kmp_stg_parse_int(name, value, 0, INT_MAX, &kmp_diag);
} // __kmp_stg_parse_diag

static void __kmp_stg_print_diag(kmp_str_buf_t *buffer, char const *name,
                                 void *data) {
  __kmp_stg_print_int(buffer, name, kmp_diag);
} // __kmp_stg_print_diag

#endif // KMP_DEBUG

// -----------------------------------------------------------------------------
// KMP_ALIGN_ALLOC

static void __kmp_stg_parse_align_alloc(char const *name, char const *value,
                                        void *data) {
  __kmp_stg_parse_size(name, value, CACHE_LINE, INT_MAX, NULL,
                       &__kmp_align_alloc, 1);
} // __kmp_stg_parse_align_alloc

static void __kmp_stg_print_align_alloc(kmp_str_buf_t *buffer, char const *name,
                                        void *data) {
  __kmp_stg_print_size(buffer, name, __kmp_align_alloc);
} // __kmp_stg_print_align_alloc

// -----------------------------------------------------------------------------
// KMP_PLAIN_BARRIER, KMP_FORKJOIN_BARRIER, KMP_REDUCTION_BARRIER

// TODO: Remove __kmp_barrier_branch_bit_env_name varibale, remove loops from
// parse and print functions, pass required info through data argument.

static void __kmp_stg_parse_barrier_branch_bit(char const *name,
                                               char const *value, void *data) {
  const char *var;

  /* ---------- Barrier branch bit control ------------ */
  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
    var = __kmp_barrier_branch_bit_env_name[i];
    if ((strcmp(var, name) == 0) && (value != 0)) {
      char *comma;

      comma = CCAST(char *, strchr(value, ','));
      __kmp_barrier_gather_branch_bits[i] =
          (kmp_uint32)__kmp_str_to_int(value, ',');
      /* is there a specified release parameter? */
      if (comma == NULL) {
        __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
      } else {
        __kmp_barrier_release_branch_bits[i] =
            (kmp_uint32)__kmp_str_to_int(comma + 1, 0);

        if (__kmp_barrier_release_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
          __kmp_msg(kmp_ms_warning,
                    KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
                    __kmp_msg_null);
          __kmp_barrier_release_branch_bits[i] = __kmp_barrier_release_bb_dflt;
        }
      }
      if (__kmp_barrier_gather_branch_bits[i] > KMP_MAX_BRANCH_BITS) {
        KMP_WARNING(BarrGatherValueInvalid, name, value);
        KMP_INFORM(Using_uint_Value, name, __kmp_barrier_gather_bb_dflt);
        __kmp_barrier_gather_branch_bits[i] = __kmp_barrier_gather_bb_dflt;
      }
    }
    K_DIAG(1, ("%s == %d,%d\n", __kmp_barrier_branch_bit_env_name[i],
               __kmp_barrier_gather_branch_bits[i],
               __kmp_barrier_release_branch_bits[i]))
  }
} // __kmp_stg_parse_barrier_branch_bit

static void __kmp_stg_print_barrier_branch_bit(kmp_str_buf_t *buffer,
                                               char const *name, void *data) {
  const char *var;
  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
    var = __kmp_barrier_branch_bit_env_name[i];
    if (strcmp(var, name) == 0) {
      if (__kmp_env_format) {
        KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_branch_bit_env_name[i]);
      } else {
        __kmp_str_buf_print(buffer, "   %s='",
                            __kmp_barrier_branch_bit_env_name[i]);
      }
      __kmp_str_buf_print(buffer, "%d,%d'\n",
                          __kmp_barrier_gather_branch_bits[i],
                          __kmp_barrier_release_branch_bits[i]);
    }
  }
} // __kmp_stg_print_barrier_branch_bit

// ----------------------------------------------------------------------------
// KMP_PLAIN_BARRIER_PATTERN, KMP_FORKJOIN_BARRIER_PATTERN,
// KMP_REDUCTION_BARRIER_PATTERN

// TODO: Remove __kmp_barrier_pattern_name variable, remove loops from parse and
// print functions, pass required data to functions through data argument.

static void __kmp_stg_parse_barrier_pattern(char const *name, char const *value,
                                            void *data) {
  const char *var;
  /* ---------- Barrier method control ------------ */

  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
    var = __kmp_barrier_pattern_env_name[i];

    if ((strcmp(var, name) == 0) && (value != 0)) {
      int j;
      char *comma = CCAST(char *, strchr(value, ','));

      /* handle first parameter: gather pattern */
      for (j = bp_linear_bar; j < bp_last_bar; j++) {
        if (__kmp_match_with_sentinel(__kmp_barrier_pattern_name[j], value, 1,
                                      ',')) {
          __kmp_barrier_gather_pattern[i] = (kmp_bar_pat_e)j;
          break;
        }
      }
      if (j == bp_last_bar) {
        KMP_WARNING(BarrGatherValueInvalid, name, value);
        KMP_INFORM(Using_str_Value, name,
                   __kmp_barrier_pattern_name[bp_linear_bar]);
      }

      /* handle second parameter: release pattern */
      if (comma != NULL) {
        for (j = bp_linear_bar; j < bp_last_bar; j++) {
          if (__kmp_str_match(__kmp_barrier_pattern_name[j], 1, comma + 1)) {
            __kmp_barrier_release_pattern[i] = (kmp_bar_pat_e)j;
            break;
          }
        }
        if (j == bp_last_bar) {
          __kmp_msg(kmp_ms_warning,
                    KMP_MSG(BarrReleaseValueInvalid, name, comma + 1),
                    __kmp_msg_null);
          KMP_INFORM(Using_str_Value, name,
                     __kmp_barrier_pattern_name[bp_linear_bar]);
        }
      }
    }
  }
} // __kmp_stg_parse_barrier_pattern

static void __kmp_stg_print_barrier_pattern(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  const char *var;
  for (int i = bs_plain_barrier; i < bs_last_barrier; i++) {
    var = __kmp_barrier_pattern_env_name[i];
    if (strcmp(var, name) == 0) {
      int j = __kmp_barrier_gather_pattern[i];
      int k = __kmp_barrier_release_pattern[i];
      if (__kmp_env_format) {
        KMP_STR_BUF_PRINT_NAME_EX(__kmp_barrier_pattern_env_name[i]);
      } else {
        __kmp_str_buf_print(buffer, "   %s='",
                            __kmp_barrier_pattern_env_name[i]);
      }
      __kmp_str_buf_print(buffer, "%s,%s'\n", __kmp_barrier_pattern_name[j],
                          __kmp_barrier_pattern_name[k]);
    }
  }
} // __kmp_stg_print_barrier_pattern

// -----------------------------------------------------------------------------
// KMP_ABORT_DELAY

static void __kmp_stg_parse_abort_delay(char const *name, char const *value,
                                        void *data) {
  // Units of KMP_DELAY_ABORT are seconds, units of __kmp_abort_delay is
  // milliseconds.
  int delay = __kmp_abort_delay / 1000;
  __kmp_stg_parse_int(name, value, 0, INT_MAX / 1000, &delay);
  __kmp_abort_delay = delay * 1000;
} // __kmp_stg_parse_abort_delay

static void __kmp_stg_print_abort_delay(kmp_str_buf_t *buffer, char const *name,
                                        void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_abort_delay);
} // __kmp_stg_print_abort_delay

// -----------------------------------------------------------------------------
// KMP_CPUINFO_FILE

static void __kmp_stg_parse_cpuinfo_file(char const *name, char const *value,
                                         void *data) {
#if KMP_AFFINITY_SUPPORTED
  __kmp_stg_parse_str(name, value, &__kmp_cpuinfo_file);
  K_DIAG(1, ("__kmp_cpuinfo_file == %s\n", __kmp_cpuinfo_file));
#endif
} //__kmp_stg_parse_cpuinfo_file

static void __kmp_stg_print_cpuinfo_file(kmp_str_buf_t *buffer,
                                         char const *name, void *data) {
#if KMP_AFFINITY_SUPPORTED
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME;
  } else {
    __kmp_str_buf_print(buffer, "   %s", name);
  }
  if (__kmp_cpuinfo_file) {
    __kmp_str_buf_print(buffer, "='%s'\n", __kmp_cpuinfo_file);
  } else {
    __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
  }
#endif
} //__kmp_stg_print_cpuinfo_file

// -----------------------------------------------------------------------------
// KMP_FORCE_REDUCTION, KMP_DETERMINISTIC_REDUCTION

static void __kmp_stg_parse_force_reduction(char const *name, char const *value,
                                            void *data) {
  kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
  int rc;

  rc = __kmp_stg_check_rivals(name, value, reduction->rivals);
  if (rc) {
    return;
  }
  if (reduction->force) {
    if (value != 0) {
      if (__kmp_str_match("critical", 0, value))
        __kmp_force_reduction_method = critical_reduce_block;
      else if (__kmp_str_match("atomic", 0, value))
        __kmp_force_reduction_method = atomic_reduce_block;
      else if (__kmp_str_match("tree", 0, value))
        __kmp_force_reduction_method = tree_reduce_block;
      else {
        KMP_FATAL(UnknownForceReduction, name, value);
      }
    }
  } else {
    __kmp_stg_parse_bool(name, value, &__kmp_determ_red);
    if (__kmp_determ_red) {
      __kmp_force_reduction_method = tree_reduce_block;
    } else {
      __kmp_force_reduction_method = reduction_method_not_defined;
    }
  }
  K_DIAG(1, ("__kmp_force_reduction_method == %d\n",
             __kmp_force_reduction_method));
} // __kmp_stg_parse_force_reduction

static void __kmp_stg_print_force_reduction(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {

  kmp_stg_fr_data_t *reduction = (kmp_stg_fr_data_t *)data;
  if (reduction->force) {
    if (__kmp_force_reduction_method == critical_reduce_block) {
      __kmp_stg_print_str(buffer, name, "critical");
    } else if (__kmp_force_reduction_method == atomic_reduce_block) {
      __kmp_stg_print_str(buffer, name, "atomic");
    } else if (__kmp_force_reduction_method == tree_reduce_block) {
      __kmp_stg_print_str(buffer, name, "tree");
    } else {
      if (__kmp_env_format) {
        KMP_STR_BUF_PRINT_NAME;
      } else {
        __kmp_str_buf_print(buffer, "   %s", name);
      }
      __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
    }
  } else {
    __kmp_stg_print_bool(buffer, name, __kmp_determ_red);
  }

} // __kmp_stg_print_force_reduction

// -----------------------------------------------------------------------------
// KMP_STORAGE_MAP

static void __kmp_stg_parse_storage_map(char const *name, char const *value,
                                        void *data) {
  if (__kmp_str_match("verbose", 1, value)) {
    __kmp_storage_map = TRUE;
    __kmp_storage_map_verbose = TRUE;
    __kmp_storage_map_verbose_specified = TRUE;

  } else {
    __kmp_storage_map_verbose = FALSE;
    __kmp_stg_parse_bool(name, value, &__kmp_storage_map); // !!!
  }
} // __kmp_stg_parse_storage_map

static void __kmp_stg_print_storage_map(kmp_str_buf_t *buffer, char const *name,
                                        void *data) {
  if (__kmp_storage_map_verbose || __kmp_storage_map_verbose_specified) {
    __kmp_stg_print_str(buffer, name, "verbose");
  } else {
    __kmp_stg_print_bool(buffer, name, __kmp_storage_map);
  }
} // __kmp_stg_print_storage_map

// -----------------------------------------------------------------------------
// KMP_ALL_THREADPRIVATE

static void __kmp_stg_parse_all_threadprivate(char const *name,
                                              char const *value, void *data) {
  __kmp_stg_parse_int(name, value,
                      __kmp_allThreadsSpecified ? __kmp_max_nth : 1,
                      __kmp_max_nth, &__kmp_tp_capacity);
} // __kmp_stg_parse_all_threadprivate

static void __kmp_stg_print_all_threadprivate(kmp_str_buf_t *buffer,
                                              char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_tp_capacity);
}

// -----------------------------------------------------------------------------
// KMP_FOREIGN_THREADS_THREADPRIVATE

static void __kmp_stg_parse_foreign_threads_threadprivate(char const *name,
                                                          char const *value,
                                                          void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_foreign_tp);
} // __kmp_stg_parse_foreign_threads_threadprivate

static void __kmp_stg_print_foreign_threads_threadprivate(kmp_str_buf_t *buffer,
                                                          char const *name,
                                                          void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_foreign_tp);
} // __kmp_stg_print_foreign_threads_threadprivate

// -----------------------------------------------------------------------------
// KMP_AFFINITY, GOMP_CPU_AFFINITY, KMP_TOPOLOGY_METHOD

#if KMP_AFFINITY_SUPPORTED
// Parse the proc id list.  Return TRUE if successful, FALSE otherwise.
static int __kmp_parse_affinity_proc_id_list(const char *var, const char *env,
                                             const char **nextEnv,
                                             char **proclist) {
  const char *scan = env;
  const char *next = scan;
  int empty = TRUE;

  *proclist = NULL;

  for (;;) {
    int start, end, stride;

    SKIP_WS(scan);
    next = scan;
    if (*next == '\0') {
      break;
    }

    if (*next == '{') {
      int num;
      next++; // skip '{'
      SKIP_WS(next);
      scan = next;

      // Read the first integer in the set.
      if ((*next < '0') || (*next > '9')) {
        KMP_WARNING(AffSyntaxError, var);
        return FALSE;
      }
      SKIP_DIGITS(next);
      num = __kmp_str_to_int(scan, *next);
      KMP_ASSERT(num >= 0);

      for (;;) {
        // Check for end of set.
        SKIP_WS(next);
        if (*next == '}') {
          next++; // skip '}'
          break;
        }

        // Skip optional comma.
        if (*next == ',') {
          next++;
        }
        SKIP_WS(next);

        // Read the next integer in the set.
        scan = next;
        if ((*next < '0') || (*next > '9')) {
          KMP_WARNING(AffSyntaxError, var);
          return FALSE;
        }

        SKIP_DIGITS(next);
        num = __kmp_str_to_int(scan, *next);
        KMP_ASSERT(num >= 0);
      }
      empty = FALSE;

      SKIP_WS(next);
      if (*next == ',') {
        next++;
      }
      scan = next;
      continue;
    }

    // Next character is not an integer => end of list
    if ((*next < '0') || (*next > '9')) {
      if (empty) {
        KMP_WARNING(AffSyntaxError, var);
        return FALSE;
      }
      break;
    }

    // Read the first integer.
    SKIP_DIGITS(next);
    start = __kmp_str_to_int(scan, *next);
    KMP_ASSERT(start >= 0);
    SKIP_WS(next);

    // If this isn't a range, then go on.
    if (*next != '-') {
      empty = FALSE;

      // Skip optional comma.
      if (*next == ',') {
        next++;
      }
      scan = next;
      continue;
    }

    // This is a range.  Skip over the '-' and read in the 2nd int.
    next++; // skip '-'
    SKIP_WS(next);
    scan = next;
    if ((*next < '0') || (*next > '9')) {
      KMP_WARNING(AffSyntaxError, var);
      return FALSE;
    }
    SKIP_DIGITS(next);
    end = __kmp_str_to_int(scan, *next);
    KMP_ASSERT(end >= 0);

    // Check for a stride parameter
    stride = 1;
    SKIP_WS(next);
    if (*next == ':') {
      // A stride is specified.  Skip over the ':" and read the 3rd int.
      int sign = +1;
      next++; // skip ':'
      SKIP_WS(next);
      scan = next;
      if (*next == '-') {
        sign = -1;
        next++;
        SKIP_WS(next);
        scan = next;
      }
      if ((*next < '0') || (*next > '9')) {
        KMP_WARNING(AffSyntaxError, var);
        return FALSE;
      }
      SKIP_DIGITS(next);
      stride = __kmp_str_to_int(scan, *next);
      KMP_ASSERT(stride >= 0);
      stride *= sign;
    }

    // Do some range checks.
    if (stride == 0) {
      KMP_WARNING(AffZeroStride, var);
      return FALSE;
    }
    if (stride > 0) {
      if (start > end) {
        KMP_WARNING(AffStartGreaterEnd, var, start, end);
        return FALSE;
      }
    } else {
      if (start < end) {
        KMP_WARNING(AffStrideLessZero, var, start, end);
        return FALSE;
      }
    }
    if ((end - start) / stride > 65536) {
      KMP_WARNING(AffRangeTooBig, var, end, start, stride);
      return FALSE;
    }

    empty = FALSE;

    // Skip optional comma.
    SKIP_WS(next);
    if (*next == ',') {
      next++;
    }
    scan = next;
  }

  *nextEnv = next;

  {
    int len = next - env;
    char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
    KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
    retlist[len] = '\0';
    *proclist = retlist;
  }
  return TRUE;
}

// If KMP_AFFINITY is specified without a type, then
// __kmp_affinity_notype should point to its setting.
static kmp_setting_t *__kmp_affinity_notype = NULL;

static void __kmp_parse_affinity_env(char const *name, char const *value,
                                     enum affinity_type *out_type,
                                     char **out_proclist, int *out_verbose,
                                     int *out_warn, int *out_respect,
                                     enum affinity_gran *out_gran,
                                     int *out_gran_levels, int *out_dups,
                                     int *out_compact, int *out_offset) {
  char *buffer = NULL; // Copy of env var value.
  char *buf = NULL; // Buffer for strtok_r() function.
  char *next = NULL; // end of token / start of next.
  const char *start; // start of current token (for err msgs)
  int count = 0; // Counter of parsed integer numbers.
  int number[2]; // Parsed numbers.

  // Guards.
  int type = 0;
  int proclist = 0;
  int verbose = 0;
  int warnings = 0;
  int respect = 0;
  int gran = 0;
  int dups = 0;

  KMP_ASSERT(value != NULL);

  if (TCR_4(__kmp_init_middle)) {
    KMP_WARNING(EnvMiddleWarn, name);
    __kmp_env_toPrint(name, 0);
    return;
  }
  __kmp_env_toPrint(name, 1);

  buffer =
      __kmp_str_format("%s", value); // Copy env var to keep original intact.
  buf = buffer;
  SKIP_WS(buf);

// Helper macros.

// If we see a parse error, emit a warning and scan to the next ",".
//
// FIXME - there's got to be a better way to print an error
// message, hopefully without overwriting peices of buf.
#define EMIT_WARN(skip, errlist)                                               \
  {                                                                            \
    char ch;                                                                   \
    if (skip) {                                                                \
      SKIP_TO(next, ',');                                                      \
    }                                                                          \
    ch = *next;                                                                \
    *next = '\0';                                                              \
    KMP_WARNING errlist;                                                       \
    *next = ch;                                                                \
    if (skip) {                                                                \
      if (ch == ',')                                                           \
        next++;                                                                \
    }                                                                          \
    buf = next;                                                                \
  }

#define _set_param(_guard, _var, _val)                                         \
  {                                                                            \
    if (_guard == 0) {                                                         \
      _var = _val;                                                             \
    } else {                                                                   \
      EMIT_WARN(FALSE, (AffParamDefined, name, start));                        \
    }                                                                          \
    ++_guard;                                                                  \
  }

#define set_type(val) _set_param(type, *out_type, val)
#define set_verbose(val) _set_param(verbose, *out_verbose, val)
#define set_warnings(val) _set_param(warnings, *out_warn, val)
#define set_respect(val) _set_param(respect, *out_respect, val)
#define set_dups(val) _set_param(dups, *out_dups, val)
#define set_proclist(val) _set_param(proclist, *out_proclist, val)

#define set_gran(val, levels)                                                  \
  {                                                                            \
    if (gran == 0) {                                                           \
      *out_gran = val;                                                         \
      *out_gran_levels = levels;                                               \
    } else {                                                                   \
      EMIT_WARN(FALSE, (AffParamDefined, name, start));                        \
    }                                                                          \
    ++gran;                                                                    \
  }

  KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
                   (__kmp_nested_proc_bind.used > 0));

  while (*buf != '\0') {
    start = next = buf;

    if (__kmp_match_str("none", buf, CCAST(const char **, &next))) {
      set_type(affinity_none);
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
      buf = next;
    } else if (__kmp_match_str("scatter", buf, CCAST(const char **, &next))) {
      set_type(affinity_scatter);
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
      buf = next;
    } else if (__kmp_match_str("compact", buf, CCAST(const char **, &next))) {
      set_type(affinity_compact);
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
      buf = next;
    } else if (__kmp_match_str("logical", buf, CCAST(const char **, &next))) {
      set_type(affinity_logical);
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
      buf = next;
    } else if (__kmp_match_str("physical", buf, CCAST(const char **, &next))) {
      set_type(affinity_physical);
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
      buf = next;
    } else if (__kmp_match_str("explicit", buf, CCAST(const char **, &next))) {
      set_type(affinity_explicit);
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
      buf = next;
    } else if (__kmp_match_str("balanced", buf, CCAST(const char **, &next))) {
      set_type(affinity_balanced);
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
      buf = next;
    } else if (__kmp_match_str("disabled", buf, CCAST(const char **, &next))) {
      set_type(affinity_disabled);
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
      buf = next;
    } else if (__kmp_match_str("verbose", buf, CCAST(const char **, &next))) {
      set_verbose(TRUE);
      buf = next;
    } else if (__kmp_match_str("noverbose", buf, CCAST(const char **, &next))) {
      set_verbose(FALSE);
      buf = next;
    } else if (__kmp_match_str("warnings", buf, CCAST(const char **, &next))) {
      set_warnings(TRUE);
      buf = next;
    } else if (__kmp_match_str("nowarnings", buf,
                               CCAST(const char **, &next))) {
      set_warnings(FALSE);
      buf = next;
    } else if (__kmp_match_str("respect", buf, CCAST(const char **, &next))) {
      set_respect(TRUE);
      buf = next;
    } else if (__kmp_match_str("norespect", buf, CCAST(const char **, &next))) {
      set_respect(FALSE);
      buf = next;
    } else if (__kmp_match_str("duplicates", buf,
                               CCAST(const char **, &next)) ||
               __kmp_match_str("dups", buf, CCAST(const char **, &next))) {
      set_dups(TRUE);
      buf = next;
    } else if (__kmp_match_str("noduplicates", buf,
                               CCAST(const char **, &next)) ||
               __kmp_match_str("nodups", buf, CCAST(const char **, &next))) {
      set_dups(FALSE);
      buf = next;
    } else if (__kmp_match_str("granularity", buf,
                               CCAST(const char **, &next)) ||
               __kmp_match_str("gran", buf, CCAST(const char **, &next))) {
      SKIP_WS(next);
      if (*next != '=') {
        EMIT_WARN(TRUE, (AffInvalidParam, name, start));
        continue;
      }
      next++; // skip '='
      SKIP_WS(next);

      buf = next;
      if (__kmp_match_str("fine", buf, CCAST(const char **, &next))) {
        set_gran(affinity_gran_fine, -1);
        buf = next;
      } else if (__kmp_match_str("thread", buf, CCAST(const char **, &next))) {
        set_gran(affinity_gran_thread, -1);
        buf = next;
      } else if (__kmp_match_str("core", buf, CCAST(const char **, &next))) {
        set_gran(affinity_gran_core, -1);
        buf = next;
#if KMP_USE_HWLOC
      } else if (__kmp_match_str("tile", buf, CCAST(const char **, &next))) {
        set_gran(affinity_gran_tile, -1);
        buf = next;
#endif
      } else if (__kmp_match_str("package", buf, CCAST(const char **, &next))) {
        set_gran(affinity_gran_package, -1);
        buf = next;
      } else if (__kmp_match_str("node", buf, CCAST(const char **, &next))) {
        set_gran(affinity_gran_node, -1);
        buf = next;
#if KMP_GROUP_AFFINITY
      } else if (__kmp_match_str("group", buf, CCAST(const char **, &next))) {
        set_gran(affinity_gran_group, -1);
        buf = next;
#endif /* KMP_GROUP AFFINITY */
      } else if ((*buf >= '0') && (*buf <= '9')) {
        int n;
        next = buf;
        SKIP_DIGITS(next);
        n = __kmp_str_to_int(buf, *next);
        KMP_ASSERT(n >= 0);
        buf = next;
        set_gran(affinity_gran_default, n);
      } else {
        EMIT_WARN(TRUE, (AffInvalidParam, name, start));
        continue;
      }
    } else if (__kmp_match_str("proclist", buf, CCAST(const char **, &next))) {
      char *temp_proclist;

      SKIP_WS(next);
      if (*next != '=') {
        EMIT_WARN(TRUE, (AffInvalidParam, name, start));
        continue;
      }
      next++; // skip '='
      SKIP_WS(next);
      if (*next != '[') {
        EMIT_WARN(TRUE, (AffInvalidParam, name, start));
        continue;
      }
      next++; // skip '['
      buf = next;
      if (!__kmp_parse_affinity_proc_id_list(
              name, buf, CCAST(const char **, &next), &temp_proclist)) {
        // warning already emitted.
        SKIP_TO(next, ']');
        if (*next == ']')
          next++;
        SKIP_TO(next, ',');
        if (*next == ',')
          next++;
        buf = next;
        continue;
      }
      if (*next != ']') {
        EMIT_WARN(TRUE, (AffInvalidParam, name, start));
        continue;
      }
      next++; // skip ']'
      set_proclist(temp_proclist);
    } else if ((*buf >= '0') && (*buf <= '9')) {
      // Parse integer numbers -- permute and offset.
      int n;
      next = buf;
      SKIP_DIGITS(next);
      n = __kmp_str_to_int(buf, *next);
      KMP_ASSERT(n >= 0);
      buf = next;
      if (count < 2) {
        number[count] = n;
      } else {
        KMP_WARNING(AffManyParams, name, start);
      }
      ++count;
    } else {
      EMIT_WARN(TRUE, (AffInvalidParam, name, start));
      continue;
    }

    SKIP_WS(next);
    if (*next == ',') {
      next++;
      SKIP_WS(next);
    } else if (*next != '\0') {
      const char *temp = next;
      EMIT_WARN(TRUE, (ParseExtraCharsWarn, name, temp));
      continue;
    }
    buf = next;
  } // while

#undef EMIT_WARN
#undef _set_param
#undef set_type
#undef set_verbose
#undef set_warnings
#undef set_respect
#undef set_granularity

  __kmp_str_free(&buffer);

  if (proclist) {
    if (!type) {
      KMP_WARNING(AffProcListNoType, name);
      *out_type = affinity_explicit;
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
    } else if (*out_type != affinity_explicit) {
      KMP_WARNING(AffProcListNotExplicit, name);
      KMP_ASSERT(*out_proclist != NULL);
      KMP_INTERNAL_FREE(*out_proclist);
      *out_proclist = NULL;
    }
  }
  switch (*out_type) {
  case affinity_logical:
  case affinity_physical: {
    if (count > 0) {
      *out_offset = number[0];
    }
    if (count > 1) {
      KMP_WARNING(AffManyParamsForLogic, name, number[1]);
    }
  } break;
  case affinity_balanced: {
    if (count > 0) {
      *out_compact = number[0];
    }
    if (count > 1) {
      *out_offset = number[1];
    }

    if (__kmp_affinity_gran == affinity_gran_default) {
#if KMP_MIC_SUPPORTED
      if (__kmp_mic_type != non_mic) {
        if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
          KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "fine");
        }
        __kmp_affinity_gran = affinity_gran_fine;
      } else
#endif
      {
        if (__kmp_affinity_verbose || __kmp_affinity_warnings) {
          KMP_WARNING(AffGranUsing, "KMP_AFFINITY", "core");
        }
        __kmp_affinity_gran = affinity_gran_core;
      }
    }
  } break;
  case affinity_scatter:
  case affinity_compact: {
    if (count > 0) {
      *out_compact = number[0];
    }
    if (count > 1) {
      *out_offset = number[1];
    }
  } break;
  case affinity_explicit: {
    if (*out_proclist == NULL) {
      KMP_WARNING(AffNoProcList, name);
      __kmp_affinity_type = affinity_none;
    }
    if (count > 0) {
      KMP_WARNING(AffNoParam, name, "explicit");
    }
  } break;
  case affinity_none: {
    if (count > 0) {
      KMP_WARNING(AffNoParam, name, "none");
    }
  } break;
  case affinity_disabled: {
    if (count > 0) {
      KMP_WARNING(AffNoParam, name, "disabled");
    }
  } break;
  case affinity_default: {
    if (count > 0) {
      KMP_WARNING(AffNoParam, name, "default");
    }
  } break;
  default: { KMP_ASSERT(0); }
  }
} // __kmp_parse_affinity_env

static void __kmp_stg_parse_affinity(char const *name, char const *value,
                                     void *data) {
  kmp_setting_t **rivals = (kmp_setting_t **)data;
  int rc;

  rc = __kmp_stg_check_rivals(name, value, rivals);
  if (rc) {
    return;
  }

  __kmp_parse_affinity_env(name, value, &__kmp_affinity_type,
                           &__kmp_affinity_proclist, &__kmp_affinity_verbose,
                           &__kmp_affinity_warnings,
                           &__kmp_affinity_respect_mask, &__kmp_affinity_gran,
                           &__kmp_affinity_gran_levels, &__kmp_affinity_dups,
                           &__kmp_affinity_compact, &__kmp_affinity_offset);

} // __kmp_stg_parse_affinity

static void __kmp_stg_print_affinity(kmp_str_buf_t *buffer, char const *name,
                                     void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME_EX(name);
  } else {
    __kmp_str_buf_print(buffer, "   %s='", name);
  }
  if (__kmp_affinity_verbose) {
    __kmp_str_buf_print(buffer, "%s,", "verbose");
  } else {
    __kmp_str_buf_print(buffer, "%s,", "noverbose");
  }
  if (__kmp_affinity_warnings) {
    __kmp_str_buf_print(buffer, "%s,", "warnings");
  } else {
    __kmp_str_buf_print(buffer, "%s,", "nowarnings");
  }
  if (KMP_AFFINITY_CAPABLE()) {
    if (__kmp_affinity_respect_mask) {
      __kmp_str_buf_print(buffer, "%s,", "respect");
    } else {
      __kmp_str_buf_print(buffer, "%s,", "norespect");
    }
    switch (__kmp_affinity_gran) {
    case affinity_gran_default:
      __kmp_str_buf_print(buffer, "%s", "granularity=default,");
      break;
    case affinity_gran_fine:
      __kmp_str_buf_print(buffer, "%s", "granularity=fine,");
      break;
    case affinity_gran_thread:
      __kmp_str_buf_print(buffer, "%s", "granularity=thread,");
      break;
    case affinity_gran_core:
      __kmp_str_buf_print(buffer, "%s", "granularity=core,");
      break;
    case affinity_gran_package:
      __kmp_str_buf_print(buffer, "%s", "granularity=package,");
      break;
    case affinity_gran_node:
      __kmp_str_buf_print(buffer, "%s", "granularity=node,");
      break;
#if KMP_GROUP_AFFINITY
    case affinity_gran_group:
      __kmp_str_buf_print(buffer, "%s", "granularity=group,");
      break;
#endif /* KMP_GROUP_AFFINITY */
    }
  }
  if (!KMP_AFFINITY_CAPABLE()) {
    __kmp_str_buf_print(buffer, "%s", "disabled");
  } else
    switch (__kmp_affinity_type) {
    case affinity_none:
      __kmp_str_buf_print(buffer, "%s", "none");
      break;
    case affinity_physical:
      __kmp_str_buf_print(buffer, "%s,%d", "physical", __kmp_affinity_offset);
      break;
    case affinity_logical:
      __kmp_str_buf_print(buffer, "%s,%d", "logical", __kmp_affinity_offset);
      break;
    case affinity_compact:
      __kmp_str_buf_print(buffer, "%s,%d,%d", "compact", __kmp_affinity_compact,
                          __kmp_affinity_offset);
      break;
    case affinity_scatter:
      __kmp_str_buf_print(buffer, "%s,%d,%d", "scatter", __kmp_affinity_compact,
                          __kmp_affinity_offset);
      break;
    case affinity_explicit:
      __kmp_str_buf_print(buffer, "%s=[%s],%s", "proclist",
                          __kmp_affinity_proclist, "explicit");
      break;
    case affinity_balanced:
      __kmp_str_buf_print(buffer, "%s,%d,%d", "balanced",
                          __kmp_affinity_compact, __kmp_affinity_offset);
      break;
    case affinity_disabled:
      __kmp_str_buf_print(buffer, "%s", "disabled");
      break;
    case affinity_default:
      __kmp_str_buf_print(buffer, "%s", "default");
      break;
    default:
      __kmp_str_buf_print(buffer, "%s", "<unknown>");
      break;
    }
  __kmp_str_buf_print(buffer, "'\n");
} //__kmp_stg_print_affinity

#ifdef KMP_GOMP_COMPAT

static void __kmp_stg_parse_gomp_cpu_affinity(char const *name,
                                              char const *value, void *data) {
  const char *next = NULL;
  char *temp_proclist;
  kmp_setting_t **rivals = (kmp_setting_t **)data;
  int rc;

  rc = __kmp_stg_check_rivals(name, value, rivals);
  if (rc) {
    return;
  }

  if (TCR_4(__kmp_init_middle)) {
    KMP_WARNING(EnvMiddleWarn, name);
    __kmp_env_toPrint(name, 0);
    return;
  }

  __kmp_env_toPrint(name, 1);

  if (__kmp_parse_affinity_proc_id_list(name, value, &next, &temp_proclist)) {
    SKIP_WS(next);
    if (*next == '\0') {
      // GOMP_CPU_AFFINITY => granularity=fine,explicit,proclist=...
      __kmp_affinity_proclist = temp_proclist;
      __kmp_affinity_type = affinity_explicit;
      __kmp_affinity_gran = affinity_gran_fine;
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
    } else {
      KMP_WARNING(AffSyntaxError, name);
      if (temp_proclist != NULL) {
        KMP_INTERNAL_FREE((void *)temp_proclist);
      }
    }
  } else {
    // Warning already emitted
    __kmp_affinity_type = affinity_none;
    __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
  }
} // __kmp_stg_parse_gomp_cpu_affinity

#endif /* KMP_GOMP_COMPAT */

/*-----------------------------------------------------------------------------
The OMP_PLACES proc id list parser. Here is the grammar:

place_list := place
place_list := place , place_list
place := num
place := place : num
place := place : num : signed
place := { subplacelist }
place := ! place                  // (lowest priority)
subplace_list := subplace
subplace_list := subplace , subplace_list
subplace := num
subplace := num : num
subplace := num : num : signed
signed := num
signed := + signed
signed := - signed
-----------------------------------------------------------------------------*/

static int __kmp_parse_subplace_list(const char *var, const char **scan) {
  const char *next;

  for (;;) {
    int start, count, stride;

    //
    // Read in the starting proc id
    //
    SKIP_WS(*scan);
    if ((**scan < '0') || (**scan > '9')) {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    next = *scan;
    SKIP_DIGITS(next);
    start = __kmp_str_to_int(*scan, *next);
    KMP_ASSERT(start >= 0);
    *scan = next;

    // valid follow sets are ',' ':' and '}'
    SKIP_WS(*scan);
    if (**scan == '}') {
      break;
    }
    if (**scan == ',') {
      (*scan)++; // skip ','
      continue;
    }
    if (**scan != ':') {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    (*scan)++; // skip ':'

    // Read count parameter
    SKIP_WS(*scan);
    if ((**scan < '0') || (**scan > '9')) {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    next = *scan;
    SKIP_DIGITS(next);
    count = __kmp_str_to_int(*scan, *next);
    KMP_ASSERT(count >= 0);
    *scan = next;

    // valid follow sets are ',' ':' and '}'
    SKIP_WS(*scan);
    if (**scan == '}') {
      break;
    }
    if (**scan == ',') {
      (*scan)++; // skip ','
      continue;
    }
    if (**scan != ':') {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    (*scan)++; // skip ':'

    // Read stride parameter
    int sign = +1;
    for (;;) {
      SKIP_WS(*scan);
      if (**scan == '+') {
        (*scan)++; // skip '+'
        continue;
      }
      if (**scan == '-') {
        sign *= -1;
        (*scan)++; // skip '-'
        continue;
      }
      break;
    }
    SKIP_WS(*scan);
    if ((**scan < '0') || (**scan > '9')) {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    next = *scan;
    SKIP_DIGITS(next);
    stride = __kmp_str_to_int(*scan, *next);
    KMP_ASSERT(stride >= 0);
    *scan = next;
    stride *= sign;

    // valid follow sets are ',' and '}'
    SKIP_WS(*scan);
    if (**scan == '}') {
      break;
    }
    if (**scan == ',') {
      (*scan)++; // skip ','
      continue;
    }

    KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
    return FALSE;
  }
  return TRUE;
}

static int __kmp_parse_place(const char *var, const char **scan) {
  const char *next;

  // valid follow sets are '{' '!' and num
  SKIP_WS(*scan);
  if (**scan == '{') {
    (*scan)++; // skip '{'
    if (!__kmp_parse_subplace_list(var, scan)) {
      return FALSE;
    }
    if (**scan != '}') {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    (*scan)++; // skip '}'
  } else if (**scan == '!') {
    (*scan)++; // skip '!'
    return __kmp_parse_place(var, scan); //'!' has lower precedence than ':'
  } else if ((**scan >= '0') && (**scan <= '9')) {
    next = *scan;
    SKIP_DIGITS(next);
    int proc = __kmp_str_to_int(*scan, *next);
    KMP_ASSERT(proc >= 0);
    *scan = next;
  } else {
    KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
    return FALSE;
  }
  return TRUE;
}

static int __kmp_parse_place_list(const char *var, const char *env,
                                  char **place_list) {
  const char *scan = env;
  const char *next = scan;

  for (;;) {
    int count, stride;

    if (!__kmp_parse_place(var, &scan)) {
      return FALSE;
    }

    // valid follow sets are ',' ':' and EOL
    SKIP_WS(scan);
    if (*scan == '\0') {
      break;
    }
    if (*scan == ',') {
      scan++; // skip ','
      continue;
    }
    if (*scan != ':') {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    scan++; // skip ':'

    // Read count parameter
    SKIP_WS(scan);
    if ((*scan < '0') || (*scan > '9')) {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    next = scan;
    SKIP_DIGITS(next);
    count = __kmp_str_to_int(scan, *next);
    KMP_ASSERT(count >= 0);
    scan = next;

    // valid follow sets are ',' ':' and EOL
    SKIP_WS(scan);
    if (*scan == '\0') {
      break;
    }
    if (*scan == ',') {
      scan++; // skip ','
      continue;
    }
    if (*scan != ':') {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    scan++; // skip ':'

    // Read stride parameter
    int sign = +1;
    for (;;) {
      SKIP_WS(scan);
      if (*scan == '+') {
        scan++; // skip '+'
        continue;
      }
      if (*scan == '-') {
        sign *= -1;
        scan++; // skip '-'
        continue;
      }
      break;
    }
    SKIP_WS(scan);
    if ((*scan < '0') || (*scan > '9')) {
      KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
      return FALSE;
    }
    next = scan;
    SKIP_DIGITS(next);
    stride = __kmp_str_to_int(scan, *next);
    KMP_ASSERT(stride >= 0);
    scan = next;
    stride *= sign;

    // valid follow sets are ',' and EOL
    SKIP_WS(scan);
    if (*scan == '\0') {
      break;
    }
    if (*scan == ',') {
      scan++; // skip ','
      continue;
    }

    KMP_WARNING(SyntaxErrorUsing, var, "\"threads\"");
    return FALSE;
  }

  {
    int len = scan - env;
    char *retlist = (char *)__kmp_allocate((len + 1) * sizeof(char));
    KMP_MEMCPY_S(retlist, (len + 1) * sizeof(char), env, len * sizeof(char));
    retlist[len] = '\0';
    *place_list = retlist;
  }
  return TRUE;
}

static void __kmp_stg_parse_places(char const *name, char const *value,
                                   void *data) {
  int count;
  const char *scan = value;
  const char *next = scan;
  const char *kind = "\"threads\"";
  kmp_setting_t **rivals = (kmp_setting_t **)data;
  int rc;

  rc = __kmp_stg_check_rivals(name, value, rivals);
  if (rc) {
    return;
  }

  // If OMP_PROC_BIND is not specified but OMP_PLACES is,
  // then let OMP_PROC_BIND default to true.
  if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
    __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
  }

  //__kmp_affinity_num_places = 0;

  if (__kmp_match_str("threads", scan, &next)) {
    scan = next;
    __kmp_affinity_type = affinity_compact;
    __kmp_affinity_gran = affinity_gran_thread;
    __kmp_affinity_dups = FALSE;
    kind = "\"threads\"";
  } else if (__kmp_match_str("cores", scan, &next)) {
    scan = next;
    __kmp_affinity_type = affinity_compact;
    __kmp_affinity_gran = affinity_gran_core;
    __kmp_affinity_dups = FALSE;
    kind = "\"cores\"";
#if KMP_USE_HWLOC
  } else if (__kmp_match_str("tiles", scan, &next)) {
    scan = next;
    __kmp_affinity_type = affinity_compact;
    __kmp_affinity_gran = affinity_gran_tile;
    __kmp_affinity_dups = FALSE;
    kind = "\"tiles\"";
#endif
  } else if (__kmp_match_str("sockets", scan, &next)) {
    scan = next;
    __kmp_affinity_type = affinity_compact;
    __kmp_affinity_gran = affinity_gran_package;
    __kmp_affinity_dups = FALSE;
    kind = "\"sockets\"";
  } else {
    if (__kmp_affinity_proclist != NULL) {
      KMP_INTERNAL_FREE((void *)__kmp_affinity_proclist);
      __kmp_affinity_proclist = NULL;
    }
    if (__kmp_parse_place_list(name, value, &__kmp_affinity_proclist)) {
      __kmp_affinity_type = affinity_explicit;
      __kmp_affinity_gran = affinity_gran_fine;
      __kmp_affinity_dups = FALSE;
      if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
        __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
      }
    }
    return;
  }

  if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default) {
    __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
  }

  SKIP_WS(scan);
  if (*scan == '\0') {
    return;
  }

  // Parse option count parameter in parentheses
  if (*scan != '(') {
    KMP_WARNING(SyntaxErrorUsing, name, kind);
    return;
  }
  scan++; // skip '('

  SKIP_WS(scan);
  next = scan;
  SKIP_DIGITS(next);
  count = __kmp_str_to_int(scan, *next);
  KMP_ASSERT(count >= 0);
  scan = next;

  SKIP_WS(scan);
  if (*scan != ')') {
    KMP_WARNING(SyntaxErrorUsing, name, kind);
    return;
  }
  scan++; // skip ')'

  SKIP_WS(scan);
  if (*scan != '\0') {
    KMP_WARNING(ParseExtraCharsWarn, name, scan);
  }
  __kmp_affinity_num_places = count;
}

static void __kmp_stg_print_places(kmp_str_buf_t *buffer, char const *name,
                                   void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME;
  } else {
    __kmp_str_buf_print(buffer, "   %s", name);
  }
  if ((__kmp_nested_proc_bind.used == 0) ||
      (__kmp_nested_proc_bind.bind_types == NULL) ||
      (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)) {
    __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
  } else if (__kmp_affinity_type == affinity_explicit) {
    if (__kmp_affinity_proclist != NULL) {
      __kmp_str_buf_print(buffer, "='%s'\n", __kmp_affinity_proclist);
    } else {
      __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
    }
  } else if (__kmp_affinity_type == affinity_compact) {
    int num;
    if (__kmp_affinity_num_masks > 0) {
      num = __kmp_affinity_num_masks;
    } else if (__kmp_affinity_num_places > 0) {
      num = __kmp_affinity_num_places;
    } else {
      num = 0;
    }
    if (__kmp_affinity_gran == affinity_gran_thread) {
      if (num > 0) {
        __kmp_str_buf_print(buffer, "='threads(%d)'\n", num);
      } else {
        __kmp_str_buf_print(buffer, "='threads'\n");
      }
    } else if (__kmp_affinity_gran == affinity_gran_core) {
      if (num > 0) {
        __kmp_str_buf_print(buffer, "='cores(%d)' \n", num);
      } else {
        __kmp_str_buf_print(buffer, "='cores'\n");
      }
#if KMP_USE_HWLOC
    } else if (__kmp_affinity_gran == affinity_gran_tile) {
      if (num > 0) {
        __kmp_str_buf_print(buffer, "='tiles(%d)' \n", num);
      } else {
        __kmp_str_buf_print(buffer, "='tiles'\n");
      }
#endif
    } else if (__kmp_affinity_gran == affinity_gran_package) {
      if (num > 0) {
        __kmp_str_buf_print(buffer, "='sockets(%d)'\n", num);
      } else {
        __kmp_str_buf_print(buffer, "='sockets'\n");
      }
    } else {
      __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
    }
  } else {
    __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
  }
}

static void __kmp_stg_parse_topology_method(char const *name, char const *value,
                                            void *data) {
  if (__kmp_str_match("all", 1, value)) {
    __kmp_affinity_top_method = affinity_top_method_all;
  }
#if KMP_USE_HWLOC
  else if (__kmp_str_match("hwloc", 1, value)) {
    __kmp_affinity_top_method = affinity_top_method_hwloc;
  }
#endif
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
  else if (__kmp_str_match("x2apic id", 9, value) ||
           __kmp_str_match("x2apic_id", 9, value) ||
           __kmp_str_match("x2apic-id", 9, value) ||
           __kmp_str_match("x2apicid", 8, value) ||
           __kmp_str_match("cpuid leaf 11", 13, value) ||
           __kmp_str_match("cpuid_leaf_11", 13, value) ||
           __kmp_str_match("cpuid-leaf-11", 13, value) ||
           __kmp_str_match("cpuid leaf11", 12, value) ||
           __kmp_str_match("cpuid_leaf11", 12, value) ||
           __kmp_str_match("cpuid-leaf11", 12, value) ||
           __kmp_str_match("cpuidleaf 11", 12, value) ||
           __kmp_str_match("cpuidleaf_11", 12, value) ||
           __kmp_str_match("cpuidleaf-11", 12, value) ||
           __kmp_str_match("cpuidleaf11", 11, value) ||
           __kmp_str_match("cpuid 11", 8, value) ||
           __kmp_str_match("cpuid_11", 8, value) ||
           __kmp_str_match("cpuid-11", 8, value) ||
           __kmp_str_match("cpuid11", 7, value) ||
           __kmp_str_match("leaf 11", 7, value) ||
           __kmp_str_match("leaf_11", 7, value) ||
           __kmp_str_match("leaf-11", 7, value) ||
           __kmp_str_match("leaf11", 6, value)) {
    __kmp_affinity_top_method = affinity_top_method_x2apicid;
  } else if (__kmp_str_match("apic id", 7, value) ||
             __kmp_str_match("apic_id", 7, value) ||
             __kmp_str_match("apic-id", 7, value) ||
             __kmp_str_match("apicid", 6, value) ||
             __kmp_str_match("cpuid leaf 4", 12, value) ||
             __kmp_str_match("cpuid_leaf_4", 12, value) ||
             __kmp_str_match("cpuid-leaf-4", 12, value) ||
             __kmp_str_match("cpuid leaf4", 11, value) ||
             __kmp_str_match("cpuid_leaf4", 11, value) ||
             __kmp_str_match("cpuid-leaf4", 11, value) ||
             __kmp_str_match("cpuidleaf 4", 11, value) ||
             __kmp_str_match("cpuidleaf_4", 11, value) ||
             __kmp_str_match("cpuidleaf-4", 11, value) ||
             __kmp_str_match("cpuidleaf4", 10, value) ||
             __kmp_str_match("cpuid 4", 7, value) ||
             __kmp_str_match("cpuid_4", 7, value) ||
             __kmp_str_match("cpuid-4", 7, value) ||
             __kmp_str_match("cpuid4", 6, value) ||
             __kmp_str_match("leaf 4", 6, value) ||
             __kmp_str_match("leaf_4", 6, value) ||
             __kmp_str_match("leaf-4", 6, value) ||
             __kmp_str_match("leaf4", 5, value)) {
    __kmp_affinity_top_method = affinity_top_method_apicid;
  }
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
  else if (__kmp_str_match("/proc/cpuinfo", 2, value) ||
           __kmp_str_match("cpuinfo", 5, value)) {
    __kmp_affinity_top_method = affinity_top_method_cpuinfo;
  }
#if KMP_GROUP_AFFINITY
  else if (__kmp_str_match("group", 1, value)) {
    __kmp_affinity_top_method = affinity_top_method_group;
  }
#endif /* KMP_GROUP_AFFINITY */
  else if (__kmp_str_match("flat", 1, value)) {
    __kmp_affinity_top_method = affinity_top_method_flat;
  } else {
    KMP_WARNING(StgInvalidValue, name, value);
  }
} // __kmp_stg_parse_topology_method

static void __kmp_stg_print_topology_method(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  char const *value = NULL;

  switch (__kmp_affinity_top_method) {
  case affinity_top_method_default:
    value = "default";
    break;

  case affinity_top_method_all:
    value = "all";
    break;

#if KMP_ARCH_X86 || KMP_ARCH_X86_64
  case affinity_top_method_x2apicid:
    value = "x2APIC id";
    break;

  case affinity_top_method_apicid:
    value = "APIC id";
    break;
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */

#if KMP_USE_HWLOC
  case affinity_top_method_hwloc:
    value = "hwloc";
    break;
#endif

  case affinity_top_method_cpuinfo:
    value = "cpuinfo";
    break;

#if KMP_GROUP_AFFINITY
  case affinity_top_method_group:
    value = "group";
    break;
#endif /* KMP_GROUP_AFFINITY */

  case affinity_top_method_flat:
    value = "flat";
    break;
  }

  if (value != NULL) {
    __kmp_stg_print_str(buffer, name, value);
  }
} // __kmp_stg_print_topology_method

#endif /* KMP_AFFINITY_SUPPORTED */

// OMP_PROC_BIND / bind-var is functional on all 4.0 builds, including OS X*
// OMP_PLACES / place-partition-var is not.
static void __kmp_stg_parse_proc_bind(char const *name, char const *value,
                                      void *data) {
  kmp_setting_t **rivals = (kmp_setting_t **)data;
  int rc;

  rc = __kmp_stg_check_rivals(name, value, rivals);
  if (rc) {
    return;
  }

  // In OMP 4.0 OMP_PROC_BIND is a vector of proc_bind types.
  KMP_DEBUG_ASSERT((__kmp_nested_proc_bind.bind_types != NULL) &&
                   (__kmp_nested_proc_bind.used > 0));

  const char *buf = value;
  const char *next;
  int num;
  SKIP_WS(buf);
  if ((*buf >= '0') && (*buf <= '9')) {
    next = buf;
    SKIP_DIGITS(next);
    num = __kmp_str_to_int(buf, *next);
    KMP_ASSERT(num >= 0);
    buf = next;
    SKIP_WS(buf);
  } else {
    num = -1;
  }

  next = buf;
  if (__kmp_match_str("disabled", buf, &next)) {
    buf = next;
    SKIP_WS(buf);
#if KMP_AFFINITY_SUPPORTED
    __kmp_affinity_type = affinity_disabled;
#endif /* KMP_AFFINITY_SUPPORTED */
    __kmp_nested_proc_bind.used = 1;
    __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
  } else if ((num == (int)proc_bind_false) ||
             __kmp_match_str("false", buf, &next)) {
    buf = next;
    SKIP_WS(buf);
#if KMP_AFFINITY_SUPPORTED
    __kmp_affinity_type = affinity_none;
#endif /* KMP_AFFINITY_SUPPORTED */
    __kmp_nested_proc_bind.used = 1;
    __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
  } else if ((num == (int)proc_bind_true) ||
             __kmp_match_str("true", buf, &next)) {
    buf = next;
    SKIP_WS(buf);
    __kmp_nested_proc_bind.used = 1;
    __kmp_nested_proc_bind.bind_types[0] = proc_bind_true;
  } else {
    // Count the number of values in the env var string
    const char *scan;
    int nelem = 1;
    for (scan = buf; *scan != '\0'; scan++) {
      if (*scan == ',') {
        nelem++;
      }
    }

    // Create / expand the nested proc_bind array as needed
    if (__kmp_nested_proc_bind.size < nelem) {
      __kmp_nested_proc_bind.bind_types =
          (kmp_proc_bind_t *)KMP_INTERNAL_REALLOC(
              __kmp_nested_proc_bind.bind_types,
              sizeof(kmp_proc_bind_t) * nelem);
      if (__kmp_nested_proc_bind.bind_types == NULL) {
        KMP_FATAL(MemoryAllocFailed);
      }
      __kmp_nested_proc_bind.size = nelem;
    }
    __kmp_nested_proc_bind.used = nelem;

    if (nelem > 1 && !__kmp_dflt_max_active_levels_set)
      __kmp_dflt_max_active_levels = KMP_MAX_ACTIVE_LEVELS_LIMIT;

    // Save values in the nested proc_bind array
    int i = 0;
    for (;;) {
      enum kmp_proc_bind_t bind;

      if ((num == (int)proc_bind_master) ||
          __kmp_match_str("master", buf, &next)) {
        buf = next;
        SKIP_WS(buf);
        bind = proc_bind_master;
      } else if ((num == (int)proc_bind_close) ||
                 __kmp_match_str("close", buf, &next)) {
        buf = next;
        SKIP_WS(buf);
        bind = proc_bind_close;
      } else if ((num == (int)proc_bind_spread) ||
                 __kmp_match_str("spread", buf, &next)) {
        buf = next;
        SKIP_WS(buf);
        bind = proc_bind_spread;
      } else {
        KMP_WARNING(StgInvalidValue, name, value);
        __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
        __kmp_nested_proc_bind.used = 1;
        return;
      }

      __kmp_nested_proc_bind.bind_types[i++] = bind;
      if (i >= nelem) {
        break;
      }
      KMP_DEBUG_ASSERT(*buf == ',');
      buf++;
      SKIP_WS(buf);

      // Read next value if it was specified as an integer
      if ((*buf >= '0') && (*buf <= '9')) {
        next = buf;
        SKIP_DIGITS(next);
        num = __kmp_str_to_int(buf, *next);
        KMP_ASSERT(num >= 0);
        buf = next;
        SKIP_WS(buf);
      } else {
        num = -1;
      }
    }
    SKIP_WS(buf);
  }
  if (*buf != '\0') {
    KMP_WARNING(ParseExtraCharsWarn, name, buf);
  }
}

static void __kmp_stg_print_proc_bind(kmp_str_buf_t *buffer, char const *name,
                                      void *data) {
  int nelem = __kmp_nested_proc_bind.used;
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME;
  } else {
    __kmp_str_buf_print(buffer, "   %s", name);
  }
  if (nelem == 0) {
    __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
  } else {
    int i;
    __kmp_str_buf_print(buffer, "='", name);
    for (i = 0; i < nelem; i++) {
      switch (__kmp_nested_proc_bind.bind_types[i]) {
      case proc_bind_false:
        __kmp_str_buf_print(buffer, "false");
        break;

      case proc_bind_true:
        __kmp_str_buf_print(buffer, "true");
        break;

      case proc_bind_master:
        __kmp_str_buf_print(buffer, "master");
        break;

      case proc_bind_close:
        __kmp_str_buf_print(buffer, "close");
        break;

      case proc_bind_spread:
        __kmp_str_buf_print(buffer, "spread");
        break;

      case proc_bind_intel:
        __kmp_str_buf_print(buffer, "intel");
        break;

      case proc_bind_default:
        __kmp_str_buf_print(buffer, "default");
        break;
      }
      if (i < nelem - 1) {
        __kmp_str_buf_print(buffer, ",");
      }
    }
    __kmp_str_buf_print(buffer, "'\n");
  }
}

static void __kmp_stg_parse_display_affinity(char const *name,
                                             char const *value, void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_display_affinity);
}
static void __kmp_stg_print_display_affinity(kmp_str_buf_t *buffer,
                                             char const *name, void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_display_affinity);
}
static void __kmp_stg_parse_affinity_format(char const *name, char const *value,
                                            void *data) {
  size_t length = KMP_STRLEN(value);
  __kmp_strncpy_truncate(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, value,
                         length);
}
static void __kmp_stg_print_affinity_format(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME_EX(name);
  } else {
    __kmp_str_buf_print(buffer, "   %s='", name);
  }
  __kmp_str_buf_print(buffer, "%s'\n", __kmp_affinity_format);
}
// OMP_ALLOCATOR sets default allocator
static void __kmp_stg_parse_allocator(char const *name, char const *value,
                                      void *data) {
  /*
    The value can be any predefined allocator:
    omp_default_mem_alloc = 1;
    omp_large_cap_mem_alloc = 2;
    omp_const_mem_alloc = 3;
    omp_high_bw_mem_alloc = 4;
    omp_low_lat_mem_alloc = 5;
    omp_cgroup_mem_alloc = 6;
    omp_pteam_mem_alloc = 7;
    omp_thread_mem_alloc = 8;
    Acceptable value is either a digit or a string.
  */
  const char *buf = value;
  const char *next;
  int num;
  SKIP_WS(buf);
  if ((*buf > '0') && (*buf < '9')) {
    next = buf;
    SKIP_DIGITS(next);
    num = __kmp_str_to_int(buf, *next);
    KMP_ASSERT(num > 0);
    switch (num) {
    case 4:
      if (__kmp_memkind_available) {
        __kmp_def_allocator = omp_high_bw_mem_alloc;
      } else {
        __kmp_msg(kmp_ms_warning,
                  KMP_MSG(OmpNoAllocator, "omp_high_bw_mem_alloc"),
                  __kmp_msg_null);
        __kmp_def_allocator = omp_default_mem_alloc;
      }
      break;
    case 1:
      __kmp_def_allocator = omp_default_mem_alloc;
      break;
    case 2:
      __kmp_msg(kmp_ms_warning,
                KMP_MSG(OmpNoAllocator, "omp_large_cap_mem_alloc"),
                __kmp_msg_null);
      __kmp_def_allocator = omp_default_mem_alloc;
      break;
    case 3:
      __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_const_mem_alloc"),
                __kmp_msg_null);
      __kmp_def_allocator = omp_default_mem_alloc;
      break;
    case 5:
      __kmp_msg(kmp_ms_warning,
                KMP_MSG(OmpNoAllocator, "omp_low_lat_mem_alloc"),
                __kmp_msg_null);
      __kmp_def_allocator = omp_default_mem_alloc;
      break;
    case 6:
      __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_cgroup_mem_alloc"),
                __kmp_msg_null);
      __kmp_def_allocator = omp_default_mem_alloc;
      break;
    case 7:
      __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_pteam_mem_alloc"),
                __kmp_msg_null);
      __kmp_def_allocator = omp_default_mem_alloc;
      break;
    case 8:
      __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_thread_mem_alloc"),
                __kmp_msg_null);
      __kmp_def_allocator = omp_default_mem_alloc;
      break;
    }
    return;
  }
  next = buf;
  if (__kmp_match_str("omp_high_bw_mem_alloc", buf, &next)) {
    if (__kmp_memkind_available) {
      __kmp_def_allocator = omp_high_bw_mem_alloc;
    } else {
      __kmp_msg(kmp_ms_warning,
                KMP_MSG(OmpNoAllocator, "omp_high_bw_mem_alloc"),
                __kmp_msg_null);
      __kmp_def_allocator = omp_default_mem_alloc;
    }
  } else if (__kmp_match_str("omp_default_mem_alloc", buf, &next)) {
    __kmp_def_allocator = omp_default_mem_alloc;
  } else if (__kmp_match_str("omp_large_cap_mem_alloc", buf, &next)) {
    __kmp_msg(kmp_ms_warning,
              KMP_MSG(OmpNoAllocator, "omp_large_cap_mem_alloc"),
              __kmp_msg_null);
    __kmp_def_allocator = omp_default_mem_alloc;
  } else if (__kmp_match_str("omp_const_mem_alloc", buf, &next)) {
    __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_const_mem_alloc"),
              __kmp_msg_null);
    __kmp_def_allocator = omp_default_mem_alloc;
  } else if (__kmp_match_str("omp_low_lat_mem_alloc", buf, &next)) {
    __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_low_lat_mem_alloc"),
              __kmp_msg_null);
    __kmp_def_allocator = omp_default_mem_alloc;
  } else if (__kmp_match_str("omp_cgroup_mem_alloc", buf, &next)) {
    __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_cgroup_mem_alloc"),
              __kmp_msg_null);
    __kmp_def_allocator = omp_default_mem_alloc;
  } else if (__kmp_match_str("omp_pteam_mem_alloc", buf, &next)) {
    __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_pteam_mem_alloc"),
              __kmp_msg_null);
    __kmp_def_allocator = omp_default_mem_alloc;
  } else if (__kmp_match_str("omp_thread_mem_alloc", buf, &next)) {
    __kmp_msg(kmp_ms_warning, KMP_MSG(OmpNoAllocator, "omp_thread_mem_alloc"),
              __kmp_msg_null);
    __kmp_def_allocator = omp_default_mem_alloc;
  }
  buf = next;
  SKIP_WS(buf);
  if (*buf != '\0') {
    KMP_WARNING(ParseExtraCharsWarn, name, buf);
  }
}

static void __kmp_stg_print_allocator(kmp_str_buf_t *buffer, char const *name,
                                      void *data) {
  if (__kmp_def_allocator == omp_default_mem_alloc) {
    __kmp_stg_print_str(buffer, name, "omp_default_mem_alloc");
  } else if (__kmp_def_allocator == omp_high_bw_mem_alloc) {
    __kmp_stg_print_str(buffer, name, "omp_high_bw_mem_alloc");
  } else if (__kmp_def_allocator == omp_large_cap_mem_alloc) {
    __kmp_stg_print_str(buffer, name, "omp_large_cap_mem_alloc");
  } else if (__kmp_def_allocator == omp_const_mem_alloc) {
    __kmp_stg_print_str(buffer, name, "omp_const_mem_alloc");
  } else if (__kmp_def_allocator == omp_low_lat_mem_alloc) {
    __kmp_stg_print_str(buffer, name, "omp_low_lat_mem_alloc");
  } else if (__kmp_def_allocator == omp_cgroup_mem_alloc) {
    __kmp_stg_print_str(buffer, name, "omp_cgroup_mem_alloc");
  } else if (__kmp_def_allocator == omp_pteam_mem_alloc) {
    __kmp_stg_print_str(buffer, name, "omp_pteam_mem_alloc");
  } else if (__kmp_def_allocator == omp_thread_mem_alloc) {
    __kmp_stg_print_str(buffer, name, "omp_thread_mem_alloc");
  }
}

// -----------------------------------------------------------------------------
// OMP_DYNAMIC

static void __kmp_stg_parse_omp_dynamic(char const *name, char const *value,
                                        void *data) {
  __kmp_stg_parse_bool(name, value, &(__kmp_global.g.g_dynamic));
} // __kmp_stg_parse_omp_dynamic

static void __kmp_stg_print_omp_dynamic(kmp_str_buf_t *buffer, char const *name,
                                        void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_global.g.g_dynamic);
} // __kmp_stg_print_omp_dynamic

static void __kmp_stg_parse_kmp_dynamic_mode(char const *name,
                                             char const *value, void *data) {
  if (TCR_4(__kmp_init_parallel)) {
    KMP_WARNING(EnvParallelWarn, name);
    __kmp_env_toPrint(name, 0);
    return;
  }
#ifdef USE_LOAD_BALANCE
  else if (__kmp_str_match("load balance", 2, value) ||
           __kmp_str_match("load_balance", 2, value) ||
           __kmp_str_match("load-balance", 2, value) ||
           __kmp_str_match("loadbalance", 2, value) ||
           __kmp_str_match("balance", 1, value)) {
    __kmp_global.g.g_dynamic_mode = dynamic_load_balance;
  }
#endif /* USE_LOAD_BALANCE */
  else if (__kmp_str_match("thread limit", 1, value) ||
           __kmp_str_match("thread_limit", 1, value) ||
           __kmp_str_match("thread-limit", 1, value) ||
           __kmp_str_match("threadlimit", 1, value) ||
           __kmp_str_match("limit", 2, value)) {
    __kmp_global.g.g_dynamic_mode = dynamic_thread_limit;
  } else if (__kmp_str_match("random", 1, value)) {
    __kmp_global.g.g_dynamic_mode = dynamic_random;
  } else {
    KMP_WARNING(StgInvalidValue, name, value);
  }
} //__kmp_stg_parse_kmp_dynamic_mode

static void __kmp_stg_print_kmp_dynamic_mode(kmp_str_buf_t *buffer,
                                             char const *name, void *data) {
#if KMP_DEBUG
  if (__kmp_global.g.g_dynamic_mode == dynamic_default) {
    __kmp_str_buf_print(buffer, "   %s: %s \n", name, KMP_I18N_STR(NotDefined));
  }
#ifdef USE_LOAD_BALANCE
  else if (__kmp_global.g.g_dynamic_mode == dynamic_load_balance) {
    __kmp_stg_print_str(buffer, name, "load balance");
  }
#endif /* USE_LOAD_BALANCE */
  else if (__kmp_global.g.g_dynamic_mode == dynamic_thread_limit) {
    __kmp_stg_print_str(buffer, name, "thread limit");
  } else if (__kmp_global.g.g_dynamic_mode == dynamic_random) {
    __kmp_stg_print_str(buffer, name, "random");
  } else {
    KMP_ASSERT(0);
  }
#endif /* KMP_DEBUG */
} // __kmp_stg_print_kmp_dynamic_mode

#ifdef USE_LOAD_BALANCE

// -----------------------------------------------------------------------------
// KMP_LOAD_BALANCE_INTERVAL

static void __kmp_stg_parse_ld_balance_interval(char const *name,
                                                char const *value, void *data) {
  double interval = __kmp_convert_to_double(value);
  if (interval >= 0) {
    __kmp_load_balance_interval = interval;
  } else {
    KMP_WARNING(StgInvalidValue, name, value);
  }
} // __kmp_stg_parse_load_balance_interval

static void __kmp_stg_print_ld_balance_interval(kmp_str_buf_t *buffer,
                                                char const *name, void *data) {
#if KMP_DEBUG
  __kmp_str_buf_print(buffer, "   %s=%8.6f\n", name,
                      __kmp_load_balance_interval);
#endif /* KMP_DEBUG */
} // __kmp_stg_print_load_balance_interval

#endif /* USE_LOAD_BALANCE */

// -----------------------------------------------------------------------------
// KMP_INIT_AT_FORK

static void __kmp_stg_parse_init_at_fork(char const *name, char const *value,
                                         void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_need_register_atfork);
  if (__kmp_need_register_atfork) {
    __kmp_need_register_atfork_specified = TRUE;
  }
} // __kmp_stg_parse_init_at_fork

static void __kmp_stg_print_init_at_fork(kmp_str_buf_t *buffer,
                                         char const *name, void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_need_register_atfork_specified);
} // __kmp_stg_print_init_at_fork

// -----------------------------------------------------------------------------
// KMP_SCHEDULE

static void __kmp_stg_parse_schedule(char const *name, char const *value,
                                     void *data) {

  if (value != NULL) {
    size_t length = KMP_STRLEN(value);
    if (length > INT_MAX) {
      KMP_WARNING(LongValue, name);
    } else {
      const char *semicolon;
      if (value[length - 1] == '"' || value[length - 1] == '\'')
        KMP_WARNING(UnbalancedQuotes, name);
      do {
        char sentinel;

        semicolon = strchr(value, ';');
        if (*value && semicolon != value) {
          const char *comma = strchr(value, ',');

          if (comma) {
            ++comma;
            sentinel = ',';
          } else
            sentinel = ';';
          if (!__kmp_strcasecmp_with_sentinel("static", value, sentinel)) {
            if (!__kmp_strcasecmp_with_sentinel("greedy", comma, ';')) {
              __kmp_static = kmp_sch_static_greedy;
              continue;
            } else if (!__kmp_strcasecmp_with_sentinel("balanced", comma,
                                                       ';')) {
              __kmp_static = kmp_sch_static_balanced;
              continue;
            }
          } else if (!__kmp_strcasecmp_with_sentinel("guided", value,
                                                     sentinel)) {
            if (!__kmp_strcasecmp_with_sentinel("iterative", comma, ';')) {
              __kmp_guided = kmp_sch_guided_iterative_chunked;
              continue;
            } else if (!__kmp_strcasecmp_with_sentinel("analytical", comma,
                                                       ';')) {
              /* analytical not allowed for too many threads */
              __kmp_guided = kmp_sch_guided_analytical_chunked;
              continue;
            }
          }
          KMP_WARNING(InvalidClause, name, value);
        } else
          KMP_WARNING(EmptyClause, name);
      } while ((value = semicolon ? semicolon + 1 : NULL));
    }
  }

} // __kmp_stg_parse__schedule

static void __kmp_stg_print_schedule(kmp_str_buf_t *buffer, char const *name,
                                     void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME_EX(name);
  } else {
    __kmp_str_buf_print(buffer, "   %s='", name);
  }
  if (__kmp_static == kmp_sch_static_greedy) {
    __kmp_str_buf_print(buffer, "%s", "static,greedy");
  } else if (__kmp_static == kmp_sch_static_balanced) {
    __kmp_str_buf_print(buffer, "%s", "static,balanced");
  }
  if (__kmp_guided == kmp_sch_guided_iterative_chunked) {
    __kmp_str_buf_print(buffer, ";%s'\n", "guided,iterative");
  } else if (__kmp_guided == kmp_sch_guided_analytical_chunked) {
    __kmp_str_buf_print(buffer, ";%s'\n", "guided,analytical");
  }
} // __kmp_stg_print_schedule

// -----------------------------------------------------------------------------
// OMP_SCHEDULE

static inline void __kmp_omp_schedule_restore() {
#if KMP_USE_HIER_SCHED
  __kmp_hier_scheds.deallocate();
#endif
  __kmp_chunk = 0;
  __kmp_sched = kmp_sch_default;
}

// if parse_hier = true:
//    Parse [HW,][modifier:]kind[,chunk]
// else:
//    Parse [modifier:]kind[,chunk]
static const char *__kmp_parse_single_omp_schedule(const char *name,
                                                   const char *value,
                                                   bool parse_hier = false) {
  /* get the specified scheduling style */
  const char *ptr = value;
  const char *delim;
  int chunk = 0;
  enum sched_type sched = kmp_sch_default;
  if (*ptr == '\0')
    return NULL;
  delim = ptr;
  while (*delim != ',' && *delim != ':' && *delim != '\0')
    delim++;
#if KMP_USE_HIER_SCHED
  kmp_hier_layer_e layer = kmp_hier_layer_e::LAYER_THREAD;
  if (parse_hier) {
    if (*delim == ',') {
      if (!__kmp_strcasecmp_with_sentinel("L1", ptr, ',')) {
        layer = kmp_hier_layer_e::LAYER_L1;
      } else if (!__kmp_strcasecmp_with_sentinel("L2", ptr, ',')) {
        layer = kmp_hier_layer_e::LAYER_L2;
      } else if (!__kmp_strcasecmp_with_sentinel("L3", ptr, ',')) {
        layer = kmp_hier_layer_e::LAYER_L3;
      } else if (!__kmp_strcasecmp_with_sentinel("NUMA", ptr, ',')) {
        layer = kmp_hier_layer_e::LAYER_NUMA;
      }
    }
    if (layer != kmp_hier_layer_e::LAYER_THREAD && *delim != ',') {
      // If there is no comma after the layer, then this schedule is invalid
      KMP_WARNING(StgInvalidValue, name, value);
      __kmp_omp_schedule_restore();
      return NULL;
    } else if (layer != kmp_hier_layer_e::LAYER_THREAD) {
      ptr = ++delim;
      while (*delim != ',' && *delim != ':' && *delim != '\0')
        delim++;
    }
  }
#endif // KMP_USE_HIER_SCHED
  // Read in schedule modifier if specified
  enum sched_type sched_modifier = (enum sched_type)0;
  if (*delim == ':') {
    if (!__kmp_strcasecmp_with_sentinel("monotonic", ptr, *delim)) {
      sched_modifier = sched_type::kmp_sch_modifier_monotonic;
      ptr = ++delim;
      while (*delim != ',' && *delim != ':' && *delim != '\0')
        delim++;
    } else if (!__kmp_strcasecmp_with_sentinel("nonmonotonic", ptr, *delim)) {
      sched_modifier = sched_type::kmp_sch_modifier_nonmonotonic;
      ptr = ++delim;
      while (*delim != ',' && *delim != ':' && *delim != '\0')
        delim++;
    } else if (!parse_hier) {
      // If there is no proper schedule modifier, then this schedule is invalid
      KMP_WARNING(StgInvalidValue, name, value);
      __kmp_omp_schedule_restore();
      return NULL;
    }
  }
  // Read in schedule kind (required)
  if (!__kmp_strcasecmp_with_sentinel("dynamic", ptr, *delim))
    sched = kmp_sch_dynamic_chunked;
  else if (!__kmp_strcasecmp_with_sentinel("guided", ptr, *delim))
    sched = kmp_sch_guided_chunked;
  // AC: TODO: probably remove TRAPEZOIDAL (OMP 3.0 does not allow it)
  else if (!__kmp_strcasecmp_with_sentinel("auto", ptr, *delim))
    sched = kmp_sch_auto;
  else if (!__kmp_strcasecmp_with_sentinel("trapezoidal", ptr, *delim))
    sched = kmp_sch_trapezoidal;
  else if (!__kmp_strcasecmp_with_sentinel("static", ptr, *delim))
    sched = kmp_sch_static;
#if KMP_STATIC_STEAL_ENABLED
  else if (!__kmp_strcasecmp_with_sentinel("static_steal", ptr, *delim))
    sched = kmp_sch_static_steal;
#endif
  else {
    // If there is no proper schedule kind, then this schedule is invalid
    KMP_WARNING(StgInvalidValue, name, value);
    __kmp_omp_schedule_restore();
    return NULL;
  }

  // Read in schedule chunk size if specified
  if (*delim == ',') {
    ptr = delim + 1;
    SKIP_WS(ptr);
    if (!isdigit(*ptr)) {
      // If there is no chunk after comma, then this schedule is invalid
      KMP_WARNING(StgInvalidValue, name, value);
      __kmp_omp_schedule_restore();
      return NULL;
    }
    SKIP_DIGITS(ptr);
    // auto schedule should not specify chunk size
    if (sched == kmp_sch_auto) {
      __kmp_msg(kmp_ms_warning, KMP_MSG(IgnoreChunk, name, delim),
                __kmp_msg_null);
    } else {
      if (sched == kmp_sch_static)
        sched = kmp_sch_static_chunked;
      chunk = __kmp_str_to_int(delim + 1, *ptr);
      if (chunk < 1) {
        chunk = KMP_DEFAULT_CHUNK;
        __kmp_msg(kmp_ms_warning, KMP_MSG(InvalidChunk, name, delim),
                  __kmp_msg_null);
        KMP_INFORM(Using_int_Value, name, __kmp_chunk);
        // AC: next block commented out until KMP_DEFAULT_CHUNK != KMP_MIN_CHUNK
        // (to improve code coverage :)
        // The default chunk size is 1 according to standard, thus making
        // KMP_MIN_CHUNK not 1 we would introduce mess:
        // wrong chunk becomes 1, but it will be impossible to explicitly set
        // to 1 because it becomes KMP_MIN_CHUNK...
        // } else if ( chunk < KMP_MIN_CHUNK ) {
        //   chunk = KMP_MIN_CHUNK;
      } else if (chunk > KMP_MAX_CHUNK) {
        chunk = KMP_MAX_CHUNK;
        __kmp_msg(kmp_ms_warning, KMP_MSG(LargeChunk, name, delim),
                  __kmp_msg_null);
        KMP_INFORM(Using_int_Value, name, chunk);
      }
    }
  } else {
    ptr = delim;
  }

  SCHEDULE_SET_MODIFIERS(sched, sched_modifier);

#if KMP_USE_HIER_SCHED
  if (layer != kmp_hier_layer_e::LAYER_THREAD) {
    __kmp_hier_scheds.append(sched, chunk, layer);
  } else
#endif
  {
    __kmp_chunk = chunk;
    __kmp_sched = sched;
  }
  return ptr;
}

static void __kmp_stg_parse_omp_schedule(char const *name, char const *value,
                                         void *data) {
  size_t length;
  const char *ptr = value;
  SKIP_WS(ptr);
  if (value) {
    length = KMP_STRLEN(value);
    if (length) {
      if (value[length - 1] == '"' || value[length - 1] == '\'')
        KMP_WARNING(UnbalancedQuotes, name);
/* get the specified scheduling style */
#if KMP_USE_HIER_SCHED
      if (!__kmp_strcasecmp_with_sentinel("EXPERIMENTAL", ptr, ' ')) {
        SKIP_TOKEN(ptr);
        SKIP_WS(ptr);
        while ((ptr = __kmp_parse_single_omp_schedule(name, ptr, true))) {
          while (*ptr == ' ' || *ptr == '\t' || *ptr == ':')
            ptr++;
          if (*ptr == '\0')
            break;
        }
      } else
#endif
        __kmp_parse_single_omp_schedule(name, ptr);
    } else
      KMP_WARNING(EmptyString, name);
  }
#if KMP_USE_HIER_SCHED
  __kmp_hier_scheds.sort();
#endif
  K_DIAG(1, ("__kmp_static == %d\n", __kmp_static))
  K_DIAG(1, ("__kmp_guided == %d\n", __kmp_guided))
  K_DIAG(1, ("__kmp_sched == %d\n", __kmp_sched))
  K_DIAG(1, ("__kmp_chunk == %d\n", __kmp_chunk))
} // __kmp_stg_parse_omp_schedule

static void __kmp_stg_print_omp_schedule(kmp_str_buf_t *buffer,
                                         char const *name, void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME_EX(name);
  } else {
    __kmp_str_buf_print(buffer, "   %s='", name);
  }
  enum sched_type sched = SCHEDULE_WITHOUT_MODIFIERS(__kmp_sched);
  if (SCHEDULE_HAS_MONOTONIC(__kmp_sched)) {
    __kmp_str_buf_print(buffer, "monotonic:");
  } else if (SCHEDULE_HAS_NONMONOTONIC(__kmp_sched)) {
    __kmp_str_buf_print(buffer, "nonmonotonic:");
  }
  if (__kmp_chunk) {
    switch (sched) {
    case kmp_sch_dynamic_chunked:
      __kmp_str_buf_print(buffer, "%s,%d'\n", "dynamic", __kmp_chunk);
      break;
    case kmp_sch_guided_iterative_chunked:
    case kmp_sch_guided_analytical_chunked:
      __kmp_str_buf_print(buffer, "%s,%d'\n", "guided", __kmp_chunk);
      break;
    case kmp_sch_trapezoidal:
      __kmp_str_buf_print(buffer, "%s,%d'\n", "trapezoidal", __kmp_chunk);
      break;
    case kmp_sch_static:
    case kmp_sch_static_chunked:
    case kmp_sch_static_balanced:
    case kmp_sch_static_greedy:
      __kmp_str_buf_print(buffer, "%s,%d'\n", "static", __kmp_chunk);
      break;
    case kmp_sch_static_steal:
      __kmp_str_buf_print(buffer, "%s,%d'\n", "static_steal", __kmp_chunk);
      break;
    case kmp_sch_auto:
      __kmp_str_buf_print(buffer, "%s,%d'\n", "auto", __kmp_chunk);
      break;
    }
  } else {
    switch (sched) {
    case kmp_sch_dynamic_chunked:
      __kmp_str_buf_print(buffer, "%s'\n", "dynamic");
      break;
    case kmp_sch_guided_iterative_chunked:
    case kmp_sch_guided_analytical_chunked:
      __kmp_str_buf_print(buffer, "%s'\n", "guided");
      break;
    case kmp_sch_trapezoidal:
      __kmp_str_buf_print(buffer, "%s'\n", "trapezoidal");
      break;
    case kmp_sch_static:
    case kmp_sch_static_chunked:
    case kmp_sch_static_balanced:
    case kmp_sch_static_greedy:
      __kmp_str_buf_print(buffer, "%s'\n", "static");
      break;
    case kmp_sch_static_steal:
      __kmp_str_buf_print(buffer, "%s'\n", "static_steal");
      break;
    case kmp_sch_auto:
      __kmp_str_buf_print(buffer, "%s'\n", "auto");
      break;
    }
  }
} // __kmp_stg_print_omp_schedule

#if KMP_USE_HIER_SCHED
// -----------------------------------------------------------------------------
// KMP_DISP_HAND_THREAD
static void __kmp_stg_parse_kmp_hand_thread(char const *name, char const *value,
                                            void *data) {
  __kmp_stg_parse_bool(name, value, &(__kmp_dispatch_hand_threading));
} // __kmp_stg_parse_kmp_hand_thread

static void __kmp_stg_print_kmp_hand_thread(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_dispatch_hand_threading);
} // __kmp_stg_print_kmp_hand_thread
#endif

// -----------------------------------------------------------------------------
// KMP_ATOMIC_MODE

static void __kmp_stg_parse_atomic_mode(char const *name, char const *value,
                                        void *data) {
  // Modes: 0 -- do not change default; 1 -- Intel perf mode, 2 -- GOMP
  // compatibility mode.
  int mode = 0;
  int max = 1;
#ifdef KMP_GOMP_COMPAT
  max = 2;
#endif /* KMP_GOMP_COMPAT */
  __kmp_stg_parse_int(name, value, 0, max, &mode);
  // TODO; parse_int is not very suitable for this case. In case of overflow it
  // is better to use
  // 0 rather that max value.
  if (mode > 0) {
    __kmp_atomic_mode = mode;
  }
} // __kmp_stg_parse_atomic_mode

static void __kmp_stg_print_atomic_mode(kmp_str_buf_t *buffer, char const *name,
                                        void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_atomic_mode);
} // __kmp_stg_print_atomic_mode

// -----------------------------------------------------------------------------
// KMP_CONSISTENCY_CHECK

static void __kmp_stg_parse_consistency_check(char const *name,
                                              char const *value, void *data) {
  if (!__kmp_strcasecmp_with_sentinel("all", value, 0)) {
    // Note, this will not work from kmp_set_defaults because th_cons stack was
    // not allocated
    // for existed thread(s) thus the first __kmp_push_<construct> will break
    // with assertion.
    // TODO: allocate th_cons if called from kmp_set_defaults.
    __kmp_env_consistency_check = TRUE;
  } else if (!__kmp_strcasecmp_with_sentinel("none", value, 0)) {
    __kmp_env_consistency_check = FALSE;
  } else {
    KMP_WARNING(StgInvalidValue, name, value);
  }
} // __kmp_stg_parse_consistency_check

static void __kmp_stg_print_consistency_check(kmp_str_buf_t *buffer,
                                              char const *name, void *data) {
#if KMP_DEBUG
  const char *value = NULL;

  if (__kmp_env_consistency_check) {
    value = "all";
  } else {
    value = "none";
  }

  if (value != NULL) {
    __kmp_stg_print_str(buffer, name, value);
  }
#endif /* KMP_DEBUG */
} // __kmp_stg_print_consistency_check

#if USE_ITT_BUILD
// -----------------------------------------------------------------------------
// KMP_ITT_PREPARE_DELAY

#if USE_ITT_NOTIFY

static void __kmp_stg_parse_itt_prepare_delay(char const *name,
                                              char const *value, void *data) {
  // Experimental code: KMP_ITT_PREPARE_DELAY specifies numbert of loop
  // iterations.
  int delay = 0;
  __kmp_stg_parse_int(name, value, 0, INT_MAX, &delay);
  __kmp_itt_prepare_delay = delay;
} // __kmp_str_parse_itt_prepare_delay

static void __kmp_stg_print_itt_prepare_delay(kmp_str_buf_t *buffer,
                                              char const *name, void *data) {
  __kmp_stg_print_uint64(buffer, name, __kmp_itt_prepare_delay);

} // __kmp_str_print_itt_prepare_delay

#endif // USE_ITT_NOTIFY
#endif /* USE_ITT_BUILD */

// -----------------------------------------------------------------------------
// KMP_MALLOC_POOL_INCR

static void __kmp_stg_parse_malloc_pool_incr(char const *name,
                                             char const *value, void *data) {
  __kmp_stg_parse_size(name, value, KMP_MIN_MALLOC_POOL_INCR,
                       KMP_MAX_MALLOC_POOL_INCR, NULL, &__kmp_malloc_pool_incr,
                       1);
} // __kmp_stg_parse_malloc_pool_incr

static void __kmp_stg_print_malloc_pool_incr(kmp_str_buf_t *buffer,
                                             char const *name, void *data) {
  __kmp_stg_print_size(buffer, name, __kmp_malloc_pool_incr);

} // _kmp_stg_print_malloc_pool_incr

#ifdef KMP_DEBUG

// -----------------------------------------------------------------------------
// KMP_PAR_RANGE

static void __kmp_stg_parse_par_range_env(char const *name, char const *value,
                                          void *data) {
  __kmp_stg_parse_par_range(name, value, &__kmp_par_range,
                            __kmp_par_range_routine, __kmp_par_range_filename,
                            &__kmp_par_range_lb, &__kmp_par_range_ub);
} // __kmp_stg_parse_par_range_env

static void __kmp_stg_print_par_range_env(kmp_str_buf_t *buffer,
                                          char const *name, void *data) {
  if (__kmp_par_range != 0) {
    __kmp_stg_print_str(buffer, name, par_range_to_print);
  }
} // __kmp_stg_print_par_range_env

#endif

// -----------------------------------------------------------------------------
// KMP_GTID_MODE

static void __kmp_stg_parse_gtid_mode(char const *name, char const *value,
                                      void *data) {
  // Modes:
  //   0 -- do not change default
  //   1 -- sp search
  //   2 -- use "keyed" TLS var, i.e.
  //        pthread_getspecific(Linux* OS/OS X*) or TlsGetValue(Windows* OS)
  //   3 -- __declspec(thread) TLS var in tdata section
  int mode = 0;
  int max = 2;
#ifdef KMP_TDATA_GTID
  max = 3;
#endif /* KMP_TDATA_GTID */
  __kmp_stg_parse_int(name, value, 0, max, &mode);
  // TODO; parse_int is not very suitable for this case. In case of overflow it
  // is better to use 0 rather that max value.
  if (mode == 0) {
    __kmp_adjust_gtid_mode = TRUE;
  } else {
    __kmp_gtid_mode = mode;
    __kmp_adjust_gtid_mode = FALSE;
  }
} // __kmp_str_parse_gtid_mode

static void __kmp_stg_print_gtid_mode(kmp_str_buf_t *buffer, char const *name,
                                      void *data) {
  if (__kmp_adjust_gtid_mode) {
    __kmp_stg_print_int(buffer, name, 0);
  } else {
    __kmp_stg_print_int(buffer, name, __kmp_gtid_mode);
  }
} // __kmp_stg_print_gtid_mode

// -----------------------------------------------------------------------------
// KMP_NUM_LOCKS_IN_BLOCK

static void __kmp_stg_parse_lock_block(char const *name, char const *value,
                                       void *data) {
  __kmp_stg_parse_int(name, value, 0, KMP_INT_MAX, &__kmp_num_locks_in_block);
} // __kmp_str_parse_lock_block

static void __kmp_stg_print_lock_block(kmp_str_buf_t *buffer, char const *name,
                                       void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_num_locks_in_block);
} // __kmp_stg_print_lock_block

// -----------------------------------------------------------------------------
// KMP_LOCK_KIND

#if KMP_USE_DYNAMIC_LOCK
#define KMP_STORE_LOCK_SEQ(a) (__kmp_user_lock_seq = lockseq_##a)
#else
#define KMP_STORE_LOCK_SEQ(a)
#endif

static void __kmp_stg_parse_lock_kind(char const *name, char const *value,
                                      void *data) {
  if (__kmp_init_user_locks) {
    KMP_WARNING(EnvLockWarn, name);
    return;
  }

  if (__kmp_str_match("tas", 2, value) ||
      __kmp_str_match("test and set", 2, value) ||
      __kmp_str_match("test_and_set", 2, value) ||
      __kmp_str_match("test-and-set", 2, value) ||
      __kmp_str_match("test andset", 2, value) ||
      __kmp_str_match("test_andset", 2, value) ||
      __kmp_str_match("test-andset", 2, value) ||
      __kmp_str_match("testand set", 2, value) ||
      __kmp_str_match("testand_set", 2, value) ||
      __kmp_str_match("testand-set", 2, value) ||
      __kmp_str_match("testandset", 2, value)) {
    __kmp_user_lock_kind = lk_tas;
    KMP_STORE_LOCK_SEQ(tas);
  }
#if KMP_USE_FUTEX
  else if (__kmp_str_match("futex", 1, value)) {
    if (__kmp_futex_determine_capable()) {
      __kmp_user_lock_kind = lk_futex;
      KMP_STORE_LOCK_SEQ(futex);
    } else {
      KMP_WARNING(FutexNotSupported, name, value);
    }
  }
#endif
  else if (__kmp_str_match("ticket", 2, value)) {
    __kmp_user_lock_kind = lk_ticket;
    KMP_STORE_LOCK_SEQ(ticket);
  } else if (__kmp_str_match("queuing", 1, value) ||
             __kmp_str_match("queue", 1, value)) {
    __kmp_user_lock_kind = lk_queuing;
    KMP_STORE_LOCK_SEQ(queuing);
  } else if (__kmp_str_match("drdpa ticket", 1, value) ||
             __kmp_str_match("drdpa_ticket", 1, value) ||
             __kmp_str_match("drdpa-ticket", 1, value) ||
             __kmp_str_match("drdpaticket", 1, value) ||
             __kmp_str_match("drdpa", 1, value)) {
    __kmp_user_lock_kind = lk_drdpa;
    KMP_STORE_LOCK_SEQ(drdpa);
  }
#if KMP_USE_ADAPTIVE_LOCKS
  else if (__kmp_str_match("adaptive", 1, value)) {
    if (__kmp_cpuinfo.rtm) { // ??? Is cpuinfo available here?
      __kmp_user_lock_kind = lk_adaptive;
      KMP_STORE_LOCK_SEQ(adaptive);
    } else {
      KMP_WARNING(AdaptiveNotSupported, name, value);
      __kmp_user_lock_kind = lk_queuing;
      KMP_STORE_LOCK_SEQ(queuing);
    }
  }
#endif // KMP_USE_ADAPTIVE_LOCKS
#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
  else if (__kmp_str_match("rtm", 1, value)) {
    if (__kmp_cpuinfo.rtm) {
      __kmp_user_lock_kind = lk_rtm;
      KMP_STORE_LOCK_SEQ(rtm);
    } else {
      KMP_WARNING(AdaptiveNotSupported, name, value);
      __kmp_user_lock_kind = lk_queuing;
      KMP_STORE_LOCK_SEQ(queuing);
    }
  } else if (__kmp_str_match("hle", 1, value)) {
    __kmp_user_lock_kind = lk_hle;
    KMP_STORE_LOCK_SEQ(hle);
  }
#endif
  else {
    KMP_WARNING(StgInvalidValue, name, value);
  }
}

static void __kmp_stg_print_lock_kind(kmp_str_buf_t *buffer, char const *name,
                                      void *data) {
  const char *value = NULL;

  switch (__kmp_user_lock_kind) {
  case lk_default:
    value = "default";
    break;

  case lk_tas:
    value = "tas";
    break;

#if KMP_USE_FUTEX
  case lk_futex:
    value = "futex";
    break;
#endif

#if KMP_USE_DYNAMIC_LOCK && KMP_USE_TSX
  case lk_rtm:
    value = "rtm";
    break;

  case lk_hle:
    value = "hle";
    break;
#endif

  case lk_ticket:
    value = "ticket";
    break;

  case lk_queuing:
    value = "queuing";
    break;

  case lk_drdpa:
    value = "drdpa";
    break;
#if KMP_USE_ADAPTIVE_LOCKS
  case lk_adaptive:
    value = "adaptive";
    break;
#endif
  }

  if (value != NULL) {
    __kmp_stg_print_str(buffer, name, value);
  }
}

// -----------------------------------------------------------------------------
// KMP_SPIN_BACKOFF_PARAMS

// KMP_SPIN_BACKOFF_PARAMS=max_backoff[,min_tick] (max backoff size, min tick
// for machine pause)
static void __kmp_stg_parse_spin_backoff_params(const char *name,
                                                const char *value, void *data) {
  const char *next = value;

  int total = 0; // Count elements that were set. It'll be used as an array size
  int prev_comma = FALSE; // For correct processing sequential commas
  int i;

  kmp_uint32 max_backoff = __kmp_spin_backoff_params.max_backoff;
  kmp_uint32 min_tick = __kmp_spin_backoff_params.min_tick;

  // Run only 3 iterations because it is enough to read two values or find a
  // syntax error
  for (i = 0; i < 3; i++) {
    SKIP_WS(next);

    if (*next == '\0') {
      break;
    }
    // Next character is not an integer or not a comma OR number of values > 2
    // => end of list
    if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
      KMP_WARNING(EnvSyntaxError, name, value);
      return;
    }
    // The next character is ','
    if (*next == ',') {
      // ',' is the first character
      if (total == 0 || prev_comma) {
        total++;
      }
      prev_comma = TRUE;
      next++; // skip ','
      SKIP_WS(next);
    }
    // Next character is a digit
    if (*next >= '0' && *next <= '9') {
      int num;
      const char *buf = next;
      char const *msg = NULL;
      prev_comma = FALSE;
      SKIP_DIGITS(next);
      total++;

      const char *tmp = next;
      SKIP_WS(tmp);
      if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
        KMP_WARNING(EnvSpacesNotAllowed, name, value);
        return;
      }

      num = __kmp_str_to_int(buf, *next);
      if (num <= 0) { // The number of retries should be > 0
        msg = KMP_I18N_STR(ValueTooSmall);
        num = 1;
      } else if (num > KMP_INT_MAX) {
        msg = KMP_I18N_STR(ValueTooLarge);
        num = KMP_INT_MAX;
      }
      if (msg != NULL) {
        // Message is not empty. Print warning.
        KMP_WARNING(ParseSizeIntWarn, name, value, msg);
        KMP_INFORM(Using_int_Value, name, num);
      }
      if (total == 1) {
        max_backoff = num;
      } else if (total == 2) {
        min_tick = num;
      }
    }
  }
  KMP_DEBUG_ASSERT(total > 0);
  if (total <= 0) {
    KMP_WARNING(EnvSyntaxError, name, value);
    return;
  }
  __kmp_spin_backoff_params.max_backoff = max_backoff;
  __kmp_spin_backoff_params.min_tick = min_tick;
}

static void __kmp_stg_print_spin_backoff_params(kmp_str_buf_t *buffer,
                                                char const *name, void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME_EX(name);
  } else {
    __kmp_str_buf_print(buffer, "   %s='", name);
  }
  __kmp_str_buf_print(buffer, "%d,%d'\n", __kmp_spin_backoff_params.max_backoff,
                      __kmp_spin_backoff_params.min_tick);
}

#if KMP_USE_ADAPTIVE_LOCKS

// -----------------------------------------------------------------------------
// KMP_ADAPTIVE_LOCK_PROPS, KMP_SPECULATIVE_STATSFILE

// Parse out values for the tunable parameters from a string of the form
// KMP_ADAPTIVE_LOCK_PROPS=max_soft_retries[,max_badness]
static void __kmp_stg_parse_adaptive_lock_props(const char *name,
                                                const char *value, void *data) {
  int max_retries = 0;
  int max_badness = 0;

  const char *next = value;

  int total = 0; // Count elements that were set. It'll be used as an array size
  int prev_comma = FALSE; // For correct processing sequential commas
  int i;

  // Save values in the structure __kmp_speculative_backoff_params
  // Run only 3 iterations because it is enough to read two values or find a
  // syntax error
  for (i = 0; i < 3; i++) {
    SKIP_WS(next);

    if (*next == '\0') {
      break;
    }
    // Next character is not an integer or not a comma OR number of values > 2
    // => end of list
    if (((*next < '0' || *next > '9') && *next != ',') || total > 2) {
      KMP_WARNING(EnvSyntaxError, name, value);
      return;
    }
    // The next character is ','
    if (*next == ',') {
      // ',' is the first character
      if (total == 0 || prev_comma) {
        total++;
      }
      prev_comma = TRUE;
      next++; // skip ','
      SKIP_WS(next);
    }
    // Next character is a digit
    if (*next >= '0' && *next <= '9') {
      int num;
      const char *buf = next;
      char const *msg = NULL;
      prev_comma = FALSE;
      SKIP_DIGITS(next);
      total++;

      const char *tmp = next;
      SKIP_WS(tmp);
      if ((*next == ' ' || *next == '\t') && (*tmp >= '0' && *tmp <= '9')) {
        KMP_WARNING(EnvSpacesNotAllowed, name, value);
        return;
      }

      num = __kmp_str_to_int(buf, *next);
      if (num < 0) { // The number of retries should be >= 0
        msg = KMP_I18N_STR(ValueTooSmall);
        num = 1;
      } else if (num > KMP_INT_MAX) {
        msg = KMP_I18N_STR(ValueTooLarge);
        num = KMP_INT_MAX;
      }
      if (msg != NULL) {
        // Message is not empty. Print warning.
        KMP_WARNING(ParseSizeIntWarn, name, value, msg);
        KMP_INFORM(Using_int_Value, name, num);
      }
      if (total == 1) {
        max_retries = num;
      } else if (total == 2) {
        max_badness = num;
      }
    }
  }
  KMP_DEBUG_ASSERT(total > 0);
  if (total <= 0) {
    KMP_WARNING(EnvSyntaxError, name, value);
    return;
  }
  __kmp_adaptive_backoff_params.max_soft_retries = max_retries;
  __kmp_adaptive_backoff_params.max_badness = max_badness;
}

static void __kmp_stg_print_adaptive_lock_props(kmp_str_buf_t *buffer,
                                                char const *name, void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_NAME_EX(name);
  } else {
    __kmp_str_buf_print(buffer, "   %s='", name);
  }
  __kmp_str_buf_print(buffer, "%d,%d'\n",
                      __kmp_adaptive_backoff_params.max_soft_retries,
                      __kmp_adaptive_backoff_params.max_badness);
} // __kmp_stg_print_adaptive_lock_props

#if KMP_DEBUG_ADAPTIVE_LOCKS

static void __kmp_stg_parse_speculative_statsfile(char const *name,
                                                  char const *value,
                                                  void *data) {
  __kmp_stg_parse_file(name, value, "", CCAST(char**, &__kmp_speculative_statsfile));
} // __kmp_stg_parse_speculative_statsfile

static void __kmp_stg_print_speculative_statsfile(kmp_str_buf_t *buffer,
                                                  char const *name,
                                                  void *data) {
  if (__kmp_str_match("-", 0, __kmp_speculative_statsfile)) {
    __kmp_stg_print_str(buffer, name, "stdout");
  } else {
    __kmp_stg_print_str(buffer, name, __kmp_speculative_statsfile);
  }

} // __kmp_stg_print_speculative_statsfile

#endif // KMP_DEBUG_ADAPTIVE_LOCKS

#endif // KMP_USE_ADAPTIVE_LOCKS

// -----------------------------------------------------------------------------
// KMP_HW_SUBSET (was KMP_PLACE_THREADS)

// The longest observable sequence of items is
// Socket-Node-Tile-Core-Thread
// So, let's limit to 5 levels for now
// The input string is usually short enough, let's use 512 limit for now
#define MAX_T_LEVEL 5
#define MAX_STR_LEN 512
static void __kmp_stg_parse_hw_subset(char const *name, char const *value,
                                      void *data) {
  // Value example: 1s,5c@3,2T
  // Which means "use 1 socket, 5 cores with offset 3, 2 threads per core"
  kmp_setting_t **rivals = (kmp_setting_t **)data;
  if (strcmp(name, "KMP_PLACE_THREADS") == 0) {
    KMP_INFORM(EnvVarDeprecated, name, "KMP_HW_SUBSET");
  }
  if (__kmp_stg_check_rivals(name, value, rivals)) {
    return;
  }

  char *components[MAX_T_LEVEL];
  char const *digits = "0123456789";
  char input[MAX_STR_LEN];
  size_t len = 0, mlen = MAX_STR_LEN;
  int level = 0;
  // Canonize the string (remove spaces, unify delimiters, etc.)
  char *pos = CCAST(char *, value);
  while (*pos && mlen) {
    if (*pos != ' ') { // skip spaces
      if (len == 0 && *pos == ':') {
        __kmp_hws_abs_flag = 1; // if the first symbol is ":", skip it
      } else {
        input[len] = toupper(*pos);
        if (input[len] == 'X')
          input[len] = ','; // unify delimiters of levels
        if (input[len] == 'O' && strchr(digits, *(pos + 1)))
          input[len] = '@'; // unify delimiters of offset
        len++;
      }
    }
    mlen--;
    pos++;
  }
  if (len == 0 || mlen == 0)
    goto err; // contents is either empty or too long
  input[len] = '\0';
  __kmp_hws_requested = 1; // mark that subset requested
  // Split by delimiter
  pos = input;
  components[level++] = pos;
  while ((pos = strchr(pos, ','))) {
    if (level >= MAX_T_LEVEL)
      goto err; // too many components provided
    *pos = '\0'; // modify input and avoid more copying
    components[level++] = ++pos; // expect something after ","
  }
  // Check each component
  for (int i = 0; i < level; ++i) {
    int offset = 0;
    int num = atoi(components[i]); // each component should start with a number
    if ((pos = strchr(components[i], '@'))) {
      offset = atoi(pos + 1); // save offset
      *pos = '\0'; // cut the offset from the component
    }
    pos = components[i] + strspn(components[i], digits);
    if (pos == components[i])
      goto err;
    // detect the component type
    switch (*pos) {
    case 'S': // Socket
      if (__kmp_hws_socket.num > 0)
        goto err; // duplicate is not allowed
      __kmp_hws_socket.num = num;
      __kmp_hws_socket.offset = offset;
      break;
    case 'N': // NUMA Node
      if (__kmp_hws_node.num > 0)
        goto err; // duplicate is not allowed
      __kmp_hws_node.num = num;
      __kmp_hws_node.offset = offset;
      break;
    case 'L': // Cache
      if (*(pos + 1) == '2') { // L2 - Tile
        if (__kmp_hws_tile.num > 0)
          goto err; // duplicate is not allowed
        __kmp_hws_tile.num = num;
        __kmp_hws_tile.offset = offset;
      } else if (*(pos + 1) == '3') { // L3 - Socket
        if (__kmp_hws_socket.num > 0)
          goto err; // duplicate is not allowed
        __kmp_hws_socket.num = num;
        __kmp_hws_socket.offset = offset;
      } else if (*(pos + 1) == '1') { // L1 - Core
        if (__kmp_hws_core.num > 0)
          goto err; // duplicate is not allowed
        __kmp_hws_core.num = num;
        __kmp_hws_core.offset = offset;
      }
      break;
    case 'C': // Core (or Cache?)
      if (*(pos + 1) != 'A') {
        if (__kmp_hws_core.num > 0)
          goto err; // duplicate is not allowed
        __kmp_hws_core.num = num;
        __kmp_hws_core.offset = offset;
      } else { // Cache
        char *d = pos + strcspn(pos, digits); // find digit
        if (*d == '2') { // L2 - Tile
          if (__kmp_hws_tile.num > 0)
            goto err; // duplicate is not allowed
          __kmp_hws_tile.num = num;
          __kmp_hws_tile.offset = offset;
        } else if (*d == '3') { // L3 - Socket
          if (__kmp_hws_socket.num > 0)
            goto err; // duplicate is not allowed
          __kmp_hws_socket.num = num;
          __kmp_hws_socket.offset = offset;
        } else if (*d == '1') { // L1 - Core
          if (__kmp_hws_core.num > 0)
            goto err; // duplicate is not allowed
          __kmp_hws_core.num = num;
          __kmp_hws_core.offset = offset;
        } else {
          goto err;
        }
      }
      break;
    case 'T': // Thread
      if (__kmp_hws_proc.num > 0)
        goto err; // duplicate is not allowed
      __kmp_hws_proc.num = num;
      __kmp_hws_proc.offset = offset;
      break;
    default:
      goto err;
    }
  }
  return;
err:
  KMP_WARNING(AffHWSubsetInvalid, name, value);
  __kmp_hws_requested = 0; // mark that subset not requested
  return;
}

static void __kmp_stg_print_hw_subset(kmp_str_buf_t *buffer, char const *name,
                                      void *data) {
  if (__kmp_hws_requested) {
    int comma = 0;
    kmp_str_buf_t buf;
    __kmp_str_buf_init(&buf);
    if (__kmp_env_format)
      KMP_STR_BUF_PRINT_NAME_EX(name);
    else
      __kmp_str_buf_print(buffer, "   %s='", name);
    if (__kmp_hws_socket.num) {
      __kmp_str_buf_print(&buf, "%ds", __kmp_hws_socket.num);
      if (__kmp_hws_socket.offset)
        __kmp_str_buf_print(&buf, "@%d", __kmp_hws_socket.offset);
      comma = 1;
    }
    if (__kmp_hws_node.num) {
      __kmp_str_buf_print(&buf, "%s%dn", comma ? "," : "", __kmp_hws_node.num);
      if (__kmp_hws_node.offset)
        __kmp_str_buf_print(&buf, "@%d", __kmp_hws_node.offset);
      comma = 1;
    }
    if (__kmp_hws_tile.num) {
      __kmp_str_buf_print(&buf, "%s%dL2", comma ? "," : "", __kmp_hws_tile.num);
      if (__kmp_hws_tile.offset)
        __kmp_str_buf_print(&buf, "@%d", __kmp_hws_tile.offset);
      comma = 1;
    }
    if (__kmp_hws_core.num) {
      __kmp_str_buf_print(&buf, "%s%dc", comma ? "," : "", __kmp_hws_core.num);
      if (__kmp_hws_core.offset)
        __kmp_str_buf_print(&buf, "@%d", __kmp_hws_core.offset);
      comma = 1;
    }
    if (__kmp_hws_proc.num)
      __kmp_str_buf_print(&buf, "%s%dt", comma ? "," : "", __kmp_hws_proc.num);
    __kmp_str_buf_print(buffer, "%s'\n", buf.str);
    __kmp_str_buf_free(&buf);
  }
}

#if USE_ITT_BUILD
// -----------------------------------------------------------------------------
// KMP_FORKJOIN_FRAMES

static void __kmp_stg_parse_forkjoin_frames(char const *name, char const *value,
                                            void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_forkjoin_frames);
} // __kmp_stg_parse_forkjoin_frames

static void __kmp_stg_print_forkjoin_frames(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_forkjoin_frames);
} // __kmp_stg_print_forkjoin_frames

// -----------------------------------------------------------------------------
// KMP_FORKJOIN_FRAMES_MODE

static void __kmp_stg_parse_forkjoin_frames_mode(char const *name,
                                                 char const *value,
                                                 void *data) {
  __kmp_stg_parse_int(name, value, 0, 3, &__kmp_forkjoin_frames_mode);
} // __kmp_stg_parse_forkjoin_frames

static void __kmp_stg_print_forkjoin_frames_mode(kmp_str_buf_t *buffer,
                                                 char const *name, void *data) {
  __kmp_stg_print_int(buffer, name, __kmp_forkjoin_frames_mode);
} // __kmp_stg_print_forkjoin_frames
#endif /* USE_ITT_BUILD */

// -----------------------------------------------------------------------------
// KMP_ENABLE_TASK_THROTTLING

static void __kmp_stg_parse_task_throttling(char const *name,
                                            char const *value, void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_enable_task_throttling);
} // __kmp_stg_parse_task_throttling


static void __kmp_stg_print_task_throttling(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_enable_task_throttling);
} // __kmp_stg_print_task_throttling

// -----------------------------------------------------------------------------
// OMP_DISPLAY_ENV

static void __kmp_stg_parse_omp_display_env(char const *name, char const *value,
                                            void *data) {
  if (__kmp_str_match("VERBOSE", 1, value)) {
    __kmp_display_env_verbose = TRUE;
  } else {
    __kmp_stg_parse_bool(name, value, &__kmp_display_env);
  }
} // __kmp_stg_parse_omp_display_env

static void __kmp_stg_print_omp_display_env(kmp_str_buf_t *buffer,
                                            char const *name, void *data) {
  if (__kmp_display_env_verbose) {
    __kmp_stg_print_str(buffer, name, "VERBOSE");
  } else {
    __kmp_stg_print_bool(buffer, name, __kmp_display_env);
  }
} // __kmp_stg_print_omp_display_env

static void __kmp_stg_parse_omp_cancellation(char const *name,
                                             char const *value, void *data) {
  if (TCR_4(__kmp_init_parallel)) {
    KMP_WARNING(EnvParallelWarn, name);
    return;
  } // read value before first parallel only
  __kmp_stg_parse_bool(name, value, &__kmp_omp_cancellation);
} // __kmp_stg_parse_omp_cancellation

static void __kmp_stg_print_omp_cancellation(kmp_str_buf_t *buffer,
                                             char const *name, void *data) {
  __kmp_stg_print_bool(buffer, name, __kmp_omp_cancellation);
} // __kmp_stg_print_omp_cancellation

#if OMPT_SUPPORT
static int __kmp_tool = 1;

static void __kmp_stg_parse_omp_tool(char const *name, char const *value,
                                     void *data) {
  __kmp_stg_parse_bool(name, value, &__kmp_tool);
} // __kmp_stg_parse_omp_tool

static void __kmp_stg_print_omp_tool(kmp_str_buf_t *buffer, char const *name,
                                     void *data) {
  if (__kmp_env_format) {
    KMP_STR_BUF_PRINT_BOOL_EX(name, __kmp_tool, "enabled", "disabled");
  } else {
    __kmp_str_buf_print(buffer, "   %s=%s\n", name,
                        __kmp_tool ? "enabled" : "disabled");
  }
} // __kmp_stg_print_omp_tool

static char *__kmp_tool_libraries = NULL;

static void __kmp_stg_parse_omp_tool_libraries(char const *name,
                                               char const *value, void *data) {
  __kmp_stg_parse_str(name, value, &__kmp_tool_libraries);
} // __kmp_stg_parse_omp_tool_libraries

static void __kmp_stg_print_omp_tool_libraries(kmp_str_buf_t *buffer,
                                               char const *name, void *data) {
  if (__kmp_tool_libraries)
    __kmp_stg_print_str(buffer, name, __kmp_tool_libraries);
  else {
    if (__kmp_env_format) {
      KMP_STR_BUF_PRINT_NAME;
    } else {
      __kmp_str_buf_print(buffer, "   %s", name);
    }
    __kmp_str_buf_print(buffer, ": %s\n", KMP_I18N_STR(NotDefined));
  }
} // __kmp_stg_print_omp_tool_libraries

#endif

// Table.

static kmp_setting_t __kmp_stg_table[] = {

    {"KMP_ALL_THREADS", __kmp_stg_parse_device_thread_limit, NULL, NULL, 0, 0},
    {"KMP_BLOCKTIME", __kmp_stg_parse_blocktime, __kmp_stg_print_blocktime,
     NULL, 0, 0},
    {"KMP_USE_YIELD", __kmp_stg_parse_use_yield, __kmp_stg_print_use_yield,
     NULL, 0, 0},
    {"KMP_DUPLICATE_LIB_OK", __kmp_stg_parse_duplicate_lib_ok,
     __kmp_stg_print_duplicate_lib_ok, NULL, 0, 0},
    {"KMP_LIBRARY", __kmp_stg_parse_wait_policy, __kmp_stg_print_wait_policy,
     NULL, 0, 0},
    {"KMP_DEVICE_THREAD_LIMIT", __kmp_stg_parse_device_thread_limit,
     __kmp_stg_print_device_thread_limit, NULL, 0, 0},
#if KMP_USE_MONITOR
    {"KMP_MONITOR_STACKSIZE", __kmp_stg_parse_monitor_stacksize,
     __kmp_stg_print_monitor_stacksize, NULL, 0, 0},
#endif
    {"KMP_SETTINGS", __kmp_stg_parse_settings, __kmp_stg_print_settings, NULL,
     0, 0},
    {"KMP_STACKOFFSET", __kmp_stg_parse_stackoffset,
     __kmp_stg_print_stackoffset, NULL, 0, 0},
    {"KMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
     NULL, 0, 0},
    {"KMP_STACKPAD", __kmp_stg_parse_stackpad, __kmp_stg_print_stackpad, NULL,
     0, 0},
    {"KMP_VERSION", __kmp_stg_parse_version, __kmp_stg_print_version, NULL, 0,
     0},
    {"KMP_WARNINGS", __kmp_stg_parse_warnings, __kmp_stg_print_warnings, NULL,
     0, 0},

    {"OMP_NESTED", __kmp_stg_parse_nested, __kmp_stg_print_nested, NULL, 0, 0},
    {"OMP_NUM_THREADS", __kmp_stg_parse_num_threads,
     __kmp_stg_print_num_threads, NULL, 0, 0},
    {"OMP_STACKSIZE", __kmp_stg_parse_stacksize, __kmp_stg_print_stacksize,
     NULL, 0, 0},

    {"KMP_TASKING", __kmp_stg_parse_tasking, __kmp_stg_print_tasking, NULL, 0,
     0},
    {"KMP_TASK_STEALING_CONSTRAINT", __kmp_stg_parse_task_stealing,
     __kmp_stg_print_task_stealing, NULL, 0, 0},
    {"OMP_MAX_ACTIVE_LEVELS", __kmp_stg_parse_max_active_levels,
     __kmp_stg_print_max_active_levels, NULL, 0, 0},
    {"OMP_DEFAULT_DEVICE", __kmp_stg_parse_default_device,
     __kmp_stg_print_default_device, NULL, 0, 0},
    {"OMP_TARGET_OFFLOAD", __kmp_stg_parse_target_offload,
     __kmp_stg_print_target_offload, NULL, 0, 0},
    {"OMP_MAX_TASK_PRIORITY", __kmp_stg_parse_max_task_priority,
     __kmp_stg_print_max_task_priority, NULL, 0, 0},
    {"KMP_TASKLOOP_MIN_TASKS", __kmp_stg_parse_taskloop_min_tasks,
     __kmp_stg_print_taskloop_min_tasks, NULL, 0, 0},
    {"OMP_THREAD_LIMIT", __kmp_stg_parse_thread_limit,
     __kmp_stg_print_thread_limit, NULL, 0, 0},
    {"KMP_TEAMS_THREAD_LIMIT", __kmp_stg_parse_teams_thread_limit,
     __kmp_stg_print_teams_thread_limit, NULL, 0, 0},
    {"OMP_WAIT_POLICY", __kmp_stg_parse_wait_policy,
     __kmp_stg_print_wait_policy, NULL, 0, 0},
    {"KMP_DISP_NUM_BUFFERS", __kmp_stg_parse_disp_buffers,
     __kmp_stg_print_disp_buffers, NULL, 0, 0},
#if KMP_NESTED_HOT_TEAMS
    {"KMP_HOT_TEAMS_MAX_LEVEL", __kmp_stg_parse_hot_teams_level,
     __kmp_stg_print_hot_teams_level, NULL, 0, 0},
    {"KMP_HOT_TEAMS_MODE", __kmp_stg_parse_hot_teams_mode,
     __kmp_stg_print_hot_teams_mode, NULL, 0, 0},
#endif // KMP_NESTED_HOT_TEAMS

#if KMP_HANDLE_SIGNALS
    {"KMP_HANDLE_SIGNALS", __kmp_stg_parse_handle_signals,
     __kmp_stg_print_handle_signals, NULL, 0, 0},
#endif

#if KMP_ARCH_X86 || KMP_ARCH_X86_64
    {"KMP_INHERIT_FP_CONTROL", __kmp_stg_parse_inherit_fp_control,
     __kmp_stg_print_inherit_fp_control, NULL, 0, 0},
#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */

#ifdef KMP_GOMP_COMPAT
    {"GOMP_STACKSIZE", __kmp_stg_parse_stacksize, NULL, NULL, 0, 0},
#endif

#ifdef KMP_DEBUG
    {"KMP_A_DEBUG", __kmp_stg_parse_a_debug, __kmp_stg_print_a_debug, NULL, 0,
     0},
    {"KMP_B_DEBUG", __kmp_stg_parse_b_debug, __kmp_stg_print_b_debug, NULL, 0,
     0},
    {"KMP_C_DEBUG", __kmp_stg_parse_c_debug, __kmp_stg_print_c_debug, NULL, 0,
     0},
    {"KMP_D_DEBUG", __kmp_stg_parse_d_debug, __kmp_stg_print_d_debug, NULL, 0,
     0},
    {"KMP_E_DEBUG", __kmp_stg_parse_e_debug, __kmp_stg_print_e_debug, NULL, 0,
     0},
    {"KMP_F_DEBUG", __kmp_stg_parse_f_debug, __kmp_stg_print_f_debug, NULL, 0,
     0},
    {"KMP_DEBUG", __kmp_stg_parse_debug, NULL, /* no print */ NULL, 0, 0},
    {"KMP_DEBUG_BUF", __kmp_stg_parse_debug_buf, __kmp_stg_print_debug_buf,
     NULL, 0, 0},
    {"KMP_DEBUG_BUF_ATOMIC", __kmp_stg_parse_debug_buf_atomic,
     __kmp_stg_print_debug_buf_atomic, NULL, 0, 0},
    {"KMP_DEBUG_BUF_CHARS", __kmp_stg_parse_debug_buf_chars,
     __kmp_stg_print_debug_buf_chars, NULL, 0, 0},
    {"KMP_DEBUG_BUF_LINES", __kmp_stg_parse_debug_buf_lines,
     __kmp_stg_print_debug_buf_lines, NULL, 0, 0},
    {"KMP_DIAG", __kmp_stg_parse_diag, __kmp_stg_print_diag, NULL, 0, 0},

    {"KMP_PAR_RANGE", __kmp_stg_parse_par_range_env,
     __kmp_stg_print_par_range_env, NULL, 0, 0},
#endif // KMP_DEBUG

    {"KMP_ALIGN_ALLOC", __kmp_stg_parse_align_alloc,
     __kmp_stg_print_align_alloc, NULL, 0, 0},

    {"KMP_PLAIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
     __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
    {"KMP_PLAIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
     __kmp_stg_print_barrier_pattern, NULL, 0, 0},
    {"KMP_FORKJOIN_BARRIER", __kmp_stg_parse_barrier_branch_bit,
     __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
    {"KMP_FORKJOIN_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
     __kmp_stg_print_barrier_pattern, NULL, 0, 0},
#if KMP_FAST_REDUCTION_BARRIER
    {"KMP_REDUCTION_BARRIER", __kmp_stg_parse_barrier_branch_bit,
     __kmp_stg_print_barrier_branch_bit, NULL, 0, 0},
    {"KMP_REDUCTION_BARRIER_PATTERN", __kmp_stg_parse_barrier_pattern,
     __kmp_stg_print_barrier_pattern, NULL, 0, 0},
#endif

    {"KMP_ABORT_DELAY", __kmp_stg_parse_abort_delay,
     __kmp_stg_print_abort_delay, NULL, 0, 0},
    {"KMP_CPUINFO_FILE", __kmp_stg_parse_cpuinfo_file,
     __kmp_stg_print_cpuinfo_file, NULL, 0, 0},
    {"KMP_FORCE_REDUCTION", __kmp_stg_parse_force_reduction,
     __kmp_stg_print_force_reduction, NULL, 0, 0},
    {"KMP_DETERMINISTIC_REDUCTION", __kmp_stg_parse_force_reduction,
     __kmp_stg_print_force_reduction, NULL, 0, 0},
    {"KMP_STORAGE_MAP", __kmp_stg_parse_storage_map,
     __kmp_stg_print_storage_map, NULL, 0, 0},
    {"KMP_ALL_THREADPRIVATE", __kmp_stg_parse_all_threadprivate,
     __kmp_stg_print_all_threadprivate, NULL, 0, 0},
    {"KMP_FOREIGN_THREADS_THREADPRIVATE",
     __kmp_stg_parse_foreign_threads_threadprivate,
     __kmp_stg_print_foreign_threads_threadprivate, NULL, 0, 0},

#if KMP_AFFINITY_SUPPORTED
    {"KMP_AFFINITY", __kmp_stg_parse_affinity, __kmp_stg_print_affinity, NULL,
     0, 0},
#ifdef KMP_GOMP_COMPAT
    {"GOMP_CPU_AFFINITY", __kmp_stg_parse_gomp_cpu_affinity, NULL,
     /* no print */ NULL, 0, 0},
#endif /* KMP_GOMP_COMPAT */
    {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
     NULL, 0, 0},
    {"OMP_PLACES", __kmp_stg_parse_places, __kmp_stg_print_places, NULL, 0, 0},
    {"KMP_TOPOLOGY_METHOD", __kmp_stg_parse_topology_method,
     __kmp_stg_print_topology_method, NULL, 0, 0},

#else

    // KMP_AFFINITY is not supported on OS X*, nor is OMP_PLACES.
    // OMP_PROC_BIND and proc-bind-var are supported, however.
    {"OMP_PROC_BIND", __kmp_stg_parse_proc_bind, __kmp_stg_print_proc_bind,
     NULL, 0, 0},

#endif // KMP_AFFINITY_SUPPORTED
    {"OMP_DISPLAY_AFFINITY", __kmp_stg_parse_display_affinity,
     __kmp_stg_print_display_affinity, NULL, 0, 0},
    {"OMP_AFFINITY_FORMAT", __kmp_stg_parse_affinity_format,
     __kmp_stg_print_affinity_format, NULL, 0, 0},
    {"KMP_INIT_AT_FORK", __kmp_stg_parse_init_at_fork,
     __kmp_stg_print_init_at_fork, NULL, 0, 0},
    {"KMP_SCHEDULE", __kmp_stg_parse_schedule, __kmp_stg_print_schedule, NULL,
     0, 0},
    {"OMP_SCHEDULE", __kmp_stg_parse_omp_schedule, __kmp_stg_print_omp_schedule,
     NULL, 0, 0},
#if KMP_USE_HIER_SCHED
    {"KMP_DISP_HAND_THREAD", __kmp_stg_parse_kmp_hand_thread,
     __kmp_stg_print_kmp_hand_thread, NULL, 0, 0},
#endif
    {"KMP_ATOMIC_MODE", __kmp_stg_parse_atomic_mode,
     __kmp_stg_print_atomic_mode, NULL, 0, 0},
    {"KMP_CONSISTENCY_CHECK", __kmp_stg_parse_consistency_check,
     __kmp_stg_print_consistency_check, NULL, 0, 0},

#if USE_ITT_BUILD && USE_ITT_NOTIFY
    {"KMP_ITT_PREPARE_DELAY", __kmp_stg_parse_itt_prepare_delay,
     __kmp_stg_print_itt_prepare_delay, NULL, 0, 0},
#endif /* USE_ITT_BUILD && USE_ITT_NOTIFY */
    {"KMP_MALLOC_POOL_INCR", __kmp_stg_parse_malloc_pool_incr,
     __kmp_stg_print_malloc_pool_incr, NULL, 0, 0},
    {"KMP_GTID_MODE", __kmp_stg_parse_gtid_mode, __kmp_stg_print_gtid_mode,
     NULL, 0, 0},
    {"OMP_DYNAMIC", __kmp_stg_parse_omp_dynamic, __kmp_stg_print_omp_dynamic,
     NULL, 0, 0},
    {"KMP_DYNAMIC_MODE", __kmp_stg_parse_kmp_dynamic_mode,
     __kmp_stg_print_kmp_dynamic_mode, NULL, 0, 0},

#ifdef USE_LOAD_BALANCE
    {"KMP_LOAD_BALANCE_INTERVAL", __kmp_stg_parse_ld_balance_interval,
     __kmp_stg_print_ld_balance_interval, NULL, 0, 0},
#endif

    {"KMP_NUM_LOCKS_IN_BLOCK", __kmp_stg_parse_lock_block,
     __kmp_stg_print_lock_block, NULL, 0, 0},
    {"KMP_LOCK_KIND", __kmp_stg_parse_lock_kind, __kmp_stg_print_lock_kind,
     NULL, 0, 0},
    {"KMP_SPIN_BACKOFF_PARAMS", __kmp_stg_parse_spin_backoff_params,
     __kmp_stg_print_spin_backoff_params, NULL, 0, 0},
#if KMP_USE_ADAPTIVE_LOCKS
    {"KMP_ADAPTIVE_LOCK_PROPS", __kmp_stg_parse_adaptive_lock_props,
     __kmp_stg_print_adaptive_lock_props, NULL, 0, 0},
#if KMP_DEBUG_ADAPTIVE_LOCKS
    {"KMP_SPECULATIVE_STATSFILE", __kmp_stg_parse_speculative_statsfile,
     __kmp_stg_print_speculative_statsfile, NULL, 0, 0},
#endif
#endif // KMP_USE_ADAPTIVE_LOCKS
    {"KMP_PLACE_THREADS", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
     NULL, 0, 0},
    {"KMP_HW_SUBSET", __kmp_stg_parse_hw_subset, __kmp_stg_print_hw_subset,
     NULL, 0, 0},
#if USE_ITT_BUILD
    {"KMP_FORKJOIN_FRAMES", __kmp_stg_parse_forkjoin_frames,
     __kmp_stg_print_forkjoin_frames, NULL, 0, 0},
    {"KMP_FORKJOIN_FRAMES_MODE", __kmp_stg_parse_forkjoin_frames_mode,
     __kmp_stg_print_forkjoin_frames_mode, NULL, 0, 0},
#endif
    {"KMP_ENABLE_TASK_THROTTLING", __kmp_stg_parse_task_throttling,
     __kmp_stg_print_task_throttling, NULL, 0, 0},

    {"OMP_DISPLAY_ENV", __kmp_stg_parse_omp_display_env,
     __kmp_stg_print_omp_display_env, NULL, 0, 0},
    {"OMP_CANCELLATION", __kmp_stg_parse_omp_cancellation,
     __kmp_stg_print_omp_cancellation, NULL, 0, 0},
    {"OMP_ALLOCATOR", __kmp_stg_parse_allocator, __kmp_stg_print_allocator,
     NULL, 0, 0},

#if OMPT_SUPPORT
    {"OMP_TOOL", __kmp_stg_parse_omp_tool, __kmp_stg_print_omp_tool, NULL, 0,
     0},
    {"OMP_TOOL_LIBRARIES", __kmp_stg_parse_omp_tool_libraries,
     __kmp_stg_print_omp_tool_libraries, NULL, 0, 0},
#endif

    {"", NULL, NULL, NULL, 0, 0}}; // settings

static int const __kmp_stg_count =
    sizeof(__kmp_stg_table) / sizeof(kmp_setting_t);

static inline kmp_setting_t *__kmp_stg_find(char const *name) {

  int i;
  if (name != NULL) {
    for (i = 0; i < __kmp_stg_count; ++i) {
      if (strcmp(__kmp_stg_table[i].name, name) == 0) {
        return &__kmp_stg_table[i];
      }
    }
  }
  return NULL;

} // __kmp_stg_find

static int __kmp_stg_cmp(void const *_a, void const *_b) {
  const kmp_setting_t *a = RCAST(const kmp_setting_t *, _a);
  const kmp_setting_t *b = RCAST(const kmp_setting_t *, _b);

  // Process KMP_AFFINITY last.
  // It needs to come after OMP_PLACES and GOMP_CPU_AFFINITY.
  if (strcmp(a->name, "KMP_AFFINITY") == 0) {
    if (strcmp(b->name, "KMP_AFFINITY") == 0) {
      return 0;
    }
    return 1;
  } else if (strcmp(b->name, "KMP_AFFINITY") == 0) {
    return -1;
  }
  return strcmp(a->name, b->name);
} // __kmp_stg_cmp

static void __kmp_stg_init(void) {

  static int initialized = 0;

  if (!initialized) {

    // Sort table.
    qsort(__kmp_stg_table, __kmp_stg_count - 1, sizeof(kmp_setting_t),
          __kmp_stg_cmp);

    { // Initialize *_STACKSIZE data.
      kmp_setting_t *kmp_stacksize =
          __kmp_stg_find("KMP_STACKSIZE"); // 1st priority.
#ifdef KMP_GOMP_COMPAT
      kmp_setting_t *gomp_stacksize =
          __kmp_stg_find("GOMP_STACKSIZE"); // 2nd priority.
#endif
      kmp_setting_t *omp_stacksize =
          __kmp_stg_find("OMP_STACKSIZE"); // 3rd priority.

      // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
      // !!! Compiler does not understand rivals is used and optimizes out
      // assignments
      // !!!     rivals[ i ++ ] = ...;
      static kmp_setting_t *volatile rivals[4];
      static kmp_stg_ss_data_t kmp_data = {1, CCAST(kmp_setting_t **, rivals)};
#ifdef KMP_GOMP_COMPAT
      static kmp_stg_ss_data_t gomp_data = {1024,
                                            CCAST(kmp_setting_t **, rivals)};
#endif
      static kmp_stg_ss_data_t omp_data = {1024,
                                           CCAST(kmp_setting_t **, rivals)};
      int i = 0;

      rivals[i++] = kmp_stacksize;
#ifdef KMP_GOMP_COMPAT
      if (gomp_stacksize != NULL) {
        rivals[i++] = gomp_stacksize;
      }
#endif
      rivals[i++] = omp_stacksize;
      rivals[i++] = NULL;

      kmp_stacksize->data = &kmp_data;
#ifdef KMP_GOMP_COMPAT
      if (gomp_stacksize != NULL) {
        gomp_stacksize->data = &gomp_data;
      }
#endif
      omp_stacksize->data = &omp_data;
    }

    { // Initialize KMP_LIBRARY and OMP_WAIT_POLICY data.
      kmp_setting_t *kmp_library =
          __kmp_stg_find("KMP_LIBRARY"); // 1st priority.
      kmp_setting_t *omp_wait_policy =
          __kmp_stg_find("OMP_WAIT_POLICY"); // 2nd priority.

      // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
      static kmp_setting_t *volatile rivals[3];
      static kmp_stg_wp_data_t kmp_data = {0, CCAST(kmp_setting_t **, rivals)};
      static kmp_stg_wp_data_t omp_data = {1, CCAST(kmp_setting_t **, rivals)};
      int i = 0;

      rivals[i++] = kmp_library;
      if (omp_wait_policy != NULL) {
        rivals[i++] = omp_wait_policy;
      }
      rivals[i++] = NULL;

      kmp_library->data = &kmp_data;
      if (omp_wait_policy != NULL) {
        omp_wait_policy->data = &omp_data;
      }
    }

    { // Initialize KMP_DEVICE_THREAD_LIMIT and KMP_ALL_THREADS
      kmp_setting_t *kmp_device_thread_limit =
          __kmp_stg_find("KMP_DEVICE_THREAD_LIMIT"); // 1st priority.
      kmp_setting_t *kmp_all_threads =
          __kmp_stg_find("KMP_ALL_THREADS"); // 2nd priority.

      // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
      static kmp_setting_t *volatile rivals[3];
      int i = 0;

      rivals[i++] = kmp_device_thread_limit;
      rivals[i++] = kmp_all_threads;
      rivals[i++] = NULL;

      kmp_device_thread_limit->data = CCAST(kmp_setting_t **, rivals);
      kmp_all_threads->data = CCAST(kmp_setting_t **, rivals);
    }

    { // Initialize KMP_HW_SUBSET and KMP_PLACE_THREADS
      // 1st priority
      kmp_setting_t *kmp_hw_subset = __kmp_stg_find("KMP_HW_SUBSET");
      // 2nd priority
      kmp_setting_t *kmp_place_threads = __kmp_stg_find("KMP_PLACE_THREADS");

      // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
      static kmp_setting_t *volatile rivals[3];
      int i = 0;

      rivals[i++] = kmp_hw_subset;
      rivals[i++] = kmp_place_threads;
      rivals[i++] = NULL;

      kmp_hw_subset->data = CCAST(kmp_setting_t **, rivals);
      kmp_place_threads->data = CCAST(kmp_setting_t **, rivals);
    }

#if KMP_AFFINITY_SUPPORTED
    { // Initialize KMP_AFFINITY, GOMP_CPU_AFFINITY, and OMP_PROC_BIND data.
      kmp_setting_t *kmp_affinity =
          __kmp_stg_find("KMP_AFFINITY"); // 1st priority.
      KMP_DEBUG_ASSERT(kmp_affinity != NULL);

#ifdef KMP_GOMP_COMPAT
      kmp_setting_t *gomp_cpu_affinity =
          __kmp_stg_find("GOMP_CPU_AFFINITY"); // 2nd priority.
      KMP_DEBUG_ASSERT(gomp_cpu_affinity != NULL);
#endif

      kmp_setting_t *omp_proc_bind =
          __kmp_stg_find("OMP_PROC_BIND"); // 3rd priority.
      KMP_DEBUG_ASSERT(omp_proc_bind != NULL);

      // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
      static kmp_setting_t *volatile rivals[4];
      int i = 0;

      rivals[i++] = kmp_affinity;

#ifdef KMP_GOMP_COMPAT
      rivals[i++] = gomp_cpu_affinity;
      gomp_cpu_affinity->data = CCAST(kmp_setting_t **, rivals);
#endif

      rivals[i++] = omp_proc_bind;
      omp_proc_bind->data = CCAST(kmp_setting_t **, rivals);
      rivals[i++] = NULL;

      static kmp_setting_t *volatile places_rivals[4];
      i = 0;

      kmp_setting_t *omp_places = __kmp_stg_find("OMP_PLACES"); // 3rd priority.
      KMP_DEBUG_ASSERT(omp_places != NULL);

      places_rivals[i++] = kmp_affinity;
#ifdef KMP_GOMP_COMPAT
      places_rivals[i++] = gomp_cpu_affinity;
#endif
      places_rivals[i++] = omp_places;
      omp_places->data = CCAST(kmp_setting_t **, places_rivals);
      places_rivals[i++] = NULL;
    }
#else
// KMP_AFFINITY not supported, so OMP_PROC_BIND has no rivals.
// OMP_PLACES not supported yet.
#endif // KMP_AFFINITY_SUPPORTED

    { // Initialize KMP_DETERMINISTIC_REDUCTION and KMP_FORCE_REDUCTION data.
      kmp_setting_t *kmp_force_red =
          __kmp_stg_find("KMP_FORCE_REDUCTION"); // 1st priority.
      kmp_setting_t *kmp_determ_red =
          __kmp_stg_find("KMP_DETERMINISTIC_REDUCTION"); // 2nd priority.

      // !!! volatile keyword is Intel(R) C Compiler bug CQ49908 workaround.
      static kmp_setting_t *volatile rivals[3];
      static kmp_stg_fr_data_t force_data = {1,
                                             CCAST(kmp_setting_t **, rivals)};
      static kmp_stg_fr_data_t determ_data = {0,
                                              CCAST(kmp_setting_t **, rivals)};
      int i = 0;

      rivals[i++] = kmp_force_red;
      if (kmp_determ_red != NULL) {
        rivals[i++] = kmp_determ_red;
      }
      rivals[i++] = NULL;

      kmp_force_red->data = &force_data;
      if (kmp_determ_red != NULL) {
        kmp_determ_red->data = &determ_data;
      }
    }

    initialized = 1;
  }

  // Reset flags.
  int i;
  for (i = 0; i < __kmp_stg_count; ++i) {
    __kmp_stg_table[i].set = 0;
  }

} // __kmp_stg_init

static void __kmp_stg_parse(char const *name, char const *value) {
  // On Windows* OS there are some nameless variables like "C:=C:\" (yeah,
  // really nameless, they are presented in environment block as
  // "=C:=C\\\x00=D:=D:\\\x00...", so let us skip them.
  if (name[0] == 0) {
    return;
  }

  if (value != NULL) {
    kmp_setting_t *setting = __kmp_stg_find(name);
    if (setting != NULL) {
      setting->parse(name, value, setting->data);
      setting->defined = 1;
    }
  }

} // __kmp_stg_parse

static int __kmp_stg_check_rivals( // 0 -- Ok, 1 -- errors found.
    char const *name, // Name of variable.
    char const *value, // Value of the variable.
    kmp_setting_t **rivals // List of rival settings (must include current one).
    ) {

  if (rivals == NULL) {
    return 0;
  }

  // Loop thru higher priority settings (listed before current).
  int i = 0;
  for (; strcmp(rivals[i]->name, name) != 0; i++) {
    KMP_DEBUG_ASSERT(rivals[i] != NULL);

#if KMP_AFFINITY_SUPPORTED
    if (rivals[i] == __kmp_affinity_notype) {
      // If KMP_AFFINITY is specified without a type name,
      // it does not rival OMP_PROC_BIND or GOMP_CPU_AFFINITY.
      continue;
    }
#endif

    if (rivals[i]->set) {
      KMP_WARNING(StgIgnored, name, rivals[i]->name);
      return 1;
    }
  }

  ++i; // Skip current setting.
  return 0;

} // __kmp_stg_check_rivals

static int __kmp_env_toPrint(char const *name, int flag) {
  int rc = 0;
  kmp_setting_t *setting = __kmp_stg_find(name);
  if (setting != NULL) {
    rc = setting->defined;
    if (flag >= 0) {
      setting->defined = flag;
    }
  }
  return rc;
}

static void __kmp_aux_env_initialize(kmp_env_blk_t *block) {

  char const *value;

  /* OMP_NUM_THREADS */
  value = __kmp_env_blk_var(block, "OMP_NUM_THREADS");
  if (value) {
    ompc_set_num_threads(__kmp_dflt_team_nth);
  }

  /* KMP_BLOCKTIME */
  value = __kmp_env_blk_var(block, "KMP_BLOCKTIME");
  if (value) {
    kmpc_set_blocktime(__kmp_dflt_blocktime);
  }

  /* OMP_NESTED */
  value = __kmp_env_blk_var(block, "OMP_NESTED");
  if (value) {
    ompc_set_nested(__kmp_dflt_max_active_levels > 1);
  }

  /* OMP_DYNAMIC */
  value = __kmp_env_blk_var(block, "OMP_DYNAMIC");
  if (value) {
    ompc_set_dynamic(__kmp_global.g.g_dynamic);
  }
}

void __kmp_env_initialize(char const *string) {

  kmp_env_blk_t block;
  int i;

  __kmp_stg_init();

  // Hack!!!
  if (string == NULL) {
    // __kmp_max_nth = __kmp_sys_max_nth;
    __kmp_threads_capacity =
        __kmp_initial_threads_capacity(__kmp_dflt_team_nth_ub);
  }
  __kmp_env_blk_init(&block, string);

  // update the set flag on all entries that have an env var
  for (i = 0; i < block.count; ++i) {
    if ((block.vars[i].name == NULL) || (*block.vars[i].name == '\0')) {
      continue;
    }
    if (block.vars[i].value == NULL) {
      continue;
    }
    kmp_setting_t *setting = __kmp_stg_find(block.vars[i].name);
    if (setting != NULL) {
      setting->set = 1;
    }
  }

  // We need to know if blocktime was set when processing OMP_WAIT_POLICY
  blocktime_str = __kmp_env_blk_var(&block, "KMP_BLOCKTIME");

  // Special case. If we parse environment, not a string, process KMP_WARNINGS
  // first.
  if (string == NULL) {
    char const *name = "KMP_WARNINGS";
    char const *value = __kmp_env_blk_var(&block, name);
    __kmp_stg_parse(name, value);
  }

#if KMP_AFFINITY_SUPPORTED
  // Special case. KMP_AFFINITY is not a rival to other affinity env vars
  // if no affinity type is specified.  We want to allow
  // KMP_AFFINITY=[no],verbose/[no]warnings/etc.  to be enabled when
  // specifying the affinity type via GOMP_CPU_AFFINITY or the OMP 4.0
  // affinity mechanism.
  __kmp_affinity_notype = NULL;
  char const *aff_str = __kmp_env_blk_var(&block, "KMP_AFFINITY");
  if (aff_str != NULL) {
// Check if the KMP_AFFINITY type is specified in the string.
// We just search the string for "compact", "scatter", etc.
// without really parsing the string.  The syntax of the
// KMP_AFFINITY env var is such that none of the affinity
// type names can appear anywhere other that the type
// specifier, even as substrings.
//
// I can't find a case-insensitive version of strstr on Windows* OS.
// Use the case-sensitive version for now.

#if KMP_OS_WINDOWS
#define FIND strstr
#else
#define FIND strcasestr
#endif

    if ((FIND(aff_str, "none") == NULL) &&
        (FIND(aff_str, "physical") == NULL) &&
        (FIND(aff_str, "logical") == NULL) &&
        (FIND(aff_str, "compact") == NULL) &&
        (FIND(aff_str, "scatter") == NULL) &&
        (FIND(aff_str, "explicit") == NULL) &&
        (FIND(aff_str, "balanced") == NULL) &&
        (FIND(aff_str, "disabled") == NULL)) {
      __kmp_affinity_notype = __kmp_stg_find("KMP_AFFINITY");
    } else {
      // A new affinity type is specified.
      // Reset the affinity flags to their default values,
      // in case this is called from kmp_set_defaults().
      __kmp_affinity_type = affinity_default;
      __kmp_affinity_gran = affinity_gran_default;
      __kmp_affinity_top_method = affinity_top_method_default;
      __kmp_affinity_respect_mask = affinity_respect_mask_default;
    }
#undef FIND

    // Also reset the affinity flags if OMP_PROC_BIND is specified.
    aff_str = __kmp_env_blk_var(&block, "OMP_PROC_BIND");
    if (aff_str != NULL) {
      __kmp_affinity_type = affinity_default;
      __kmp_affinity_gran = affinity_gran_default;
      __kmp_affinity_top_method = affinity_top_method_default;
      __kmp_affinity_respect_mask = affinity_respect_mask_default;
    }
  }

#endif /* KMP_AFFINITY_SUPPORTED */

  // Set up the nested proc bind type vector.
  if (__kmp_nested_proc_bind.bind_types == NULL) {
    __kmp_nested_proc_bind.bind_types =
        (kmp_proc_bind_t *)KMP_INTERNAL_MALLOC(sizeof(kmp_proc_bind_t));
    if (__kmp_nested_proc_bind.bind_types == NULL) {
      KMP_FATAL(MemoryAllocFailed);
    }
    __kmp_nested_proc_bind.size = 1;
    __kmp_nested_proc_bind.used = 1;
#if KMP_AFFINITY_SUPPORTED
    __kmp_nested_proc_bind.bind_types[0] = proc_bind_default;
#else
    // default proc bind is false if affinity not supported
    __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
#endif
  }

  // Set up the affinity format ICV
  // Grab the default affinity format string from the message catalog
  kmp_msg_t m =
      __kmp_msg_format(kmp_i18n_msg_AffFormatDefault, "%P", "%i", "%n", "%A");
  KMP_DEBUG_ASSERT(KMP_STRLEN(m.str) < KMP_AFFINITY_FORMAT_SIZE);

  if (__kmp_affinity_format == NULL) {
    __kmp_affinity_format =
        (char *)KMP_INTERNAL_MALLOC(sizeof(char) * KMP_AFFINITY_FORMAT_SIZE);
  }
  KMP_STRCPY_S(__kmp_affinity_format, KMP_AFFINITY_FORMAT_SIZE, m.str);
  __kmp_str_free(&m.str);

  // Now process all of the settings.
  for (i = 0; i < block.count; ++i) {
    __kmp_stg_parse(block.vars[i].name, block.vars[i].value);
  }

  // If user locks have been allocated yet, don't reset the lock vptr table.
  if (!__kmp_init_user_locks) {
    if (__kmp_user_lock_kind == lk_default) {
      __kmp_user_lock_kind = lk_queuing;
    }
#if KMP_USE_DYNAMIC_LOCK
    __kmp_init_dynamic_user_locks();
#else
    __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
#endif
  } else {
    KMP_DEBUG_ASSERT(string != NULL); // kmp_set_defaults() was called
    KMP_DEBUG_ASSERT(__kmp_user_lock_kind != lk_default);
// Binds lock functions again to follow the transition between different
// KMP_CONSISTENCY_CHECK values. Calling this again is harmless as long
// as we do not allow lock kind changes after making a call to any
// user lock functions (true).
#if KMP_USE_DYNAMIC_LOCK
    __kmp_init_dynamic_user_locks();
#else
    __kmp_set_user_lock_vptrs(__kmp_user_lock_kind);
#endif
  }

#if KMP_AFFINITY_SUPPORTED

  if (!TCR_4(__kmp_init_middle)) {
#if KMP_USE_HWLOC
    // Force using hwloc when either tiles or numa nodes requested within
    // KMP_HW_SUBSET and no other topology method is requested
    if ((__kmp_hws_node.num > 0 || __kmp_hws_tile.num > 0 ||
         __kmp_affinity_gran == affinity_gran_tile) &&
        (__kmp_affinity_top_method == affinity_top_method_default)) {
      __kmp_affinity_top_method = affinity_top_method_hwloc;
    }
#endif
    // Determine if the machine/OS is actually capable of supporting
    // affinity.
    const char *var = "KMP_AFFINITY";
    KMPAffinity::pick_api();
#if KMP_USE_HWLOC
    // If Hwloc topology discovery was requested but affinity was also disabled,
    // then tell user that Hwloc request is being ignored and use default
    // topology discovery method.
    if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
        __kmp_affinity_dispatch->get_api_type() != KMPAffinity::HWLOC) {
      KMP_WARNING(AffIgnoringHwloc, var);
      __kmp_affinity_top_method = affinity_top_method_all;
    }
#endif
    if (__kmp_affinity_type == affinity_disabled) {
      KMP_AFFINITY_DISABLE();
    } else if (!KMP_AFFINITY_CAPABLE()) {
      __kmp_affinity_dispatch->determine_capable(var);
      if (!KMP_AFFINITY_CAPABLE()) {
        if (__kmp_affinity_verbose ||
            (__kmp_affinity_warnings &&
             (__kmp_affinity_type != affinity_default) &&
             (__kmp_affinity_type != affinity_none) &&
             (__kmp_affinity_type != affinity_disabled))) {
          KMP_WARNING(AffNotSupported, var);
        }
        __kmp_affinity_type = affinity_disabled;
        __kmp_affinity_respect_mask = 0;
        __kmp_affinity_gran = affinity_gran_fine;
      }
    }

    if (__kmp_affinity_type == affinity_disabled) {
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
    } else if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_true) {
      // OMP_PROC_BIND=true maps to OMP_PROC_BIND=spread.
      __kmp_nested_proc_bind.bind_types[0] = proc_bind_spread;
    }

    if (KMP_AFFINITY_CAPABLE()) {

#if KMP_GROUP_AFFINITY
      // This checks to see if the initial affinity mask is equal
      // to a single windows processor group.  If it is, then we do
      // not respect the initial affinity mask and instead, use the
      // entire machine.
      bool exactly_one_group = false;
      if (__kmp_num_proc_groups > 1) {
        int group;
        bool within_one_group;
        // Get the initial affinity mask and determine if it is
        // contained within a single group.
        kmp_affin_mask_t *init_mask;
        KMP_CPU_ALLOC(init_mask);
        __kmp_get_system_affinity(init_mask, TRUE);
        group = __kmp_get_proc_group(init_mask);
        within_one_group = (group >= 0);
        // If the initial affinity is within a single group,
        // then determine if it is equal to that single group.
        if (within_one_group) {
          DWORD num_bits_in_group = __kmp_GetActiveProcessorCount(group);
          DWORD num_bits_in_mask = 0;
          for (int bit = init_mask->begin(); bit != init_mask->end();
               bit = init_mask->next(bit))
            num_bits_in_mask++;
          exactly_one_group = (num_bits_in_group == num_bits_in_mask);
        }
        KMP_CPU_FREE(init_mask);
      }

      // Handle the Win 64 group affinity stuff if there are multiple
      // processor groups, or if the user requested it, and OMP 4.0
      // affinity is not in effect.
      if (((__kmp_num_proc_groups > 1) &&
           (__kmp_affinity_type == affinity_default) &&
           (__kmp_nested_proc_bind.bind_types[0] == proc_bind_default)) ||
          (__kmp_affinity_top_method == affinity_top_method_group)) {
        if (__kmp_affinity_respect_mask == affinity_respect_mask_default &&
            exactly_one_group) {
          __kmp_affinity_respect_mask = FALSE;
        }
        if (__kmp_affinity_type == affinity_default) {
          __kmp_affinity_type = affinity_compact;
          __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
        }
        if (__kmp_affinity_top_method == affinity_top_method_default) {
          if (__kmp_affinity_gran == affinity_gran_default) {
            __kmp_affinity_top_method = affinity_top_method_group;
            __kmp_affinity_gran = affinity_gran_group;
          } else if (__kmp_affinity_gran == affinity_gran_group) {
            __kmp_affinity_top_method = affinity_top_method_group;
          } else {
            __kmp_affinity_top_method = affinity_top_method_all;
          }
        } else if (__kmp_affinity_top_method == affinity_top_method_group) {
          if (__kmp_affinity_gran == affinity_gran_default) {
            __kmp_affinity_gran = affinity_gran_group;
          } else if ((__kmp_affinity_gran != affinity_gran_group) &&
                     (__kmp_affinity_gran != affinity_gran_fine) &&
                     (__kmp_affinity_gran != affinity_gran_thread)) {
            const char *str = NULL;
            switch (__kmp_affinity_gran) {
            case affinity_gran_core:
              str = "core";
              break;
            case affinity_gran_package:
              str = "package";
              break;
            case affinity_gran_node:
              str = "node";
              break;
            case affinity_gran_tile:
              str = "tile";
              break;
            default:
              KMP_DEBUG_ASSERT(0);
            }
            KMP_WARNING(AffGranTopGroup, var, str);
            __kmp_affinity_gran = affinity_gran_fine;
          }
        } else {
          if (__kmp_affinity_gran == affinity_gran_default) {
            __kmp_affinity_gran = affinity_gran_core;
          } else if (__kmp_affinity_gran == affinity_gran_group) {
            const char *str = NULL;
            switch (__kmp_affinity_type) {
            case affinity_physical:
              str = "physical";
              break;
            case affinity_logical:
              str = "logical";
              break;
            case affinity_compact:
              str = "compact";
              break;
            case affinity_scatter:
              str = "scatter";
              break;
            case affinity_explicit:
              str = "explicit";
              break;
            // No MIC on windows, so no affinity_balanced case
            default:
              KMP_DEBUG_ASSERT(0);
            }
            KMP_WARNING(AffGranGroupType, var, str);
            __kmp_affinity_gran = affinity_gran_core;
          }
        }
      } else

#endif /* KMP_GROUP_AFFINITY */

      {
        if (__kmp_affinity_respect_mask == affinity_respect_mask_default) {
#if KMP_GROUP_AFFINITY
          if (__kmp_num_proc_groups > 1 && exactly_one_group) {
            __kmp_affinity_respect_mask = FALSE;
          } else
#endif /* KMP_GROUP_AFFINITY */
          {
            __kmp_affinity_respect_mask = TRUE;
          }
        }
        if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
            (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
          if (__kmp_affinity_type == affinity_default) {
            __kmp_affinity_type = affinity_compact;
            __kmp_affinity_dups = FALSE;
          }
        } else if (__kmp_affinity_type == affinity_default) {
#if KMP_MIC_SUPPORTED
          if (__kmp_mic_type != non_mic) {
            __kmp_nested_proc_bind.bind_types[0] = proc_bind_intel;
          } else
#endif
          {
            __kmp_nested_proc_bind.bind_types[0] = proc_bind_false;
          }
#if KMP_MIC_SUPPORTED
          if (__kmp_mic_type != non_mic) {
            __kmp_affinity_type = affinity_scatter;
          } else
#endif
          {
            __kmp_affinity_type = affinity_none;
          }
        }
        if ((__kmp_affinity_gran == affinity_gran_default) &&
            (__kmp_affinity_gran_levels < 0)) {
#if KMP_MIC_SUPPORTED
          if (__kmp_mic_type != non_mic) {
            __kmp_affinity_gran = affinity_gran_fine;
          } else
#endif
          {
            __kmp_affinity_gran = affinity_gran_core;
          }
        }
        if (__kmp_affinity_top_method == affinity_top_method_default) {
          __kmp_affinity_top_method = affinity_top_method_all;
        }
      }
    }

    K_DIAG(1, ("__kmp_affinity_type         == %d\n", __kmp_affinity_type));
    K_DIAG(1, ("__kmp_affinity_compact      == %d\n", __kmp_affinity_compact));
    K_DIAG(1, ("__kmp_affinity_offset       == %d\n", __kmp_affinity_offset));
    K_DIAG(1, ("__kmp_affinity_verbose      == %d\n", __kmp_affinity_verbose));
    K_DIAG(1, ("__kmp_affinity_warnings     == %d\n", __kmp_affinity_warnings));
    K_DIAG(1, ("__kmp_affinity_respect_mask == %d\n",
               __kmp_affinity_respect_mask));
    K_DIAG(1, ("__kmp_affinity_gran         == %d\n", __kmp_affinity_gran));

    KMP_DEBUG_ASSERT(__kmp_affinity_type != affinity_default);
    KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.bind_types[0] != proc_bind_default);
    K_DIAG(1, ("__kmp_nested_proc_bind.bind_types[0] == %d\n",
               __kmp_nested_proc_bind.bind_types[0]));
  }

#endif /* KMP_AFFINITY_SUPPORTED */

  if (__kmp_version) {
    __kmp_print_version_1();
  }

  // Post-initialization step: some env. vars need their value's further
  // processing
  if (string != NULL) { // kmp_set_defaults() was called
    __kmp_aux_env_initialize(&block);
  }

  __kmp_env_blk_free(&block);

  KMP_MB();

} // __kmp_env_initialize

void __kmp_env_print() {

  kmp_env_blk_t block;
  int i;
  kmp_str_buf_t buffer;

  __kmp_stg_init();
  __kmp_str_buf_init(&buffer);

  __kmp_env_blk_init(&block, NULL);
  __kmp_env_blk_sort(&block);

  // Print real environment values.
  __kmp_str_buf_print(&buffer, "\n%s\n\n", KMP_I18N_STR(UserSettings));
  for (i = 0; i < block.count; ++i) {
    char const *name = block.vars[i].name;
    char const *value = block.vars[i].value;
    if ((KMP_STRLEN(name) > 4 && strncmp(name, "KMP_", 4) == 0) ||
        strncmp(name, "OMP_", 4) == 0
#ifdef KMP_GOMP_COMPAT
        || strncmp(name, "GOMP_", 5) == 0
#endif // KMP_GOMP_COMPAT
        ) {
      __kmp_str_buf_print(&buffer, "   %s=%s\n", name, value);
    }
  }
  __kmp_str_buf_print(&buffer, "\n");

  // Print internal (effective) settings.
  __kmp_str_buf_print(&buffer, "%s\n\n", KMP_I18N_STR(EffectiveSettings));
  for (int i = 0; i < __kmp_stg_count; ++i) {
    if (__kmp_stg_table[i].print != NULL) {
      __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
                               __kmp_stg_table[i].data);
    }
  }

  __kmp_printf("%s", buffer.str);

  __kmp_env_blk_free(&block);
  __kmp_str_buf_free(&buffer);

  __kmp_printf("\n");

} // __kmp_env_print

void __kmp_env_print_2() {
  __kmp_display_env_impl(__kmp_display_env, __kmp_display_env_verbose);
} // __kmp_env_print_2


void __kmp_display_env_impl(int display_env, int display_env_verbose) {
  kmp_env_blk_t block;
  kmp_str_buf_t buffer;

  __kmp_env_format = 1;

  __kmp_stg_init();
  __kmp_str_buf_init(&buffer);

  __kmp_env_blk_init(&block, NULL);
  __kmp_env_blk_sort(&block);

  __kmp_str_buf_print(&buffer, "\n%s\n", KMP_I18N_STR(DisplayEnvBegin));
  __kmp_str_buf_print(&buffer, "   _OPENMP='%d'\n", __kmp_openmp_version);

  for (int i = 0; i < __kmp_stg_count; ++i) {
    if (__kmp_stg_table[i].print != NULL &&
        ((display_env &&
          strncmp(__kmp_stg_table[i].name, "OMP_", 4) == 0) ||
         display_env_verbose)) {
      __kmp_stg_table[i].print(&buffer, __kmp_stg_table[i].name,
                               __kmp_stg_table[i].data);
    }
  }

  __kmp_str_buf_print(&buffer, "%s\n", KMP_I18N_STR(DisplayEnvEnd));
  __kmp_str_buf_print(&buffer, "\n");

  __kmp_printf("%s", buffer.str);

  __kmp_env_blk_free(&block);
  __kmp_str_buf_free(&buffer);

  __kmp_printf("\n");
}

// end of file