// File: /workspace/github_c_makefile_star2_O2/tomka[P]cliaspora/http.c
// Function: http_upload
int
http_upload(ssl_conn_t *cp, const char *url, const char *cookie,
	    const char *accept, const char *agent, const char *file)
{
	int	   n;
	long	   len;
	FILE	   *fp;
	char	   *rq, buf[1024];
	http_req_t hdr;

	if ((fp = fopen(file, "r")) == NULL) {
		warn("%s", file); return (-1);
	}
	if (fseek(fp, 0, SEEK_END) == -1) {
		warn("fseek()"); (void)fclose(fp); return (-1);
	}
	if ((len = ftell(fp)) == -1) {
		warn("ftell()"); (void)fclose(fp); return (-1);
	}
	if (len > HTTP_FILESZ_LIMIT) {
		warnx("'%s' exceeds file size-limit of %d MB", file,
		    HTTP_FILESZ_LIMIT / (1024 * 1024));
		(void)fclose(fp); return (-1);
	}
	(void)memset(&hdr, 0, sizeof(hdr));
	hdr.ua	   = agent;
	hdr.cl	   = (int)len;
	hdr.ct	   = "application/octet-stream";
	hdr.url	   = url;
	hdr.type   = HTTP_RQ_TYPE_POST;
	hdr.host   = cp->host;
	hdr.cookie = cookie;
	hdr.accept = accept;

	if ((rq = http_gen_req(&hdr)) == NULL) {
		(void)fclose(fp); return (-1);
	}
	if (ssl_write(cp, rq, strlen(rq)) == -1) {
		free(rq); (void)fclose(fp); return (-1);
	}
	free(rq);

	rewind(fp);
	while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
		if (ssl_write(cp, buf, n) == -1) {
			(void)fclose(fp); return (-1);
		}
	}
	(void)fclose(fp);

	return (get_http_status(cp));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %r9, %r13
movq %r8, %r14
movq %rcx, (%rsp)
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r15
leaq 0x273a(%rip), %rsi      # 0xa4be
movq %r9, %rdi
callq 0x23b0
testq %rax, %rax
je 0x7dd2
movq %rax, %rbx
pushq $0x2
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x2320
cmpl $-0x1, %eax
je 0x7de5
movq %rbx, %rdi
callq 0x2030
cmpq $-0x1, %rax
je 0x7dee
cmpq $0x400001, %rax         # imm = 0x400001
jl 0x7e19
leaq 0x3ac7(%rip), %rdi      # 0xb88a
pushq $0x4
popq %rdx
movq %r13, %rsi
xorl %eax, %eax
callq 0x22e0
jmp 0x7dfc
leaq 0x3a35(%rip), %rdi      # 0xb80e
movq %r13, %rsi
xorl %eax, %eax
callq 0x2110
jmp 0x7e04
leaq 0x3a8e(%rip), %rdi      # 0xb87a
jmp 0x7df5
leaq 0x3a8d(%rip), %rdi      # 0xb882
xorl %eax, %eax
callq 0x2110
movq %rbx, %rdi
callq 0x2280
pushq $-0x1
popq %rax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
leaq 0x8(%rsp), %rdi
andq $0x0, 0x38(%rdi)
movups %xmm0, 0x18(%rdi)
movups %xmm0, 0x28(%rdi)
movq %r14, 0x10(%rdi)
movl %eax, (%rdi)
leaq 0x39f6(%rip), %rax      # 0xb831
movq %rax, 0x20(%rdi)
movq %rbp, 0x8(%rdi)
movl $0x2, 0x4(%rdi)
movq %r15, %r13
movq 0x18(%r15), %rax
movq %rax, 0x30(%rdi)
movq %r12, 0x40(%rdi)
movq (%rsp), %rax
movq %rax, 0x28(%rdi)
callq 0x7790
testq %rax, %rax
je 0x7dfc
movq %rax, %r14
movq %rax, %rdi
callq 0x2150
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x74e2
movl %eax, %ebp
movq %r14, %rdi
callq 0x23d0
cmpl $-0x1, %ebp
je 0x7dfc
movq %rbx, %rdi
callq 0x20b0
leaq 0x50(%rsp), %r14
pushq $0x1
popq %r15
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rcx
callq 0x24e0
testl %eax, %eax
jle 0x7edc
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x74e2
cmpl $-0x1, %eax
jne 0x7ea8
jmp 0x7dfc
movq %rbx, %rdi
callq 0x2280
movq %r13, %rdi
callq 0x7a9e
jmp 0x7e07
nopl (%rax)