// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x38(%rbp), %rdi
leaq 0x35d8(%rip), %rsi      # 0xea16
callq 0x23b0
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jne 0xb46b
movq -0x38(%rbp), %rsi
leaq 0x445a(%rip), %rdi      # 0xf8b2
movb $0x0, %al
callq 0x2120
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb677
movq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x2330
cmpl $-0x1, %eax
jne 0xb4a5
leaq 0x4495(%rip), %rdi      # 0xf91e
movb $0x0, %al
callq 0x2120
movq -0x50(%rbp), %rdi
callq 0x22a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb677
movq -0x50(%rbp), %rdi
callq 0x2030
movq %rax, -0x48(%rbp)
cmpq $-0x1, %rax
jne 0xb4db
leaq 0x4467(%rip), %rdi      # 0xf926
movb $0x0, %al
callq 0x2120
movq -0x50(%rbp), %rdi
callq 0x22a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb677
cmpq $0x400000, -0x48(%rbp)  # imm = 0x400000
jle 0xb511
movq -0x38(%rbp), %rsi
leaq 0x443e(%rip), %rdi      # 0xf92e
movl $0x4, %edx
movb $0x0, %al
callq 0x22f0
movq -0x50(%rbp), %rdi
callq 0x22a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb677
leaq -0x4a8(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x21d0
movq -0x30(%rbp), %rax
movq %rax, -0x498(%rbp)
movq -0x48(%rbp), %rax
movl %eax, -0x4a8(%rbp)
leaq 0x4395(%rip), %rax      # 0xf8d5
movq %rax, -0x488(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x4a0(%rbp)
movl $0x2, -0x4a4(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x478(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x468(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x480(%rbp)
leaq -0x4a8(%rbp), %rdi
callq 0xaa60
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jne 0xb5ac
movq -0x50(%rbp), %rdi
callq 0x22a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb677
movq -0x10(%rbp), %rax
movq %rax, -0x4b8(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x4b0(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2160
movq -0x4b8(%rbp), %rdi
movq -0x4b0(%rbp), %rsi
movq %rax, %rdx
callq 0xa550
cmpl $-0x1, %eax
jne 0xb601
movq -0x58(%rbp), %rdi
callq 0x23d0
movq -0x50(%rbp), %rdi
callq 0x22a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb677
movq -0x58(%rbp), %rdi
callq 0x23d0
movq -0x50(%rbp), %rdi
callq 0x20c0
leaq -0x460(%rbp), %rdi
movq -0x50(%rbp), %rcx
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x24e0
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jle 0xb662
movq -0x10(%rbp), %rdi
leaq -0x460(%rbp), %rsi
movslq -0x3c(%rbp), %rdx
callq 0xa550
cmpl $-0x1, %eax
jne 0xb660
movq -0x50(%rbp), %rdi
callq 0x22a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb677
jmp 0xb613
movq -0x50(%rbp), %rdi
callq 0x22a0
movq -0x10(%rbp), %rdi
callq 0xafc0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)