// File: /workspace/github_c_makefile_star2_O1/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 0x7828
testq %rax, %rax
je 0x4458
movq %rax, %r15
leaq 0x6267(%rip), %rdi      # 0xa478
xorl %ebx, %ebx
movq %r12, %rsi
xorl %eax, %eax
callq 0x99a1
testq %rax, %rax
je 0x4488
movq %rax, %r12
movq 0x8(%r14), %rdx
leaq 0x6251(%rip), %rcx      # 0xa485
leaq 0x61c5(%rip), %r8       # 0xa400
movq %r15, %rdi
movq %rax, %rsi
callq 0x833e
movl %eax, %ebp
movq %r12, %rdi
callq 0x23c0
cmpl $-0x1, %ebp
je 0x4450
cmpl $0xc8, %ebp
je 0x4279
cmpl $0x191, %ebp            # imm = 0x191
jne 0x445c
leaq 0x6196(%rip), %rdi      # 0xa40a
jmp 0x4477
callq 0x87ec
testq %rax, %rax
je 0x4450
movq %rax, %r14
movq %r15, %rdi
callq 0x7e06
testq %rax, %rax
je 0x4470
cmpb $0x5b, (%rax)
jne 0x428a
movq %r14, %rdi
movq %rax, %rsi
callq 0x885e
movq %rax, %rbx
movq %r15, %rdi
callq 0x7a3f
testq %rbx, %rbx
je 0x449a
movq 0x10(%r14), %r15
testq %r15, %r15
je 0x44a4
leaq 0x785e(%rip), %rbp      # 0xbb31
xorl %ebx, %ebx
movq %rbx, %rax
testq %rbx, %rbx
je 0x431a
movq %rax, %r13
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x42dd
movl $0x30, %edi
callq 0x2420
movq %rax, 0x28(%r13)
testq %rax, %rax
je 0x4347
movq %rax, %r12
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
movq $0x0, 0x28(%rax)
jmp 0x434a
movl $0x30, %edi
callq 0x2420
testq %rax, %rax
je 0x4354
movq %rax, %r12
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
movq $0x0, 0x28(%rax)
jmp 0x4357
xorl %r12d, %r12d
testq %r12, %r12
jne 0x4363
jmp 0x44b2
xorl %r12d, %r12d
movq %r12, %rbx
testq %r12, %r12
je 0x44b0
movq %r15, %rdi
leaq 0x649a(%rip), %rsi      # 0xa807
callq 0x8fba
testq %rax, %rax
je 0x437f
movq 0x10(%rax), %rax
movl (%rax), %eax
jmp 0x4381
xorl %eax, %eax
movl %eax, (%r12)
movq %r15, %rdi
leaq 0x6141(%rip), %rsi      # 0xa4d0
callq 0x8fba
testq %rax, %rax
je 0x439f
movq 0x10(%rax), %rdi
jmp 0x43a2
movq %rbp, %rdi
callq 0x2570
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x44b2
movq %r15, %rdi
leaq 0x6116(%rip), %rsi      # 0xa4d5
callq 0x8fba
testq %rax, %rax
je 0x43cf
movq 0x10(%rax), %rdi
jmp 0x43d2
movq %rbp, %rdi
callq 0x2570
movq %rax, 0x20(%r12)
testq %rax, %rax
je 0x44b2
movq %r15, %rdi
leaq 0x60ed(%rip), %rsi      # 0xa4dc
callq 0x8fba
testq %rax, %rax
je 0x43ff
movq 0x10(%rax), %rdi
jmp 0x4402
movq %rbp, %rdi
callq 0x2570
movq %rax, 0x10(%r12)
testq %rax, %rax
je 0x44b2
movq %r15, %rdi
leaq 0x60c4(%rip), %rsi      # 0xa4e3
callq 0x8fba
testq %rax, %rax
je 0x442f
movq 0x10(%rax), %rdi
jmp 0x4432
movq %rbp, %rdi
callq 0x2570
movq %rax, 0x18(%r12)
testq %rax, %rax
je 0x44b2
movq 0x18(%r15), %r15
testq %r15, %r15
jne 0x42d5
jmp 0x44a6
movq %r15, %rdi
callq 0x7a3f
xorl %ebx, %ebx
jmp 0x4488
leaq 0x6274(%rip), %rdi      # 0xa6d7
xorl %ebx, %ebx
movl %ebp, %esi
xorl %eax, %eax
callq 0x22d0
jmp 0x4480
leaq 0x6024(%rip), %rdi      # 0xa49b
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x22d0
movq %r15, %rdi
callq 0x7a3f
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x8814
jmp 0x4458
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x8814
jmp 0x4488
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x8814
movq %rbx, %rdi
callq 0x628c
jmp 0x4458