decompiled_code:
unsigned __int64 __fastcall tt_calc_block_size(unsigned __int64 a1, char a2)
{
unsigned __int64 result; // rax

if ( a1 <= 1024LL << (a2 - 1) )
{
result = 1024LL;
}
else
{
result = 1024LL;
do
result *= 2LL;
while ( result << (a2 - 1) < a1 );
}
if ( result < 0x10000 )
result = 0x10000LL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(unsigned __int64 a1, char a2)
{
unsigned __int64 result; // rax

if ( a1 <= 1024LL << (a2 - 1) )
{
result = 1024LL;
}
else
{
result = 1024LL;
do
result *= 2LL;
while ( result << (a2 - 1) < a1 );
}
if ( result < 0x10000 )
result = 0x10000LL;
return result;
}

original_code:
u_int64_t tt_calc_block_size(u_int64_t filesize, unsigned max_levels)
{
    u_int64_t tmp = 1024;
    u_int64_t maxHashes = 1ULL << (max_levels - 1);
    while((maxHashes * tmp) < filesize)
        tmp *= 2;
    if(tmp < 64*1024)
        tmp = 64*1024;
    return tmp;
}

canonical_original_code:
unsigned int tt_calc_block_size(unsigned int filesize, unsigned int max_levels)
{
    unsigned int tmp = 1024;
    unsigned int maxHashes = 1ULL << (max_levels - 1);
    while((maxHashes * tmp) < filesize)
        tmp *= 2;
    if(tmp < 64*1024)
        tmp = 64*1024;
    return tmp;
}

variable_types:
filesize
unsigned int

variable_types:
tmp
unsigned int

variable_types:
maxHashes
unsigned int


repo: rufuscoder/Shakespeer

decompiled_code:
__int64 country_map_create()
{
add_country("af", "Afghanistan");
add_country("ax", (char *)&byte_F1B);
add_country("al", "Albania");
add_country("dz", "Algeria");
add_country("as", "American Samoa");
add_country("ad", "Andorra");
add_country("ao", "Angola");
add_country("ai", "Anguilla");
add_country("aq", "Antarctica");
add_country("ag", "Antigua and Barbuda");
add_country("ar", "Argentina");
add_country("am", "Armenia");
add_country("aw", "Aruba");
add_country("au", "Australia");
add_country("at", "Austria");
add_country("az", "Azerbaijan");
add_country("bs", "Bahamas");
add_country("bh", "Bahrain");
add_country("bd", "Bangladesh");
add_country("bb", "Barbados");
add_country("by", "Belarus");
add_country("be", "Belgium");
add_country("bz", "Belize");
add_country("bj", "Benin");
add_country("bm", "Bermuda");
add_country("bt", "Bhutan");
add_country("bo", "Bolivia");
add_country("ba", "Bosnia and Herzegovina");
add_country("bw", "Botswana");
add_country("bv", "Bouvet Island");
add_country("br", "Brazil");
add_country("io", "British Indian Ocean Territory");
add_country("bn", "Brunei Darussalam");
add_country("bg", "Bulgaria");
add_country("bf", "Burkina Faso");
add_country("bi", "Burundi");
add_country("kh", "Cambodia");
add_country("cm", "Cameroon");
add_country("ca", "Canada");
add_country("cv", "Cape Verde");
add_country("ky", "Cayman Islands");
add_country("cf", "Central African Republic");
add_country("td", "Chad");
add_country("cl", "Chile");
add_country("cn", "China");
add_country("cx", "Christmas Island");
add_country("cc", "Cocos (keeling) Islands");
add_country("co", "Colombia");
add_country("km", "Comoros");
add_country("cg", "Congo");
add_country("cd", "Congo, the Democratic Republic of the");
add_country("ck", "Cook Islands");
add_country("cr", "Costa Rica");
add_country("ci", "Cote D'ivoire");
add_country("hr", "Croatia");
add_country("cu", "Cuba");
add_country("cy", "Cyprus");
add_country("cz", "Czech Republic");
add_country("dk", "Denmark");
add_country("dj", "Djibouti");
add_country("dm", "Dominica");
add_country("do", "Dominican Republic");
add_country("ec", "Ecuador");
add_country("eg", "Egypt");
add_country("sv", "El Salvador");
add_country("gq", "Equatorial Guinea");
add_country("er", "Eritrea");
add_country("ee", "Estonia");
add_country("et", "Ethiopia");
add_country("fk", "Falkland Islands (malvinas)");
add_country("fo", "Faroe Islands");
add_country("fj", "Fiji");
add_country("fi", "Finland");
add_country("fr", "France");
add_country("gf", "French Guiana");
add_country("pf", "French Polynesia");
add_country("tf", "French Southern Territories");
add_country("ga", "Gabon");
add_country("gm", "Gambia");
add_country("ge", "Georgia");
add_country("de", "Germany");
add_country("gh", "Ghana");
add_country("gi", "Gibraltar");
add_country("gr", "Greece");
add_country("gl", "Greenland");
add_country("gd", "Grenada");
add_country("gp", "Guadeloupe");
add_country("gu", "Guam");
add_country("gt", "Guatemala");
add_country(" gg", "Guernsey");
add_country("gn", "Guinea");
add_country("gw", "Guinea-bissau");
add_country("gy", "Guyana");
add_country("ht", "Haiti");
add_country("hm", "Heard Island and Mcdonald Islands");
add_country("va", "Holy See (vatican City State)");
add_country("hn", "Honduras");
add_country("hk", "Hong Kong");
add_country("hu", "Hungary");
add_country("is", "Iceland");
add_country("in", "India");
add_country("id", "Indonesia");
add_country("ir", "Iran, Islamic Republic of");
add_country("iq", "Iraq");
add_country("ie", "Ireland");
add_country("im", "Isle of Man");
add_country("il", "Israel");
add_country("it", "Italy");
add_country("jm", "Jamaica");
add_country("jp", "Japan");
add_country("je", "Jersey");
add_country("jo", "Jordan");
add_country("kz", "Kazakhstan");
add_country("ke", "Kenya");
add_country("ki", "Kiribati");
add_country("kp", "Korea, Democratic People's Republic of");
add_country("kr", "Korea, Republic of");
add_country("kw", "Kuwait");
add_country("kg", "Kyrgyzstan");
add_country("la", "Lao People's Democratic Republic");
add_country("lv", "Latvia");
add_country("lb", "Lebanon");
add_country("ls", "Lesotho");
add_country("lr", "Liberia");
add_country("ly", "Libyan Arab Jamahiriya");
add_country("li", "Liechtenstein");
add_country("lt", "Lithuania");
add_country("lu", "Luxembourg");
add_country("mo", "Macao");
add_country("mk", "Macedonia, the Former Yugoslav Republic of");
add_country("mg", "Madagascar");
add_country("mw", "Malawi");
add_country("my", "Malaysia");
add_country("mv", "Maldives");
add_country("ml", "Mali");
add_country("mt", "Malta");
add_country("mh", "Marshall Islands");
add_country("mq", "Martinique");
add_country("mr", "Mauritania");
add_country("mu", "Mauritius");
add_country("yt", "Mayotte");
add_country("mx", "Mexico");
add_country("fm", "Micronesia, Federated States of");
add_country("md", "Moldova, Republic of");
add_country("mc", "Monaco");
add_country("mn", "Mongolia");
add_country("ms", "Montserrat");
add_country("ma", "Morocco");
add_country("mz", "Mozambique");
add_country("mm", "Myanmar");
add_country("na", "Namibia");
add_country("nr", "Nauru");
add_country("np", "Nepal");
add_country("nl", "Netherlands");
add_country("an", "Netherlands Antilles");
add_country("nc", "New Caledonia");
add_country("nz", "New Zealand");
add_country("ni", "Nicaragua");
add_country("ne", "Niger");
add_country("ng", "Nigeria");
add_country("nu", "Niue");
add_country("nf", "Norfolk Island");
add_country("mp", "Northern Mariana Islands");
add_country("no", "Norway");
add_country("om", "Oman");
add_country("pk", "Pakistan");
add_country("pw", "Palau");
add_country("ps", "Palestinian Territory, Occupied");
add_country("pa", "Panama");
add_country("pg", "Papua New Guinea");
add_country("py", "Paraguay");
add_country("pe", "Peru");
add_country("ph", "Philippines");
add_country("pn", "Pitcairn");
add_country("pl", "Poland");
add_country("pt", "Portugal");
add_country("pr", "Puerto Rico");
add_country("qa", "Qatar");
add_country("re", "Reunion");
add_country("ro", "Romania");
add_country("ru", "Russian Federation");
add_country("rw", "Rwanda");
add_country("sh", "Saint Helena");
add_country("kn", "Saint Kitts and Nevis");
add_country("lc", "Saint Lucia");
add_country("pm", "Saint Pierre and Miquelon");
add_country("vc", "Saint Vincent and the Grenadines");
add_country("ws", "Samoa");
add_country("sm", "San Marino");
add_country("st", "Sao Tome and Principe");
add_country("sa", "Saudi Arabia");
add_country("sn", "Senegal");
add_country("cs", "Serbia and Montenegro");
add_country("sc", "Seychelles");
add_country("sl", "Sierra Leone");
add_country("sg", "Singapore");
add_country("sk", "Slovakia");
add_country("si", "Slovenia");
add_country("sb", "Solomon Islands");
add_country("so", "Somalia");
add_country("za", "South Africa");
add_country("gs", "South Georgia and the South Sandwich Islands");
add_country("es", "Spain");
add_country("lk", "Sri Lanka");
add_country("sd", "Sudan");
add_country("sr", "Suriname");
add_country("sj", "Svalbard and Jan Mayen");
add_country("sz", "Swaziland");
add_country("se", "Sweden");
add_country("ch", "Switzerland");
add_country("sy", "Syrian Arab Republic");
add_country("tw", "Taiwan, Province of China");
add_country("tj", "Tajikistan");
add_country("tz", "Tanzania, United Republic of");
add_country("th", "Thailand");
add_country("tl", "Timor-leste");
add_country("tg", "Togo");
add_country("tk", "Tokelau");
add_country("to", "Tonga");
add_country("tt", "Trinidad and Tobago");
add_country("tn", "Tunisia");
add_country("tr", "Turkey");
add_country("tm", "Turkmenistan");
add_country("tc", "Turks and Caicos Islands");
add_country("tv", "Tuvalu");
add_country("ug", "Uganda");
add_country("ua", "Ukraine");
add_country("ae", "United Arab Emirates");
add_country("gb", "United Kingdom");
add_country("us", "United States");
add_country("um", "United States Minor Outlying Islands");
add_country("uy", "Uruguay");
add_country("uz", "Uzbekistan");
add_country("vu", "Vanuatu");
add_country("ve", "Venezuela");
add_country("vn", "Viet Nam");
add_country("vg", "Virgin Islands, British");
add_country("vi", "Virgin Islands, U.s.");
add_country("wf", "Wallis and Futuna");
add_country("eh", "Western Sahara");
add_country("ye", "Yemen");
add_country("zm", "Zambia");
return add_country("zw", "Zimbabwe");
}

canonical_decompiled_code:
__int64 func1()
{
func0("af", "Afghanistan");
func0("ax", (char *)&byte_F1B);
func0("al", "Albania");
func0("dz", "Algeria");
func0("as", "American Samoa");
func0("ad", "Andorra");
func0("ao", "Angola");
func0("ai", "Anguilla");
func0("aq", "Antarctica");
func0("ag", "Antigua and Barbuda");
func0("ar", "Argentina");
func0("am", "Armenia");
func0("aw", "Aruba");
func0("au", "Australia");
func0("at", "Austria");
func0("az", "Azerbaijan");
func0("bs", "Bahamas");
func0("bh", "Bahrain");
func0("bd", "Bangladesh");
func0("bb", "Barbados");
func0("by", "Belarus");
func0("be", "Belgium");
func0("bz", "Belize");
func0("bj", "Benin");
func0("bm", "Bermuda");
func0("bt", "Bhutan");
func0("bo", "Bolivia");
func0("ba", "Bosnia and Herzegovina");
func0("bw", "Botswana");
func0("bv", "Bouvet Island");
func0("br", "Brazil");
func0("io", "British Indian Ocean Territory");
func0("bn", "Brunei Darussalam");
func0("bg", "Bulgaria");
func0("bf", "Burkina Faso");
func0("bi", "Burundi");
func0("kh", "Cambodia");
func0("cm", "Cameroon");
func0("ca", "Canada");
func0("cv", "Cape Verde");
func0("ky", "Cayman Islands");
func0("cf", "Central African Republic");
func0("td", "Chad");
func0("cl", "Chile");
func0("cn", "China");
func0("cx", "Christmas Island");
func0("cc", "Cocos (keeling) Islands");
func0("co", "Colombia");
func0("km", "Comoros");
func0("cg", "Congo");
func0("cd", "Congo, the Democratic Republic of the");
func0("ck", "Cook Islands");
func0("cr", "Costa Rica");
func0("ci", "Cote D'ivoire");
func0("hr", "Croatia");
func0("cu", "Cuba");
func0("cy", "Cyprus");
func0("cz", "Czech Republic");
func0("dk", "Denmark");
func0("dj", "Djibouti");
func0("dm", "Dominica");
func0("do", "Dominican Republic");
func0("ec", "Ecuador");
func0("eg", "Egypt");
func0("sv", "El Salvador");
func0("gq", "Equatorial Guinea");
func0("er", "Eritrea");
func0("ee", "Estonia");
func0("et", "Ethiopia");
func0("fk", "Falkland Islands (malvinas)");
func0("fo", "Faroe Islands");
func0("fj", "Fiji");
func0("fi", "Finland");
func0("fr", "France");
func0("gf", "French Guiana");
func0("pf", "French Polynesia");
func0("tf", "French Southern Territories");
func0("ga", "Gabon");
func0("gm", "Gambia");
func0("ge", "Georgia");
func0("de", "Germany");
func0("gh", "Ghana");
func0("gi", "Gibraltar");
func0("gr", "Greece");
func0("gl", "Greenland");
func0("gd", "Grenada");
func0("gp", "Guadeloupe");
func0("gu", "Guam");
func0("gt", "Guatemala");
func0(" gg", "Guernsey");
func0("gn", "Guinea");
func0("gw", "Guinea-bissau");
func0("gy", "Guyana");
func0("ht", "Haiti");
func0("hm", "Heard Island and Mcdonald Islands");
func0("va", "Holy See (vatican City State)");
func0("hn", "Honduras");
func0("hk", "Hong Kong");
func0("hu", "Hungary");
func0("is", "Iceland");
func0("in", "India");
func0("id", "Indonesia");
func0("ir", "Iran, Islamic Republic of");
func0("iq", "Iraq");
func0("ie", "Ireland");
func0("im", "Isle of Man");
func0("il", "Israel");
func0("it", "Italy");
func0("jm", "Jamaica");
func0("jp", "Japan");
func0("je", "Jersey");
func0("jo", "Jordan");
func0("kz", "Kazakhstan");
func0("ke", "Kenya");
func0("ki", "Kiribati");
func0("kp", "Korea, Democratic People's Republic of");
func0("kr", "Korea, Republic of");
func0("kw", "Kuwait");
func0("kg", "Kyrgyzstan");
func0("la", "Lao People's Democratic Republic");
func0("lv", "Latvia");
func0("lb", "Lebanon");
func0("ls", "Lesotho");
func0("lr", "Liberia");
func0("ly", "Libyan Arab Jamahiriya");
func0("li", "Liechtenstein");
func0("lt", "Lithuania");
func0("lu", "Luxembourg");
func0("mo", "Macao");
func0("mk", "Macedonia, the Former Yugoslav Republic of");
func0("mg", "Madagascar");
func0("mw", "Malawi");
func0("my", "Malaysia");
func0("mv", "Maldives");
func0("ml", "Mali");
func0("mt", "Malta");
func0("mh", "Marshall Islands");
func0("mq", "Martinique");
func0("mr", "Mauritania");
func0("mu", "Mauritius");
func0("yt", "Mayotte");
func0("mx", "Mexico");
func0("fm", "Micronesia, Federated States of");
func0("md", "Moldova, Republic of");
func0("mc", "Monaco");
func0("mn", "Mongolia");
func0("ms", "Montserrat");
func0("ma", "Morocco");
func0("mz", "Mozambique");
func0("mm", "Myanmar");
func0("na", "Namibia");
func0("nr", "Nauru");
func0("np", "Nepal");
func0("nl", "Netherlands");
func0("an", "Netherlands Antilles");
func0("nc", "New Caledonia");
func0("nz", "New Zealand");
func0("ni", "Nicaragua");
func0("ne", "Niger");
func0("ng", "Nigeria");
func0("nu", "Niue");
func0("nf", "Norfolk Island");
func0("mp", "Northern Mariana Islands");
func0("no", "Norway");
func0("om", "Oman");
func0("pk", "Pakistan");
func0("pw", "Palau");
func0("ps", "Palestinian Territory, Occupied");
func0("pa", "Panama");
func0("pg", "Papua New Guinea");
func0("py", "Paraguay");
func0("pe", "Peru");
func0("ph", "Philippines");
func0("pn", "Pitcairn");
func0("pl", "Poland");
func0("pt", "Portugal");
func0("pr", "Puerto Rico");
func0("qa", "Qatar");
func0("re", "Reunion");
func0("ro", "Romania");
func0("ru", "Russian Federation");
func0("rw", "Rwanda");
func0("sh", "Saint Helena");
func0("kn", "Saint Kitts and Nevis");
func0("lc", "Saint Lucia");
func0("pm", "Saint Pierre and Miquelon");
func0("vc", "Saint Vincent and the Grenadines");
func0("ws", "Samoa");
func0("sm", "San Marino");
func0("st", "Sao Tome and Principe");
func0("sa", "Saudi Arabia");
func0("sn", "Senegal");
func0("cs", "Serbia and Montenegro");
func0("sc", "Seychelles");
func0("sl", "Sierra Leone");
func0("sg", "Singapore");
func0("sk", "Slovakia");
func0("si", "Slovenia");
func0("sb", "Solomon Islands");
func0("so", "Somalia");
func0("za", "South Africa");
func0("gs", "South Georgia and the South Sandwich Islands");
func0("es", "Spain");
func0("lk", "Sri Lanka");
func0("sd", "Sudan");
func0("sr", "Suriname");
func0("sj", "Svalbard and Jan Mayen");
func0("sz", "Swaziland");
func0("se", "Sweden");
func0("ch", "Switzerland");
func0("sy", "Syrian Arab Republic");
func0("tw", "Taiwan, Province of China");
func0("tj", "Tajikistan");
func0("tz", "Tanzania, United Republic of");
func0("th", "Thailand");
func0("tl", "Timor-leste");
func0("tg", "Togo");
func0("tk", "Tokelau");
func0("to", "Tonga");
func0("tt", "Trinidad and Tobago");
func0("tn", "Tunisia");
func0("tr", "Turkey");
func0("tm", "Turkmenistan");
func0("tc", "Turks and Caicos Islands");
func0("tv", "Tuvalu");
func0("ug", "Uganda");
func0("ua", "Ukraine");
func0("ae", "United Arab Emirates");
func0("gb", "United Kingdom");
func0("us", "United States");
func0("um", "United States Minor Outlying Islands");
func0("uy", "Uruguay");
func0("uz", "Uzbekistan");
func0("vu", "Vanuatu");
func0("ve", "Venezuela");
func0("vn", "Viet Nam");
func0("vg", "Virgin Islands, British");
func0("vi", "Virgin Islands, U.s.");
func0("wf", "Wallis and Futuna");
func0("eh", "Western Sahara");
func0("ye", "Yemen");
func0("zm", "Zambia");
return func0("zw", "Zimbabwe");
}

original_code:
static void country_map_create(void)
{
    add_country("af", "Afghanistan");
    add_country("ax", "Åland Islands");
    add_country("al", "Albania");
    add_country("dz", "Algeria");
    add_country("as", "American Samoa");
    add_country("ad", "Andorra");
    add_country("ao", "Angola");
    add_country("ai", "Anguilla");
    add_country("aq", "Antarctica");
    add_country("ag", "Antigua and Barbuda");
    add_country("ar", "Argentina");
    add_country("am", "Armenia");
    add_country("aw", "Aruba");
    add_country("au", "Australia");
    add_country("at", "Austria");
    add_country("az", "Azerbaijan");
    add_country("bs", "Bahamas");
    add_country("bh", "Bahrain");
    add_country("bd", "Bangladesh");
    add_country("bb", "Barbados");
    add_country("by", "Belarus");
    add_country("be", "Belgium");
    add_country("bz", "Belize");
    add_country("bj", "Benin");
    add_country("bm", "Bermuda");
    add_country("bt", "Bhutan");
    add_country("bo", "Bolivia");
    add_country("ba", "Bosnia and Herzegovina");
    add_country("bw", "Botswana");
    add_country("bv", "Bouvet Island");
    add_country("br", "Brazil");
    add_country("io", "British Indian Ocean Territory");
    add_country("bn", "Brunei Darussalam");
    add_country("bg", "Bulgaria");
    add_country("bf", "Burkina Faso");
    add_country("bi", "Burundi");
    add_country("kh", "Cambodia");
    add_country("cm", "Cameroon");
    add_country("ca", "Canada");
    add_country("cv", "Cape Verde");
    add_country("ky", "Cayman Islands");
    add_country("cf", "Central African Republic");
    add_country("td", "Chad");
    add_country("cl", "Chile");
    add_country("cn", "China");
    add_country("cx", "Christmas Island");
    add_country("cc", "Cocos (keeling) Islands");
    add_country("co", "Colombia");
    add_country("km", "Comoros");
    add_country("cg", "Congo");
    add_country("cd", "Congo, the Democratic Republic of the");
    add_country("ck", "Cook Islands");
    add_country("cr", "Costa Rica");
    add_country("ci", "Cote D'ivoire");
    add_country("hr", "Croatia");
    add_country("cu", "Cuba");
    add_country("cy", "Cyprus");
    add_country("cz", "Czech Republic");
    add_country("dk", "Denmark");
    add_country("dj", "Djibouti");
    add_country("dm", "Dominica");
    add_country("do", "Dominican Republic");
    add_country("ec", "Ecuador");
    add_country("eg", "Egypt");
    add_country("sv", "El Salvador");
    add_country("gq", "Equatorial Guinea");
    add_country("er", "Eritrea");
    add_country("ee", "Estonia");
    add_country("et", "Ethiopia");
    add_country("fk", "Falkland Islands (malvinas)");
    add_country("fo", "Faroe Islands");
    add_country("fj", "Fiji");
    add_country("fi", "Finland");
    add_country("fr", "France");
    add_country("gf", "French Guiana");
    add_country("pf", "French Polynesia");
    add_country("tf", "French Southern Territories");
    add_country("ga", "Gabon");
    add_country("gm", "Gambia");
    add_country("ge", "Georgia");
    add_country("de", "Germany");
    add_country("gh", "Ghana");
    add_country("gi", "Gibraltar");
    add_country("gr", "Greece");
    add_country("gl", "Greenland");
    add_country("gd", "Grenada");
    add_country("gp", "Guadeloupe");
    add_country("gu", "Guam");
    add_country("gt", "Guatemala");
    add_country(" gg", "Guernsey");
    add_country("gn", "Guinea");
    add_country("gw", "Guinea-bissau");
    add_country("gy", "Guyana");
    add_country("ht", "Haiti");
    add_country("hm", "Heard Island and Mcdonald Islands");
    add_country("va", "Holy See (vatican City State)");
    add_country("hn", "Honduras");
    add_country("hk", "Hong Kong");
    add_country("hu", "Hungary");
    add_country("is", "Iceland");
    add_country("in", "India");
    add_country("id", "Indonesia");
    add_country("ir", "Iran, Islamic Republic of");
    add_country("iq", "Iraq");
    add_country("ie", "Ireland");
    add_country("im", "Isle of Man");
    add_country("il", "Israel");
    add_country("it", "Italy");
    add_country("jm", "Jamaica");
    add_country("jp", "Japan");
    add_country("je", "Jersey");
    add_country("jo", "Jordan");
    add_country("kz", "Kazakhstan");
    add_country("ke", "Kenya");
    add_country("ki", "Kiribati");
    add_country("kp", "Korea, Democratic People's Republic of");
    add_country("kr", "Korea, Republic of");
    add_country("kw", "Kuwait");
    add_country("kg", "Kyrgyzstan");
    add_country("la", "Lao People's Democratic Republic");
    add_country("lv", "Latvia");
    add_country("lb", "Lebanon");
    add_country("ls", "Lesotho");
    add_country("lr", "Liberia");
    add_country("ly", "Libyan Arab Jamahiriya");
    add_country("li", "Liechtenstein");
    add_country("lt", "Lithuania");
    add_country("lu", "Luxembourg");
    add_country("mo", "Macao");
    add_country("mk", "Macedonia, the Former Yugoslav Republic of");
    add_country("mg", "Madagascar");
    add_country("mw", "Malawi");
    add_country("my", "Malaysia");
    add_country("mv", "Maldives");
    add_country("ml", "Mali");
    add_country("mt", "Malta");
    add_country("mh", "Marshall Islands");
    add_country("mq", "Martinique");
    add_country("mr", "Mauritania");
    add_country("mu", "Mauritius");
    add_country("yt", "Mayotte");
    add_country("mx", "Mexico");
    add_country("fm", "Micronesia, Federated States of");
    add_country("md", "Moldova, Republic of");
    add_country("mc", "Monaco");
    add_country("mn", "Mongolia");
    add_country("ms", "Montserrat");
    add_country("ma", "Morocco");
    add_country("mz", "Mozambique");
    add_country("mm", "Myanmar");
    add_country("na", "Namibia");
    add_country("nr", "Nauru");
    add_country("np", "Nepal");
    add_country("nl", "Netherlands");
    add_country("an", "Netherlands Antilles");
    add_country("nc", "New Caledonia");
    add_country("nz", "New Zealand");
    add_country("ni", "Nicaragua");
    add_country("ne", "Niger");
    add_country("ng", "Nigeria");
    add_country("nu", "Niue");
    add_country("nf", "Norfolk Island");
    add_country("mp", "Northern Mariana Islands");
    add_country("no", "Norway");
    add_country("om", "Oman");
    add_country("pk", "Pakistan");
    add_country("pw", "Palau");
    add_country("ps", "Palestinian Territory, Occupied");
    add_country("pa", "Panama");
    add_country("pg", "Papua New Guinea");
    add_country("py", "Paraguay");
    add_country("pe", "Peru");
    add_country("ph", "Philippines");
    add_country("pn", "Pitcairn");
    add_country("pl", "Poland");
    add_country("pt", "Portugal");
    add_country("pr", "Puerto Rico");
    add_country("qa", "Qatar");
    add_country("re", "Reunion");
    add_country("ro", "Romania");
    add_country("ru", "Russian Federation");
    add_country("rw", "Rwanda");
    add_country("sh", "Saint Helena");
    add_country("kn", "Saint Kitts and Nevis");
    add_country("lc", "Saint Lucia");
    add_country("pm", "Saint Pierre and Miquelon");
    add_country("vc", "Saint Vincent and the Grenadines");
    add_country("ws", "Samoa");
    add_country("sm", "San Marino");
    add_country("st", "Sao Tome and Principe");
    add_country("sa", "Saudi Arabia");
    add_country("sn", "Senegal");
    add_country("cs", "Serbia and Montenegro");
    add_country("sc", "Seychelles");
    add_country("sl", "Sierra Leone");
    add_country("sg", "Singapore");
    add_country("sk", "Slovakia");
    add_country("si", "Slovenia");
    add_country("sb", "Solomon Islands");
    add_country("so", "Somalia");
    add_country("za", "South Africa");
    add_country("gs", "South Georgia and the South Sandwich Islands");
    add_country("es", "Spain");
    add_country("lk", "Sri Lanka");
    add_country("sd", "Sudan");
    add_country("sr", "Suriname");
    add_country("sj", "Svalbard and Jan Mayen");
    add_country("sz", "Swaziland");
    add_country("se", "Sweden");
    add_country("ch", "Switzerland");
    add_country("sy", "Syrian Arab Republic");
    add_country("tw", "Taiwan, Province of China");
    add_country("tj", "Tajikistan");
    add_country("tz", "Tanzania, United Republic of");
    add_country("th", "Thailand");
    add_country("tl", "Timor-leste");
    add_country("tg", "Togo");
    add_country("tk", "Tokelau");
    add_country("to", "Tonga");
    add_country("tt", "Trinidad and Tobago");
    add_country("tn", "Tunisia");
    add_country("tr", "Turkey");
    add_country("tm", "Turkmenistan");
    add_country("tc", "Turks and Caicos Islands");
    add_country("tv", "Tuvalu");
    add_country("ug", "Uganda");
    add_country("ua", "Ukraine");
    add_country("ae", "United Arab Emirates");
    add_country("gb", "United Kingdom");
    add_country("us", "United States");
    add_country("um", "United States Minor Outlying Islands");
    add_country("uy", "Uruguay");
    add_country("uz", "Uzbekistan");
    add_country("vu", "Vanuatu");
    add_country("ve", "Venezuela");
    add_country("vn", "Viet Nam");
    add_country("vg", "Virgin Islands, British");
    add_country("vi", "Virgin Islands, U.s.");
    add_country("wf", "Wallis and Futuna");
    add_country("eh", "Western Sahara");
    add_country("ye", "Yemen");
    add_country("zm", "Zambia");
    add_country("zw", "Zimbabwe");
}

canonical_original_code:
static void country_map_create()
{
    add_country("af", "Afghanistan");
    add_country("ax", "Åland Islands");
    add_country("al", "Albania");
    add_country("dz", "Algeria");
    add_country("as", "American Samoa");
    add_country("ad", "Andorra");
    add_country("ao", "Angola");
    add_country("ai", "Anguilla");
    add_country("aq", "Antarctica");
    add_country("ag", "Antigua and Barbuda");
    add_country("ar", "Argentina");
    add_country("am", "Armenia");
    add_country("aw", "Aruba");
    add_country("au", "Australia");
    add_country("at", "Austria");
    add_country("az", "Azerbaijan");
    add_country("bs", "Bahamas");
    add_country("bh", "Bahrain");
    add_country("bd", "Bangladesh");
    add_country("bb", "Barbados");
    add_country("by", "Belarus");
    add_country("be", "Belgium");
    add_country("bz", "Belize");
    add_country("bj", "Benin");
    add_country("bm", "Bermuda");
    add_country("bt", "Bhutan");
    add_country("bo", "Bolivia");
    add_country("ba", "Bosnia and Herzegovina");
    add_country("bw", "Botswana");
    add_country("bv", "Bouvet Island");
    add_country("br", "Brazil");
    add_country("io", "British Indian Ocean Territory");
    add_country("bn", "Brunei Darussalam");
    add_country("bg", "Bulgaria");
    add_country("bf", "Burkina Faso");
    add_country("bi", "Burundi");
    add_country("kh", "Cambodia");
    add_country("cm", "Cameroon");
    add_country("ca", "Canada");
    add_country("cv", "Cape Verde");
    add_country("ky", "Cayman Islands");
    add_country("cf", "Central African Republic");
    add_country("td", "Chad");
    add_country("cl", "Chile");
    add_country("cn", "China");
    add_country("cx", "Christmas Island");
    add_country("cc", "Cocos (keeling) Islands");
    add_country("co", "Colombia");
    add_country("km", "Comoros");
    add_country("cg", "Congo");
    add_country("cd", "Congo, the Democratic Republic of the");
    add_country("ck", "Cook Islands");
    add_country("cr", "Costa Rica");
    add_country("ci", "Cote D'ivoire");
    add_country("hr", "Croatia");
    add_country("cu", "Cuba");
    add_country("cy", "Cyprus");
    add_country("cz", "Czech Republic");
    add_country("dk", "Denmark");
    add_country("dj", "Djibouti");
    add_country("dm", "Dominica");
    add_country("do", "Dominican Republic");
    add_country("ec", "Ecuador");
    add_country("eg", "Egypt");
    add_country("sv", "El Salvador");
    add_country("gq", "Equatorial Guinea");
    add_country("er", "Eritrea");
    add_country("ee", "Estonia");
    add_country("et", "Ethiopia");
    add_country("fk", "Falkland Islands (malvinas)");
    add_country("fo", "Faroe Islands");
    add_country("fj", "Fiji");
    add_country("fi", "Finland");
    add_country("fr", "France");
    add_country("gf", "French Guiana");
    add_country("pf", "French Polynesia");
    add_country("tf", "French Southern Territories");
    add_country("ga", "Gabon");
    add_country("gm", "Gambia");
    add_country("ge", "Georgia");
    add_country("de", "Germany");
    add_country("gh", "Ghana");
    add_country("gi", "Gibraltar");
    add_country("gr", "Greece");
    add_country("gl", "Greenland");
    add_country("gd", "Grenada");
    add_country("gp", "Guadeloupe");
    add_country("gu", "Guam");
    add_country("gt", "Guatemala");
    add_country(" gg", "Guernsey");
    add_country("gn", "Guinea");
    add_country("gw", "Guinea-bissau");
    add_country("gy", "Guyana");
    add_country("ht", "Haiti");
    add_country("hm", "Heard Island and Mcdonald Islands");
    add_country("va", "Holy See (vatican City State)");
    add_country("hn", "Honduras");
    add_country("hk", "Hong Kong");
    add_country("hu", "Hungary");
    add_country("is", "Iceland");
    add_country("in", "India");
    add_country("id", "Indonesia");
    add_country("ir", "Iran, Islamic Republic of");
    add_country("iq", "Iraq");
    add_country("ie", "Ireland");
    add_country("im", "Isle of Man");
    add_country("il", "Israel");
    add_country("it", "Italy");
    add_country("jm", "Jamaica");
    add_country("jp", "Japan");
    add_country("je", "Jersey");
    add_country("jo", "Jordan");
    add_country("kz", "Kazakhstan");
    add_country("ke", "Kenya");
    add_country("ki", "Kiribati");
    add_country("kp", "Korea, Democratic People's Republic of");
    add_country("kr", "Korea, Republic of");
    add_country("kw", "Kuwait");
    add_country("kg", "Kyrgyzstan");
    add_country("la", "Lao People's Democratic Republic");
    add_country("lv", "Latvia");
    add_country("lb", "Lebanon");
    add_country("ls", "Lesotho");
    add_country("lr", "Liberia");
    add_country("ly", "Libyan Arab Jamahiriya");
    add_country("li", "Liechtenstein");
    add_country("lt", "Lithuania");
    add_country("lu", "Luxembourg");
    add_country("mo", "Macao");
    add_country("mk", "Macedonia, the Former Yugoslav Republic of");
    add_country("mg", "Madagascar");
    add_country("mw", "Malawi");
    add_country("my", "Malaysia");
    add_country("mv", "Maldives");
    add_country("ml", "Mali");
    add_country("mt", "Malta");
    add_country("mh", "Marshall Islands");
    add_country("mq", "Martinique");
    add_country("mr", "Mauritania");
    add_country("mu", "Mauritius");
    add_country("yt", "Mayotte");
    add_country("mx", "Mexico");
    add_country("fm", "Micronesia, Federated States of");
    add_country("md", "Moldova, Republic of");
    add_country("mc", "Monaco");
    add_country("mn", "Mongolia");
    add_country("ms", "Montserrat");
    add_country("ma", "Morocco");
    add_country("mz", "Mozambique");
    add_country("mm", "Myanmar");
    add_country("na", "Namibia");
    add_country("nr", "Nauru");
    add_country("np", "Nepal");
    add_country("nl", "Netherlands");
    add_country("an", "Netherlands Antilles");
    add_country("nc", "New Caledonia");
    add_country("nz", "New Zealand");
    add_country("ni", "Nicaragua");
    add_country("ne", "Niger");
    add_country("ng", "Nigeria");
    add_country("nu", "Niue");
    add_country("nf", "Norfolk Island");
    add_country("mp", "Northern Mariana Islands");
    add_country("no", "Norway");
    add_country("om", "Oman");
    add_country("pk", "Pakistan");
    add_country("pw", "Palau");
    add_country("ps", "Palestinian Territory, Occupied");
    add_country("pa", "Panama");
    add_country("pg", "Papua New Guinea");
    add_country("py", "Paraguay");
    add_country("pe", "Peru");
    add_country("ph", "Philippines");
    add_country("pn", "Pitcairn");
    add_country("pl", "Poland");
    add_country("pt", "Portugal");
    add_country("pr", "Puerto Rico");
    add_country("qa", "Qatar");
    add_country("re", "Reunion");
    add_country("ro", "Romania");
    add_country("ru", "Russian Federation");
    add_country("rw", "Rwanda");
    add_country("sh", "Saint Helena");
    add_country("kn", "Saint Kitts and Nevis");
    add_country("lc", "Saint Lucia");
    add_country("pm", "Saint Pierre and Miquelon");
    add_country("vc", "Saint Vincent and the Grenadines");
    add_country("ws", "Samoa");
    add_country("sm", "San Marino");
    add_country("st", "Sao Tome and Principe");
    add_country("sa", "Saudi Arabia");
    add_country("sn", "Senegal");
    add_country("cs", "Serbia and Montenegro");
    add_country("sc", "Seychelles");
    add_country("sl", "Sierra Leone");
    add_country("sg", "Singapore");
    add_country("sk", "Slovakia");
    add_country("si", "Slovenia");
    add_country("sb", "Solomon Islands");
    add_country("so", "Somalia");
    add_country("za", "South Africa");
    add_country("gs", "South Georgia and the South Sandwich Islands");
    add_country("es", "Spain");
    add_country("lk", "Sri Lanka");
    add_country("sd", "Sudan");
    add_country("sr", "Suriname");
    add_country("sj", "Svalbard and Jan Mayen");
    add_country("sz", "Swaziland");
    add_country("se", "Sweden");
    add_country("ch", "Switzerland");
    add_country("sy", "Syrian Arab Republic");
    add_country("tw", "Taiwan, Province of China");
    add_country("tj", "Tajikistan");
    add_country("tz", "Tanzania, United Republic of");
    add_country("th", "Thailand");
    add_country("tl", "Timor-leste");
    add_country("tg", "Togo");
    add_country("tk", "Tokelau");
    add_country("to", "Tonga");
    add_country("tt", "Trinidad and Tobago");
    add_country("tn", "Tunisia");
    add_country("tr", "Turkey");
    add_country("tm", "Turkmenistan");
    add_country("tc", "Turks and Caicos Islands");
    add_country("tv", "Tuvalu");
    add_country("ug", "Uganda");
    add_country("ua", "Ukraine");
    add_country("ae", "United Arab Emirates");
    add_country("gb", "United Kingdom");
    add_country("us", "United States");
    add_country("um", "United States Minor Outlying Islands");
    add_country("uy", "Uruguay");
    add_country("uz", "Uzbekistan");
    add_country("vu", "Vanuatu");
    add_country("ve", "Venezuela");
    add_country("vn", "Viet Nam");
    add_country("vg", "Virgin Islands, British");
    add_country("vi", "Virgin Islands, U.s.");
    add_country("wf", "Wallis and Futuna");
    add_country("eh", "Western Sahara");
    add_country("ye", "Yemen");
    add_country("zm", "Zambia");
    add_country("zw", "Zimbabwe");
}

return_type: void


decompiled_code:
__int64 __fastcall country_map_lookup(char *s2)
{
__int64 v1; // rbx

if ( !initialized )
{
country_map_create();
initialized = 1;
}
v1 = country_list_head;
if ( country_list_head )
{
while ( strcmp(*(const char **)(v1 + 16), s2) )
{
v1 = *(_QWORD *)v1;
if ( !v1 )
return v1;
}
v1 = *(_QWORD *)(v1 + 24);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
__int64 v1; // rbx

if ( !initialized )
{
func1();
initialized = 1;
}
v1 = country_list_head;
if ( country_list_head )
{
while ( strcmp(*(const char **)(v1 + 16), s2) )
{
v1 = *(_QWORD *)v1;
if ( !v1 )
return v1;
}
v1 = *(_QWORD *)(v1 + 24);
}
return v1;
}

original_code:
const char *country_map_lookup(const char *code)
{
    struct country *c;
    if(!initialized)
    {
        country_map_create();
        initialized = 1;
    }
    for((c) = ((&country_list_head)->lh_first); (c)!= ((void *)0); (c) = ((c)->link.le_next))
    {
        if(strcmp(c->code, code) == 0)
            return c->country;
    }
    return ((void *)0);
}

canonical_original_code:
char *country_map_lookup(char *code)
{
    struct country *c;
    if(!initialized)
    {
        country_map_create();
        initialized = 1;
    }
    for((c) = ((&country_list_head)->lh_first); (c)!= ((void *)0); (c) = ((c)->link.le_next))
    {
        if(strcmp(c->code, code) == 0)
            return c->country;
    }
    return ((void *)0);
}

variable_types:
code
char *

variable_types: struct country { struct { struct country *le_next; struct country **le_prev; } link; char *code; char *country; } *

return_type: char *


decompiled_code:
char *__fastcall iconv_string_full(void *ptr, __int64 a2, const char *a3, const char *a4, _QWORD *a5, _QWORD *a6, int a7)
{
char *v7; // r12
size_t v8; // rbp
iconv_t v12; // r14
__int64 v13; // r15
char *v14; // rbx
int *v15; // rbp
unsigned int v17; // eax
int v18; // er12
int v19; // eax
size_t v21; // [rsp+8h] [rbp-60h]
size_t outbytesleft; // [rsp+10h] [rbp-58h] BYREF
size_t inbytesleft; // [rsp+18h] [rbp-50h] BYREF
char *outbuf; // [rsp+20h] [rbp-48h] BYREF
char *inbuf; // [rsp+28h] [rbp-40h] BYREF

v7 = (char *)ptr;
if ( !ptr )
return 0LL;
v8 = a2;
if ( a2 < 0 )
v8 = strlen((const char *)ptr);
if ( !v8 )
return 0LL;
if ( !strcmp(a3, a4) )
return strdup((const char *)ptr);
v12 = iconv_open(a4, a3);
if ( v12 == (iconv_t)-1LL )
{
v17 = getpid();
sp_log(16LL, "[%d] (%s:%i) failed to open iconv: src=[%s], dst=[%s]", v17, "iconv_string_full", 56LL, a3, a4);
v14 = 0LL;
}
else
{
v13 = 2 * v8;
v14 = (char *)malloc(2 * v8 + 1);
if ( a7 > 0 )
v7 = strdup((const char *)ptr);
inbuf = v7;
outbuf = v14;
v21 = v8;
inbytesleft = v8;
outbytesleft = 2 * v8;
v15 = _errno_location();
while ( 1 )
{
*v15 = 0;
if ( iconv(v12, &inbuf, &inbytesleft, &outbuf, &outbytesleft) != -1LL )
break;
if ( *v15 == 7 )
{
v13 += v21;
v14 = (char *)realloc(v14, v13 + 1);
outbytesleft = v13 + v14 - outbuf;
}
else
{
if ( *v15 != 84 || a7 <= 0 )
{
free(v14);
v14 = 0LL;
goto LABEL_14;
}
*inbuf = a7;
}
if ( !v14 )
goto LABEL_14;
}
*outbuf = 0;
LABEL_14:
if ( a5 )
*a5 = inbuf - v7;
if ( a7 > 0 )
free(v7);
if ( a6 )
{
if ( v14 )
*a6 = v13 - outbytesleft;
else
*a6 = 0LL;
}
v18 = *v15;
*v15 = 0;
v19 = iconv_close(v12);
if ( v18 && !v19 )
*v15 = v18;
}
return v14;
}

canonical_decompiled_code:
char *__fastcall func0(void *ptr, __int64 a2, const char *a3, const char *a4, _QWORD *a5, _QWORD *a6, int a7)
{
char *v7; // r12
size_t v8; // rbp
iconv_t v12; // r14
__int64 v13; // r15
char *v14; // rbx
int *v15; // rbp
unsigned int v17; // eax
int v18; // er12
int v19; // eax
size_t v21; // [rsp+8h] [rbp-60h]
size_t outbytesleft; // [rsp+10h] [rbp-58h] BYREF
size_t inbytesleft; // [rsp+18h] [rbp-50h] BYREF
char *outbuf; // [rsp+20h] [rbp-48h] BYREF
char *inbuf; // [rsp+28h] [rbp-40h] BYREF

v7 = (char *)ptr;
if ( !ptr )
return 0LL;
v8 = a2;
if ( a2 < 0 )
v8 = strlen((const char *)ptr);
if ( !v8 )
return 0LL;
if ( !strcmp(a3, a4) )
return strdup((const char *)ptr);
v12 = iconv_open(a4, a3);
if ( v12 == (iconv_t)-1LL )
{
v17 = getpid();
sp_log(16LL, "[%d] (%s:%i) failed to open iconv: src=[%s], dst=[%s]", v17, "iconv_string_full", 56LL, a3, a4);
v14 = 0LL;
}
else
{
v13 = 2 * v8;
v14 = (char *)malloc(2 * v8 + 1);
if ( a7 > 0 )
v7 = strdup((const char *)ptr);
inbuf = v7;
outbuf = v14;
v21 = v8;
inbytesleft = v8;
outbytesleft = 2 * v8;
v15 = _errno_location();
while ( 1 )
{
*v15 = 0;
if ( iconv(v12, &inbuf, &inbytesleft, &outbuf, &outbytesleft) != -1LL )
break;
if ( *v15 == 7 )
{
v13 += v21;
v14 = (char *)realloc(v14, v13 + 1);
outbytesleft = v13 + v14 - outbuf;
}
else
{
if ( *v15 != 84 || a7 <= 0 )
{
free(v14);
v14 = 0LL;
goto LABEL_14;
}
*inbuf = a7;
}
if ( !v14 )
goto LABEL_14;
}
*outbuf = 0;
LABEL_14:
if ( a5 )
*a5 = inbuf - v7;
if ( a7 > 0 )
free(v7);
if ( a6 )
{
if ( v14 )
*a6 = v13 - outbytesleft;
else
*a6 = 0LL;
}
v18 = *v15;
*v15 = 0;
v19 = iconv_close(v12);
if ( v18 && !v19 )
*v15 = v18;
}
return v14;
}

original_code:
char *iconv_string_full(const char *string, ssize_t length,
                        const char *src_encoding,
                        const char *dst_encoding,
                        size_t *src_used_bytes_p, size_t *dst_length_p,
                        int replacement_char)
{
    iconv_t cd;
    if(string == ((void *)0))
        return ((void *)0);
    if(length < 0)
        length = strlen(string);
    if(length == 0)
        return ((void *)0);
    if(strcmp(src_encoding, dst_encoding) == 0)
        return strdup(string);
    cd = iconv_open(dst_encoding, src_encoding);
    if(cd == (iconv_t)-1)
    {
        sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "failed to open iconv: src=[%s], dst=[%s]", getpid(), __func__, 56, src_encoding, dst_encoding);
        return ((void *)0);
    }
    size_t dst_length = length * 2;
    char *dst = malloc(dst_length + 1);
    char *wstring = (char *)string;
    if(replacement_char > 0)
        wstring = strdup(string);
    char *inp = ( char *)wstring;
    char *outp = dst;
    size_t inbytesleft = length;
    size_t outbytesleft = dst_length;
    while(1)
    {
        (*__errno_location ()) = 0;
        size_t rc = iconv(cd, &inp, &inbytesleft, &outp, &outbytesleft);
        if(rc == (size_t)-1)
        {
            switch((*__errno_location ()))
            {
                case 84:
                    if(replacement_char > 0)
                    {
                        *(char *)inp = (char)replacement_char;
                        break;
                    }
                case 22:
                default:
                    free(dst);
                    dst = ((void *)0);
                    break;
                case 7:
                    dst_length += length;
                    dst = realloc(dst, dst_length + 1);
                    size_t used = outp - dst;
                    outbytesleft = dst_length - used;
                    outp = dst + used;
                    break;
            }
            if(dst == ((void *)0))
                break;
        }
        else
        {
            *outp = 0;
            break;
        }
    }
    if(src_used_bytes_p)
        *src_used_bytes_p = inp - wstring;
    if(replacement_char > 0)
        free(wstring);
    if(dst_length_p)
    {
        if(dst)
            *dst_length_p = dst_length - outbytesleft;
        else
            *dst_length_p = 0;
    }
    int save_errno = (*__errno_location ());
    (*__errno_location ()) = 0;
    if(iconv_close(cd) == 0 && save_errno != 0)
        (*__errno_location ()) = save_errno;
    return dst;
}

canonical_original_code:
char *iconv_string_full(char *string, long length, char *src_encoding, char *dst_encoding, unsigned long *src_used_bytes_p, unsigned long *dst_length_p, int replacement_char)
{
    void *cd;
    if(string == ((void *)0))
        return ((void *)0);
    if(length < 0)
        length = strlen(string);
    if(length == 0)
        return ((void *)0);
    if(strcmp(src_encoding, dst_encoding) == 0)
        return strdup(string);
    cd = iconv_open(dst_encoding, src_encoding);
    if(cd == (iconv_t)-1)
    {
        sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "failed to open iconv: src=[%s], dst=[%s]", getpid(), __func__, 56, src_encoding, dst_encoding);
        return ((void *)0);
    }
    unsigned long dst_length = length * 2;
    char *dst = malloc(dst_length + 1);
    char *wstring = (char *)string;
    if(replacement_char > 0)
        wstring = strdup(string);
    char *inp = ( char *)wstring;
    char *outp = dst;
    unsigned long inbytesleft = length;
    unsigned long outbytesleft = dst_length;
    while(1)
    {
        (*__errno_location ()) = 0;
        unsigned long rc = iconv(cd, &inp, &inbytesleft, &outp, &outbytesleft);
        if(rc == (unsigned long)-1)
        {
            switch((*__errno_location ()))
            {
                case 84:
                    if(replacement_char > 0)
                    {
                        *(char *)inp = (char)replacement_char;
                        break;
                    }
                case 22:
                default:
                    free(dst);
                    dst = ((void *)0);
                    break;
                case 7:
                    dst_length += length;
                    dst = realloc(dst, dst_length + 1);
                    unsigned long used = outp - dst;
                    outbytesleft = dst_length - used;
                    outp = dst + used;
                    break;
            }
            if(dst == ((void *)0))
                break;
        }
        else
        {
            *outp = 0;
            break;
        }
    }
    if(src_used_bytes_p)
        *src_used_bytes_p = inp - wstring;
    if(replacement_char > 0)
        free(wstring);
    if(dst_length_p)
    {
        if(dst)
            *dst_length_p = dst_length - outbytesleft;
        else
            *dst_length_p = 0;
    }
    int save_errno = (*__errno_location ());
    (*__errno_location ()) = 0;
    if(iconv_close(cd) == 0 && save_errno != 0)
        (*__errno_location ()) = save_errno;
    return dst;
}

variable_types:
string
char *

variable_types: length long

variable_types:
cd
void *

variable_types:
dst
char *

variable_types:
wstring
char *

variable_types:
inp
char *

variable_types:
outp
char *

variable_types:
inbytesleft
unsigned long

variable_types:
outbytesleft
unsigned long

variable_types:
rc
unsigned long

variable_types:
used
unsigned long


decompiled_code:
char *__fastcall iconv_string(void *a1, __int64 a2, const char *a3, const char *a4)
{
return iconv_string_full(a1, a2, a3, a4, 0LL, 0LL, -1);
}

canonical_decompiled_code:
char *__fastcall func1(void *a1, __int64 a2, const char *a3, const char *a4)
{
return func0(a1, a2, a3, a4, 0LL, 0LL, -1);
}

original_code:
char *iconv_string(const char *string, ssize_t length,
                        const char *src_encoding,
                        const char *dst_encoding)
{
    return iconv_string_full(string, length, src_encoding, dst_encoding,
            ((void *)0), ((void *)0), -1);
}

canonical_original_code:
char *iconv_string(char *string, long length, char *src_encoding, char *dst_encoding)
{
    return iconv_string_full(string, length, src_encoding, dst_encoding,
            ((void *)0), ((void *)0), -1);
}


decompiled_code:
char *__fastcall iconv_string_lossy(void *a1, __int64 a2, const char *a3, const char *a4)
{
return iconv_string_full(a1, a2, a3, a4, 0LL, 0LL, 63);
}

