// File: /workspace/github_c_makefile_star2_O3/tomka[P]cliaspora/cliaspora.c
// Function: get_msg_index
static msg_idx_t *
get_msg_index(session_t *sp)
{
	int	    page, status;
	bool	    complete, error;
	msg_idx_t   *index, *ip;
	const char  tmpl[] = "/conversations?page=%d";
	char	    url[sizeof(tmpl) + 16], *p;
	ssl_conn_t  *cp;
	json_node_t *node, *jp1, *jp2, *jp3, *jp4;
	errno = 0;

	jp1 = node = new_json_node();
	if (node == NULL)
		return (NULL);
	for (complete = error = false, page = 1; !error && !complete; page++) {
		(void)snprintf(url, sizeof(url), tmpl, page);
		if ((cp = ssl_connect(sp->host, sp->port)) == NULL)
			return (NULL);
		status = http_get(cp, url, sp->cookie,
		    "application/json, */*", USER_AGENT);
		if (status == HTTP_UNAUTHORIZED) {
			warnx("You're not logged in. Please create a " \
			    "new session");
			error = true;
		} else if (status != HTTP_OK && status != HTTP_FOUND) {
			error = true;
			warnx("Server replied with code %d", status);
		} else if (status == -1)
			error = true;
		while (!error && !complete && (p = ssl_readln(cp)) != NULL) {
			if (strncmp(p, "[]", 2) == 0)
				complete = true;
			else if (*p == '[') {
				if (parse_json(jp1, p) == NULL)
					error = true;
				break;
			}
		}
		if (!error && !complete) {
			if ((jp1 = json_add_node(jp1)) == NULL)
				error = true;
		}
		ssl_disconnect(cp);
	}
	if (error) {
		free_json_node(node);
		return (NULL);
	}
	for (index = NULL, jp1 = node; jp1 != NULL; jp1 = jp1->next) {
		if (jp1->type != JSON_TYPE_ARRAY)
			continue;
		for (jp2 = jp1->val; jp2 != NULL; jp2 = jp2->next) {
			jp3 = find_json_node(jp2, "conversation");
			if (jp3 != NULL) {
				if (index == NULL) {
					ip = index = new_msg_idx_node(NULL);
					if (ip == NULL)
						goto error;
				} else {
					ip = new_msg_idx_node(index);
					if (ip == NULL)
						goto error;
				}
				jp4 = find_json_node(jp3->val, "subject");
				if (jp4 != NULL) {
					ip->subject = strdup((char *)jp4->val);
					if (ip->subject == NULL)
						goto error;
				}
				jp4 = find_json_node(jp3->val, "author_id");
				if (jp4 != NULL) {
					ip->aid = *(int *)jp4->val;
				}
				jp4 = find_json_node(jp3->val, "id");
				if (jp4 != NULL) {
					ip->mid = *(int *)jp4->val;
				}
				jp4 = find_json_node(jp3->val, "created_at");
				if (jp4 != NULL) {
					ip->date = strdup((char *)jp4->val);
					if (ip->date == NULL)
						goto error;
				}
			}
		}
	}
  	free_json_node(node);
	return ((sp->midx = index));
error:
	free_json_node(node);
	free_msg_idx(index);

	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r15
callq 0x2060
movl $0x0, (%rax)
callq 0x868c
testq %rax, %rax
je 0x4b75
movl $0x1, %ebp
leaq 0x10(%rsp), %rbx
movq %rax, (%rsp)
movq %rax, %r14
movq %r15, 0x8(%rsp)
movl $0x27, %esi
movq %rbx, %rdi
leaq 0x67f9(%rip), %rdx      # 0xb0e0
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2530
movq (%r15), %rdi
movzwl 0x10(%r15), %esi
callq 0x7710
testq %rax, %rax
je 0x4b75
movq %rax, %r12
movq 0x8(%r15), %rdx
movq %rax, %rdi
movq %rbx, %r13
movq %rbx, %rsi
leaq 0x5b68(%rip), %rcx      # 0xa485
leaq 0x5adc(%rip), %r8       # 0xa400
callq 0x81ee
cmpl $0xc8, %eax
je 0x493e
cmpl $0x191, %eax            # imm = 0x191
je 0x4976
cmpl $0x12e, %eax            # imm = 0x12E
jne 0x4989
movq %r12, %rdi
callq 0x7ce0
xorl %ebx, %ebx
testq %rax, %rax
je 0x4971
cmpb $0x5b, (%rax)
jne 0x493e
movl $0x1, %r15d
cmpb $0x5d, 0x1(%rax)
je 0x49a1
movq %r14, %rdi
movq %rax, %rsi
callq 0x86fd
xorl %ebx, %ebx
testq %rax, %rax
sete %bl
xorl %r15d, %r15d
jmp 0x49a1
xorl %r15d, %r15d
leaq 0x5a8a(%rip), %rdi      # 0xa40a
xorl %eax, %eax
callq 0x22d0
jmp 0x499c
xorl %r15d, %r15d
leaq 0x5d28(%rip), %rdi      # 0xa6bb
movl %eax, %esi
xorl %eax, %eax
callq 0x22d0
movl $0x1, %ebx
orl %ebx, %r15d
jne 0x49d4
movq %r14, %rdi
callq 0x8e78
movq %rax, %r14
movq %r12, %rdi
callq 0x7921
incl %ebp
testq %r14, %r14
movq 0x8(%rsp), %r15
movq %r13, %rbx
jne 0x48d8
sete %al
movzbl %al, %ebx
jmp 0x49e1
movq %r12, %rdi
callq 0x7921
movq 0x8(%rsp), %r15
testl %ebx, %ebx
movq (%rsp), %rdi
je 0x49f3
callq 0x86b0
jmp 0x4b75
xorl %ebx, %ebx
movq %rdi, %r12
cmpb $0x3, (%r12)
jne 0x4b31
movq 0x10(%r12), %rbp
testq %rbp, %rbp
je 0x4b31
movq %rbp, %rdi
leaq 0x5e27(%rip), %rsi      # 0xa842
callq 0x8e20
testq %rax, %rax
je 0x4b28
movq %rax, %r14
movq %rbx, %rax
testq %rbx, %rbx
je 0x4a5f
movq %rax, %r15
movq 0x18(%rax), %rax
testq %rax, %rax
jne 0x4a34
movq %rbx, %r13
movl $0x20, %edi
callq 0x2420
movq %rax, 0x18(%r15)
testq %rax, %rax
je 0x4b4e
movq %rax, %rbx
jmp 0x4a78
movl $0x20, %edi
callq 0x2420
testq %rax, %rax
je 0x4b89
movq %rax, %rbx
movq %rax, %r13
movq $-0x1, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
movq $0x0, 0x18(%rbx)
movq 0x10(%r14), %rdi
leaq 0x58d5(%rip), %rsi      # 0xa36e
callq 0x8e20
testq %rax, %rax
je 0x4ab9
movq 0x10(%rax), %rdi
callq 0x2570
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x4b4e
movq 0x10(%r14), %rdi
leaq 0x5d8b(%rip), %rsi      # 0xa84f
callq 0x8e20
testq %rax, %rax
je 0x4ad6
movq 0x10(%rax), %rax
movl (%rax), %eax
movl %eax, (%rbx)
movq 0x10(%r14), %rdi
leaq 0x5d0a(%rip), %rsi      # 0xa7eb
callq 0x8e20
testq %rax, %rax
movq 0x8(%rsp), %r15
je 0x4af9
movq 0x10(%rax), %rax
movl (%rax), %eax
movl %eax, 0x4(%rbx)
movq 0x10(%r14), %rdi
leaq 0x5d55(%rip), %rsi      # 0xa859
callq 0x8e20
testq %rax, %rax
je 0x4b25
movq 0x10(%rax), %rdi
callq 0x2570
movq %rax, 0x10(%rbx)
testq %rax, %rax
movq %r13, %rbx
jne 0x4b28
jmp 0x4b51
movq %r13, %rbx
movq 0x18(%rbp), %rbp
jmp 0x4a08
movq 0x18(%r12), %r12
testq %r12, %r12
jne 0x49f8
movq (%rsp), %rdi
callq 0x86b0
movq %rbx, 0x18(%r15)
jmp 0x4b77
movq %r13, %rbx
movq (%rsp), %rdi
callq 0x86b0
movq 0x8(%rbx), %rdi
callq 0x23c0
movq 0x10(%rbx), %rdi
callq 0x23c0
movq 0x18(%rbx), %rbx
testq %rbx, %rbx
jne 0x4b5a
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rdi
jmp 0x49e9