// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rdi, 0x40(%rsp)
leaq 0x68(%rsp), %rax
movq %rsi, (%rax)
movq %rdx, 0x8(%rax)
movq %rdx, %rcx
shrq $0x38, %rcx
xorl $0xf, %ecx
testq %rdx, %rdx
cmovnsq %rax, %rbx
cmovnsl %ecx, %edx
leaq (%rdx,%rbx), %r14
movw $0x22, 0x30(%rsp)
movb $0xe, 0x3f(%rsp)
testl %edx, %edx
je 0x142a8
leaq 0x30(%rsp), %r13
leaq 0x1ba04(%rip), %r12     # 0x2fa80
movq %rbx, %r15
movq %r14, %rax
subq %r15, %rax
cmpq $0x10, %rax
jl 0x140d6
movdqu (%r15), %xmm0
movdqa %xmm0, %xmm1
pxor 0x1b984(%rip), %xmm1    # 0x2fa20
movdqa 0x1b98c(%rip), %xmm2    # 0x2fa30
pcmpgtb %xmm1, %xmm2
movdqa %xmm0, %xmm1
pcmpeqb 0x1b99c(%rip), %xmm1    # 0x2fa50
pcmpeqb 0x1b984(%rip), %xmm0    # 0x2fa40
por %xmm1, %xmm0
por %xmm2, %xmm0
pmovmskb %xmm0, %eax
testl %eax, %eax
je 0x14189
bsfl %eax, %eax
addq %rax, %r15
movb (%r15), %al
movl %eax, %ecx
xorb $0x2, %cl
movzbl %al, %ebp
cmpb $0x21, %cl
jb 0x140f3
cmpb $0x7f, %al
je 0x140f3
cmpl $0x5c, %ebp
jne 0x1429c
movq %r15, %rdx
subq %rbx, %rdx
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x5990
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rax
movq %rsi, (%rsp)
movq %rax, 0x8(%rsp)
movq %rax, %rcx
shrq $0x38, %rcx
xorq $0xf, %rcx
testq %rax, %rax
movl %eax, %edx
cmovnsq %rcx, %rdx
movq %rsp, %rax
cmovnsq %rax, %rsi
movq %r13, %rdi
callq 0x1967e
leaq 0x1(%r15), %rbx
leal -0x8(%rbp), %eax
cmpl $0x5, %eax
ja 0x14167
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1b99f(%rip), %rsi     # 0x2fb01
jmp 0x14297
cmpl $0x22, %ebp
je 0x14288
cmpl $0x5c, %ebp
jne 0x14192
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1b986(%rip), %rsi     # 0x2fb0a
jmp 0x14297
addq $0xf, %r15
jmp 0x1429c
movl $0x4, %edx
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x1b137
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)
movq %rax, %rcx
shrq $0x38, %rcx
xorq $0xf, %rcx
testq %rax, %rax
movl %eax, %edx
cmovnsq %rcx, %rdx
movq %rsp, %rbp
cmovnsq %rbp, %rsi
leaq 0x10(%rsp), %rdi
callq 0x1967e
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
movq %rsi, (%rsp)
movq %rax, 0x8(%rsp)
movq %rax, %rcx
shrq $0x38, %rcx
xorq $0xf, %rcx
testq %rax, %rax
movl %eax, %edx
cmovnsq %rcx, %rdx
cmovnsq %rbp, %rsi
movq %r13, %rdi
callq 0x1967e
cmpb $0x0, 0x1f(%rsp)
jns 0x14231
movq 0x10(%rsp), %rdi
callq 0x3430
cmpb $0x0, 0x2f(%rsp)
jns 0x1429c
movq 0x20(%rsp), %rdi
callq 0x3430
jmp 0x1429c
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1b8ab(%rip), %rsi     # 0x2fafe
jmp 0x14297
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1b894(%rip), %rsi     # 0x2faf8
jmp 0x14297
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1b88f(%rip), %rsi     # 0x2fb04
jmp 0x14297
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1b875(%rip), %rsi     # 0x2fafb
jmp 0x14297
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1b870(%rip), %rsi     # 0x2fb07
callq 0x1967e
incq %r15
cmpq %r14, %r15
jb 0x1407f
subq %rbx, %r14
leaq 0x58(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x5990
movq (%r12), %rsi
movq 0x8(%r12), %rax
movq %rsp, %rbx
movq %rsi, (%rbx)
movq %rax, 0x8(%rbx)
movq %rax, %rcx
shrq $0x38, %rcx
xorq $0xf, %rcx
testq %rax, %rax
movl %eax, %edx
cmovnsq %rcx, %rdx
cmovnsq %rbx, %rsi
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x1967e
movups (%r14), %xmm0
movups %xmm0, (%rbx)
movq %rsp, %rsi
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x19592
leaq 0x1b039(%rip), %rsi     # 0x2f34f
movl $0x1, %edx
movq %rbx, %rdi
callq 0x1967e
cmpb $0x0, 0xf(%r14)
jns 0x14334
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