canonical_decompiled_code:
char *__fastcall func2(void *a1, __int64 a2, const char *a3, const char *a4)
{
return func0(a1, a2, a3, a4, 0LL, 0LL, 63);
}

original_code:
char *iconv_string_lossy(const char *string, ssize_t length,
                        const char *src_encoding,
                        const char *dst_encoding)
{
    return iconv_string_full(string, length, src_encoding, dst_encoding,
            ((void *)0), ((void *)0), '?');
}

canonical_original_code:
char *iconv_string_lossy(char *string, long length, char *src_encoding, char *dst_encoding)
{
    return iconv_string_full(string, length, src_encoding, dst_encoding,
            ((void *)0), ((void *)0), '?');
}


decompiled_code:
char *__fastcall iconv_string_escaped(void *a1, __int64 a2, const char *a3, const char *a4)
{
return iconv_string_full(a1, a2, a3, a4, 0LL, 0LL, 63);
}

canonical_decompiled_code:
char *__fastcall func3(void *a1, __int64 a2, const char *a3, const char *a4)
{
return func0(a1, a2, a3, a4, 0LL, 0LL, 63);
}

original_code:
char *iconv_string_escaped(const char *string, ssize_t length,
                           const char *src_encoding,
                           const char *dst_encoding)
{
    return iconv_string_full(string, length, src_encoding, dst_encoding,
            ((void *)0), ((void *)0), '?');
}

