// File: /workspace/github_c_makefile_star2_O2/tomka[P]cliaspora/cliaspora.c
// Function: lookup_user
static contact_t *
lookup_user(session_t *sp, const char *handle)
{
	int	    status;
	char	    *url, *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);
	if ((url = strduprintf("/people?q=%s", handle)) == NULL)
		return (NULL);
	status = http_get(cp, url, sp->cookie, "application/json, */*",
	    USER_AGENT);
	free(url);
	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) {
		warnx("Server replied with code %d", status);
		ssl_disconnect(cp); return (NULL);
	}
	jp1 = node = new_json_node();
	if (node == NULL) {
		ssl_disconnect(cp); return (NULL);
	}
	while ((p = ssl_readln(cp)) != NULL && *p != '[')
		;
	if (p == NULL) {
		warnx("Unexpected server answer"); ssl_disconnect(cp);
		return (NULL);
	}
	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 = 0;
		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 (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 %rsi, %r12
movq %rdi, %rbx
callq 0x2060
andl $0x0, (%rax)
movq (%rbx), %rdi
movzwl 0x10(%rbx), %esi
callq 0x70dc
testq %rax, %rax
je 0x57ee
movq %rax, %r15
leaq 0x4e7e(%rip), %rdi      # 0xa478
xorl %r14d, %r14d
movq %r12, %rsi
xorl %eax, %eax
callq 0x918a
testq %rax, %rax
je 0x5821
movq %rax, %r12
movq 0x8(%rbx), %rdx
leaq 0x4e67(%rip), %rcx      # 0xa485
leaq 0x4ddb(%rip), %r8       # 0xa400
movq %r15, %rdi
movq %rax, %rsi
callq 0x7b3c
movl %eax, %ebx
movq %r12, %rdi
callq 0x23d0
cmpl $-0x1, %ebx
je 0x57e6
cmpl $0xc8, %ebx
je 0x5663
cmpl $0x191, %ebx            # imm = 0x191
jne 0x57f3
leaq 0x4dac(%rip), %rdi      # 0xa40a
jmp 0x580f
callq 0x7fe3
testq %rax, %rax
je 0x57e6
movq %rax, %rbx
movq %r15, %rdi
callq 0x764f
testq %rax, %rax
je 0x5808
cmpb $0x5b, (%rax)
jne 0x5674
movq %rbx, %rdi
movq %rax, %rsi
callq 0x8047
movq %rax, %r14
movq %r15, %rdi
callq 0x72d8
testq %r14, %r14
je 0x584a
movq %rbx, %r12
addq $0x10, %r12
movq $0x0, (%rsp)
leaq 0x4df5(%rip), %rbp      # 0xa4b4
leaq 0x6448(%rip), %r15      # 0xbb0e
xorl %r14d, %r14d
movq (%r12), %r12
testq %r12, %r12
je 0x5854
testq %r14, %r14
je 0x56f1
movq %r14, %rdi
callq 0x5cae
testq %rax, %rax
je 0x5833
movq %rax, %r13
jmp 0x5707
xorl %edi, %edi
callq 0x5cae
testq %rax, %rax
je 0x5837
movq %rax, %r13
movq %rax, %r14
movq %r12, %rdi
leaq 0x50da(%rip), %rsi      # 0xa7eb
callq 0x871d
testq %rax, %rax
je 0x5723
movq 0x10(%rax), %rax
movl (%rax), %eax
jmp 0x5725
xorl %eax, %eax
movl %eax, (%r13)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x871d
testq %rax, %rax
je 0x573f
movq 0x10(%rax), %rdi
jmp 0x5742
movq %r15, %rdi
callq 0x2580
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x5833
movq %r12, %rdi
leaq 0x4d5b(%rip), %rsi      # 0xa4b9
callq 0x871d
testq %rax, %rax
je 0x576e
movq 0x10(%rax), %rdi
jmp 0x5771
movq %r15, %rdi
callq 0x2580
movq %rax, 0x20(%r13)
testq %rax, %rax
je 0x5833
movq %r12, %rdi
leaq 0x4d33(%rip), %rsi      # 0xa4c0
callq 0x871d
testq %rax, %rax
je 0x579d
movq 0x10(%rax), %rdi
jmp 0x57a0
movq %r15, %rdi
callq 0x2580
movq %rax, 0x10(%r13)
testq %rax, %rax
je 0x5833
movq %r12, %rdi
leaq 0x4d0b(%rip), %rsi      # 0xa4c7
callq 0x871d
testq %rax, %rax
je 0x57cc
movq 0x10(%rax), %rdi
jmp 0x57cf
movq %r15, %rdi
callq 0x2580
movq %rax, 0x18(%r13)
testq %rax, %rax
je 0x5833
addq $0x18, %r12
jmp 0x56c9
movq %r15, %rdi
callq 0x72d8
xorl %r14d, %r14d
jmp 0x5821
leaq 0x4ec1(%rip), %rdi      # 0xa6bb
xorl %r14d, %r14d
movl %ebx, %esi
xorl %eax, %eax
callq 0x22e0
jmp 0x5819
leaq 0x4c8c(%rip), %rdi      # 0xa49b
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x22e0
movq %r15, %rdi
callq 0x72d8
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, (%rsp)
movq %rbx, %rdi
callq 0x8002
movq (%rsp), %rdi
callq 0x5cf4
jmp 0x57ee
movq %rbx, %rdi
callq 0x8002
jmp 0x57ee
movq %rbx, %rdi
callq 0x8002
jmp 0x5821