// File: /workspace/github_c_makefile_star2_O2/tomka[P]cliaspora/cliaspora.c
// Function: get_contacts
static contact_t *
get_contacts(session_t *sp)
{
	int	    status;
	char	    *p;
	contact_t   *contacts, *ctp;
	ssl_conn_t  *cp;
	json_node_t *node, *jp1, *jp2;

	errno = 0;
	if ((cp = ssl_connect(sp->host, sp->port)) == NULL)
		return (NULL);
	status = http_get(cp, "/contacts", sp->cookie,
	    "application/json, */*", USER_AGENT);
	if (status == HTTP_UNAUTHORIZED) {
		warnx("You're not logged in. Please create a new session");
		ssl_disconnect(cp);
		return (NULL);
	} else if (status == -1) {
		ssl_disconnect(cp);
		return (NULL);
	} else if (status != HTTP_OK && status != HTTP_FOUND) {
		warnx("Server replied with code %d", status);
		ssl_disconnect(cp); return (NULL);
	}
	jp1 = node = new_json_node();
	if (node == NULL)
		return (NULL);
	while ((p = ssl_readln(cp)) != NULL && *p != '[')
		;
	if (*p != '[') {
		if (errno == 0)
			warnx("Server reply not understood");
		ssl_disconnect(cp);
		return (NULL);
	}
	if (parse_json(node, p) == NULL) {
		ssl_disconnect(cp); free_json_node(node);
		return (NULL);
	}
	ssl_disconnect(cp);
	
	for (contacts = NULL, jp1 = node->val; jp1 != NULL; jp1 = jp1->next) {
		if (contacts == NULL) {
			if ((contacts = new_contact_node(NULL)) == NULL)
				goto error;
			ctp = contacts;
		} else if ((ctp = new_contact_node(contacts)) == NULL)
			goto error;
		if ((jp2 = find_json_node(jp1, "id")) != NULL)
			ctp->id = *(int *)jp2->val;
		else
			ctp->id = -1;
		if ((jp2 = find_json_node(jp1, "name")) != NULL) {
			if ((ctp->name = strdup((char *)jp2->val)) == NULL)
				goto error;
		} else if ((ctp->name = strdup("")) == NULL)
			goto error;
		if ((jp2 = find_json_node(jp1, "avatar")) != NULL) {
			if ((ctp->avatar = strdup((char *)jp2->val)) == NULL)
				goto error;
		} else if ((ctp->avatar = strdup("")) == NULL)
			goto error;
		if ((jp2 = find_json_node(jp1, "handle")) != NULL) {
			if ((ctp->handle = strdup((char *)jp2->val)) == NULL)
				goto error;
		} else if ((ctp->handle = strdup("")) == NULL)
			goto error;
		if ((jp2 = find_json_node(jp1, "url")) != NULL) {
			if ((ctp->url = strdup((char *)jp2->val)) == NULL)
				goto error;
		} else if ((ctp->url = strdup("")) == NULL)
			goto error;
	}
  	free_json_node(node);
	return ((sp->contacts = contacts));
error:
	free_json_node(node);
	free_contacts(contacts);

	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x2060
andl $0x0, (%rax)
movq (%rbx), %rdi
movzwl 0x10(%rbx), %esi
callq 0x70dc
testq %rax, %rax
je 0x5b51
movq %rax, %r15
movq 0x8(%rbx), %rdx
leaq 0x4f21(%rip), %rsi      # 0xa864
leaq 0x4b3b(%rip), %rcx      # 0xa485
leaq 0x4aaf(%rip), %r8       # 0xa400
movq %rax, %rdi
callq 0x7b3c
cmpl $-0x1, %eax
je 0x5b0b
cmpl $0xc8, %eax
je 0x5991
cmpl $0x12e, %eax            # imm = 0x12E
je 0x5991
cmpl $0x191, %eax            # imm = 0x191
jne 0x5b15
leaq 0x4a88(%rip), %rdi      # 0xa40a
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x22e0
jmp 0x5b28
callq 0x7fe3
testq %rax, %rax
je 0x5b51
movq %rax, %r14
movq %r15, %rdi
callq 0x764f
testq %rax, %rax
je 0x5b54
cmpb $0x5b, (%rax)
jne 0x59a2
movq %r14, %rdi
movq %rax, %rsi
callq 0x8047
movq %rax, %r12
movq %r15, %rdi
callq 0x72d8
testq %r12, %r12
je 0x5b49
movq %r14, %r13
addq $0x10, %r13
movq $0x0, (%rsp)
leaq 0x6121(%rip), %rbp      # 0xbb0e
xorl %r12d, %r12d
movq (%r13), %r13
testq %r13, %r13
je 0x5b66
testq %r12, %r12
je 0x5a18
movq %r12, %rdi
callq 0x5cae
testq %rax, %rax
je 0x5b32
movq %rax, %r15
jmp 0x5a2e
xorl %edi, %edi
callq 0x5cae
testq %rax, %rax
je 0x5b36
movq %rax, %r15
movq %rax, %r12
movq %r13, %rdi
leaq 0x4db3(%rip), %rsi      # 0xa7eb
callq 0x871d
pushq $-0x1
popq %rcx
testq %rax, %rax
je 0x5a4b
movq 0x10(%rax), %rax
movl (%rax), %ecx
movl %ecx, (%r15)
movq %r13, %rdi
leaq 0x4a5c(%rip), %rsi      # 0xa4b4
callq 0x871d
testq %rax, %rax
je 0x5a68
movq 0x10(%rax), %rdi
jmp 0x5a6b
movq %rbp, %rdi
callq 0x2580
movq %rax, 0x8(%r15)
testq %rax, %rax
je 0x5b32
movq %r13, %rdi
leaq 0x4a32(%rip), %rsi      # 0xa4b9
callq 0x871d
testq %rax, %rax
je 0x5a97
movq 0x10(%rax), %rdi
jmp 0x5a9a
movq %rbp, %rdi
callq 0x2580
movq %rax, 0x20(%r15)
testq %rax, %rax
je 0x5b32
movq %r13, %rdi
leaq 0x4a0a(%rip), %rsi      # 0xa4c0
callq 0x871d
testq %rax, %rax
je 0x5ac6
movq 0x10(%rax), %rdi
jmp 0x5ac9
movq %rbp, %rdi
callq 0x2580
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x5b32
movq %r13, %rdi
leaq 0x49e6(%rip), %rsi      # 0xa4c7
callq 0x871d
testq %rax, %rax
je 0x5af1
movq 0x10(%rax), %rdi
jmp 0x5af4
movq %rbp, %rdi
callq 0x2580
movq %rax, 0x18(%r15)
testq %rax, %rax
je 0x5b32
addq $0x18, %r13
jmp 0x59f0
movq %r15, %rdi
callq 0x72d8
jmp 0x5b51
leaq 0x4b9f(%rip), %rdi      # 0xa6bb
xorl %r12d, %r12d
movl %eax, %esi
xorl %eax, %eax
callq 0x22e0
movq %r15, %rdi
callq 0x72d8
jmp 0x5b54
movq %r12, (%rsp)
movq %r14, %rdi
callq 0x8002
movq (%rsp), %rdi
callq 0x5cf4
jmp 0x5b51
movq %r14, %rdi
callq 0x8002
xorl %r12d, %r12d
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x8002
movq %r12, 0x20(%rbx)
jmp 0x5b54