canonical_original_code:
char *iconv_string_escaped(char *string, long length, char *src_encoding, char *dst_encoding)
{
    return iconv_string_full(string, length, src_encoding, dst_encoding,
            ((void *)0), ((void *)0), '?');
}


decompiled_code:
__int64 __fastcall test_connection_string(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx
const char **v4; // r8
bool v5; // zf

if ( !a1 )
return 6LL;
v1 = rx_search(a1, "tcp:([0-9]+)[[:space:]]*udp:([0-9]+)");
if ( !v1 )
return 6;
v2 = 6;
if ( *(_DWORD *)v1 == 2 )
{
v4 = *(const char ***)(v1 + 8);
if ( !strcmp(*v4, "0") )
{
v5 = strcmp(v4[1], "0") == 0;
v2 = !v5;
if ( !v5 )
v2 = 4;
}
}
return v2;
}

original_code:
static int test_connection_string(const char *string)
{
    if(string == ((void *)0))
    {
        return 6;
    }
    int rc = 6;
    rx_subs_t *subs = rx_search(string, "tcp:([0-9]+)[[:space:]]*udp:([0-9]+)");
    if(subs && subs->nsubs == 2)
    {
        rc = 2 | 4;
        if(strcmp(subs->subs[0], "0") == 0)
        {
            if(strcmp(subs->subs[1], "0") == 0)
            {
                rc = 0;
            }
            else
            {
                rc = 4;
            }
        }
    }
    return rc;
}

