// File: /workspace/github_c_makefile_star2_O0/tomka[P]cliaspora/cliaspora.c
// Function: upload
static int
upload(session_t *sp, const char *aspect, const char *msg, char * const *files)
{
	int	   aid, i, j, n, ret, status, id[24];
	char	   *rq, *p, idstr[24], lst[sizeof(id) * (20 + 3) / sizeof(int)];
	ssl_conn_t *cp;
	const char tmpl[] = "{\"status_message\":{\"text\":\"%s\","	\
			    "\"provider_display_name\":\"cliaspora\"}," \
			    "\"aspect_ids\":\"%s\",\"photos\":[%s]}";

	errno = 0;
	if (strcmp(aspect, "public") == 0)
		(void)strncpy(idstr, "public", sizeof(idstr));
	else if ((aid = get_aspect_id(sp, aspect)) == -1) {
                warnx("Unknown aspect '%s'", aspect); return (-1);
	} else
		(void)snprintf(idstr, sizeof(idstr), "%d", aid);
	for (n = 0; n < sizeof(id) / sizeof(int) && *files != NULL; files++) {
		if ((id[n] = upload_file(sp, *files)) == -1)
			warnx("Failed to upload image '%s'", *files);
		else
			n++;
	}
	if (n <= 0)
		return (-1);
	for (i = j = 0; i < n; i++) {
		(void)snprintf(lst + j, sizeof(lst) - j,
		    i < n - 1 ? "\"%d\"," : "\"%d\"", id[i]);
		j = strlen(lst);
	}
	if (msg != NULL) {
		if ((p = json_escape_str(msg)) == NULL)
			return (-1);
	} else
		p = NULL;
	rq = strduprintf(tmpl, msg != NULL ? p : "", idstr, lst);
	free(p);
	if (rq == NULL)
		return (-1);
	if ((cp = ssl_connect(sp->host, sp->port)) == NULL) {
		free(rq); return (-1);
	}
	status = http_post(cp, "/status_messages", sp->cookie, NULL,
	    USER_AGENT, HTTP_POST_TYPE_JSON, rq);
	free(rq);
	if (status == HTTP_UNAUTHORIZED) {
		warnx("You're not logged in. Please create a new session");
		ret = -1;
	} else if (status == HTTP_FOUND)
		ret = 0;
	else if (status == -1)
		ret = -1;
	else {
		warnx("Server replied with code %d", status);
		ret = -1;
	}
	ssl_disconnect(cp);
	return (ret);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x390, %rsp            # imm = 0x390
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
leaq -0x370(%rbp), %rdi
leaq 0x9c07(%rip), %rsi      # 0xefc0
movl $0x65, %edx
callq 0x2220
callq 0x2060
movl $0x0, (%rax)
movq -0x18(%rbp), %rdi
leaq 0x8ed6(%rip), %rsi      # 0xe2af
callq 0x2460
cmpl $0x0, %eax
jne 0x53fd
leaq -0xd0(%rbp), %rdi
leaq 0x8ebe(%rip), %rsi      # 0xe2af
movl $0x18, %edx
callq 0x21b0
jmp 0x544f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5320
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
jne 0x5430
movq -0x18(%rbp), %rsi
leaq 0x8e99(%rip), %rdi      # 0xe2b6
movb $0x0, %al
callq 0x22f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5706
leaq -0xd0(%rbp), %rdi
movl -0x2c(%rbp), %ecx
movl $0x18, %esi
leaq 0xa3c1(%rip), %rdx      # 0xf807
movb $0x0, %al
callq 0x2540
jmp 0x544f
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq $0x18, %rcx
movb %al, -0x371(%rbp)
jae 0x5479
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
setne %al
movb %al, -0x371(%rbp)
movb -0x371(%rbp), %al
testb $0x1, %al
jne 0x5485
jmp 0x54d5
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
callq 0x6a20
movslq -0x38(%rbp), %rcx
movl %eax, -0xa0(%rbp,%rcx,4)
cmpl $-0x1, %eax
jne 0x54bc
movq -0x28(%rbp), %rax
movq (%rax), %rsi
leaq 0x95a0(%rip), %rdi      # 0xea53
movb $0x0, %al
callq 0x22f0
jmp 0x54c5
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x54c7
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
jmp 0x5456
cmpl $0x0, -0x38(%rbp)
jg 0x54e7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5706
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x5563
leaq -0x300(%rbp), %rdi
movslq -0x34(%rbp), %rax
addq %rax, %rdi
movslq -0x34(%rbp), %rax
movl $0x228, %esi            # imm = 0x228
subq %rax, %rsi
movl -0x30(%rbp), %ecx
movl -0x38(%rbp), %r8d
subl $0x1, %r8d
leaq 0x954c(%rip), %rdx      # 0xea75
leaq 0x953f(%rip), %rax      # 0xea6f
cmpl %r8d, %ecx
cmovlq %rax, %rdx
movslq -0x30(%rbp), %rax
movl -0xa0(%rbp,%rax,4), %ecx
movb $0x0, %al
callq 0x2540
leaq -0x300(%rbp), %rdi
callq 0x2160
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x54f5
cmpq $0x0, -0x20(%rbp)
je 0x558e
movq -0x20(%rbp), %rdi
callq 0xc550
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
jne 0x558c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5706
jmp 0x5599
movq $0x0, -0xb0(%rbp)
leaq -0x370(%rbp), %rax
movq %rax, -0x380(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x55be
movq -0xb0(%rbp), %rax
movq %rax, -0x388(%rbp)
jmp 0x55ce
leaq 0xa73d(%rip), %rax      # 0xfd02
movq %rax, -0x388(%rbp)
jmp 0x55ce
movq -0x380(%rbp), %rdi
movq -0x388(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
leaq -0x300(%rbp), %rcx
movb $0x0, %al
callq 0xd570
movq %rax, -0xa8(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x23d0
cmpq $0x0, -0xa8(%rbp)
jne 0x561a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5706
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %esi
callq 0x9f10
movq %rax, -0x308(%rbp)
cmpq $0x0, %rax
jne 0x5653
movq -0xa8(%rbp), %rdi
callq 0x23d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5706
movq -0x308(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0xa8(%rbp), %rax
leaq 0x93d2(%rip), %rsi      # 0xea42
xorl %ecx, %ecx
leaq 0x92c3(%rip), %r8       # 0xe93c
movl $0x1, %r9d
movq %rax, (%rsp)
callq 0xb1a0
movl %eax, -0x40(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x23d0
cmpl $0x191, -0x40(%rbp)     # imm = 0x191
jne 0x56b7
leaq 0x929f(%rip), %rdi      # 0xe946
movb $0x0, %al
callq 0x22f0
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
jmp 0x56f4
cmpl $0x12e, -0x40(%rbp)     # imm = 0x12E
jne 0x56c9
movl $0x0, -0x3c(%rbp)
jmp 0x56f2
cmpl $-0x1, -0x40(%rbp)
jne 0x56d8
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
jmp 0x56f0
movl -0x40(%rbp), %esi
leaq 0x9531(%rip), %rdi      # 0xec13
movb $0x0, %al
callq 0x22f0
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
jmp 0x56f2
jmp 0x56f4
movq -0x308(%rbp), %rdi
callq 0xa220
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x390, %rsp            # imm = 0x390
popq %rbp
retq
nopw %cs:(%rax,%rax)