// File: /workspace/github_c_makefile_star2_O3/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, %r14
callq 0x2060
movl $0x0, (%rax)
movq (%r14), %rdi
movzwl 0x10(%r14), %esi
callq 0x7710
testq %rax, %rax
je 0x44d4
movq %rax, %r15
leaq 0x61c6(%rip), %rdi      # 0xa478
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x9772
testq %rax, %rax
je 0x4504
movq %rax, %r12
movq 0x8(%r14), %rdx
leaq 0x61b0(%rip), %rcx      # 0xa485
leaq 0x6124(%rip), %r8       # 0xa400
movq %r15, %rdi
movq %rax, %rsi
callq 0x81ee
movl %eax, %ebp
movq %r12, %rdi
callq 0x23c0
cmpl $-0x1, %ebp
je 0x44cc
cmpl $0xc8, %ebp
je 0x431a
cmpl $0x191, %ebp            # imm = 0x191
jne 0x44d8
leaq 0x60f5(%rip), %rdi      # 0xa40a
jmp 0x44f3
callq 0x868c
testq %rax, %rax
je 0x44cc
movq %rax, %r14
movq %r15, %rdi
callq 0x7ce0
testq %rax, %rax
je 0x44ec
cmpb $0x5b, (%rax)
jne 0x432b
movq %r14, %rdi
movq %rax, %rsi
callq 0x86fd
movq %rax, %rbx
movq %r15, %rdi
callq 0x7921
testq %rbx, %rbx
je 0x4516
movq 0x10(%r14), %r15
testq %r15, %r15
je 0x4520
leaq 0x77cd(%rip), %rbp      # 0xbb41
xorl %ebx, %ebx
movq %rbx, %rax
testq %rbx, %rbx
je 0x43a6
movq %rax, %r13
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x437e
movl $0x30, %edi
callq 0x2420
movq %rax, 0x28(%r13)
testq %rax, %rax
je 0x452e
movq %rax, %r12
jmp 0x43bf
movl $0x30, %edi
callq 0x2420
testq %rax, %rax
je 0x452c
movq %rax, %r12
movq %rax, %rbx
movl $0xffffffff, (%r12)     # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r12)
movups %xmm0, 0x18(%r12)
movq $0x0, 0x28(%r12)
movq %r15, %rdi
leaq 0x6402(%rip), %rsi      # 0xa7eb
callq 0x8e20
testq %rax, %rax
je 0x43fb
movq 0x10(%rax), %rax
movl (%rax), %eax
jmp 0x43fd
xorl %eax, %eax
movl %eax, (%r12)
movq %r15, %rdi
leaq 0x60a9(%rip), %rsi      # 0xa4b4
callq 0x8e20
testq %rax, %rax
je 0x441b
movq 0x10(%rax), %rdi
jmp 0x441e
movq %rbp, %rdi
callq 0x2570
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x452e
movq %r15, %rdi
leaq 0x607e(%rip), %rsi      # 0xa4b9
callq 0x8e20
testq %rax, %rax
je 0x444b
movq 0x10(%rax), %rdi
jmp 0x444e
movq %rbp, %rdi
callq 0x2570
movq %rax, 0x20(%r12)
testq %rax, %rax
je 0x452e
movq %r15, %rdi
leaq 0x6055(%rip), %rsi      # 0xa4c0
callq 0x8e20
testq %rax, %rax
je 0x447b
movq 0x10(%rax), %rdi
jmp 0x447e
movq %rbp, %rdi
callq 0x2570
movq %rax, 0x10(%r12)
testq %rax, %rax
je 0x452e
movq %r15, %rdi
leaq 0x602c(%rip), %rsi      # 0xa4c7
callq 0x8e20
testq %rax, %rax
je 0x44ab
movq 0x10(%rax), %rdi
jmp 0x44ae
movq %rbp, %rdi
callq 0x2570
movq %rax, 0x18(%r12)
testq %rax, %rax
je 0x452e
movq 0x18(%r15), %r15
testq %r15, %r15
jne 0x4376
jmp 0x4522
movq %r15, %rdi
callq 0x7921
xorl %ebx, %ebx
jmp 0x4504
leaq 0x61dc(%rip), %rdi      # 0xa6bb
xorl %ebx, %ebx
movl %ebp, %esi
xorl %eax, %eax
callq 0x22d0
jmp 0x44fc
leaq 0x5fa8(%rip), %rdi      # 0xa49b
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x22d0
movq %r15, %rdi
callq 0x7921
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x86b0
jmp 0x44d4
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x86b0
jmp 0x4504
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x86b0
movq %rbx, %rdi
callq 0x61de
jmp 0x44d4