// File: /workspace/github_c_makefile_star2_O3/tomka[P]cliaspora/json.c
// Function: parse_json
char *
parse_json(json_node_t *node, char *str)
{
	int  curpos;
	char *p;
	bool error;

	for (; str != NULL;) {
		str = (char *)skip_ws(str);
		if (*str == '\0') {
			node->next = NULL;
			return (str);
		}
		if (*str == '"') {
			p = get_string(str, &error, &curpos);
			if (p == NULL && error)
				return (NULL);
			str = (char *)skip_ws(str + curpos);
			if (*str == ':') {
				node->var = strdup(p);
				str++;
			} else {
				node->type = JSON_TYPE_STRING;
				if ((node->val = strdup(p)) == NULL)
					return (NULL);
			}
		} else if (isdigit(*str)) {
			p = get_string(str, &error, &curpos);
			if (p == NULL && error)
				return (NULL);
			node->type = JSON_TYPE_NUMBER;
			if ((node->val = malloc(sizeof(int))) == NULL)
				return (NULL);
			*(int *)node->val = strtol(p, NULL, 10);
			str += curpos;
		} else if (strncmp(str, "null",  4) == 0) {
			p = get_string(str, &error, &curpos);
			if (p == NULL && error)
				return (NULL);
			node->type = JSON_TYPE_NUMBER;
			if ((node->val = malloc(sizeof(int))) == NULL)
				return (NULL);
			*(int *)node->val  = 0;
			str += curpos;
		} else if (strncmp(str, "true",  4) == 0) {
			p = get_string(str, &error, &curpos);
			if (p == NULL && error)
				return (NULL);
			node->type = JSON_TYPE_BOOL;
			if ((node->val = malloc(sizeof(bool))) == NULL)
				return (NULL);
			*(bool *)node->val  = true;
			str += curpos;
		} else if (strncmp(str, "false", 5) == 0) {
			p = get_string(str, &error, &curpos);
			if (p == NULL && error)
				return (NULL);
			node->type = JSON_TYPE_BOOL;
			if ((node->val = malloc(sizeof(bool))) == NULL)
				return (NULL);
			*(bool *)node->val  = false;
			str += curpos;
		} else if (*str == '{') {
			if ((node->val = new_json_node()) == NULL)
				return (NULL);
			node->type = JSON_TYPE_OBJECT;
			str = parse_json(node->val, ++str);
		} else if (*str == '[') {
			if ((node->val = new_json_node()) == NULL)
				return (NULL);
			node->type = JSON_TYPE_ARRAY;
			str = parse_json(node->val, ++str);
		} else if (*str == ',') {
			if ((node->next = new_json_node()) == NULL)
				return (NULL);
			++str; node = node->next;
		} else if (*str == '\0') {
			node->next = NULL;
			return (str);
		} else if (*str == '}' || *str == ']') {
			node->next = NULL;
			return (++str);
		} else {
			warnx("Syntax error in JSON string.");
			return (NULL);
		}
	}
	return (str);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rsi, %rsi
je 0x8a66
movq %rsi, %rbp
movq %rdi, %r14
leaq 0x4(%rsp), %r12
movb (%rbp), %r15b
testb %r15b, %r15b
je 0x8a21
callq 0x22e0
movq %rax, %r13
movq (%rax), %rax
leaq 0x1(%rbp), %rbx
movsbq %r15b, %rcx
movzwl (%rax,%rcx,2), %ecx
btl $0xd, %ecx
jae 0x875a
movb 0x1(%rbp), %r15b
incq %rbp
incq %rbx
testb %r15b, %r15b
jne 0x8738
jmp 0x8a21
cmpb $0x22, %r15b
jne 0x87b8
movq %rbp, %rdi
movq %rsp, %rsi
movq %r12, %rdx
callq 0x8a7a
testq %rax, %rax
jne 0x877d
cmpl $0x0, (%rsp)
jne 0x8a66
movslq 0x4(%rsp), %rsi
movb (%rbp,%rsi), %cl
addq %rsi, %rbp
testb %cl, %cl
je 0x88d2
movq (%r13), %rdx
addq %rsi, %rbx
movsbq %cl, %rsi
testb $0x20, 0x1(%rdx,%rsi,2)
je 0x88bc
incq %rbp
movb (%rbx), %cl
incq %rbx
testb %cl, %cl
jne 0x8798
jmp 0x88d2
btl $0xb, %ecx
jb 0x8867
movl $0x4, %edx
movq %rbp, %rdi
leaq 0x31ab(%rip), %rsi      # 0xb97c
callq 0x2170
testl %eax, %eax
je 0x88f3
movl $0x4, %edx
movq %rbp, %rdi
leaq 0x2e18(%rip), %rsi      # 0xb605
callq 0x2170
testl %eax, %eax
je 0x8916
movl $0x5, %edx
movq %rbp, %rdi
leaq 0x2d55(%rip), %rsi      # 0xb55e
callq 0x2170
testl %eax, %eax
je 0x8956
movzbl %r15b, %eax
cmpl $0x5c, %eax
jg 0x89b0
cmpl $0x2c, %eax
je 0x89f1
cmpl $0x5b, %eax
jne 0x8a4c
movl $0x20, %edi
callq 0x2420
testq %rax, %rax
je 0x8a42
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movq %rax, 0x10(%r14)
movb $0x3, (%r14)
jmp 0x89de
movq %rbp, %rdi
movq %rsp, %rsi
movq %r12, %rdx
callq 0x8a7a
movq %rax, %rbx
testq %rax, %rax
jne 0x8887
cmpl $0x0, (%rsp)
jne 0x8a66
movb $0x2, (%r14)
movl $0x4, %edi
callq 0x2420
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x8a66
movq %rbx, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x2460
movq 0x10(%r14), %rcx
movl %eax, (%rcx)
jmp 0x8994
cmpb $0x3a, %cl
jne 0x88d2
movq %rax, %rdi
callq 0x2570
movq %rax, 0x8(%r14)
jmp 0x899f
movb $0x1, (%r14)
movq %rax, %rdi
callq 0x2570
movq %rax, 0x10(%r14)
movq %rbp, %rbx
testq %rax, %rax
jne 0x899f
jmp 0x8a66
movq %rbp, %rdi
movq %rsp, %rsi
movq %r12, %rdx
callq 0x8a7a
testq %rax, %rax
jne 0x8910
cmpl $0x0, (%rsp)
jne 0x8a66
movb $0x2, (%r14)
jmp 0x8977
movq %rbp, %rdi
movq %rsp, %rsi
movq %r12, %rdx
callq 0x8a7a
testq %rax, %rax
jne 0x8933
cmpl $0x0, (%rsp)
jne 0x8a66
movb $0x5, (%r14)
movl $0x4, %edi
callq 0x2420
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x8a66
movl $0x1, (%rax)
jmp 0x8994
movq %rbp, %rdi
movq %rsp, %rsi
movq %r12, %rdx
callq 0x8a7a
testq %rax, %rax
jne 0x8973
cmpl $0x0, (%rsp)
jne 0x8a66
movb $0x5, (%r14)
movl $0x4, %edi
callq 0x2420
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x8a66
movl $0x0, (%rax)
movslq 0x4(%rsp), %rax
addq %rax, %rbp
movq %rbp, %rbx
movq %rbx, %rbp
testq %rbx, %rbx
jne 0x871c
jmp 0x8a66
cmpl $0x7b, %eax
jne 0x8a2b
movl $0x20, %edi
callq 0x2420
testq %rax, %rax
je 0x8a42
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movq %rax, 0x10(%r14)
movb $0x4, (%r14)
incq %rbp
movq %rax, %rdi
movq %rbp, %rsi
callq 0x86fd
movq %rax, %rbx
jmp 0x899f
movl $0x20, %edi
callq 0x2420
testq %rax, %rax
je 0x8a5e
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movq %rax, 0x18(%r14)
incq %rbp
movq %rax, %r14
jmp 0x899c
movq $0x0, 0x18(%r14)
jmp 0x8a68
cmpl $0x5d, %eax
je 0x8a35
cmpl $0x7d, %eax
jne 0x8a4c
movq $0x0, 0x18(%r14)
incq %rbp
jmp 0x8a68
movq $0x0, 0x10(%r14)
jmp 0x8a66
leaq 0x2f2e(%rip), %rdi      # 0xb981
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x22d0
jmp 0x8a68
movq $0x0, 0x18(%r14)
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq