// File: /workspace/github_c_makefile_star2_O3/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 0x6056
testl %eax, %eax
js 0x6449
cmpl $0x61, %eax
jg 0x62e8
cmpl $0x22, %eax
je 0x6430
cmpl $0x2f, %eax
je 0x6430
cmpl $0x5c, %eax
je 0x6430
jmp 0x6449
leal -0x6e(%rax), %ecx
cmpl $0x7, %ecx
ja 0x630a
leaq 0x62e9(%rip), %rax      # 0xc5e0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0xa, %eax
jmp 0x6430
cmpl $0x66, %eax
je 0x642b
cmpl $0x62, %eax
jne 0x6449
movl $0x8, %eax
jmp 0x6430
leaq 0x4(%rsp), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x61e0
cmpq $0x4, %rax
jl 0x6449
leaq 0x7(%rsp), %rax
xorl %ecx, %ecx
xorl %r13d, %r13d
movsbl (%rax), %edx
orl $0x20, %edx
leal -0x30(%rdx), %esi
cmpl $0xa, %esi
jb 0x636b
leal -0x61(%rdx), %esi
cmpl $0x5, %esi
ja 0x6449
addl $-0x26, %edx
movl %edx, %esi
movl %esi, %edx
shlq %cl, %rdx
orq %rdx, %r13
addq $0x4, %rcx
decq %rax
cmpq $0x10, %rcx
jne 0x634c
testq %r13, %r13
js 0x6449
movl %r13d, %eax
notl %eax
testl $0xd800, %eax           # imm = 0xD800
jne 0x6474
movb $0x1, %al
movl %eax, (%rsp)
movq $-0x1, 0x8(%rsp)
movq %rbx, %rdi
callq 0x6056
testl %eax, %eax
js 0x6449
cmpl $0x5c, %eax
jne 0x6484
movq %rbx, %rdi
callq 0x6056
testl %eax, %eax
js 0x6449
cmpl $0x75, %eax
jne 0x648a
leaq 0x4(%rsp), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x61e0
cmpq $0x4, %rax
jl 0x6449
leaq 0x4(%rsp), %rdi
callq 0x652c
testq %rax, %rax
js 0x6449
movl %eax, %ecx
notl %ecx
testl $0xdc00, %ecx           # imm = 0xDC00
jne 0x651d
shlq $0xa, %r13
movl $0xfca02400, %ecx       # imm = 0xFCA02400
addq %rcx, %rax
addq %rax, %r13
jmp 0x6495
movl $0xd, %eax
jmp 0x6430
movl $0x9, %eax
jmp 0x6430
movl $0xc, %eax
leaq 0x8(%r15), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rcx
movl %eax, %r8d
callq 0x6163
testl %eax, %eax
je 0x6470
movl 0x58(%rbx), %eax
testb %al, %al
jne 0x6456
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 0x645f
movb $0x1, %al
movl %eax, (%rsp)
movq $-0x1, 0x8(%rsp)
jmp 0x6495
decq 0x38(%rbx)
jmp 0x6495
decq 0x38(%rbx)
movl $0x0, (%rsp)
movb $0x1, %r12b
movl %r13d, %edi
leaq 0x8(%r15), %r13
leaq 0x14(%rsp), %rbp
movq %rbp, %rsi
callq 0x65fd
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rax, %r9
callq 0x656d
testl %eax, %eax
jne 0x6449
testb %r12b, %r12b
je 0x64ef
xorl %ebp, %ebp
cmpb $0x0, (%rsp)
jne 0x645f
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x629f
testl %eax, %eax
jne 0x6449
jmp 0x645f
leaq 0x14(%rsp), %rbp
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x65fd
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rax, %r9
callq 0x656d
jmp 0x6445
movl %eax, %eax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
jmp 0x6498