// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movq %rsi, %r15
leaq 0x68(%rsp), %rax
movq %rsi, (%rax)
movq %rdx, 0x8(%rax)
movzbl 0xf(%rax), %ecx
movl %ecx, %esi
xorl $0xf, %esi
testb %cl, %cl
cmovnsq %rax, %r15
cmovnsl %esi, %edx
leaq (%rdx,%r15), %r14
movw $0x22, 0x30(%rsp)
movb $0xe, 0x3f(%rsp)
testl %edx, %edx
movq %rdi, 0x40(%rsp)
je 0x1402c
leaq 0x30(%rsp), %r13
leaq 0x1bc64(%rip), %r12     # 0x2fa60
movq %r15, %rax
movq %r14, %rcx
subq %rax, %rcx
cmpq $0x10, %rcx
jl 0x13e5e
movdqu (%rax), %xmm0
movdqa %xmm0, %xmm1
pxor 0x1bbe5(%rip), %xmm1    # 0x2fa00
movdqa 0x1bbed(%rip), %xmm2    # 0x2fa10
pcmpgtb %xmm1, %xmm2
movdqa %xmm0, %xmm1
pcmpeqb 0x1bbfd(%rip), %xmm1    # 0x2fa30
pcmpeqb 0x1bbe5(%rip), %xmm0    # 0x2fa20
por %xmm1, %xmm0
por %xmm2, %xmm0
pmovmskb %xmm0, %ecx
bsfl %ecx, %ebx
movl $0xf, %edx
cmovel %edx, %ebx
addq %rax, %rbx
testl %ecx, %ecx
jne 0x13e61
jmp 0x1401d
movq %rax, %rbx
movb (%rbx), %al
movl %eax, %ecx
xorb $0x2, %cl
movzbl %al, %ebp
cmpb $0x21, %cl
jb 0x13e7d
cmpb $0x7f, %al
je 0x13e7d
cmpl $0x5c, %ebp
jne 0x1401d
movq %rbx, %rdx
subq %r15, %rdx
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x5040
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rax
movq %rsi, (%rsp)
movq %rax, 0x8(%rsp)
movzbl 0xf(%rsp), %ecx
movq %rcx, %rdi
xorq $0xf, %rdi
testb %cl, %cl
movl %eax, %edx
movq %rsp, %rax
cmovnsq %rax, %rsi
cmovnsq %rdi, %rdx
movq %r13, %rdi
callq 0x19466
leaq 0x1(%rbx), %r15
leal -0x8(%rbp), %eax
cmpl $0x5, %eax
ja 0x13ef1
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1bbf5(%rip), %rsi     # 0x2fae1
jmp 0x14018
cmpl $0x22, %ebp
je 0x14009
cmpl $0x5c, %ebp
jne 0x13f13
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1bbdc(%rip), %rsi     # 0x2faea
jmp 0x14018
movl $0x4, %edx
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x1b7eb
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
movw $0x755c, 0x10(%rsp)     # imm = 0x755C
movb $0x0, 0x12(%rsp)
movb $0xd, 0x1f(%rsp)
movq %rsi, (%rsp)
movq %rax, 0x8(%rsp)
movzbl 0xf(%rsp), %ecx
movq %rcx, %rdi
xorq $0xf, %rdi
testb %cl, %cl
movl %eax, %edx
movq %rsp, %rbp
cmovnsq %rbp, %rsi
cmovnsq %rdi, %rdx
leaq 0x10(%rsp), %rdi
callq 0x19466
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
movq %rsi, (%rsp)
movq %rax, 0x8(%rsp)
movzbl 0xf(%rsp), %ecx
movq %rcx, %rdi
xorq $0xf, %rdi
testb %cl, %cl
movl %eax, %edx
cmovnsq %rbp, %rsi
cmovnsq %rdi, %rdx
movq %r13, %rdi
callq 0x19466
cmpb $0x0, 0x1f(%rsp)
jns 0x13fb2
movq 0x10(%rsp), %rdi
callq 0x3430
cmpb $0x0, 0x2f(%rsp)
jns 0x1401d
movq 0x20(%rsp), %rdi
callq 0x3430
jmp 0x1401d
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1bb0a(%rip), %rsi     # 0x2fade
jmp 0x14018
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1baf3(%rip), %rsi     # 0x2fad8
jmp 0x14018
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1baee(%rip), %rsi     # 0x2fae4
jmp 0x14018
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1bad4(%rip), %rsi     # 0x2fadb
jmp 0x14018
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1bacf(%rip), %rsi     # 0x2fae7
callq 0x19466
incq %rbx
movq %rbx, %rax
cmpq %r14, %rbx
jb 0x13dff
subq %r15, %r14
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x5040
movq (%r12), %rsi
movq 0x8(%r12), %rax
movq %rsp, %rbx
movq %rsi, (%rbx)
movq %rax, 0x8(%rbx)
movzbl 0xf(%rbx), %ecx
movq %rcx, %rdi
xorq $0xf, %rdi
testb %cl, %cl
movl %eax, %edx
cmovnsq %rbx, %rsi
cmovnsq %rdi, %rdx
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x19466
movups (%r14), %xmm0
movups %xmm0, (%rbx)
movq %rsp, %rsi
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x19372
leaq 0x1b2c2(%rip), %rsi     # 0x2f35b
movl $0x1, %edx
movq %rbx, %rdi
callq 0x19466
cmpb $0x0, 0xf(%r14)
jns 0x140b7
movq 0x30(%rsp), %rdi
callq 0x3430
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop