// File: /workspace/github_c_makefile_star2_O3/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 0x5fda(%rip), %rsi      # 0xaf00
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, 0x8(%rsp)
movl $0x0, (%rax)
leaq 0x52b4(%rip), %rsi      # 0xa20f
movq %r14, %rdi
callq 0x2450
testl %eax, %eax
movq %rbx, 0x10(%rsp)
je 0x4fa1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4ec6
cmpl $-0x1, %eax
je 0x52b1
movq %r12, 0x20(%rsp)
leaq 0x67d7(%rip), %rdx      # 0xb763
leaq 0x30(%rsp), %rdi
movl $0x18, %esi
movl %eax, %ecx
xorl %eax, %eax
callq 0x2530
jmp 0x4fbb
movq %r12, 0x20(%rsp)
movups 0x6467(%rip), %xmm0     # 0xb414
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
xorl %r12d, %r12d
xorl %eax, %eax
movq 0x8(%rsp), %rbx
movq (%r15), %rbp
testq %rbp, %rbp
je 0x521d
movq %rax, 0x28(%rsp)
movl $0x0, (%rbx)
movq %rbp, %rdi
movl $0x2f, %esi
callq 0x2300
leaq 0x1(%rax), %rdi
testq %rax, %rax
cmoveq %rbp, %rdi
callq 0x807d
testq %rax, %rax
je 0x5171
movq %rax, %r14
leaq 0x5516(%rip), %rdi      # 0xa522
movq %rax, %rsi
xorl %eax, %eax
callq 0x9772
movq %rax, %r13
movq %r14, %rdi
callq 0x23c0
testq %r13, %r13
je 0x5171
movq 0x10(%rsp), %rbx
movq (%rbx), %rdi
movzwl 0x10(%rbx), %esi
callq 0x7710
testq %rax, %rax
je 0x508b
movq %rax, %r14
movq 0x8(%rbx), %rdx
movq %rax, %rdi
movq %r13, %rsi
leaq 0x550d(%rip), %rcx      # 0xa561
leaq 0x53a5(%rip), %r8       # 0xa400
movq %rbp, %r9
callq 0x8417
movl %eax, %ebp
movq %r13, %rdi
callq 0x23c0
cmpl $-0x1, %ebp
je 0x5095
cmpl $0x191, %ebp            # imm = 0x191
movq 0x8(%rsp), %rbx
jne 0x50a7
leaq 0x5384(%rip), %rdi      # 0xa40a
jmp 0x5162
movq %r13, %rdi
callq 0x23c0
jmp 0x509d
movq %r14, %rdi
callq 0x7921
movq 0x8(%rsp), %rbx
jmp 0x5171
leal -0xca(%rbp), %eax
cmpl $-0x2, %eax
jae 0x50c7
leaq 0x5602(%rip), %rdi      # 0xa6bb
movl %ebp, %esi
xorl %eax, %eax
callq 0x22d0
jmp 0x5169
movq %r14, %rdi
callq 0x7ce0
testq %rax, %rax
je 0x515b
movq %rax, %r13
cmpb $0x7b, (%rax)
jne 0x50c7
callq 0x868c
testq %rax, %rax
je 0x5169
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
callq 0x86fd
movq %rax, %r13
movq %r14, %rdi
callq 0x7921
testq %r13, %r13
je 0x51a2
movq %rbp, 0x18(%rsp)
movq 0x10(%rbp), %r14
testq %r14, %r14
leaq 0x5453(%rip), %r13      # 0xa572
leaq 0x5451(%rip), %rbp      # 0xa577
je 0x5141
movq 0x8(%r14), %rdi
movq %r13, %rsi
callq 0x2450
testl %eax, %eax
je 0x51ac
movq 0x18(%r14), %r14
testq %r14, %r14
jne 0x5128
movq 0x18(%rsp), %rdi
callq 0x86b0
leaq 0x542b(%rip), %rdi      # 0xa57d
xorl %eax, %eax
callq 0x22d0
jmp 0x5171
leaq 0x52f9(%rip), %rdi      # 0xa45b
xorl %eax, %eax
callq 0x22d0
movq %r14, %rdi
callq 0x7921
movl $0xffffffff, 0x50(%rsp,%r12,4) # imm = 0xFFFFFFFF
movq (%r15), %rsi
leaq 0x5377(%rip), %rdi      # 0xa4fb
xorl %eax, %eax
callq 0x22d0
movq 0x28(%rsp), %rax
addq $0x8, %r15
movl %eax, %r12d
cmpl $0x18, %eax
jb 0x4fc5
jmp 0x521d
movq %rbp, %rdi
callq 0x86b0
jmp 0x5171
movq 0x10(%r14), %r14
testq %r14, %r14
je 0x5141
movq 0x8(%r14), %rdi
movq %rbp, %rsi
callq 0x2450
testl %eax, %eax
je 0x51cb
movq 0x18(%r14), %r14
jmp 0x51b0
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x5141
movq 0x8(%rax), %rcx
cmpb $0x69, (%rcx)
jne 0x51ed
cmpb $0x64, 0x1(%rcx)
jne 0x51ed
cmpb $0x0, 0x2(%rcx)
je 0x51f3
movq 0x18(%rax), %rax
jmp 0x51cf
movq 0x10(%rax), %rax
movl (%rax), %ebp
movq 0x18(%rsp), %rdi
callq 0x86b0
cmpl $-0x1, %ebp
je 0x514b
movl %ebp, 0x50(%rsp,%r12,4)
movq 0x28(%rsp), %rax
incl %eax
jmp 0x5190
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testl %eax, %eax
jle 0x53a6
leal -0x1(%rax), %r12d
movl %eax, %ebx
leaq 0x52df(%rip), %r13      # 0xa517
leaq 0x52de(%rip), %rbp      # 0xa51d
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 %r12, %r14
movq %rbp, %rdx
cmovbq %r13, %rdx
movl 0x50(%rsp,%r14,4), %ecx
xorl %eax, %eax
callq 0x2530
movq %r15, %rdi
callq 0x2150
incq %r14
cmpq %r14, %rbx
jne 0x524c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x52cd
callq 0x8eb3
movq %rax, %rsi
movq %rax, %r15
testq %rax, %rax
movq 0x10(%rsp), %rbx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x52e2
jmp 0x53a6
leaq 0x4f5e(%rip), %rdi      # 0xa216
movq %r14, %rsi
xorl %eax, %eax
callq 0x22d0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x53a6
leaq 0x686d(%rip), %rsi      # 0xbb41
xorl %r15d, %r15d
movq 0x10(%rsp), %rbx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0xb0(%rsp), %rdi
leaq 0x30(%rsp), %rdx
leaq 0x120(%rsp), %rcx
xorl %eax, %eax
callq 0x9772
movq %rax, %r12
movq %r15, %rdi
callq 0x23c0
testq %r12, %r12
je 0x53a6
movq (%rbx), %rdi
movzwl 0x10(%rbx), %esi
callq 0x7710
testq %rax, %rax
je 0x537e
movq %rax, %r15
movq 0x8(%rbx), %rdx
movq %r12, (%rsp)
leaq 0x51b5(%rip), %rsi      # 0xa4ea
leaq 0x50c4(%rip), %r8       # 0xa400
xorl %r14d, %r14d
movq %rax, %rdi
xorl %ecx, %ecx
movl $0x1, %r9d
callq 0x8281
movl %eax, %ebx
movq %r12, %rdi
callq 0x23c0
cmpl $-0x1, %ebx
je 0x5398
cmpl $0x12e, %ebx            # imm = 0x12E
je 0x539e
cmpl $0x191, %ebx            # imm = 0x191
jne 0x5388
leaq 0x5095(%rip), %rdi      # 0xa40a
xorl %eax, %eax
callq 0x22d0
jmp 0x5398
movq %r12, %rdi
callq 0x23c0
jmp 0x53a6
leaq 0x532c(%rip), %rdi      # 0xa6bb
movl %ebx, %esi
xorl %eax, %eax
callq 0x22d0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %r15, %rdi
callq 0x7921
movl %r14d, %eax
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq