// File: /workspace/github_c_makefile_star2_O1/TurkeyMcMac[P]ts3d/src/json.c
// Function: escape_char
static int escape_char(json_reader *reader, struct json_string *str,
	size_t *cap)
{
	/* Whether an extra hex-escaped codepoint was read which did not match
	 * the proceeding high surrogate: */
	int read_extra_cp = 0;
	/* Whether an extra non-hex escape was read: */
	int read_extra_escape = 0;
	/* The UTF-16 code units read (up to 2 are possible): */
	long utf16[2] = {-1, -1};
	/* The unicode codepoint if one was read, possibly from a surrogate
	 * pair: */
	long codepoint;
	/* The extra unpaired codepoint if it was read (-1 otherwise): */
	long extracp = -1;
	/* The UTF-8 version of a codepoint if it was read: */
	char utf8[4];
	/* The buffer of hex digits: */
	char buf[4];
	/* The amount some call to next_chars read: */
	long read;
	int ch = next_char(reader);
	if (ch < 0) goto error;
	switch (ch) {
	case 'b': ch = '\b'; break;
	case 'f': ch = '\f'; break;
	case 'n': ch = '\n'; break;
	case 'r': ch = '\r'; break;
	case 't': ch = '\t'; break;
	case '"': ch =  '"'; break;
	case'\\':/*Same as */break;
	case '/':/*escaped.*/break;
	case 'u':
		read = next_chars(reader, buf, 4);
		if (read < 4) goto error;
		utf16[0] = hex_short(buf);
		if (utf16[0] < 0) goto error;
		codepoint = utf16_to_codepoint(utf16[0]);
		if (is_high_surrogate(utf16[0])) {
			/* It wants a partner. */
			NEXT_CHAR(reader, ch, goto error);
			if (ch != '\\') {
				/* No partner; only normal chars were found: */
				reexamine_char(reader);
			} else {
				/* Escape follows. */
				NEXT_CHAR(reader, ch, goto error);
				if (ch == 'u') {
					/* Hex escape follows. */
					read = next_chars(reader, buf,
						4);
					if (read < 0) goto error;
					if (read < 4) goto error;
					utf16[1] = hex_short(buf);
					if (utf16[1] < 0) goto error;
					if (is_low_surrogate(utf16[1])) {
						/* Partner found. */
						codepoint =
							utf16_pair_to_codepoint(
							utf16[0], utf16[1]);
					} else {
						/* Extra codepoint found. */
						read_extra_cp = 1;
						extracp = utf16_to_codepoint(
								utf16[1]);
					}
				} else {
					/* Extra other escape was found, will be
					 * parsed below. (read_extra_escape) */
					reexamine_char(reader);
					read_extra_escape = 1;
				}
			}
		}
		if (push_bytes(reader, &str->bytes, &str->len, cap,
			utf8, codepoint_to_utf8(codepoint, utf8))) goto error;
		if (read_extra_cp) {
			if (push_bytes(reader, &str->bytes, &str->len, cap,
					utf8, codepoint_to_utf8(extracp, utf8)))
				goto error;
		} else if (read_extra_escape) {
			/* This will only every recurse once, since this can
			 * only occur for \uXXXX, but that is handled non-
			 * recursively. */
			if (escape_char(reader, str, cap)) goto error;
		}
		return 0;
	default:
		goto error;
	}
	if (push_byte(reader, &str->bytes, &str->len, cap, ch)) goto error;
	return 0;

error:
	set_error(reader, JSON_ERROR_ESCAPE);
	reexamine_char(reader);
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
callq 0x6099
testl %eax, %eax
js 0x6480
cmpl $0x61, %eax
jg 0x6352
cmpl $0x22, %eax
je 0x6467
cmpl $0x2f, %eax
je 0x6467
cmpl $0x5c, %eax
je 0x6467
jmp 0x6480
leal -0x6e(%rax), %ecx
cmpl $0x7, %ecx
ja 0x6374
leaq 0x620f(%rip), %rax      # 0xc570
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0xa, %eax
jmp 0x6467
cmpl $0x66, %eax
je 0x6462
cmpl $0x62, %eax
jne 0x6480
movl $0x8, %eax
jmp 0x6467
leaq 0x4(%rsp), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x6230
cmpq $0x4, %rax
jl 0x6480
leaq 0x4(%rsp), %rdi
callq 0x6552
testq %rax, %rax
js 0x6480
movq %rax, %r13
notl %eax
movq $-0x1, 0x10(%rsp)
movb $0x1, %cl
movl %ecx, 0x8(%rsp)
testl $0xd800, %eax           # imm = 0xD800
jne 0x64bd
movq %rbx, %rdi
callq 0x6099
testl %eax, %eax
js 0x6480
cmpl $0x5c, %eax
jne 0x64ab
movq %rbx, %rdi
callq 0x6099
testl %eax, %eax
js 0x6480
cmpl $0x75, %eax
jne 0x64b1
leaq 0x4(%rsp), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x6230
cmpq $0x4, %rax
jl 0x6480
leaq 0x4(%rsp), %rdi
callq 0x6552
testq %rax, %rax
js 0x6480
movl %eax, %ecx
notl %ecx
testl $0xdc00, %ecx           # imm = 0xDC00
jne 0x6543
shlq $0xa, %r13
movl $0xfca02400, %ecx       # imm = 0xFCA02400
addq %rcx, %rax
addq %rax, %r13
jmp 0x64bd
movl $0xd, %eax
jmp 0x6467
movl $0x9, %eax
jmp 0x6467
movl $0xc, %eax
leaq 0x8(%r15), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rcx
movl %eax, %r8d
callq 0x61ae
testl %eax, %eax
je 0x64a7
movl 0x58(%rbx), %eax
testb %al, %al
jne 0x648d
orl $0x10, %eax
movl %eax, 0x58(%rbx)
decq 0x38(%rbx)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x6496
decq 0x38(%rbx)
jmp 0x64bd
decq 0x38(%rbx)
movl $0x0, 0x8(%rsp)
movb $0x1, %r12b
movl %r13d, %edi
leaq 0x8(%r15), %r13
leaq 0xc(%rsp), %rbp
movq %rbp, %rsi
callq 0x662f
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rax, %r9
callq 0x659e
testl %eax, %eax
jne 0x6480
testb %r12b, %r12b
je 0x6515
xorl %ebp, %ebp
cmpb $0x0, 0x8(%rsp)
jne 0x6496
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6309
testl %eax, %eax
jne 0x6480
jmp 0x6496
leaq 0xc(%rsp), %rbp
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x662f
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rax, %r9
callq 0x659e
jmp 0x647c
movl %eax, %eax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
jmp 0x64c0