canonical_original_code:
static int test_connection_string(char *string)
{
    if(string == ((void *)0))
    {
        return 6;
    }
    int rc = 6;
    struct rx_subs *subs = rx_search(string, "tcp:([0-9]+)[[:space:]]*udp:([0-9]+)");
    if(subs && subs->nsubs == 2)
    {
        rc = 2 | 4;
        if(strcmp(subs->subs[0], "0") == 0)
        {
            if(strcmp(subs->subs[1], "0") == 0)
            {
                rc = 0;
            }
            else
            {
                rc = 4;
            }
        }
    }
    return rc;
}

variable_types: rc int

variable_types: struct rx_subs { int nsubs; char **subs; } *

return_type: int


decompiled_code:
__int64 __fastcall test_connection(int a1)
{
unsigned int v1; // ebx
__int64 v3; // rbp
unsigned int v4; // eax
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v1 = 1;
if ( a1 > 1024 )
{
ptr = 0LL;
if ( asprintf(&ptr, "%s?port=%u", "http://shakespeer.bzero.se/checkport", (unsigned int)a1) == -1 )
{
v4 = getpid();
sp_log(64LL, "[%d] (%s:%i) asprintf did not return anything", v4, "test_connection", 70LL);
}
v1 = 6;
if ( ptr )
{
v3 = dstring_new_from_url();
free(ptr);
if ( v3 )
{
v1 = test_connection_string(*(_QWORD *)(v3 + 8));
dstring_free(v3, 1LL);
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // ebx
__int64 v3; // rbp
unsigned int v4; // eax
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v1 = 1;
if ( a1 > 1024 )
{
ptr = 0LL;
if ( asprintf(&ptr, "%s?port=%u", "http://shakespeer.bzero.se/checkport", (unsigned int)a1) == -1 )
{
v4 = getpid();
sp_log(64LL, "[%d] (%s:%i) asprintf did not return anything", v4, "test_connection", 70LL);
}
v1 = 6;
if ( ptr )
{
v3 = dstring_new_from_url();
free(ptr);
if ( v3 )
{
v1 = func0(*(_QWORD *)(v3 + 8));
dstring_free(v3, 1LL);
}
}
}
return v1;
}

original_code:
int test_connection(int port)
{
    if (port <= 1024)
        return 1;
    char *url = ((void *)0);
    int num_returned_bytes = asprintf(&url, "%s?port=%u", "http://shakespeer.bzero.se/checkport", port);
    if (num_returned_bytes == -1)
        sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 70);
    if (url) {
        dstring_t *ds = dstring_new_from_url(url);
        free(url);
        if (ds) {
            int rc = test_connection_string(ds->string);
            dstring_free(ds, 1);
            return rc;
        }
    }
    return 6;
}

canonical_original_code:
int test_connection(int port)
{
    if (port <= 1024)
        return 1;
    char *url = ((void *)0);
    int num_returned_bytes = asprintf(&url, "%s?port=%u", "http://shakespeer.bzero.se/checkport", port);
    if (num_returned_bytes == -1)
        sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 70);
    if (url) {
        struct dstring *ds = dstring_new_from_url(url);
        free(url);
        if (ds) {
            int rc = test_connection_string(ds->string);
            dstring_free(ds, 1);
            return rc;
        }
    }
    return 6;
}

variable_types: port int

variable_types:
url
char *

variable_types: struct dstring { unsigned int length; unsigned int allocated; char *string; } *


decompiled_code:
__int64 __fastcall share_create_bloom(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
__int64 i; // rbx
const char *v4; // rbp
char *v5; // rax
unsigned int v6; // eax
__int64 result; // rax
unsigned int v8; // eax
float v9; // [rsp+Ch] [rbp-1Ch]

v2 = getpid();
sp_log(64LL, "[%d] (%s:%i) (re)creating bloom filter", v2, "share_create_bloom", 34LL);
if ( a1 )
{
bloom_free(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 16) = bloom_create(a2);
for ( i = file_tree_RB_MINMAX(a1 + 40, 0xFFFFFFFFLL); i; i = file_tree_RB_NEXT(i) )
{
v4 = *(const char **)(i + 64);
v5 = strrchr(v4, 47);
if ( v5 )
v4 = v5 + 1;
bloom_add_filename(*(_QWORD *)(a1 + 16), v4);
}
v9 = bloom_filled_percent(*(_QWORD *)(a1 + 16));
v6 = getpid();
result = sp_log(32LL, "[%d] (%s:%i) bloom filter is %.1f%% filled", v6, "share_create_bloom", 50LL, v9);
}
else
{
v8 = getpid();
result = sp_log(16LL, "[%d] (%s:%i) assert failed: share", v8, "share_create_bloom", 36LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
__int64 i; // rbx
const char *v4; // rbp
char *v5; // rax
unsigned int v6; // eax
__int64 result; // rax
unsigned int v8; // eax
float v9; // [rsp+Ch] [rbp-1Ch]

v2 = getpid();
sp_log(64LL, "[%d] (%s:%i) (re)creating bloom filter", v2, "share_create_bloom", 34LL);
if ( a1 )
{
bloom_free(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 16) = bloom_create(a2);
for ( i = file_tree_RB_MINMAX(a1 + 40, 0xFFFFFFFFLL); i; i = file_tree_RB_NEXT(i) )
{
v4 = *(const char **)(i + 64);
v5 = strrchr(v4, 47);
if ( v5 )
v4 = v5 + 1;
bloom_add_filename(*(_QWORD *)(a1 + 16), v4);
}
v9 = bloom_filled_percent(*(_QWORD *)(a1 + 16));
v6 = getpid();
result = sp_log(32LL, "[%d] (%s:%i) bloom filter is %.1f%% filled", v6, "share_create_bloom", 50LL, v9);
}
else
{
v8 = getpid();
result = sp_log(16LL, "[%d] (%s:%i) assert failed: share", v8, "share_create_bloom", 36LL);
}
return result;
}

original_code:
static void share_create_bloom(share_t *share, unsigned length)
{
    sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "(re)creating bloom filter", getpid(), __func__, 34);
    do { if(!(share)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "share", getpid(), __func__, 36); return; } } while(0);
    bloom_free(share->bloom);
    share->bloom = bloom_create(length);
    share_file_t *f;
    for ((f) = file_tree_RB_MINMAX(&share->files, -1); (f) != ((void *)0); (f) = file_tree_RB_NEXT(f))
    {
 char *filename = strrchr(f->partial_path, '/');
 if(filename++ == ((void *)0))
     filename = f->partial_path;
        bloom_add_filename(share->bloom, filename);
    }
    sp_log(LOG_LEVEL_INFO, "[%d] (%s:%i) " "bloom filter is %.1f%% filled", getpid(), __func__, 50, bloom_filled_percent(share->bloom));
}

canonical_original_code:
static void share_create_bloom(struct share *share, unsigned int length)
{
    sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "(re)creating bloom filter", getpid(), __func__, 34);
    do { if(!(share)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "share", getpid(), __func__, 36); return; } } while(0);
    bloom_free(share->bloom);
    share->bloom = bloom_create(length);
    struct share_file *f;
    for ((f) = file_tree_RB_MINMAX(&share->files, -1); (f) != ((void *)0); (f) = file_tree_RB_NEXT(f))
    {
 char *filename = strrchr(f->partial_path, '/');
 if(filename++ == ((void *)0))
     filename = f->partial_path;
        bloom_add_filename(share->bloom, filename);
    }
    sp_log(LOG_LEVEL_INFO, "[%d] (%s:%i) " "bloom filter is %.1f%% filled", getpid(), __func__, 50, bloom_filled_percent(share->bloom));
}

variable_types: struct share { struct { struct share_mountpoint { struct { struct share_mountpoint *le_next; struct share_mountpoint **le_prev; } link; char *local_root; char *virtual_root; struct share_stats { unsigned long size; unsigned long totsize; unsigned long dupsize; unsigned int nfiles; unsigned int ntotfiles; unsigned int nduplicates; } stats; _Bool scan_in_progress; _Bool removed; } *lh_first; } mountpoints; _Bool uptodate; int scanning; struct bloom { unsigned int length; unsigned char *filter; unsigned int collisions; } *bloom; char *cid; unsigned int listlen; struct file_tree { struct share_file { struct { struct share_file *rbe_left; struct share_file *rbe_right; struct share_file *rbe_parent; int rbe_color; } entry; struct { struct share_file *le_next; struct share_file **le_prev; } inode_link; struct { struct share_file *sle_next; } link; struct share_mountpoint *mp; char *partial_path; enum share_type { SHARE_TYPE_ANY=1, SHARE_TYPE_AUDIO=2, SHARE_TYPE_COMPRESSED=3, SHARE_TYPE_DOCUMENT=4, SHARE_TYPE_EXECUTABLE=5, SHARE_TYPE_IMAGE=6, SHARE_TYPE_MOVIE=7, SHARE_TYPE_DIRECTORY=8, SHARE_TYPE_TTH=9 } type; unsigned long size; unsigned long inode; } *rbh_root; } files; struct file_tree unhashed_files; struct { struct share_file *lh_first; } inodes[509]; } *

variable_types:
length
unsigned int

variable_types: struct share_file { struct { struct share_file *rbe_left; struct share_file *rbe_right; struct share_file *rbe_parent; int rbe_color; } entry; struct { struct share_file *le_next; struct share_file **le_prev; } inode_link; struct { struct share_file *sle_next; } link; struct share_mountpoint { struct { struct share_mountpoint *le_next; struct share_mountpoint **le_prev; } link; char *local_root; char *virtual_root; struct share_stats { unsigned long size; unsigned long totsize; unsigned long dupsize; unsigned int nfiles; unsigned int ntotfiles; unsigned int nduplicates; } stats; _Bool scan_in_progress; _Bool removed; } *mp; char *partial_path; enum share_type { SHARE_TYPE_ANY=1, SHARE_TYPE_AUDIO=2, SHARE_TYPE_COMPRESSED=3, SHARE_TYPE_DOCUMENT=4, SHARE_TYPE_EXECUTABLE=5, SHARE_TYPE_IMAGE=6, SHARE_TYPE_MOVIE=7, SHARE_TYPE_DIRECTORY=8, SHARE_TYPE_TTH=9 } type; unsigned long size; unsigned long inode; } *

variable_types:
filename
char *

user_defined_types: struct share { struct { struct share_mountpoint *lh_first; } mountpoints; _Bool uptodate; int scanning; struct bloom *bloom; char *cid; unsigned int listlen; struct file_tree files; struct file_tree unhashed_files; struct { struct share_file *lh_first; } inodes[509]; }

user_defined_types: struct share_file { struct { struct share_file *rbe_left; struct share_file *rbe_right; struct share_file *rbe_parent; int rbe_color; } entry; struct { struct share_file *le_next; struct share_file **le_prev; } inode_link; struct { struct share_file *sle_next; } link; struct share_mountpoint *mp; char *partial_path; enum share_type type; unsigned long size; unsigned long inode; }

user_defined_types: struct file_tree { struct share_file *rbh_root; }

user_defined_types: struct share_mountpoint { struct { struct share_mountpoint *le_next; struct share_mountpoint **le_prev; } link; char *local_root; char *virtual_root; struct share_stats stats; _Bool scan_in_progress; _Bool removed; }


