// File: /workspace/github_c_makefile_star2_O0/tomka[P]cliaspora/cliaspora.c
// Function: upload_file
static int
upload_file(session_t *sp, const char *file)
{
	int	    status, id;
	char	    *url, *p;
	ssl_conn_t  *cp;
	json_node_t *node, *jp1, *jp2, *jp3;

	errno = 0;
	if ((p = strrchr(file, '/')) != NULL)
		p++;
	else
		p = (char *)file;
	if ((p = urlencode(p)) == NULL)
		return (-1);
	if ((url = strduprintf("/photos?photo%%5Bpending%%5D=true&" \
	    "set_profile_image=&qqfile=%s", p)) == NULL) {
		free(p); return (-1);
	}
	free(p);
	if ((cp = ssl_connect(sp->host, sp->port)) == NULL) {
		free(url); return (-1);
	}
	status = http_upload(cp, url, sp->cookie, "application/json",
	    USER_AGENT, file);
	free(url);
	if (status == HTTP_UNAUTHORIZED) {
		warnx("You're not logged in. Please create a new session");
		ssl_disconnect(cp); return (-1);
	} else if (status == -1) {
		ssl_disconnect(cp); return (-1);
	} else if (status != HTTP_CREATED && status != HTTP_OK) {
		warnx("Server replied with code %d", status);
		ssl_disconnect(cp); return (-1);
	}	
	while ((p = ssl_readln(cp)) != NULL && *p != '{')
		;
	if (p == NULL) {
		warnx("Unexpected server reply"); ssl_disconnect(cp);
		return (-1);
	}
	if ((node = new_json_node()) == NULL) {
		ssl_disconnect(cp); return (-1);
	}
	if (parse_json(node, p) == NULL) {
		ssl_disconnect(cp); free_json_node(node);
		return (-1);
	}
	ssl_disconnect(cp);
	for (id = -1, jp1 = node->val; jp1 != NULL; jp1 = jp1->next) {
		if (strcmp(jp1->var, "data") == 0) {
			for (jp2 = jp1->val; jp2 != NULL; jp2 = jp2->next) {
				if (strcmp(jp2->var, "photo") == 0) {
					for (jp3 = jp2->val; jp3 != NULL;
					    jp3 = jp3->next) {
						if (strcmp(jp3->var, "id")
						    == 0) {
							id = *(int *)jp3->val;
							break;
						}
					}
					break;
				}
			}
			break;
		}
	}
	free_json_node(node);
	if (id == -1)
		warnx("Couldn't find the image ID");
	return (id);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
callq 0x2060
movl $0x0, (%rax)
movq -0x18(%rbp), %rdi
movl $0x2f, %esi
callq 0x2320
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x6a61
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x6a69
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0xaea0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x6a88
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d67
movq -0x30(%rbp), %rsi
leaq 0x7fe7(%rip), %rdi      # 0xea7a
movb $0x0, %al
callq 0xd570
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x6ab9
movq -0x30(%rbp), %rdi
callq 0x23d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d67
movq -0x30(%rbp), %rdi
callq 0x23d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %esi
callq 0x9f10
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x6af5
movq -0x28(%rbp), %rdi
callq 0x23d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d67
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %r9
leaq 0x7fa9(%rip), %rcx      # 0xeab9
leaq 0x7e25(%rip), %r8       # 0xe93c
callq 0xb410
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x23d0
cmpl $0x191, -0x1c(%rbp)     # imm = 0x191
jne 0x6b54
leaq 0x7e0e(%rip), %rdi      # 0xe946
movb $0x0, %al
callq 0x22f0
movq -0x38(%rbp), %rdi
callq 0xa220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d67
cmpl $-0x1, -0x1c(%rbp)
jne 0x6b6f
movq -0x38(%rbp), %rdi
callq 0xa220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d67
cmpl $0xc9, -0x1c(%rbp)
je 0x6ba7
cmpl $0xc8, -0x1c(%rbp)
je 0x6ba7
movl -0x1c(%rbp), %esi
leaq 0x8088(%rip), %rdi      # 0xec13
movb $0x0, %al
callq 0x22f0
movq -0x38(%rbp), %rdi
callq 0xa220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d67
jmp 0x6ba9
jmp 0x6bab
jmp 0x6bad
movq -0x38(%rbp), %rdi
callq 0xa790
movq %rax, %rcx
movq %rcx, -0x30(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x59(%rbp)
je 0x6bd8
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
setne %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x6be1
jmp 0x6be3
jmp 0x6bad
cmpq $0x0, -0x30(%rbp)
jne 0x6c0d
leaq 0x7da6(%rip), %rdi      # 0xe997
movb $0x0, %al
callq 0x22f0
movq -0x38(%rbp), %rdi
callq 0xa220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d67
callq 0xb820
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x6c31
movq -0x38(%rbp), %rdi
callq 0xa220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d67
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xb910
cmpq $0x0, %rax
jne 0x6c62
movq -0x38(%rbp), %rdi
callq 0xa220
movq -0x40(%rbp), %rdi
callq 0xb890
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6d67
movq -0x38(%rbp), %rdi
callq 0xa220
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x6d44
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x7e32(%rip), %rsi      # 0xeaca
callq 0x2460
cmpl $0x0, %eax
jne 0x6d31
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x6d2f
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x7e07(%rip), %rsi      # 0xeacf
callq 0x2460
cmpl $0x0, %eax
jne 0x6d1f
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x6d1d
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x804f(%rip), %rsi      # 0xed43
callq 0x2460
cmpl $0x0, %eax
jne 0x6d0d
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x6d1d
jmp 0x6d0f
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x6cde
jmp 0x6d2f
jmp 0x6d21
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x6cb2
jmp 0x6d44
jmp 0x6d33
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x6c7e
movq -0x40(%rbp), %rdi
callq 0xb890
cmpl $-0x1, -0x20(%rbp)
jne 0x6d61
leaq 0x7d7b(%rip), %rdi      # 0xead5
movb $0x0, %al
callq 0x22f0
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq