// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xc(%rsp), %r15
pushq $0x4
popq %r12
testq %rbx, %rbx
je 0x82fb
movq %rbx, %rdi
callq 0x833c
movq %rax, %rbx
movzbl (%rax), %r13d
cmpl $0x22, %r13d
je 0x8142
testl %r13d, %r13d
je 0x830f
movsbq %r13b, %rbp
callq 0x22f0
movq (%rax), %rax
testb $0x8, 0x1(%rax,%rbp,2)
jne 0x8191
movq %r14, 0x10(%rsp)
movq %r15, %r14
movq %rbx, %rdi
leaq 0x38b8(%rip), %rsi      # 0xb970
movq %r12, %r15
movq %r12, %rdx
callq 0x2170
movq %rbx, %rdi
testl %eax, %eax
je 0x8203
leaq 0x3530(%rip), %rsi      # 0xb605
movq %r15, %rdx
callq 0x2170
movq %rbx, %rdi
testl %eax, %eax
je 0x822e
leaq 0x346f(%rip), %rsi      # 0xb55e
pushq $0x5
popq %rdx
callq 0x2170
testl %eax, %eax
movq %r14, %r15
je 0x8274
cmpb $0x2c, %r13b
movq 0x10(%rsp), %r14
je 0x82ba
movzbl %bpl, %eax
cmpl $0x5b, %eax
je 0x82d3
cmpl $0x7b, %eax
jne 0x8316
callq 0x7fe3
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x82fb
movb $0x4, (%r14)
jmp 0x82e5
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
callq 0x8375
movq %rax, %r13
testq %rax, %rax
jne 0x8165
cmpl $0x0, 0xc(%rsp)
jne 0x82fb
movslq 0x8(%rsp), %rax
addq %rax, %rbx
movq %rbx, %rdi
callq 0x833c
movq %rax, %rbx
cmpb $0x3a, (%rax)
jne 0x81e5
movq %r13, %rdi
callq 0x2580
movq %rax, 0x8(%r14)
incq %rbx
jmp 0x8064
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
callq 0x8375
movq %rax, %r13
testq %rax, %rax
jne 0x81b4
cmpl $0x0, 0xc(%rsp)
jne 0x82fb
movb $0x2, (%r14)
movq %r12, %rdi
callq 0x2430
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x82fb
movq %r13, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x2470
movq 0x10(%r14), %rcx
movl %eax, (%rcx)
jmp 0x82ad
movb $0x1, (%r14)
movq %r13, %rdi
callq 0x2580
movq %rax, 0x10(%r14)
testq %rax, %rax
jne 0x8064
jmp 0x82fb
movq %r14, %r15
movq %r14, %rsi
leaq 0x8(%rsp), %rdx
callq 0x8375
testq %rax, %rax
jne 0x8223
cmpl $0x0, 0xc(%rsp)
jne 0x82fb
movq 0x10(%rsp), %r14
movb $0x2, (%r14)
jmp 0x8299
movq %r14, %r15
movq %r14, %rsi
leaq 0x8(%rsp), %rdx
callq 0x8375
testq %rax, %rax
jne 0x824e
cmpl $0x0, 0xc(%rsp)
jne 0x82fb
movq 0x10(%rsp), %r14
movb $0x5, (%r14)
movq %r12, %rdi
callq 0x2430
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x82fb
movl $0x1, (%rax)
jmp 0x82ad
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
callq 0x8375
testq %rax, %rax
movq 0x10(%rsp), %r14
jne 0x8295
cmpl $0x0, 0xc(%rsp)
jne 0x82fb
movb $0x5, (%r14)
movq %r12, %rdi
callq 0x2430
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x82fb
andl $0x0, (%rax)
movslq 0x8(%rsp), %rax
addq %rax, %rbx
jmp 0x8064
callq 0x7fe3
movq %rax, 0x18(%r14)
testq %rax, %rax
je 0x82fb
incq %rbx
movq %rax, %r14
jmp 0x8064
callq 0x7fe3
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x82fb
movb $0x3, (%r14)
incq %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x8047
movq %rax, %rbx
jmp 0x8064
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andq $0x0, 0x18(%r14)
jmp 0x82fd
cmpl $0x5d, %eax
je 0x8320
cmpl $0x7d, %eax
jne 0x832a
andq $0x0, 0x18(%r14)
incq %rbx
jmp 0x82fd
leaq 0x3644(%rip), %rdi      # 0xb975
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x22e0
jmp 0x82fd