decompiled_code:
void __fastcall share_bloom_handle_scan_finished(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rdi
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
float v9; // [rsp+Ch] [rbp-Ch]

if ( a4 )
{
v5 = *(_QWORD *)(a4 + 16);
if ( v5 )
{
v9 = bloom_filled_percent(v5);
if ( v9 > 70.0 )
{
v8 = getpid();
sp_log(
32LL,
"[%d] (%s:%i) bloom filter is %.1f%% filled, increasing filter length",
v8,
"share_bloom_handle_scan_finished",
84LL,
v9);
share_create_bloom(a4, 2 * **(_DWORD **)(a4 + 16));
}
}
else
{
v7 = getpid();
sp_log(16LL, "[%d] (%s:%i) assert failed: share->bloom", v7, "share_bloom_handle_scan_finished", 79LL);
}
}
else
{
v6 = getpid();
sp_log(16LL, "[%d] (%s:%i) assert failed: user_data", v6, "share_bloom_handle_scan_finished", 74LL);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rdi
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
float v9; // [rsp+Ch] [rbp-Ch]

if ( a4 )
{
v5 = *(_QWORD *)(a4 + 16);
if ( v5 )
{
v9 = bloom_filled_percent(v5);
if ( v9 > 70.0 )
{
v8 = getpid();
sp_log(
32LL,
"[%d] (%s:%i) bloom filter is %.1f%% filled, increasing filter length",
v8,
"share_bloom_handle_scan_finished",
84LL,
v9);
func0(a4, 2 * **(_DWORD **)(a4 + 16));
}
}
else
{
v7 = getpid();
sp_log(16LL, "[%d] (%s:%i) assert failed: share->bloom", v7, "share_bloom_handle_scan_finished", 79LL);
}
}
else
{
v6 = getpid();
sp_log(16LL, "[%d] (%s:%i) assert failed: user_data", v6, "share_bloom_handle_scan_finished", 74LL);
}
}

original_code:
static void share_bloom_handle_scan_finished(
        nc_t *nc,
        const char *channel,
        nc_share_scan_finished_t *notification,
        void *user_data)
{
 do { if(!(user_data)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "user_data", getpid(), __func__, 74); return; } } while(0);
 share_t *share = user_data;
 do { if(!(share->bloom)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "share->bloom", getpid(), __func__, 79); return; } } while(0);
 float fill = bloom_filled_percent(share->bloom);
 if(fill > 70.0)
 {
  sp_log(LOG_LEVEL_INFO, "[%d] (%s:%i) " "bloom filter is %.1f%% filled, increasing filter length", getpid(), __func__, 84, fill);
  share_create_bloom(share, share->bloom->length * 2);
 }
}

canonical_original_code:
static void share_bloom_handle_scan_finished(struct notification_center *nc, char *channel, struct nc_share_scan_finished *notification, void *user_data)
{
 do { if(!(user_data)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "user_data", getpid(), __func__, 74); return; } } while(0);
 struct share *share = user_data;
 do { if(!(share->bloom)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "share->bloom", getpid(), __func__, 79); return; } } while(0);
 float fill = bloom_filled_percent(share->bloom);
 if(fill > 70.0)
 {
  sp_log(LOG_LEVEL_INFO, "[%d] (%s:%i) " "bloom filter is %.1f%% filled, increasing filter length", getpid(), __func__, 84, fill);
  share_create_bloom(share, share->bloom->length * 2);
 }
}

variable_types: struct notification_center { struct { struct nc_observer { char *channel; void (*callback)(struct notification_center *nc, char *channel, void *data, void *user_data); void *user_data; struct { struct nc_observer *le_next; struct nc_observer **le_prev; } next; } *lh_first; } observers; } *

variable_types:
channel
char *

variable_types: struct nc_share_scan_finished { char *path; } *

variable_types: fill float

user_defined_types: struct notification_center { struct { struct nc_observer *lh_first; } observers; }

user_defined_types: struct bloom { unsigned int length; unsigned char *filter; unsigned int collisions; }

user_defined_types: struct share_stats { unsigned long size; unsigned long totsize; unsigned long dupsize; unsigned int nfiles; unsigned int ntotfiles; unsigned int nduplicates; }

user_defined_types: enum share_type { SHARE_TYPE_ANY=1, SHARE_TYPE_AUDIO=2, SHARE_TYPE_COMPRESSED=3, SHARE_TYPE_DOCUMENT=4, SHARE_TYPE_EXECUTABLE=5, SHARE_TYPE_IMAGE=6, SHARE_TYPE_MOVIE=7, SHARE_TYPE_DIRECTORY=8, SHARE_TYPE_TTH=9 }


decompiled_code:
__int64 __fastcall share_bloom_handle_did_remove_share_notification(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v5; // eax
unsigned int *v6; // rax
__int64 result; // rax
unsigned int v8; // eax
unsigned int v9; // eax

if ( a4 )
{
v5 = getpid();
sp_log(
64LL,
"[%d] (%s:%i) re-creating bloom filter after share removal",
v5,
"share_bloom_handle_did_remove_share_notification",
62LL);
v6 = *(unsigned int **)(a4 + 16);
if ( v6 )
{
result = share_create_bloom(a4, *v6);
}
else
{
v9 = getpid();
result = sp_log(
16LL,
"[%d] (%s:%i) assert failed: share->bloom",
v9,
"share_bloom_handle_did_remove_share_notification",
64LL);
}
}
else
{
v8 = getpid();
result = sp_log(
16LL,
"[%d] (%s:%i) assert failed: user_data",
v8,
"share_bloom_handle_did_remove_share_notification",
59LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v5; // eax
unsigned int *v6; // rax
__int64 result; // rax
unsigned int v8; // eax
unsigned int v9; // eax

if ( a4 )
{
v5 = getpid();
sp_log(
64LL,
"[%d] (%s:%i) re-creating bloom filter after share removal",
v5,
"share_bloom_handle_did_remove_share_notification",
62LL);
v6 = *(unsigned int **)(a4 + 16);
if ( v6 )
{
result = func0(a4, *v6);
}
else
{
v9 = getpid();
result = sp_log(
16LL,
"[%d] (%s:%i) assert failed: share->bloom",
v9,
"share_bloom_handle_did_remove_share_notification",
64LL);
}
}
else
{
v8 = getpid();
result = sp_log(
16LL,
"[%d] (%s:%i) assert failed: user_data",
v8,
"share_bloom_handle_did_remove_share_notification",
59LL);
}
return result;
}

original_code:
static void share_bloom_handle_did_remove_share_notification(
        nc_t *nc,
        const char *channel,
        nc_did_remove_share_t *notification,
        void *user_data)
{
 do { if(!(user_data)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "user_data", getpid(), __func__, 59); return; } } while(0);
 sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "re-creating bloom filter after share removal", getpid(), __func__, 62);
 share_t *share = user_data;
 do { if(!(share->bloom)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "share->bloom", getpid(), __func__, 64); return; } } while(0);
 share_create_bloom(share, share->bloom->length);
}

canonical_original_code:
static void share_bloom_handle_did_remove_share_notification(struct notification_center *nc, char *channel, struct nc_did_remove_share *notification, void *user_data)
{
 do { if(!(user_data)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "user_data", getpid(), __func__, 59); return; } } while(0);
 sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "re-creating bloom filter after share removal", getpid(), __func__, 62);
 struct share *share = user_data;
 do { if(!(share->bloom)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "share->bloom", getpid(), __func__, 64); return; } } while(0);
 share_create_bloom(share, share->bloom->length);
}

variable_types: struct nc_did_remove_share { char *local_root; _Bool is_rescan; } *

user_defined_types: struct nc_observer { char *channel; void (*callback)(struct notification_center *nc, char *channel, void *data, void *user_data); void *user_data; struct { struct nc_observer *le_next; struct nc_observer **le_prev; } next; }


decompiled_code:
__int64 __fastcall share_bloom_init(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax

v1 = nc_default();
nc_add_did_remove_share_observer(v1, share_bloom_handle_did_remove_share_notification, a1);
v2 = nc_default();
return nc_add_share_scan_finished_observer(v2, share_bloom_handle_scan_finished, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax

v1 = nc_default();
nc_add_did_remove_share_observer(v1, share_bloom_handle_did_remove_share_notification, a1);
v2 = nc_default();
return nc_add_share_scan_finished_observer(v2, share_bloom_handle_scan_finished, a1);
}

original_code:
void share_bloom_init(share_t *share)
{
 nc_add_did_remove_share_observer(nc_default(),
  share_bloom_handle_did_remove_share_notification, share);
 nc_add_share_scan_finished_observer(nc_default(),
  share_bloom_handle_scan_finished, share);
}

canonical_original_code:
void share_bloom_init(struct share *share)
{
 nc_add_did_remove_share_observer(nc_default(),
  share_bloom_handle_did_remove_share_notification, share);
 nc_add_share_scan_finished_observer(nc_default(),
  share_bloom_handle_scan_finished, share);
}


decompiled_code:
const char *sp_log_get_level()
{
const char *result; // rax

result = "debug";
if ( max_log_level != 64 )
{
result = "info";
if ( max_log_level != 32 )
{
result = "warning";
if ( max_log_level != 16 )
{
result = "error";
if ( max_log_level != 4 )
result = "none";
}
}
}
return result;
}

canonical_decompiled_code:
const char *func0()
{
const char *result; // rax

result = "debug";
if ( max_log_level != 64 )
{
result = "info";
if ( max_log_level != 32 )
{
result = "warning";
if ( max_log_level != 16 )
{
result = "error";
if ( max_log_level != 4 )
result = "none";
}
}
}
return result;
}

original_code:
const char *sp_log_get_level(void)
{
    if(max_log_level == LOG_LEVEL_DEBUG)
        return "debug";
    else if(max_log_level == LOG_LEVEL_INFO)
        return "info";
    else if(max_log_level == LOG_LEVEL_WARNING)
        return "warning";
    else if(max_log_level == LOG_LEVEL_ERROR)
        return "error";
    else
        return "none";
}

canonical_original_code:
char *sp_log_get_level()
{
    if(max_log_level == LOG_LEVEL_DEBUG)
        return "debug";
    else if(max_log_level == LOG_LEVEL_INFO)
        return "info";
    else if(max_log_level == LOG_LEVEL_WARNING)
        return "warning";
    else if(max_log_level == LOG_LEVEL_ERROR)
        return "error";
    else
        return "none";
}


decompiled_code:
__int64 sp_log(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return sp_vlog(a1, a2, va);
}

canonical_decompiled_code:
__int64 func1(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func7(a1, a2, va);
}

original_code:
void sp_log(int level, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    sp_vlog(level, fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void sp_log(int level, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    sp_vlog(level, fmt, ap);
    __builtin_va_end(ap);
}

variable_types: level int

variable_types:
fmt
char *


decompiled_code:
int __fastcall sp_log_set_level(char *s1)
{
int result; // eax
unsigned int v2; // eax

if ( s1 )
{
sp_log_max_bytes = 0x200000;
result = strcasecmp(s1, "none");
if ( result )
{
result = strcasecmp(s1, "warning");
if ( result )
{
result = strcasecmp(s1, "message");
if ( result )
{
result = strcasecmp(s1, "info");
if ( result )
{
result = strcasecmp(s1, "debug");
if ( !result )
{
max_log_level = 64;
sp_log_max_bytes = 10485760;
}
}
else
{
max_log_level = 32;
}
}
else
{
max_log_level = 32;
}
}
else
{
max_log_level = 16;
}
}
else
{
max_log_level = 4;
}
}
else
{
v2 = getpid();
result = sp_log(16LL, (__int64)"[%d] (%s:%i) assert failed: level", v2, "sp_log_set_level", 53LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1)
{
int result; // eax
unsigned int v2; // eax

if ( s1 )
{
sp_log_max_bytes = 0x200000;
result = strcasecmp(s1, "none");
if ( result )
{
result = strcasecmp(s1, "warning");
if ( result )
{
result = strcasecmp(s1, "message");
if ( result )
{
result = strcasecmp(s1, "info");
if ( result )
{
result = strcasecmp(s1, "debug");
if ( !result )
{
max_log_level = 64;
sp_log_max_bytes = 10485760;
}
}
else
{
max_log_level = 32;
}
}
else
{
max_log_level = 32;
}
}
else
{
max_log_level = 16;
}
}
else
{
max_log_level = 4;
}
}
else
{
v2 = getpid();
result = func1(16LL, (__int64)"[%d] (%s:%i) assert failed: level", v2, "sp_log_set_level", 53LL);
}
return result;
}

original_code:
void sp_log_set_level(const char *level)
{
    do { if(!(level)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "level", getpid(), __func__, 53); return; } } while(0);
    sp_log_max_bytes = 2*1024*1024;
    if(strcasecmp(level, "none") == 0)
        max_log_level = LOG_LEVEL_ERROR;
    else if(strcasecmp(level, "warning") == 0)
        max_log_level = LOG_LEVEL_WARNING;
    else if(strcasecmp(level, "message") == 0)
        max_log_level = LOG_LEVEL_INFO;
    else if(strcasecmp(level, "info") == 0)
        max_log_level = LOG_LEVEL_INFO;
    else if(strcasecmp(level, "debug") == 0)
    {
        max_log_level = LOG_LEVEL_DEBUG;
        sp_log_max_bytes = 10*1024*1024;
    }
}

canonical_original_code:
void sp_log_set_level(char *level)
{
    do { if(!(level)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "level", getpid(), __func__, 53); return; } } while(0);
    sp_log_max_bytes = 2*1024*1024;
    if(strcasecmp(level, "none") == 0)
        max_log_level = LOG_LEVEL_ERROR;
    else if(strcasecmp(level, "warning") == 0)
        max_log_level = LOG_LEVEL_WARNING;
    else if(strcasecmp(level, "message") == 0)
        max_log_level = LOG_LEVEL_INFO;
    else if(strcasecmp(level, "info") == 0)
        max_log_level = LOG_LEVEL_INFO;
    else if(strcasecmp(level, "debug") == 0)
    {
        max_log_level = LOG_LEVEL_DEBUG;
        sp_log_max_bytes = 10*1024*1024;
    }
}

variable_types:
level
char *


decompiled_code:
void __fastcall sp_log_rotate(char *old)
{
int v1; // ebx
int v2; // er12
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // er12
unsigned int v7; // eax
unsigned int v8; // eax
char *olda; // [rsp+0h] [rbp-B8h] BYREF
char *ptr; // [rsp+8h] [rbp-B0h] BYREF
struct stat64 v11; // [rsp+10h] [rbp-A8h] BYREF

if ( !stat64(old, &v11) )
{
v1 = 0;
if ( v11.st_size > sp_log_max_bytes )
{
while ( 1 )
{
if ( asprintf(&ptr, "%s.%i", old, (unsigned int)v1) == -1 )
{
v3 = getpid();
sp_log(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v3, "sp_log_rotate", 145LL);
}
v2 = access(ptr, 0);
free(ptr);
if ( v2 )
break;
if ( ++v1 == 5 )
{
if ( asprintf(&ptr, "%s.%i", old, 4LL) == -1 )
{
v4 = getpid();
sp_log(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v4, "sp_log_rotate", 156LL);
}
unlink(ptr);
free(ptr);
v1 = 4;
goto LABEL_16;
}
}
if ( v1 <= 0 )
goto LABEL_11;
do
{
LABEL_16:
v6 = v1--;
if ( asprintf(&olda, "%s.%i", old, (unsigned int)v1) == -1 )
{
v5 = getpid();
sp_log(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v5, "sp_log_rotate", 166LL);
}
if ( asprintf(&ptr, "%s.%i", old, v6) == -1 )
{
v7 = getpid();
sp_log(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v7, "sp_log_rotate", 169LL);
}
rename(olda, ptr);
free(olda);
free(ptr);
}
while ( v1 > 0 );
LABEL_11:
if ( asprintf(&ptr, "%s.0", old) == -1 )
{
v8 = getpid();
sp_log(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v8, "sp_log_rotate", 179LL);
}
rename(old, ptr);
free(ptr);
}
}
}

canonical_decompiled_code:
void __fastcall func3(char *old)
{
int v1; // ebx
int v2; // er12
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // er12
unsigned int v7; // eax
unsigned int v8; // eax
char *olda; // [rsp+0h] [rbp-B8h] BYREF
char *ptr; // [rsp+8h] [rbp-B0h] BYREF
struct stat64 v11; // [rsp+10h] [rbp-A8h] BYREF

if ( !stat64(old, &v11) )
{
v1 = 0;
if ( v11.st_size > sp_log_max_bytes )
{
while ( 1 )
{
if ( asprintf(&ptr, "%s.%i", old, (unsigned int)v1) == -1 )
{
v3 = getpid();
func1(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v3, "sp_log_rotate", 145LL);
}
v2 = access(ptr, 0);
free(ptr);
if ( v2 )
break;
if ( ++v1 == 5 )
{
if ( asprintf(&ptr, "%s.%i", old, 4LL) == -1 )
{
v4 = getpid();
func1(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v4, "sp_log_rotate", 156LL);
}
unlink(ptr);
free(ptr);
v1 = 4;
goto LABEL_16;
}
}
if ( v1 <= 0 )
goto LABEL_11;
do
{
LABEL_16:
v6 = v1--;
if ( asprintf(&olda, "%s.%i", old, (unsigned int)v1) == -1 )
{
v5 = getpid();
func1(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v5, "sp_log_rotate", 166LL);
}
if ( asprintf(&ptr, "%s.%i", old, v6) == -1 )
{
v7 = getpid();
func1(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v7, "sp_log_rotate", 169LL);
}
rename(olda, ptr);
free(olda);
free(ptr);
}
while ( v1 > 0 );
LABEL_11:
if ( asprintf(&ptr, "%s.0", old) == -1 )
{
v8 = getpid();
func1(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v8, "sp_log_rotate", 179LL);
}
rename(old, ptr);
free(ptr);
}
}
}

original_code:
static void sp_log_rotate(const char *logfile)
{
    struct stat sb;
    int num_returned_bytes;
    int rc = stat(logfile, &sb);
    if (rc == 0 && sb.st_size > sp_log_max_bytes) {
        int i;
        for (i = 0; i < 5; i++) {
            char *tmp;
            num_returned_bytes = asprintf(&tmp, "%s.%i", logfile, i);
            if (num_returned_bytes == -1)
                sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 145);
            int exists = access(tmp, 0);
            free(tmp);
            if (exists != 0)
                break;
        }
        int maxi = i;
        if (maxi == 5) {
            char *tmp;
            num_returned_bytes = asprintf(&tmp, "%s.%i", logfile, 5 - 1);
            if (num_returned_bytes == -1)
                sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 156);
            unlink(tmp);
            free(tmp);
            --maxi;
        }
        for (i = maxi; i > 0; i--) {
            char *prev;
            char *next;
            num_returned_bytes = asprintf(&prev, "%s.%i", logfile, i - 1);
            if (num_returned_bytes == -1)
                sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 166);
            num_returned_bytes = asprintf(&next, "%s.%i", logfile, i);
            if (num_returned_bytes == -1)
                sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 169);
            rename(prev, next);
            free(prev);
            free(next);
        }
        char *next;
        num_returned_bytes = asprintf(&next, "%s.0", logfile);
        if (num_returned_bytes == -1)
            sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 179);
        rename(logfile, next);
        free(next);
    }
}

