// File: /workspace/github_c_makefile_star2_O1/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 0x8ba0
movq %rsi, %r13
movq %rdi, %rbx
movq %rsp, %r14
leaq 0x4(%rsp), %r15
movb (%r13), %bpl
testb %bpl, %bpl
je 0x88a8
callq 0x22e0
movq (%rax), %rax
movsbq %bpl, %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x88a8
movb 0x1(%r13), %bpl
incq %r13
testb %bpl, %bpl
jne 0x8891
movzbl (%r13), %eax
cmpl $0x22, %eax
je 0x8973
testl %eax, %eax
je 0x8bb5
movsbq %al, %r12
callq 0x22e0
movq (%rax), %rax
testb $0x8, 0x1(%rax,%r12,2)
jne 0x89df
movl $0x4, %edx
movq %r13, %rdi
leaq 0x308b(%rip), %rsi      # 0xb970
callq 0x2170
testl %eax, %eax
je 0x8a50
movl $0x4, %edx
movq %r13, %rdi
leaq 0x2d24(%rip), %rsi      # 0xb625
callq 0x2170
testl %eax, %eax
je 0x8a72
movl $0x5, %edx
movq %r13, %rdi
leaq 0x2c61(%rip), %rsi      # 0xb57e
callq 0x2170
testl %eax, %eax
je 0x8ab1
movzbl %r12b, %eax
cmpl $0x5c, %eax
jg 0x8b0a
cmpl $0x2c, %eax
je 0x8b36
cmpl $0x5b, %eax
jne 0x8bd6
movl $0x20, %edi
callq 0x2420
testq %rax, %rax
je 0x8b7c
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
jmp 0x8b7e
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x8be9
movq %rax, %r12
testq %rax, %rax
jne 0x8993
cmpl $0x0, (%rsp)
jne 0x8ba0
movslq 0x4(%rsp), %rax
leaq (%rax,%r13), %rbp
movb (%r13,%rax), %r13b
testb %r13b, %r13b
je 0x89c5
callq 0x22e0
movq (%rax), %rax
movsbq %r13b, %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x89c5
movb 0x1(%rbp), %r13b
incq %rbp
testb %r13b, %r13b
jne 0x89ae
cmpb $0x3a, (%rbp)
jne 0x8a33
movq %r12, %rdi
callq 0x2570
movq %rax, 0x8(%rbx)
incq %rbp
jmp 0x8af9
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x8be9
movq %rax, %r12
testq %rax, %rax
jne 0x89ff
cmpl $0x0, (%rsp)
jne 0x8ba0
movb $0x2, (%rbx)
movl $0x4, %edi
callq 0x2420
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x8ba0
movq %r12, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x2460
movq 0x10(%rbx), %rcx
movl %eax, (%rcx)
jmp 0x8aee
movb $0x1, (%rbx)
movq %r12, %rdi
callq 0x2570
movq %rax, 0x10(%rbx)
testq %rax, %rax
jne 0x8af9
jmp 0x8ba0
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x8be9
testq %rax, %rax
jne 0x8a6d
cmpl $0x0, (%rsp)
jne 0x8ba0
movb $0x2, (%rbx)
jmp 0x8ad1
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x8be9
testq %rax, %rax
jne 0x8a8f
cmpl $0x0, (%rsp)
jne 0x8ba0
movb $0x5, (%rbx)
movl $0x4, %edi
callq 0x2420
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x8ba0
movl $0x1, (%rax)
jmp 0x8aee
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x8be9
testq %rax, %rax
jne 0x8ace
cmpl $0x0, (%rsp)
jne 0x8ba0
movb $0x5, (%rbx)
movl $0x4, %edi
callq 0x2420
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x8ba0
movl $0x0, (%rax)
movslq 0x4(%rsp), %rax
addq %rax, %r13
movq %r13, %rbp
movq %rbp, %r13
testq %rbp, %rbp
jne 0x8880
jmp 0x8ba0
cmpl $0x7b, %eax
jne 0x8bbf
movl $0x20, %edi
callq 0x2420
testq %rax, %rax
je 0x8b6c
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
jmp 0x8b6e
movl $0x20, %edi
callq 0x2420
testq %rax, %rax
je 0x8b59
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
jmp 0x8b5b
xorl %eax, %eax
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x8ba0
incq %r13
movq %rax, %rbx
jmp 0x8af6
xorl %eax, %eax
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x8ba0
movb $0x4, (%rbx)
jmp 0x8b8a
xorl %eax, %eax
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x8ba0
movb $0x3, (%rbx)
incq %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x885e
movq %rax, %rbp
jmp 0x8af9
xorl %r13d, %r13d
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, 0x18(%rbx)
jmp 0x8ba3
cmpl $0x5d, %eax
je 0x8bc9
cmpl $0x7d, %eax
jne 0x8bd6
movq $0x0, 0x18(%rbx)
incq %r13
jmp 0x8ba3
leaq 0x2d98(%rip), %rdi      # 0xb975
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x22d0
jmp 0x8ba3