// File: /workspace/github_c_makefile_star2_O2/Cotix[P]cReddit/libreddit/jsmn.c
// Function: jsmn_parse
jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, jsmntok_t *tokens,
		unsigned int num_tokens) {
	jsmnerr_t r;
	int i;
#ifdef JSMN_PARENT_LINKS
	int k;
#endif
	int on_key = 1;
	jsmntok_t *token;

	for (; js[parser->pos] != '\0'; parser->pos++) {
		char c;
		jsmntype_t type;

		c = js[parser->pos];
		switch (c) {
			case '{': case '[':
				token = jsmn_alloc_token(parser, tokens, num_tokens);
				if (token == NULL)
					return JSMN_ERROR_NOMEM;
				token->is_key = 0; /* Objects can't be keys */
				if (parser->toksuper != -1) {
					tokens[parser->toksuper].size++;
#ifdef JSMN_PARENT_LINKS
					token->parent = parser->toksuper;
#endif
				}
				token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
				token->start = parser->pos;
				parser->toksuper = parser->toknext - 1;
				/*
				 * The start of a new object or array means we'll encounter a key next
				 * We reset this to show that
				 */
				on_key = 1;
				break;
			case '}': case ']':
				type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
#ifdef JSMN_PARENT_LINKS
				if (parser->toknext < 1) {
					return JSMN_ERROR_INVAL;
				}
				token = &tokens[parser->toknext - 1];
				for (;;) {
					if (token->start != -1 && token->end == -1) {
						if (token->type != type) {
							return JSMN_ERROR_INVAL;
						}
						token->end = parser->pos + 1;
						parser->toksuper = token->parent;
						break;
					}
					if (token->parent == -1) {
						break;
					}
					token = &tokens[token->parent];
				}
#else
				for (i = parser->toknext - 1; i >= 0; i--) {
					token = &tokens[i];
					if (token->start != -1 && token->end == -1) {
						if (token->type != type) {
							return JSMN_ERROR_INVAL;
						}
						parser->toksuper = -1;
						token->end = parser->pos + 1;
						break;
					}
				}
				/* Error if unmatched closing bracket */
				if (i == -1) return JSMN_ERROR_INVAL;
				for (; i >= 0; i--) {
					token = &tokens[i];
					if (token->start != -1 && token->end == -1) {
						parser->toksuper = i;
						break;
					}
				}
#endif
				/*
				 * The end of an object/array also means we'll encounter a key next
				 * We change the variable againt o show this
				 *
				 * Technically this shouldn't be nessisary (Since a comma should be soon)
				 * But better to have it then not.
				 */
				on_key = 1;
				break;
			case '\"':
				r = jsmn_parse_string(parser, js, tokens, on_key, num_tokens);
				if (r < 0) return r;
				if (parser->toksuper != -1)
					tokens[parser->toksuper].size++;
				break;

			/*
			 * The next two cases represent a change between whether or not the token
			 * is a key
			 */
			case ':':
				on_key = 0;
				break;
			case ',':
				on_key = 1;
				break;
			case '\t' : case '\r' : case '\n' : case ' ':
				break;
#ifdef JSMN_STRICT
			/* In strict mode primitives are: numbers and booleans */
			case '-': case '0': case '1' : case '2': case '3' : case '4':
			case '5': case '6': case '7' : case '8': case '9':
			case 't': case 'f': case 'n' :
#else
			/* In non-strict mode every unquoted value is a primitive */
			default:
#endif
				r = jsmn_parse_primitive(parser, js, tokens, on_key, num_tokens);
				if (r < 0) return r;
				if (parser->toksuper != -1)
					tokens[parser->toksuper].size++;
				break;

#ifdef JSMN_STRICT
			/* Unexpected char in strict mode */
			default:
				return JSMN_ERROR_INVAL;
#endif

		}
	}

	for (i = parser->toknext - 1; i >= 0; i--) {
		/* Unmatched opened object or array */
		if (tokens[i].start != -1 && tokens[i].end == -1) {
			return JSMN_ERROR_PART;
		}
#ifdef JSMN_PARENT_LINKS
		if (tokens[i].type == JSMN_OBJECT || tokens[i].type == JSMN_ARRAY) {
			tokens[i].full_size += tokens[i].size;
			for (k = tokens[i].parent; k != -1; k = tokens[k].parent) {
				tokens[k].full_size += tokens[i].size;
			}
		}
#endif
	}

	return JSMN_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
leaq -0x1c(%rdx), %rax
movq %rax, 0x10(%rsp)
movl %ecx, %eax
movq %rax, 0x8(%rsp)
movl (%rdi), %r13d
pushq $0x1
popq %rbx
movabsq $0x100100002600, %rsi   # imm = 0x100100002600
movl %r13d, %eax
movb (%r12,%rax), %bpl
movzbl %bpl, %eax
leal -0x20(%rax), %ecx
cmpl $0x1a, %ecx
ja 0x35db
leaq 0x2a97(%rip), %rdx      # 0x6000
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
leal 0x1(%r13), %ebp
movl %ebp, %eax
movabsq $0x400000000002001, %rdi # imm = 0x400000000002001
movl $0xd1011, %r8d          # imm = 0xD1011
movl %eax, (%r15)
movl %eax, %ecx
movzbl (%r12,%rcx), %ecx
cmpl $0x5c, %ecx
je 0x35a9
testl %ecx, %ecx
je 0x37f9
cmpl $0x22, %ecx
jne 0x35d7
jmp 0x379f
incl %eax
movl %eax, (%r15)
movzbl (%r12,%rax), %ecx
leal -0x62(%rcx), %edx
cmpl $0x13, %edx
ja 0x35c1
btl %edx, %r8d
jb 0x35d7
addl $-0x22, %ecx
cmpl $0x3a, %ecx
ja 0x37fd
btq %rcx, %rdi
jae 0x37fd
incl %eax
jmp 0x3588
leal -0x5b(%rax), %ecx
cmpl $0x22, %ecx
ja 0x3703
movl $0x2080800, %edx        # imm = 0x2080800
btq %rcx, %rdx
jb 0x3664
movabsq $0x100000001, %rdx      # imm = 0x100000001
btq %rcx, %rdx
jb 0x3719
movabsq $0x400000004, %rdx      # imm = 0x400000004
btq %rcx, %rdx
jae 0x3703
xorl %eax, %eax
cmpb $0x7d, %bpl
setne %dl
movslq 0x4(%r15), %rcx
testq %rcx, %rcx
jle 0x3816
movb %dl, %al
incl %eax
imulq $0x1c, %rcx, %rcx
addq 0x10(%rsp), %rcx
cmpl $-0x1, 0x4(%rcx)
je 0x364d
cmpl $-0x1, 0x8(%rcx)
je 0x3778
movslq 0x18(%rcx), %rcx
cmpq $-0x1, %rcx
je 0x378e
imulq $0x1c, %rcx, %rcx
addq %r14, %rcx
jmp 0x363d
leal 0x1(%r13), %eax
movzbl %bpl, %ecx
cmpb $0x2c, %cl
ja 0x3680
btq %rcx, %rsi
jb 0x36a5
testq %rcx, %rcx
je 0x37f9
cmpl $0x5d, %ecx
je 0x36a5
cmpl $0x7d, %ecx
je 0x36a5
addb $-0x7f, %bpl
cmpb $-0x5f, %bpl
jb 0x37fd
movl %eax, (%r15)
movl %eax, %ecx
movb (%r12,%rcx), %bpl
incl %eax
jmp 0x3668
movq %rsi, %rbp
movq %r15, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
callq 0x387f
testq %rax, %rax
je 0x3812
movl (%r15), %ecx
andl $0x0, (%rax)
movl %r13d, 0x4(%rax)
movl %ecx, 0x8(%rax)
andl $0x0, 0xc(%rax)
movb 0x10(%rax), %cl
movl %ebx, %edx
andb $0x1, %dl
andb $-0x2, %cl
orb %dl, %cl
movb %cl, 0x10(%rax)
movslq 0x8(%r15), %rcx
movl %ecx, 0x18(%rax)
decl (%r15)
cmpq $-0x1, %rcx
je 0x36fb
imulq $0x1c, %rcx, %rax
incl 0xc(%r14,%rax)
movq %rbp, %rsi
jmp 0x3791
leal -0x9(%rax), %ecx
cmpl $0x2, %ecx
jb 0x3791
cmpl $0xd, %eax
je 0x3791
jmp 0x381a
movq %rsi, %r13
movq %r15, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
callq 0x387f
testq %rax, %rax
je 0x3876
andb $-0x2, 0x10(%rax)
movslq 0x8(%r15), %rcx
cmpq $-0x1, %rcx
je 0x374f
imulq $0x1c, %rcx, %rdx
incl 0xc(%r14,%rdx)
movl %ecx, 0x18(%rax)
xorl %ecx, %ecx
cmpb $0x7b, %bpl
setne %cl
incl %ecx
movl %ecx, (%rax)
movl (%r15), %ecx
movl %ecx, 0x4(%rax)
movl 0x4(%r15), %eax
decl %eax
movl %eax, 0x8(%r15)
pushq $0x1
popq %rbx
movq %r13, %rsi
jmp 0x3791
xorl %ebx, %ebx
jmp 0x3791
cmpl %eax, (%rcx)
jne 0x3816
incl %r13d
movl %r13d, 0x8(%rcx)
movl 0x18(%rcx), %eax
movl %eax, 0x8(%r15)
pushq $0x1
popq %rbx
movl (%r15), %r13d
incl %r13d
movl %r13d, (%r15)
jmp 0x354f
movq %r15, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
callq 0x387f
testq %rax, %rax
je 0x3812
movl (%r15), %ecx
movl $0x3, (%rax)
movl %ebp, 0x4(%rax)
movl %ecx, 0x8(%rax)
andl $0x0, 0xc(%rax)
movb 0x10(%rax), %cl
movl %ebx, %edx
andb $0x1, %dl
andb $-0x2, %cl
orb %dl, %cl
movb %cl, 0x10(%rax)
movslq 0x8(%r15), %rcx
movl %ecx, 0x18(%rax)
cmpq $-0x1, %rcx
je 0x37ed
imulq $0x1c, %rcx, %rax
incl 0xc(%r14,%rax)
movabsq $0x100100002600, %rsi   # imm = 0x100100002600
jmp 0x3791
pushq $-0x3
jmp 0x37ff
pushq $-0x2
popq %rax
movl %r13d, (%r15)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
jmp 0x37ff
pushq $-0x2
jmp 0x3878
testl %eax, %eax
pushq $-0x2
popq %rax
jne 0x3803
movl 0x4(%r15), %edi
pushq $-0x3
popq %rax
testl %edi, %edi
jle 0x387b
decq %rdi
imulq $0x1c, %rdi, %rdx
leaq (%r14,%rdx), %rcx
cmpl $-0x1, 0x4(%r14,%rdx)
je 0x3845
cmpl $-0x1, 0x8(%rcx)
je 0x3803
movl (%rcx), %edx
decl %edx
cmpl $0x1, %edx
ja 0x3828
movl 0xc(%rcx), %edx
addq $0x14, %rcx
movq %rdi, %rsi
addl %edx, (%rcx)
imulq $0x1c, %rsi, %rcx
movslq 0x18(%r14,%rcx), %rsi
cmpq $-0x1, %rsi
je 0x3828
imulq $0x1c, %rsi, %rcx
addq %r14, %rcx
addq $0x14, %rcx
jmp 0x3858
pushq $-0x1
popq %rax
jmp 0x3803
xorl %eax, %eax
jmp 0x3803