canonical_original_code:
static void sp_log_rotate(char *logfile)
{
    struct stat sb;
    int num_returned_bytes;
    int rc = stat(logfile, &sb);
    if (rc == 0 && sb.st_size > sp_log_max_bytes) {
        int i;
        for (i = 0; i < 5; i++) {
            char *tmp;
            num_returned_bytes = asprintf(&tmp, "%s.%i", logfile, i);
            if (num_returned_bytes == -1)
                sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 145);
            int exists = access(tmp, 0);
            free(tmp);
            if (exists != 0)
                break;
        }
        int maxi = i;
        if (maxi == 5) {
            char *tmp;
            num_returned_bytes = asprintf(&tmp, "%s.%i", logfile, 5 - 1);
            if (num_returned_bytes == -1)
                sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 156);
            unlink(tmp);
            free(tmp);
            --maxi;
        }
        for (i = maxi; i > 0; i--) {
            char *prev;
            char *next;
            num_returned_bytes = asprintf(&prev, "%s.%i", logfile, i - 1);
            if (num_returned_bytes == -1)
                sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 166);
            num_returned_bytes = asprintf(&next, "%s.%i", logfile, i);
            if (num_returned_bytes == -1)
                sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 169);
            rename(prev, next);
            free(prev);
            free(next);
        }
        char *next;
        num_returned_bytes = asprintf(&next, "%s.0", logfile);
        if (num_returned_bytes == -1)
            sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 179);
        rename(logfile, next);
        free(next);
    }
}

variable_types:
logfile
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: rc int

variable_types: i int

variable_types:
tmp
char *

variable_types: exists int

variable_types: maxi int

variable_types:
prev
char *

variable_types:
next
char *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void __fastcall event_log_callback(int a1, const char *a2)
{
int v3; // edi

v3 = 32;
if ( a1 != 1 )
{
v3 = 16;
if ( a1 != 2 )
v3 = a1 == 0 ? 64 : 4;
}
sp_glog_func(v3, a2);
}

original_code:
static void event_log_callback(int severity, const char *msg)
{
    int log_level;
    switch(severity)
    {
        case 0:
            log_level = LOG_LEVEL_DEBUG;
            break;
        case 1:
            log_level = LOG_LEVEL_INFO;
            break;
        case 2:
            log_level = LOG_LEVEL_WARNING;
            break;
        case 3:
        default:
            log_level = LOG_LEVEL_ERROR;
            break;
    }
    sp_glog_func(log_level, msg);
}

canonical_original_code:
static void event_log_callback(int severity, char *msg)
{
    int log_level;
    switch(severity)
    {
        case 0:
            log_level = LOG_LEVEL_DEBUG;
            break;
        case 1:
            log_level = LOG_LEVEL_INFO;
            break;
        case 2:
            log_level = LOG_LEVEL_WARNING;
            break;
        case 3:
        default:
            log_level = LOG_LEVEL_ERROR;
            break;
    }
    sp_glog_func(log_level, msg);
}

variable_types: severity int

variable_types:
msg
char *


decompiled_code:
void __fastcall sp_vlog(int a1, const char *a2, void *a3)
{
unsigned int v3; // eax
char *ptr; // [rsp+8h] [rbp-10h] BYREF

if ( vasprintf(&ptr, a2, a3) == -1 )
{
v3 = getpid();
sp_log(64LL, (__int64)"[%d] (%s:%i) vasprintf did not return anything", v3, "sp_vlog", 120LL);
}
sp_glog_func(a1, ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(int a1, const char *a2, void *a3)
{
unsigned int v3; // eax
char *ptr; // [rsp+8h] [rbp-10h] BYREF

if ( vasprintf(&ptr, a2, a3) == -1 )
{
v3 = getpid();
func1(64LL, (__int64)"[%d] (%s:%i) vasprintf did not return anything", v3, "sp_vlog", 120LL);
}
func5(a1, ptr);
free(ptr);
}

original_code:
void sp_vlog(int level, const char *fmt, va_list ap)
{
    char *msg;
    int num_returned_bytes = vasprintf(&msg, fmt, ap);
    if (num_returned_bytes == -1)
        sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "vasprintf did not return anything", getpid(), __func__, 120);
    sp_glog_func(level, msg);
    free(msg);
}

canonical_original_code:
void sp_vlog(int level, char *fmt, __builtin_va_list ap)
{
    char *msg;
    int num_returned_bytes = vasprintf(&msg, fmt, ap);
    if (num_returned_bytes == -1)
        sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "vasprintf did not return anything", getpid(), __func__, 120);
    sp_glog_func(level, msg);
    free(msg);
}


decompiled_code:
__int64 __fastcall sp_log_init(const char *a1, const char *a2)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
char *ptr; // [rsp+8h] [rbp-20h] BYREF

if ( asprintf(&ptr, "%s/log-%s", a1, a2) == -1 )
{
v3 = getpid();
sp_log(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v3, "sp_log_init", 231LL);
}
unlink(ptr);
free(ptr);
if ( logfp )
return (unsigned int)-(logfp == 0LL);
if ( a1 && a2 )
{
if ( asprintf(&logfile, "%s/%s.log", a1, a2) == -1 )
{
v5 = getpid();
sp_log(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v5, "sp_log_init", 251LL);
}
sp_log_reinit();
return (unsigned int)-(logfp == 0LL);
}
v4 = getpid();
sp_log(16LL, (__int64)"[%d] (%s:%i) assert failed: workdir && prefix", v4, "sp_log_init", 236LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
char *ptr; // [rsp+8h] [rbp-20h] BYREF

if ( asprintf(&ptr, "%s/log-%s", a1, a2) == -1 )
{
v3 = getpid();
func1(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v3, "sp_log_init", 231LL);
}
unlink(ptr);
free(ptr);
if ( logfp )
return (unsigned int)-(logfp == 0LL);
if ( a1 && a2 )
{
if ( asprintf(&logfile, "%s/%s.log", a1, a2) == -1 )
{
v5 = getpid();
func1(64LL, (__int64)"[%d] (%s:%i) asprintf did not return anything", v5, "sp_log_init", 251LL);
}
func4();
return (unsigned int)-(logfp == 0LL);
}
v4 = getpid();
func1(16LL, (__int64)"[%d] (%s:%i) assert failed: workdir && prefix", v4, "sp_log_init", 236LL);
return 0xFFFFFFFFLL;
}

original_code:
int sp_log_init(const char *workdir, const char *prefix)
{
    char *old_logfile;
    int num_returned_bytes;
    num_returned_bytes = asprintf(&old_logfile, "%s/log-%s", workdir, prefix);
    if (num_returned_bytes == -1)
        sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 231);
    unlink(old_logfile);
    free(old_logfile);
    if (logfp == ((void *)0)) {
        do { if(!(workdir && prefix)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "workdir && prefix", getpid(), __func__, 236); return (-1); } } while(0);
        char *forced_workdir = 0;
        num_returned_bytes = asprintf(&logfile, "%s/%s.log", workdir, prefix);
        if (num_returned_bytes == -1)
            sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 251);
        free(forced_workdir);
        sp_log_reinit();
    }
    return logfp ? 0 : -1;
}

canonical_original_code:
int sp_log_init(char *workdir, char *prefix)
{
    char *old_logfile;
    int num_returned_bytes;
    num_returned_bytes = asprintf(&old_logfile, "%s/log-%s", workdir, prefix);
    if (num_returned_bytes == -1)
        sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 231);
    unlink(old_logfile);
    free(old_logfile);
    if (logfp == ((void *)0)) {
        do { if(!(workdir && prefix)) { sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "assert failed: " "workdir && prefix", getpid(), __func__, 236); return (-1); } } while(0);
        char *forced_workdir = 0;
        num_returned_bytes = asprintf(&logfile, "%s/%s.log", workdir, prefix);
        if (num_returned_bytes == -1)
            sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 251);
        free(forced_workdir);
        sp_log_reinit();
    }
    return logfp ? 0 : -1;
}

variable_types:
workdir
char *

variable_types:
prefix
char *


decompiled_code:
void sp_log_close()
{
if ( logfp )
{
fclose(logfp);
logfp = 0LL;
free(logfile);
logfile = 0LL;
}
}

canonical_decompiled_code:
void func9()
{
if ( logfp )
{
fclose(logfp);
logfp = 0LL;
free(logfile);
logfile = 0LL;
}
}

