// File: /workspace/github_c_makefile_star2_O3/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 0x207c(%rip), %rsi      # 0xa4be
movq %r9, %rdi
callq 0x23a0
testq %rax, %rax
je 0x8494
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2310
cmpl $-0x1, %eax
je 0x84a7
movq %rbx, %rdi
callq 0x2030
cmpq $-0x1, %rax
je 0x84b0
cmpq $0x400001, %rax         # imm = 0x400001
jl 0x84dd
leaq 0x3407(%rip), %rdi      # 0xb88a
movq %r13, %rsi
movl $0x4, %edx
xorl %eax, %eax
callq 0x22d0
jmp 0x84be
leaq 0x3373(%rip), %rdi      # 0xb80e
movq %r13, %rsi
xorl %eax, %eax
callq 0x2110
jmp 0x84c6
leaq 0x33cc(%rip), %rdi      # 0xb87a
jmp 0x84b7
leaq 0x33cb(%rip), %rdi      # 0xb882
xorl %eax, %eax
callq 0x2110
movq %rbx, %rdi
callq 0x2280
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
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
movups %xmm0, 0x18(%rdi)
movups %xmm0, 0x28(%rdi)
movq $0x0, 0x38(%rdi)
movq %r14, 0x10(%rdi)
movl %eax, (%rdi)
leaq 0x332f(%rip), %rax      # 0xb831
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 (%rsp), %rax
movq %rax, 0x28(%rdi)
callq 0x7e24
testq %rax, %rax
je 0x84be
movq %rax, %r14
movq %rax, %rdi
callq 0x2150
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7b55
movl %eax, %ebp
movq %r14, %rdi
callq 0x23c0
cmpl $-0x1, %ebp
je 0x84be
movq %rbx, %rdi
callq 0x20b0
leaq 0x50(%rsp), %r14
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %rbx, %rcx
callq 0x24d0
testl %eax, %eax
jle 0x859e
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7b55
cmpl $-0x1, %eax
jne 0x8568
jmp 0x84be
movq %rbx, %rdi
callq 0x2280
movq %r15, %rdi
callq 0x814d
jmp 0x84cb
nop