//
// sub_140059D70 from 0x140059d70 to 0x140059e6e (254 bytes)
//
// 49 xrefs:
// > CCTextInputNode::insertAtCursor @ 0x1400550ef
// > CCTextInputNode::onTextFieldInsertText @ 0x140057519
// > AutoSaveSettingsLayer::updateBackupDirLabel @ 0x14009cdab
// > sub_14009D5A0 @ 0x14009d5d1
// > AdminActionConfirmPopup::init @ 0x1400a59c0
// > sub_1400AD8F0 @ 0x1400ade4c
// > AccountReviewPopup::updateCard @ 0x1400b133a
// > AccountReviewPopup::updateCard @ 0x1400b17a6
// > AccountReviewPopup::updateCard @ 0x1400b1f50
// > AccountReviewPopup::updateCard @ 0x1400b2286
// > AccountReviewPopup::buildReportedRows @ 0x1400b50d0
// > AccountReviewPopup::buildHistoryRows @ 0x1400b7fbe
// > AccountReviewPopup::onDone @ 0x1400b9c7c
// > AccountReviewPopup::adminClearReportsFinished @ 0x1400bab7b
// > AccountReviewPopup::FLAlert_Clicked @ 0x1400bb7ac
// > AccountReviewPopup::adminCloseCaseFinished @ 0x1400bcc90
// > ReportPopup::init @ 0x1400c0cf7
// > MemberListPopup::applyAddOutcome @ 0x1400ee349
// > MemberListPopup::applyAddOutcome @ 0x1400ee4b8
// > MemberListPopup::applyAddOutcome @ 0x1400ee627
// > NewThreadPopup::updateRecipientLabel @ 0x1400f1bad
// > ThreadOptionsPopup::init @ 0x1400f471c
// > InvitesPopup::buildRows @ 0x1400f86bc
// > ThreadRequestPopup::init @ 0x1400ff22b
// > DeathTrackerPopup::dtScrollKey @ 0x1401066bc
// > DeathTrackerPopup::onToggleGlobal @ 0x14010d94f
// > DeathTrackerPopup::onClose @ 0x14010e7b5
// > CustomSFXWidget::onShowInfo @ 0x140163437
// > CustomSFXWidget::onShowInfo @ 0x140163455
// > EndLevelLayer::customSetup @ 0x1402045c8
// > GameLevelManager::getDeathData @ 0x1402284ba
// > GameLevelManager::getDeathData @ 0x140228564
// > GameLevelManager::uploadLevelControls @ 0x140258f21
// > GameLevelManager::deleteLevelControls @ 0x14025969c
// > GameLevelManager::getLevelControls @ 0x140259cf5
// > LevelInfoLayer::setupPlatformerStats @ 0x14041f6c0
// > construct_environment_block @ 0x14046e677
// > LocalLevelManager::exportLevelsToFile @ 0x14046ea4d
// > sub_140485FC0 @ 0x1404860ed
// > sub_140485FC0 @ 0x140486109
// > MusicDownloadManager::getCustomSFXRawPath @ 0x140486e8a
// > MusicDownloadManager::getCustomSFXRawPath @ 0x140486f08
// > MusicDownloadManager::parseMusicLibrary @ 0x14048d763
// > PauseLayer::setupPlatformerLabels @ 0x1404da950
// > SFXBrowser::setupList @ 0x140619edf
// > SFXBrowser::setupList @ 0x140619efd
// > ??> @ 0x140887670
// > ??> @ 0x140887680
// > ??> @ 0x1409105f8
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:25:41 +0000
//
__int64 __fastcall sub_140059D70(_QWORD *a1, unsigned __int64 a2, char *a3, size_t a4)
{
unsigned __int64 v6; // r8
_QWORD *v7; // rdi
unsigned __int64 v8; // r9
_BYTE *v9; // r15
size_t v10; // rsi
v6 = a1[2];
v7 = a1;
if ( v6 < a2 )
sub_14003F4D0(a1, a2, v6, a4);
v8 = a1[3];
if ( a4 > v8 - v6 )
return sub_140059FF0(a1, a3, a4);
a1[2] = v6 + a4;
if ( v8 > 0xF )
a1 = (_QWORD *)*a1;
v9 = (char *)a1 + a2;
if ( &a3[a4] <= (char *)a1 + a2 || a3 > (char *)a1 + v6 )
{
v10 = a4;
}
else if ( v9 > a3 )
{
v10 = v9 - a3;
}
else
{
v10 = 0;
}
memmove(&v9[a4], v9, v6 - a2 + 1);
memcpy(v9, a3, v10);
memcpy(&v9[v10], &a3[v10 + a4], a4 - v10);
return (__int64)v7;
}