original_code:
void sp_log_close(void)
{
    if(logfp)
    {
        fclose(logfp);
        logfp = 0;
        free(logfile);
        logfile = 0;
    }
}

canonical_original_code:
void sp_log_close()
{
    if(logfp)
    {
        fclose(logfp);
        logfp = 0;
        free(logfile);
        logfile = 0;
    }
}


decompiled_code:
_BOOL8 __fastcall share_skip_file(char *s)
{
_BOOL8 result; // rax
char *v2; // rdx

result = 1LL;
if ( *s != 46 )
{
v2 = strchr(s, 36);
result = 1LL;
if ( !v2 )
result = strchr(s, 124) != 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *s)
{
_BOOL8 result; // rax
char *v2; // rdx

result = 1LL;
if ( *s != 46 )
{
v2 = strchr(s, 36);
result = 1LL;
if ( !v2 )
result = strchr(s, 124) != 0LL;
}
return result;
}

original_code:
static int share_skip_file(const char *filename)
{
    if(filename[0] == '.')
        return 1;
    if(strchr(filename, '$') != ((void *)0))
        return 1;
    if(strchr(filename, '|') != ((void *)0))
        return 1;
    return 0;
}

canonical_original_code:
static int share_skip_file(char *filename)
{
    if(filename[0] == '.')
        return 1;
    if(strchr(filename, '$') != ((void *)0))
        return 1;
    if(strchr(filename, '|') != ((void *)0))
        return 1;
    return 0;
}

variable_types:
filename
char *


decompiled_code:
char *__fastcall share_scan_absolute_path(const char *a1, const char *a2)
{
char *v2; // rbx
char *result; // rax
unsigned int v4; // eax
unsigned int v5; // eax
char *ptr; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)g_utf8_validate(a2, -1LL, 0LL) )
{
v2 = strdup(a2);
if ( asprintf(&ptr, "%s/%s", a1, v2) == -1 )
{
v5 = getpid();
sp_log(64LL, "[%d] (%s:%i) asprintf did not return anything", v5, "share_scan_absolute_path", 251LL);
}
free(v2);
result = ptr;
}
else
{
v4 = getpid();
sp_log(16LL, "[%d] (%s:%i) Unknown encoding in filename [%s]", v4, "share_scan_absolute_path", 233LL, a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, const char *a2)
{
char *v2; // rbx
char *result; // rax
unsigned int v4; // eax
unsigned int v5; // eax
char *ptr; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)g_utf8_validate(a2, -1LL, 0LL) )
{
v2 = strdup(a2);
if ( asprintf(&ptr, "%s/%s", a1, v2) == -1 )
{
v5 = getpid();
sp_log(64LL, "[%d] (%s:%i) asprintf did not return anything", v5, "share_scan_absolute_path", 251LL);
}
free(v2);
result = ptr;
}
else
{
v4 = getpid();
sp_log(16LL, "[%d] (%s:%i) Unknown encoding in filename [%s]", v4, "share_scan_absolute_path", 233LL, a2);
result = 0LL;
}
return result;
}

original_code:
static char *share_scan_absolute_path(const char *dirpath,
        const char *filename)
{
    if (!g_utf8_validate(filename, -1, ((void *)0))) {
        sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "Unknown encoding in filename [%s]", getpid(), __func__, 233, filename);
        return ((void *)0);
    }
    char *utf8_filename = strdup(filename);
    char *filepath;
    int num_returned_bytes = asprintf(&filepath, "%s/%s", dirpath, utf8_filename);
    if (num_returned_bytes == -1)
        sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 251);
    free(utf8_filename);
    return filepath;
}

canonical_original_code:
static char *share_scan_absolute_path(char *dirpath, char *filename)
{
    if (!g_utf8_validate(filename, -1, ((void *)0))) {
        sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "Unknown encoding in filename [%s]", getpid(), __func__, 233, filename);
        return ((void *)0);
    }
    char *utf8_filename = strdup(filename);
    char *filepath;
    int num_returned_bytes = asprintf(&filepath, "%s/%s", dirpath, utf8_filename);
    if (num_returned_bytes == -1)
        sp_log(LOG_LEVEL_DEBUG, "[%d] (%s:%i) " "asprintf did not return anything", getpid(), __func__, 251);
    free(utf8_filename);
    return filepath;
}

variable_types:
dirpath
char *

variable_types:
filepath
char *


repo: samirfor/samirforshell

decompiled_code:
char *get_usuario()
{
return getenv("USER");
}

canonical_decompiled_code:
char *func0()
{
return getenv("USER");
}

original_code:
char * get_usuario() {
    char *str = getenv("USER");
    return str;
}

canonical_original_code:
char *get_usuario() {
    char *str = getenv("USER");
    return str;
}

variable_types:
str
char *


decompiled_code:
char *get_maquina()
{
char *v0; // rbx

v0 = (char *)(int)input_malloc();
*(_QWORD *)v0 = 0x736F686C61636F6CLL;
*(_WORD *)((char *)&loc_4 + (_QWORD)v0 + 4) = 116;
gethostname(v0, 0x19uLL);
return v0;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rbx

v0 = (char *)(int)input_malloc();
*(_QWORD *)v0 = 0x736F686C61636F6CLL;
*(_WORD *)((char *)&loc_4 + (_QWORD)v0 + 4) = 116;
gethostname(v0, 0x19uLL);
return v0;
}

original_code:
char * get_maquina() {
    char *str = input_malloc();
    strcpy(str, "localhost");
    gethostname(str, 25);
    return str;
}

canonical_original_code:
char *get_maquina() {
    char *str = input_malloc();
    strcpy(str, "localhost");
    gethostname(str, 25);
    return str;
}


decompiled_code:
char *get_caminho_inicial()
{
return getenv("PWD");
}

canonical_decompiled_code:
char *func2()
{
return getenv("PWD");
}

original_code:
char * get_caminho_inicial() {
    char *str = getenv("PWD");
    return str;
}

canonical_original_code:
char *get_caminho_inicial() {
    char *str = getenv("PWD");
    return str;
}


decompiled_code:
char *get_caminho_atual()
{
return getcwd(0LL, 0LL);
}

canonical_decompiled_code:
char *func3()
{
return getcwd(0LL, 0LL);
}

original_code:
char * get_caminho_atual() {
    char *str = getcwd(((void *)0), 0);
    return str;
}

canonical_original_code:
char *get_caminho_atual() {
    char *str = getcwd(((void *)0), 0);
    return str;
}


decompiled_code:
int limpar_tela()
{
return system("clear");
}

canonical_decompiled_code:
int func4()
{
return system("clear");
}

original_code:
void limpar_tela() {
    system("clear");
}

canonical_original_code:
void limpar_tela() {
    system("clear");
}


decompiled_code:
__int64 __fastcall do_cd(char *a1)
{
char *v1; // rax
int v2; // edx
__int64 result; // rax

strtok(a1, " ");
v1 = strtok(0LL, " ");
v2 = chdir(v1);
result = 1LL;
if ( v2 == -1 )
{
puts("Ops, diretorio nao encontrado.");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
char *v1; // rax
int v2; // edx
__int64 result; // rax

strtok(a1, " ");
v1 = strtok(0LL, " ");
v2 = chdir(v1);
result = 1LL;
if ( v2 == -1 )
{
puts("Ops, diretorio nao encontrado.");
result = 0LL;
}
return result;
}

original_code:
int do_cd(char * comando) {
    char* caminho;
    int cod_retorno;
    strtok(comando, " ");
    caminho = strtok(((void *)0), " ");
    cod_retorno = chdir(caminho);
    if (cod_retorno == -1) {
        printf("Ops, diretorio nao encontrado.\n");
        return 0;
    }
    return 1;
}

canonical_original_code:
int do_cd(char *comando) {
    char *caminho;
    int cod_retorno;
    strtok(comando, " ");
    caminho = strtok(((void *)0), " ");
    cod_retorno = chdir(caminho);
    if (cod_retorno == -1) {
        printf("Ops, diretorio nao encontrado.\n");
        return 0;
    }
    return 1;
}

variable_types:
comando
char *

variable_types:
caminho
char *


trim

decompiled_code:
void *__fastcall trim(void *src)
{
__int64 i; // rbx
int v3; // ebp
char v5; // di
char *j; // rbx

for ( i = (int)strlen((const char *)src); ; *((_BYTE *)src + i) = 0 )
{
v3 = i;
if ( !isspace(*((char *)src + --i)) )
break;
}
v5 = *(_BYTE *)src;
for ( j = (char *)src; *j; v5 = *j )
{
if ( !isspace(v5) )
break;
++j;
--v3;
}
return memmove(src, j, v3 + 1);
}

canonical_decompiled_code:
void *__fastcall func7(void *src)
{
__int64 i; // rbx
int v3; // ebp
char v5; // di
char *j; // rbx

for ( i = (int)strlen((const char *)src); ; *((_BYTE *)src + i) = 0 )
{
v3 = i;
if ( !isspace(*((char *)src + --i)) )
break;
}
v5 = *(_BYTE *)src;
for ( j = (char *)src; *j; v5 = *j )
{
if ( !isspace(v5) )
break;
++j;
--v3;
}
return memmove(src, j, v3 + 1);
}

original_code:
void trim(char * str) {
    char * aux = str;
    int l = strlen(aux);
    while (isspace(aux[l - 1])) aux[--l] = 0;
    while (* aux && isspace(* aux)) ++aux, --l;
    memmove(str, aux, l + 1);
}

canonical_original_code:
void trim(char *str) {
    char *aux = str;
    int l = strlen(aux);
    while (isspace(aux[l - 1])) aux[--l] = 0;
    while (* aux && isspace(* aux)) ++aux, --l;
    memmove(str, aux, l + 1);
}

variable_types:
aux
char *

variable_types: l int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // rbp
char *v5; // r12
void *v6; // rbx

puts("::: S@mirforShell :::\n");
puts(">>> Criado por Samir <samirfor@gmail.com>");
puts("Este programa esta sob a GNU General Public License v3 <http://www.gnu.org/licenses/>");
puts("Para finalizar o programa use o comando \"sair\"\n");
v3 = get_usuario();
v4 = get_caminho_inicial();
v5 = get_maquina();
v6 = (void *)(int)input_malloc("Para finalizar o programa use o comando \"sair\"\n", argv);
do
{
printf("+%s em %s::%s$ ", v3, v5, v4);
read_string(v6);
trim(v6);
if ( (unsigned int)regexp_match("^cd ", (char *)v6) )
{
do_cd((char *)v6);
v4 = get_caminho_atual();
}
else if ( !strcasecmp((const char *)v6, "limpar") )
{
limpar_tela();
}
else
{
system((const char *)v6);
}
}
while ( strcmp((const char *)v6, "sair") );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r13
char *v4; // rbp
char *v5; // r12
void *v6; // rbx

puts("::: S@mirforShell :::\n");
puts(">>> Criado por Samir <samirfor@gmail.com>");
puts("Este programa esta sob a GNU General Public License v3 <http://www.gnu.org/licenses/>");
puts("Para finalizar o programa use o comando \"sair\"\n");
v3 = func0();
v4 = func2();
v5 = func1();
v6 = (void *)(int)input_malloc("Para finalizar o programa use o comando \"sair\"\n", argv);
do
{
printf("+%s em %s::%s$ ", v3, v5, v4);
read_string(v6);
func7(v6);
if ( (unsigned int)func6("^cd ", (char *)v6) )
{
func5((char *)v6);
v4 = func3();
}
else if ( !strcasecmp((const char *)v6, "limpar") )
{
func4();
}
else
{
system((const char *)v6);
}
}
while ( strcmp((const char *)v6, "sair") );
return 0;
}

original_code:
int main(int argc, char * argv[]) {
    printf("::: S@mirforShell :::\n\n");
    printf(">>> Criado por Samir <samirfor@gmail.com>\n");
    printf("Este programa esta sob a GNU General Public License v3 <http://www.gnu.org/licenses/>\n");
    printf("Para finalizar o programa use o comando \"sair\"\n\n");
    char * input;
    char * usuario;
    char * caminho_atual;
    char * maquina;
    usuario = get_usuario();
    caminho_atual = get_caminho_inicial();
    maquina = get_maquina();
    input = input_malloc();
    do {
        printf("+%s em %s::%s$ ", usuario, maquina, caminho_atual);
        read_string(input);
        trim(input);
        if (regexp_match("^cd ", input)) {
            do_cd(input);
            caminho_atual = get_caminho_atual();
        } else if (!strcasecmp(input, "limpar")) {
            limpar_tela();
        } else {
            system(input);
        }
    } while (strcmp(input, "sair"));
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    printf("::: S@mirforShell :::\n\n");
    printf(">>> Criado por Samir <samirfor@gmail.com>\n");
    printf("Este programa esta sob a GNU General Public License v3 <http://www.gnu.org/licenses/>\n");
    printf("Para finalizar o programa use o comando \"sair\"\n\n");
    char *input;
    char *usuario;
    char *caminho_atual;
    char *maquina;
    usuario = get_usuario();
    caminho_atual = get_caminho_inicial();
    maquina = get_maquina();
    input = input_malloc();
    do {
        printf("+%s em %s::%s$ ", usuario, maquina, caminho_atual);
        read_string(input);
        trim(input);
        if (regexp_match("^cd ", input)) {
            do_cd(input);
            caminho_atual = get_caminho_atual();
        } else if (!strcasecmp(input, "limpar")) {
            limpar_tela();
        } else {
            system(input);
        }
    } while (strcmp(input, "sair"));
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
input
char *

variable_types:
usuario
char *

variable_types:
maquina
char *