// File: /workspace/github_cpp_makefile_star2_O2/Alcaro[P]bridges/arlib/json.cpp
// Function: jsonwriter::strwrap(cstring)
string jsonwriter::strwrap(cstring s)
{
	const uint8_t * sp = s.bytes().ptr();
	const uint8_t * spe = sp + s.length();
	
	string out = "\"";
	const uint8_t * previt = sp;
	for (const uint8_t * it = sp; it < spe; it++)
	{
#ifdef __SSE2__
		if (spe-it >= 16)
		{
			__m128i chs = _mm_loadu_si128((__m128i*)it);
			
			__m128i bad1 = _mm_cmplt_epi8(_mm_xor_si128(chs, _mm_set1_epi8(0x82)), _mm_set1_epi8((int8_t)(0x21^0x80)));
			__m128i bad2 = _mm_or_si128(_mm_cmpeq_epi8(chs, _mm_set1_epi8(0x7F)), _mm_cmpeq_epi8(chs, _mm_set1_epi8(0x5C)));
			__m128i bad = _mm_or_si128(bad1, bad2);
			int mask = _mm_movemask_epi8(bad);
			if (mask == 0)
			{
				it += 16-1; // -1 for the it++ above (oddly enough, this way is faster)
				continue;
			}
			it += ctz32(mask);
		}
#endif
		
		uint8_t c = *it;
		// DEL is legal according to nst/JSONTestSuite, but let's avoid it anyways
		if ((c^2) <= 32 || c == '\\' || c == 0x7F)
		{
			out += arrayview<uint8_t>(previt, it-previt);
			previt = it+1;
			
			if(0);
			else if (c=='\n') out += "\\n";
			else if (c=='\r') out += "\\r";
			else if (c=='\t') out += "\\t";
			else if (c=='\b') out += "\\b";
			else if (c=='\f') out += "\\f";
			else if (c=='\"') out += "\\\"";
			else if (c=='\\') out += "\\\\";
			else out += "\\u"+tostringhex<4>(c);
		}
	}
	out += arrayview<uint8_t>(previt, spe-previt);
	return out+"\"";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
movq %rdi, (%rsp)
leaq 0x58(%rsp), %rax
movq %rsi, (%rax)
movq %rdx, 0x8(%rax)
movq %rdx, %rcx
shrq $0x38, %rcx
xorl $0xf, %ecx
testq %rdx, %rdx
cmovnsq %rax, %r14
cmovsq %rdx, %rcx
movl %ecx, %r15d
addq %r14, %r15
leaq 0x1848e(%rip), %rsi     # 0x2834f
leaq 0x38(%rsp), %r12
movq %r12, %rdi
callq 0x4242
leaq 0x18b0b(%rip), %r13     # 0x289e0
movq %r14, %rbp
cmpq %r15, %r14
jae 0x10064
movq %r15, %rax
subq %r14, %rax
cmpq $0x10, %rax
jl 0xff38
movdqu (%r14), %xmm0
movdqa %xmm0, %xmm1
pxor 0x18a82(%rip), %xmm1    # 0x28980
movdqa 0x18a8a(%rip), %xmm2    # 0x28990
pcmpgtb %xmm1, %xmm2
movdqa %xmm0, %xmm1
pcmpeqb 0x18a9a(%rip), %xmm1    # 0x289b0
pcmpeqb 0x18a82(%rip), %xmm0    # 0x289a0
por %xmm1, %xmm0
por %xmm2, %xmm0
pmovmskb %xmm0, %eax
testl %eax, %eax
je 0xffbc
bsfl %eax, %eax
addq %rax, %r14
movb (%r14), %al
movl %eax, %ecx
xorb $0x2, %cl
movzbl %al, %ebx
cmpb $0x21, %cl
jb 0xff55
cmpb $0x7f, %al
je 0xff55
cmpl $0x5c, %ebx
jne 0x1005c
movq %r14, %rdx
subq %rbp, %rdx
leaq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x1045e
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r12, %rdi
callq 0x4296
leaq 0x1(%r14), %rbp
leal -0x8(%rbx), %eax
cmpl $0x5, %eax
ja 0xff9f
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq %r12, %rdi
leaq 0x18ac7(%rip), %rsi     # 0x28a61
jmp 0x10057
cmpl $0x22, %ebx
je 0x1004d
cmpl $0x5c, %ebx
jne 0xffc5
movq %r12, %rdi
leaq 0x18ab3(%rip), %rsi     # 0x28a6a
jmp 0x10057
addq $0xf, %r14
jmp 0x1005c
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movl %ebx, %esi
callq 0x10493
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
leaq 0x18a80(%rip), %rsi     # 0x28a6d
callq 0x41b8
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r12, %rdi
callq 0x4296
movq %rbx, %rdi
callq 0x56b4
movq %r13, %rdi
leaq 0x189ca(%rip), %r13     # 0x289e0
callq 0x56b4
jmp 0x1005c
movq %r12, %rdi
leaq 0x18a37(%rip), %rsi     # 0x28a5e
jmp 0x10057
movq %r12, %rdi
leaq 0x18a25(%rip), %rsi     # 0x28a58
jmp 0x10057
movq %r12, %rdi
leaq 0x18a25(%rip), %rsi     # 0x28a64
jmp 0x10057
movq %r12, %rdi
leaq 0x18a10(%rip), %rsi     # 0x28a5b
jmp 0x10057
movq %r12, %rdi
leaq 0x18a10(%rip), %rsi     # 0x28a67
callq 0x426a
incq %r14
jmp 0xfed8
subq %rbp, %r15
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1045e
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x4296
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
leaq 0x182b3(%rip), %rcx     # 0x2834f
movq (%rsp), %r14
movq %r14, %rdi
callq 0x5ee3
movq %rbx, %rdi
callq 0x56b4
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq