// File: menhits[P]phplus/src/msclStringFuncs.cpp
// Function: getUniqueString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::function<bool (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)>, bool)
string getUniqueString(string hint, std::function<bool (string)> checker, bool alwaysAppendRandom)
{
	string out=hint;
	
	int attempts=0;
	bool invalid=out.empty() || !checker(out) || alwaysAppendRandom;
	
	while (invalid)
	{
		if (alwaysAppendRandom || attempts>=10)
		{
			out=hint+"_";
			
			if (attempts>20)
			{
				throw PhplusError("could not find unique random name", INTERNAL_ERROR);
			}
			
			for (int i=0; i<3; i++)
				out+=getRandChar();
		}
		else
		{
			string suffix=to_string(attempts);
			
			out=hint+"_"+suffix;
		}
		attempts++;
		invalid=!checker(out);
	}
	
	return out;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdx, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, 0x40(%rsp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, 0x38(%rsp)
movq %rdi, 0x180(%rsp)
movq %rsi, 0x178(%rsp)
movq %rdx, 0x170(%rsp)
andb $0x1, %al
movb %al, 0x16f(%rsp)
movb $0x0, 0x16e(%rsp)
callq 0xb1a0
movq 0x40(%rsp), %rdi
movl $0x0, 0x168(%rsp)
callq 0xb610
movb %al, %cl
movb $0x0, 0x133(%rsp)
movb $0x1, %al
testb $0x1, %cl
movb %al, 0x4f(%rsp)
jne 0xad098
movq 0x40(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0xb1a0
jmp 0xad05c
movq 0x28(%rsp), %rdi
movb $0x1, 0x133(%rsp)
leaq 0x140(%rsp), %rsi
callq 0xadd90
movb %al, 0x27(%rsp)
jmp 0xad07c
movb 0x27(%rsp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, 0x4f(%rsp)
jne 0xad08d
jmp 0xad098
movb 0x16f(%rsp), %al
movb %al, 0x4f(%rsp)
movb 0x4f(%rsp), %al
movb %al, 0x26(%rsp)
testb $0x1, 0x133(%rsp)
jne 0xad0ac
jmp 0xad0b9
leaq 0x140(%rsp), %rdi
callq 0xb6e8
movb 0x26(%rsp), %al
andb $0x1, %al
movb %al, 0x167(%rsp)
testb $0x1, 0x167(%rsp)
je 0xad407
testb $0x1, 0x16f(%rsp)
jne 0xad0ec
cmpl $0xa, 0x168(%rsp)
jl 0xad2cb
movq 0x30(%rsp), %rsi
leaq 0x2991e(%rip), %rdx     # 0xd6a16
leaq 0x110(%rsp), %rdi
callq 0x1ba50
jmp 0xad107
movq 0x40(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0xb450
leaq 0x110(%rsp), %rdi
callq 0xb6e8
cmpl $0x14, 0x168(%rsp)
jle 0xad288
movb $0x1, 0xd7(%rsp)
movl $0x38, %edi
callq 0xb1f0
movq %rax, 0x10(%rsp)
leaq 0xef(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0xb690
movq 0x18(%rsp), %rdx
leaq 0x29976(%rip), %rsi     # 0xd6adf
leaq 0xf0(%rsp), %rdi
callq 0xb4c0
jmp 0xad178
xorl %eax, %eax
movl %eax, %esi
leaq 0xd8(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xfbe0
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rcx
leaq 0xf0(%rsp), %rsi
movl $0x3, %edx
callq 0x35600
jmp 0xad1ac
movq 0x10(%rsp), %rdi
movb $0x0, 0xd7(%rsp)
leaq 0x68408(%rip), %rsi     # 0x1155c8
leaq -0x92b57(%rip), %rdx    # 0x1a670
callq 0xb640
jmp 0xad447
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0xad430
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
testb $0x1, 0x133(%rsp)
jne 0xad20a
jmp 0xad217
leaq 0x140(%rsp), %rdi
callq 0xb6e8
jmp 0xad430
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0xad260
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0xfc00
leaq 0xf0(%rsp), %rdi
callq 0xb6e8
leaq 0xef(%rsp), %rdi
callq 0xb3f0
testb $0x1, 0xd7(%rsp)
jne 0xad279
jmp 0xad283
movq 0x10(%rsp), %rdi
callq 0xb2d0
jmp 0xad430
movl $0x0, 0xd0(%rsp)
cmpl $0x3, 0xd0(%rsp)
jge 0xad2c6
callq 0xacf50
movq 0x40(%rsp), %rdi
movsbl %al, %esi
callq 0xb260
jmp 0xad2b1
jmp 0xad2b3
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0xad293
jmp 0xad393
movl 0x168(%rsp), %esi
leaq 0xb0(%rsp), %rdi
callq 0x2dc70
jmp 0xad2e1
movq 0x30(%rsp), %rsi
leaq 0x29729(%rip), %rdx     # 0xd6a16
leaq 0x70(%rsp), %rdi
callq 0x1ba50
jmp 0xad2f9
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x2e070
jmp 0xad315
movq 0x40(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0xb450
leaq 0x90(%rsp), %rdi
callq 0xb6e8
leaq 0x70(%rsp), %rdi
callq 0xb6e8
leaq 0xb0(%rsp), %rdi
callq 0xb6e8
jmp 0xad393
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0xad381
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0x70(%rsp), %rdi
callq 0xb6e8
leaq 0xb0(%rsp), %rdi
callq 0xb6e8
jmp 0xad430
movq 0x40(%rsp), %rsi
movl 0x168(%rsp), %eax
incl %eax
movl %eax, 0x168(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xb1a0
jmp 0xad3b4
movq 0x28(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xadd90
movb %al, 0x7(%rsp)
jmp 0xad3c9
movb 0x7(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x167(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xb6e8
jmp 0xad0c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xb6e8
jmp 0xad430
movb $0x1, 0x16e(%rsp)
testb $0x1, 0x16e(%rsp)
jne 0xad423
movq 0x40(%rsp), %rdi
callq 0xb6e8
movq 0x38(%rsp), %rax
addq $0x188, %rsp            # imm = 0x188
retq
movq 0x40(%rsp), %rdi
callq 0xb6e8
movq 0x138(%rsp), %rdi
callq 0xb680
nopw (%rax,%rax)