// File: /workspace/github_c_makefile_star2_O1/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 $0x468, %rsp            # imm = 0x468
movq %r9, %r13
movq %r8, %r14
movq %rcx, 0x8(%rsp)
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r15
leaq 0x1f41(%rip), %rsi      # 0xa4da
movq %r9, %rdi
callq 0x23a0
testq %rax, %rax
je 0x85eb
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2310
cmpl $-0x1, %eax
je 0x85fe
movq %rbx, %rdi
callq 0x2030
cmpq $-0x1, %rax
je 0x8607
cmpq $0x400001, %rax         # imm = 0x400001
jl 0x8634
leaq 0x32d0(%rip), %rdi      # 0xb8aa
movq %r13, %rsi
movl $0x4, %edx
xorl %eax, %eax
callq 0x22d0
jmp 0x8615
leaq 0x323c(%rip), %rdi      # 0xb82e
movq %r13, %rsi
xorl %eax, %eax
callq 0x2110
jmp 0x861d
leaq 0x3295(%rip), %rdi      # 0xb89a
jmp 0x860e
leaq 0x3294(%rip), %rdi      # 0xb8a2
xorl %eax, %eax
callq 0x2110
movq %rbx, %rdi
callq 0x2280
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x30(%rdi)
movq $0x0, 0x40(%rdi)
movq %r14, 0x10(%rdi)
movl %eax, (%rdi)
leaq 0x31f1(%rip), %rax      # 0xb851
movq %rax, 0x20(%rdi)
movq %rbp, 0x8(%rdi)
movl $0x2, 0x4(%rdi)
movq 0x18(%r15), %rax
movq %rax, 0x30(%rdi)
movq %r12, 0x40(%rdi)
movq 0x8(%rsp), %rax
movq %rax, 0x28(%rdi)
callq 0x7f74
testq %rax, %rax
je 0x8615
movq %rax, %r14
movq %rax, %rdi
callq 0x2150
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7c6d
movl %eax, %ebp
movq %r14, %rdi
callq 0x23c0
cmpl $-0x1, %ebp
je 0x8615
movq %rbx, %rdi
callq 0x20b0
leaq 0x60(%rsp), %r14
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %rbx, %rcx
callq 0x24d0
testl %eax, %eax
jle 0x86fd
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7c6d
cmpl $-0x1, %eax
jne 0x86c7
jmp 0x8615
movq %rbx, %rdi
callq 0x2280
movq %r15, %rdi
callq 0x829d
jmp 0x8622
nop