// File: /workspace/github_c_makefile_star2_O2/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 0x5bea
testl %eax, %eax
js 0x5f80
leal -0x6e(%rax), %ecx
cmpl $0x7, %ecx
jbe 0x5e86
cmpl $0x22, %eax
je 0x5f67
cmpl $0x2f, %eax
je 0x5f67
cmpl $0x5c, %eax
je 0x5f67
cmpl $0x66, %eax
je 0x5f64
cmpl $0x62, %eax
jne 0x5f80
pushq $0x8
jmp 0x5f66
leaq 0x5723(%rip), %rax      # 0xb5b0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
pushq $0xa
jmp 0x5f66
pushq $0x9
jmp 0x5f66
pushq $0xd
jmp 0x5f66
leaq 0x4(%rsp), %rsi
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x5d6f
cmpq $0x4, %rax
jl 0x5f80
leaq 0x4(%rsp), %rdi
callq 0x6050
testq %rax, %rax
js 0x5f80
movq %rax, %r13
notl %eax
pushq $-0x1
popq %rcx
movq %rcx, 0x10(%rsp)
movb $0x1, %cl
movl %ecx, 0x8(%rsp)
testw $0xd800, %ax            # imm = 0xD800
jne 0x5fbb
movq %rbx, %rdi
callq 0x5bea
testl %eax, %eax
js 0x5f80
cmpl $0x5c, %eax
jne 0x5fa9
movq %rbx, %rdi
callq 0x5bea
testl %eax, %eax
js 0x5f80
cmpl $0x75, %eax
jne 0x5faf
leaq 0x4(%rsp), %rsi
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x5d6f
cmpq $0x4, %rax
jl 0x5f80
leaq 0x4(%rsp), %rdi
callq 0x6050
testq %rax, %rax
js 0x5f80
movl %eax, %ecx
notl %ecx
testw $0xdc00, %cx            # imm = 0xDC00
jne 0x6041
shlq $0xa, %r13
movl $0xfca02400, %ecx       # imm = 0xFCA02400
addq %rcx, %rax
addq %rax, %r13
jmp 0x5fbb
pushq $0xc
popq %rax
leaq 0x8(%r15), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rcx
movl %eax, %r8d
callq 0x5cf4
testl %eax, %eax
je 0x5fa5
movl 0x58(%rbx), %eax
testb %al, %al
jne 0x5f8d
orl $0x10, %eax
movl %eax, 0x58(%rbx)
decq 0x38(%rbx)
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x5f94
decq 0x38(%rbx)
jmp 0x5fbb
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 0x6127
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rax, %r9
callq 0x6099
testl %eax, %eax
jne 0x5f80
testb %r12b, %r12b
je 0x6013
xorl %ebp, %ebp
cmpb $0x0, 0x8(%rsp)
jne 0x5f94
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5e26
testl %eax, %eax
jne 0x5f80
jmp 0x5f94
leaq 0xc(%rsp), %rbp
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x6127
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rax, %r9
callq 0x6099
jmp 0x5f7c
movl %eax, %eax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
jmp 0x5fbe