// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x5fae(%rip), %rsi      # 0xaf20
leaq 0xb0(%rsp), %rax
movl $0xc, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
movb $0x0, 0x64(%rax)
movl $0x7d5d7325, 0x60(%rax) # imm = 0x7D5D7325
callq 0x2060
movq %rax, 0x10(%rsp)
movl $0x0, (%rax)
leaq 0x5268(%rip), %rsi      # 0xa20f
movq %r14, %rdi
callq 0x2450
testl %eax, %eax
movq %rbx, 0x28(%rsp)
je 0x4fed
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4f12
cmpl $-0x1, %eax
je 0x530f
movq %r12, 0x20(%rsp)
leaq 0x67ab(%rip), %rdx      # 0xb783
leaq 0x30(%rsp), %rdi
movl $0x18, %esi
movl %eax, %ecx
xorl %eax, %eax
callq 0x2530
jmp 0x5007
movq %r12, 0x20(%rsp)
movups 0x643b(%rip), %xmm0     # 0xb434
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x10(%rsp), %rbx
movq (%r15), %r13
testq %r13, %r13
je 0x527d
movl $0x0, (%rbx)
movq %r13, %rdi
movl $0x2f, %esi
callq 0x2300
leaq 0x1(%rax), %rdi
testq %rax, %rax
cmoveq %r13, %rdi
callq 0x81cd
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x51e5
movq %rbp, 0x18(%rsp)
leaq 0x54e1(%rip), %rdi      # 0xa53e
movq %r14, %rsi
xorl %eax, %eax
callq 0x99a1
movq %rax, %rbp
movq %r14, %rdi
callq 0x23c0
testq %rbp, %rbp
je 0x50fb
movq 0x28(%rsp), %rbx
movq (%rbx), %rdi
movzwl 0x10(%rbx), %esi
callq 0x7828
testq %rax, %rax
je 0x50e4
movq %rax, %r14
movq 0x8(%rbx), %rdx
movq %rax, %rdi
movq %rbp, %rsi
leaq 0x54d8(%rip), %rcx      # 0xa57d
leaq 0x5354(%rip), %r8       # 0xa400
movq %r13, %r9
callq 0x856d
movl %eax, %r13d
movq %rbp, %rdi
callq 0x23c0
cmpl $-0x1, %r13d
je 0x50ee
cmpl $0x191, %r13d           # imm = 0x191
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rbp
jne 0x5105
leaq 0x532b(%rip), %rdi      # 0xa40a
jmp 0x51d1
movq %rbp, %rdi
callq 0x23c0
jmp 0x50f6
movq %r14, %rdi
callq 0x7a3f
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rbp
jmp 0x51e0
leal -0xca(%r13), %eax
cmpl $-0x2, %eax
jae 0x5127
leaq 0x55bf(%rip), %rdi      # 0xa6d7
movl %r13d, %esi
xorl %eax, %eax
callq 0x22d0
jmp 0x51d8
movq %r14, %rdi
callq 0x7e06
testq %rax, %rax
je 0x51ca
movq %rax, %r13
cmpb $0x7b, (%rax)
jne 0x5127
callq 0x87ec
testq %rax, %rax
je 0x51d8
movq %rax, %rdi
movq %rax, 0x8(%rsp)
movq %r13, %rsi
callq 0x885e
movq %rax, %r13
movq %r14, %rdi
callq 0x7a3f
testq %r13, %r13
je 0x5217
movq 0x8(%rsp), %rdi
movq 0x10(%rdi), %r14
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x51ac
movq 0x8(%r14), %rdi
leaq 0x53fd(%rip), %rsi      # 0xa58e
callq 0x2450
testl %eax, %eax
je 0x5223
movq 0x18(%r14), %r14
testq %r14, %r14
jne 0x5186
movq 0x8(%rsp), %rdi
callq 0x8814
cmpl $-0x1, %r13d
jne 0x51c5
leaq 0x53db(%rip), %rdi      # 0xa599
xorl %eax, %eax
callq 0x22d0
movl %r13d, %eax
jmp 0x51e5
leaq 0x528a(%rip), %rdi      # 0xa45b
xorl %eax, %eax
callq 0x22d0
movq %r14, %rdi
callq 0x7a3f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x50(%rsp,%r12,4)
cmpl $-0x1, %eax
je 0x51f3
incl %ebp
jmp 0x5204
movq (%r15), %rsi
leaq 0x531a(%rip), %rdi      # 0xa517
xorl %eax, %eax
callq 0x22d0
addq $0x8, %r15
movslq %ebp, %r12
cmpl $0x18, %r12d
jb 0x5011
jmp 0x527d
movq 0x8(%rsp), %rdi
callq 0x8814
jmp 0x51e0
movq 0x10(%r14), %r14
testq %r14, %r14
je 0x51a7
movq 0x8(%r14), %rdi
leaq 0x5358(%rip), %rsi      # 0xa593
callq 0x2450
testl %eax, %eax
je 0x524a
movq 0x18(%r14), %r14
jmp 0x5227
movq 0x10(%r14), %r14
testq %r14, %r14
je 0x51a7
movq 0x8(%r14), %rdi
leaq 0x55a5(%rip), %rsi      # 0xa807
callq 0x2450
testl %eax, %eax
je 0x5271
movq 0x18(%r14), %r14
jmp 0x524e
movq 0x10(%r14), %rax
movl (%rax), %r13d
jmp 0x51a7
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testl %ebp, %ebp
jle 0x5404
leal -0x1(%rbp), %eax
movslq %eax, %rbx
movl %ebp, %r12d
leaq 0x5298(%rip), %r13      # 0xa533
leaq 0x5297(%rip), %rbp      # 0xa539
leaq 0x120(%rsp), %r15
xorl %r14d, %r14d
xorl %eax, %eax
cltq
leaq (%rsp,%rax), %rdi
addq $0x120, %rdi            # imm = 0x120
movl $0x228, %esi            # imm = 0x228
subq %rax, %rsi
cmpq %rbx, %r14
movq %rbp, %rdx
cmovlq %r13, %rdx
movl 0x50(%rsp,%r14,4), %ecx
xorl %eax, %eax
callq 0x2530
movq %r15, %rdi
callq 0x2150
incq %r14
cmpq %r14, %r12
jne 0x52af
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x532b
callq 0x9051
movq %rax, %rsi
movq %rax, %r15
testq %rax, %rax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x533b
jmp 0x5404
leaq 0x4f00(%rip), %rdi      # 0xa216
movq %r14, %rsi
xorl %eax, %eax
callq 0x22d0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x5404
leaq 0x67ff(%rip), %rsi      # 0xbb31
xorl %r15d, %r15d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0xb0(%rsp), %rdi
leaq 0x30(%rsp), %rdx
leaq 0x120(%rsp), %rcx
xorl %eax, %eax
callq 0x99a1
movq %rax, %r12
movq %r15, %rdi
callq 0x23c0
testq %r12, %r12
je 0x5404
movq 0x28(%rsp), %rbx
movq (%rbx), %rdi
movzwl 0x10(%rbx), %esi
callq 0x7828
testq %rax, %rax
je 0x53dc
movq %rax, %r15
movq 0x8(%rbx), %rdx
movq %r12, (%rsp)
leaq 0x5173(%rip), %rsi      # 0xa506
leaq 0x5066(%rip), %r8       # 0xa400
xorl %r14d, %r14d
movq %rax, %rdi
xorl %ecx, %ecx
movl $0x1, %r9d
callq 0x83d9
movl %eax, %ebx
movq %r12, %rdi
callq 0x23c0
cmpl $-0x1, %ebx
je 0x53f6
cmpl $0x12e, %ebx            # imm = 0x12E
je 0x53fc
cmpl $0x191, %ebx            # imm = 0x191
jne 0x53e6
leaq 0x5037(%rip), %rdi      # 0xa40a
xorl %eax, %eax
callq 0x22d0
jmp 0x53f6
movq %r12, %rdi
callq 0x23c0
jmp 0x5404
leaq 0x52ea(%rip), %rdi      # 0xa6d7
movl %ebx, %esi
xorl %eax, %eax
callq 0x22d0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %r15, %rdi
callq 0x7a3f
movl %r14d, %eax
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq