// File: /workspace/github_c_makefile_star2_O0/tomka[P]cliaspora/http.c
// Function: http_gen_req
char *
http_gen_req(http_req_t *r)
{
	int    i, lc;
	char   *rq, *ln[16];
	size_t rqsz;

	rq = NULL; rqsz = 0; lc = 0;
	switch (r->type) {
	case HTTP_RQ_TYPE_GET:
		ln[lc++] = strduprintf(HTTP_TMPL_GET_RQ, r->url);
		ln[lc++] = strduprintf("X-Requested-With: XMLHttpRequest\r\n");
		break;
	case HTTP_RQ_TYPE_POST:
		ln[lc++] = strduprintf(HTTP_TMPL_POST_RQ, r->url);
		if (r->cl > 0)
			ln[lc++] = strduprintf(HTTP_TMPL_CONTENT_LEN, r->cl);
		break;
	case HTTP_RQ_TYPE_DELETE:
		ln[lc++] = strduprintf(HTTP_TMPL_DELETE_RQ, r->url);
		break;
	default:
		warnx("http_gen_req(): Invalid request type: %d", r->type);
		return (NULL);
	}
	if (r->host != NULL)
		ln[lc++] = strduprintf(HTTP_TMPL_HOST, r->host);
	if (r->location != NULL)
		ln[lc++] = strduprintf(HTTP_TMPL_LOCATION, r->location);
	if (r->cookie != NULL)
		ln[lc++] = strduprintf(HTTP_TMPL_COOKIE, r->cookie);
	if (r->ua != NULL)
		ln[lc++] = strduprintf(HTTP_TMPL_USER_AGENT, r->ua);
	if (r->cs != NULL)
		ln[lc++] = strduprintf(HTTP_TMPL_CHARSET, r->cs);
	else
		ln[lc++] = strduprintf(HTTP_TMPL_CHARSET, "UTF-8");
	if (r->ct != NULL)
		ln[lc++] = strduprintf(HTTP_TMPL_CONTENT_TYPE, r->ct);
	if (r->accept != NULL)
		ln[lc++] = strduprintf(HTTP_TMPL_ACCEPT, r->accept);
	ln[lc++] = strduprintf("Cache-Control: no-cache\r\n\r\n");
	for (i = 0; i < lc; i++) {
		if (ln[i] == NULL)
			goto error;
		if (strdupstrcat(&rq, &rqsz, ln[i], strlen(ln[i])) == NULL)
			goto error;
		free(ln[i]); ln[i] = NULL;
	}
	return (rq);
error:
	while (lc--)
		free(ln[lc]);
	free(rq);
	return (NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0xa8(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xac(%rbp)
subl $0x1, %eax
je 0xaabe
jmp 0xaa9d
movl -0xac(%rbp), %eax
subl $0x2, %eax
je 0xab17
jmp 0xaaaa
movl -0xac(%rbp), %eax
subl $0x3, %eax
je 0xab7c
jmp 0xabac
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x4ca2(%rip), %rdi      # 0xf76f
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
leaq 0x4c8e(%rip), %rdi      # 0xf781
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
jmp 0xabce
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x4c7e(%rip), %rdi      # 0xf7a4
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0xab7a
movq -0x10(%rbp), %rax
movl (%rax), %esi
leaq 0x4c5c(%rip), %rdi      # 0xf7b7
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
jmp 0xabce
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x4c41(%rip), %rdi      # 0xf7cc
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
jmp 0xabce
movq -0x10(%rbp), %rax
movl 0x4(%rax), %esi
leaq 0x4c27(%rip), %rdi      # 0xf7e1
movb $0x0, %al
callq 0x22f0
movq $0x0, -0x8(%rbp)
jmp 0xae8b
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0xac07
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
leaq 0x4c22(%rip), %rdi      # 0xf80a
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0xac40
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
leaq 0x4bf4(%rip), %rdi      # 0xf815
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xac79
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
leaq 0x4bca(%rip), %rdi      # 0xf824
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0xacb2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq 0x4b9e(%rip), %rdi      # 0xf831
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xaced
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0x4b76(%rip), %rdi      # 0xf842
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
jmp 0xad1a
leaq 0x4b4e(%rip), %rdi      # 0xf842
leaq 0x33cb(%rip), %rsi      # 0xe0c6
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0xad53
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
leaq 0x4b1c(%rip), %rdi      # 0xf850
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0xad8c
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
leaq 0x4af6(%rip), %rdi      # 0xf863
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
leaq 0x4add(%rip), %rdi      # 0xf870
movb $0x0, %al
callq 0xd570
movq %rax, %rcx
movl -0x18(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x18(%rbp)
cltq
movq %rcx, -0xa0(%rbp,%rax,8)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xae4b
movslq -0x14(%rbp), %rax
cmpq $0x0, -0xa0(%rbp,%rax,8)
jne 0xadd6
jmp 0xae55
movslq -0x14(%rbp), %rax
movq -0xa0(%rbp,%rax,8), %rax
movq %rax, -0xb8(%rbp)
movslq -0x14(%rbp), %rax
movq -0xa0(%rbp,%rax,8), %rdi
callq 0x2160
movq -0xb8(%rbp), %rdx
movq %rax, %rcx
leaq -0x20(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xd460
cmpq $0x0, %rax
jne 0xae1c
jmp 0xae55
movslq -0x14(%rbp), %rax
movq -0xa0(%rbp,%rax,8), %rdi
callq 0x23d0
movslq -0x14(%rbp), %rax
movq $0x0, -0xa0(%rbp,%rax,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xadb9
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xae8b
jmp 0xae57
movl -0x18(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x18(%rbp)
cmpl $0x0, %eax
je 0xae7a
movslq -0x18(%rbp), %rax
movq -0xa0(%rbp,%rax,8), %rdi
callq 0x23d0
jmp 0xae57
movq -0x20(%rbp), %rdi
callq 0x23d0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)