// File: /workspace/github_c_makefile_star2_O1/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
movq %rax, %r12
movl $0x0, (%rax)
movq (%rbx), %rdi
movzwl 0x10(%rbx), %esi
callq 0x7828
testq %rax, %rax
je 0x4822
movq %rax, %r15
movq 0x8(%rbx), %rdx
leaq 0x62ce(%rip), %rsi      # 0xa880
leaq 0x5ecc(%rip), %rcx      # 0xa485
leaq 0x5e40(%rip), %r8       # 0xa400
movq %rax, %rdi
callq 0x833e
cmpl $0x12d, %eax            # imm = 0x12D
jg 0x45e4
cmpl $-0x1, %eax
je 0x481a
cmpl $0xc8, %eax
je 0x460b
jmp 0x47e9
cmpl $0x12e, %eax            # imm = 0x12E
je 0x460b
cmpl $0x191, %eax            # imm = 0x191
jne 0x47e9
leaq 0x5e0d(%rip), %rdi      # 0xa40a
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x22d0
jmp 0x47fb
callq 0x87ec
testq %rax, %rax
je 0x4822
movq %rax, %r14
movq %r15, %rdi
callq 0x7e06
testq %rax, %rax
je 0x462e
cmpb $0x5b, (%rax)
jne 0x461c
cmpb $0x5b, (%rax)
jne 0x4805
movq %r14, %rdi
movq %rax, %rsi
callq 0x885e
movq %rax, %r12
movq %r15, %rdi
callq 0x7a3f
testq %r12, %r12
je 0x4836
movq 0x10(%r14), %r12
xorl %ebp, %ebp
testq %r12, %r12
je 0x4840
movq %rbp, %rax
testq %rbp, %rbp
je 0x46aa
movq %rax, %r13
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x466d
movl $0x30, %edi
callq 0x2420
movq %rax, 0x28(%r13)
testq %rax, %rax
je 0x46d7
movq %rax, %r15
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
movq $0x0, 0x28(%rax)
jmp 0x46da
movl $0x30, %edi
callq 0x2420
testq %rax, %rax
je 0x46e4
movq %rax, %r15
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
movq $0x0, 0x28(%rax)
jmp 0x46e7
xorl %r15d, %r15d
testq %r15, %r15
jne 0x46f3
jmp 0x4850
xorl %r15d, %r15d
movq %r15, %rbp
testq %r15, %r15
je 0x484e
movq %r12, %rdi
leaq 0x610a(%rip), %rsi      # 0xa807
callq 0x8fba
testq %rax, %rax
je 0x470f
movq 0x10(%rax), %rax
movl (%rax), %eax
jmp 0x4714
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, (%r15)
movq %r12, %rdi
leaq 0x5daf(%rip), %rsi      # 0xa4d0
callq 0x8fba
testq %rax, %rax
je 0x4731
movq 0x10(%rax), %rdi
jmp 0x4738
leaq 0x73f9(%rip), %rdi      # 0xbb31
callq 0x2570
movq %rax, 0x8(%r15)
testq %rax, %rax
je 0x4850
movq %r12, %rdi
leaq 0x5d81(%rip), %rsi      # 0xa4d5
callq 0x8fba
testq %rax, %rax
je 0x4764
movq 0x10(%rax), %rdi
jmp 0x476b
leaq 0x73c6(%rip), %rdi      # 0xbb31
callq 0x2570
movq %rax, 0x20(%r15)
testq %rax, %rax
je 0x4850
movq %r12, %rdi
leaq 0x5d55(%rip), %rsi      # 0xa4dc
callq 0x8fba
testq %rax, %rax
je 0x4797
movq 0x10(%rax), %rdi
jmp 0x479e
leaq 0x7393(%rip), %rdi      # 0xbb31
callq 0x2570
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x4850
movq %r12, %rdi
leaq 0x5d29(%rip), %rsi      # 0xa4e3
callq 0x8fba
testq %rax, %rax
je 0x47ca
movq 0x10(%rax), %rdi
jmp 0x47d1
leaq 0x7360(%rip), %rdi      # 0xbb31
callq 0x2570
movq %rax, 0x18(%r15)
testq %rax, %rax
je 0x4850
movq 0x18(%r12), %r12
jmp 0x465c
leaq 0x5ee7(%rip), %rdi      # 0xa6d7
xorl %ebp, %ebp
movl %eax, %esi
xorl %eax, %eax
callq 0x22d0
movq %r15, %rdi
callq 0x7a3f
jmp 0x4824
cmpl $0x0, (%r12)
jne 0x481a
leaq 0x5ca1(%rip), %rdi      # 0xa4b4
xorl %eax, %eax
callq 0x22d0
movq %r15, %rdi
callq 0x7a3f
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x8814
jmp 0x4822
movq %r14, %rdi
callq 0x8814
movq %rbp, 0x20(%rbx)
jmp 0x4824
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x8814
movq %rbp, %rdi
callq 0x628c
jmp 0x4822