// File: /workspace/github_c_makefile_star2_O0/tomka[P]cliaspora/cliaspora.c
// Function: diaspora_login
static char *
diaspora_login(const char *host, u_short port, const char *user,
	       const char *pass)
{
	int	   status, tries;
	char	   *cookie, *scookie, *rq, *p, *q, *u, *head, *url, *atok;
	ssl_conn_t *cp;
	const char tmpl[] = "utf8=%%E2%%9C%%93&user%%5Busername%%5D=%s&"  \
                            "user%%5Bpassword%%5D=%s&user%%5Bremember_me" \
			    "%%5D=1&commit=Sign+in&authenticity_token=%s";

	errno = 0;
	if ((cp = ssl_connect(host, port)) == NULL) {
		return (NULL);
	}
	status = http_get(cp, "/users/sign_in", NULL, "*/*", USER_AGENT);
	if (status != 200) {
		warnx("Login failed. Server replied with code %d", status);
		return (NULL);
	}
	scookie = atok = NULL;
	while ((p = ssl_readln(cp)) != NULL && atok == NULL) {
		if (strncmp(p, "Set-Cookie:", 11) == 0) {
			for (q = p; (q = strtok(q, " ;")) != NULL; q = NULL) {
				if (strncmp(q, "_diaspora_session=", 18) != 0)
					continue;
				if ((scookie = strdup(q)) == NULL) {
					warn("strdup()"); ssl_disconnect(cp);
					return (NULL);
				}
			}
		} else if ((q = strstr(p, "name=\"authenticity_token\"")) !=
		    NULL) {
			if ((p = strstr(q, "value=")) != NULL) {
				while (*p != '\0' && *p != '=')
					p++;
				if (*p == '=')
					p++;
				if (*p == '"')
					p++;
				for (q = p; *q != '\0' && *q != '"'; q++)
					;
				*q = '\0';
				atok = strdup(p);
			}
		}
	}
	ssl_disconnect(cp);
	if (atok == NULL)
		warnx("Couldn't get authenticity token");
	if (scookie == NULL)
		warnx("Couldn't get session cookie");

	rq = u = p = head = url = NULL;
	if ((u = urlencode(user)) == NULL || (p = urlencode(pass)) == NULL) {
		free(u); free(p); return (NULL);
	}
	if ((rq = strduprintf(tmpl, u, p, atok == NULL ? "" : atok)) == NULL) {
		free(u); free(p); return (NULL);
	}
	free(u); free(p);

	tries = 0;
	do {
		if (tries > 0)
			sleep(2);
		if ((cp = ssl_connect(host, port)) == NULL) {
			free(rq); return (NULL);
		}
		status = http_post(cp, "/users/sign_in", scookie, "*/*",
		    USER_AGENT, HTTP_POST_TYPE_FORM, rq);
		if (status >= 400) {
			warnx("Login failed. Server replied with code %d",
			    status);
			return (NULL);
		} else if (status == -1)
			return (NULL);
		for (cookie = NULL;
		    (p = ssl_readln(cp)) != NULL && cookie == NULL;) {
			if (strncmp(p, "Set-Cookie:", 11) == 0) {
				for (q = p; (q = strtok(q, " ;")) != NULL;
				    q = NULL) {
					if (strncmp(q,
					    "remember_user_token=", 20) != 0)
						continue;
					if ((cookie = strdup(q)) == NULL) {
						warn("strdup()");
						ssl_disconnect(cp);
						return (NULL);
					}
				}
			}
		}
		ssl_disconnect(cp);
	} while (cookie == NULL && ++tries < 10);

	free(rq); free(scookie); free(atok);

	if (cookie == NULL) {
		if (errno == 0)
			warnx("Login failed.");
		return (NULL);
	}
	return (cookie);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movw %si, %ax
movq %rdi, -0x10(%rbp)
movw %ax, -0x12(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
leaq -0x110(%rbp), %rdi
leaq 0x8084(%rip), %rsi      # 0xf110
movl $0x81, %edx
callq 0x2220
callq 0x2060
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
movzwl -0x12(%rbp), %esi
callq 0x9f10
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
jne 0x70c5
movq $0x0, -0x8(%rbp)
jmp 0x767e
movq -0x80(%rbp), %rdi
leaq 0x7b26(%rip), %rsi      # 0xebf6
xorl %eax, %eax
movl %eax, %edx
leaq 0x78f8(%rip), %rcx      # 0xe9d3
leaq 0x785a(%rip), %r8       # 0xe93c
callq 0xb0a0
movl %eax, -0x2c(%rbp)
cmpl $0xc8, -0x2c(%rbp)
je 0x7111
movl -0x2c(%rbp), %esi
leaq 0x7b08(%rip), %rdi      # 0xec05
movb $0x0, %al
callq 0x22f0
movq $0x0, -0x8(%rbp)
jmp 0x767e
movq $0x0, -0x78(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x80(%rbp), %rdi
callq 0xa790
movq %rax, %rcx
movq %rcx, -0x50(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x111(%rbp)
je 0x714d
cmpq $0x0, -0x78(%rbp)
sete %al
movb %al, -0x111(%rbp)
movb -0x111(%rbp), %al
testb $0x1, %al
jne 0x715c
jmp 0x7317
movq -0x50(%rbp), %rdi
leaq 0x7ac8(%rip), %rsi      # 0xec2f
movl $0xb, %edx
callq 0x2180
cmpl $0x0, %eax
jne 0x7200
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq 0x7aae(%rip), %rsi      # 0xec3b
callq 0x2510
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x71fb
movq -0x58(%rbp), %rdi
leaq 0x7a97(%rip), %rsi      # 0xec3e
movl $0x12, %edx
callq 0x2180
cmpl $0x0, %eax
je 0x71b8
jmp 0x71f1
movq -0x58(%rbp), %rdi
callq 0x2580
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x71ef
leaq 0x7a15(%rip), %rdi      # 0xebe7
movb $0x0, %al
callq 0x2120
movq -0x80(%rbp), %rdi
callq 0xa220
movq $0x0, -0x8(%rbp)
jmp 0x767e
jmp 0x71f1
movq $0x0, -0x58(%rbp)
jmp 0x7182
jmp 0x7312
movq -0x50(%rbp), %rdi
leaq 0x7a46(%rip), %rsi      # 0xec51
callq 0x20e0
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x7310
movq -0x58(%rbp), %rdi
leaq 0x7a42(%rip), %rsi      # 0xec6b
callq 0x20e0
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x730e
jmp 0x723e
movq -0x50(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x112(%rbp)
je 0x7265
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
setne %al
movb %al, -0x112(%rbp)
movb -0x112(%rbp), %al
testb $0x1, %al
jne 0x7271
jmp 0x727f
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x723e
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x7297
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x72af
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x113(%rbp)
je 0x72de
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
setne %al
movb %al, -0x113(%rbp)
movb -0x113(%rbp), %al
testb $0x1, %al
jne 0x72ea
jmp 0x72fa
jmp 0x72ec
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x72b7
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
movq -0x50(%rbp), %rdi
callq 0x2580
movq %rax, -0x78(%rbp)
jmp 0x7310
jmp 0x7312
jmp 0x7121
movq -0x80(%rbp), %rdi
callq 0xa220
cmpq $0x0, -0x78(%rbp)
jne 0x7335
leaq 0x7944(%rip), %rdi      # 0xec72
movb $0x0, %al
callq 0x22f0
cmpq $0x0, -0x40(%rbp)
jne 0x734a
leaq 0x794f(%rip), %rdi      # 0xec92
movb $0x0, %al
callq 0x22f0
movq $0x0, -0x70(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x20(%rbp), %rdi
callq 0xaea0
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x7398
movq -0x28(%rbp), %rdi
callq 0xaea0
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jne 0x73b7
movq -0x60(%rbp), %rdi
callq 0x23d0
movq -0x50(%rbp), %rdi
callq 0x23d0
movq $0x0, -0x8(%rbp)
jmp 0x767e
leaq -0x110(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x120(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x73f2
leaq 0x8919(%rip), %rax      # 0xfd02
movq %rax, -0x138(%rbp)
jmp 0x73fd
movq -0x78(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x120(%rbp), %rdx
movq -0x128(%rbp), %rsi
movq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rcx
movb $0x0, %al
callq 0xd570
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0x7449
movq -0x60(%rbp), %rdi
callq 0x23d0
movq -0x50(%rbp), %rdi
callq 0x23d0
movq $0x0, -0x8(%rbp)
jmp 0x767e
movq -0x60(%rbp), %rdi
callq 0x23d0
movq -0x50(%rbp), %rdi
callq 0x23d0
movl $0x0, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x7472
movl $0x2, %edi
callq 0x2210
movq -0x10(%rbp), %rdi
movzwl -0x12(%rbp), %esi
callq 0x9f10
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
jne 0x749f
movq -0x48(%rbp), %rdi
callq 0x23d0
movq $0x0, -0x8(%rbp)
jmp 0x767e
movq -0x80(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rax
leaq 0x7744(%rip), %rsi      # 0xebf6
leaq 0x751a(%rip), %rcx      # 0xe9d3
leaq 0x747c(%rip), %r8       # 0xe93c
movl $0x3, %r9d
movq %rax, (%rsp)
callq 0xb1a0
movl %eax, -0x2c(%rbp)
cmpl $0x190, -0x2c(%rbp)     # imm = 0x190
jl 0x74f9
movl -0x2c(%rbp), %esi
leaq 0x7720(%rip), %rdi      # 0xec05
movb $0x0, %al
callq 0x22f0
movq $0x0, -0x8(%rbp)
jmp 0x767e
cmpl $-0x1, -0x2c(%rbp)
jne 0x750c
movq $0x0, -0x8(%rbp)
jmp 0x767e
jmp 0x750e
movq $0x0, -0x38(%rbp)
movq -0x80(%rbp), %rdi
callq 0xa790
movq %rax, %rcx
movq %rcx, -0x50(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x139(%rbp)
je 0x7542
cmpq $0x0, -0x38(%rbp)
sete %al
movb %al, -0x139(%rbp)
movb -0x139(%rbp), %al
testb $0x1, %al
jne 0x7551
jmp 0x75f7
movq -0x50(%rbp), %rdi
leaq 0x76d3(%rip), %rsi      # 0xec2f
movl $0xb, %edx
callq 0x2180
cmpl $0x0, %eax
jne 0x75f2
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
leaq 0x76b9(%rip), %rsi      # 0xec3b
callq 0x2510
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x75f0
movq -0x58(%rbp), %rdi
leaq 0x7712(%rip), %rsi      # 0xecae
movl $0x14, %edx
callq 0x2180
cmpl $0x0, %eax
je 0x75ad
jmp 0x75e6
movq -0x58(%rbp), %rdi
callq 0x2580
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x75e4
leaq 0x7620(%rip), %rdi      # 0xebe7
movb $0x0, %al
callq 0x2120
movq -0x80(%rbp), %rdi
callq 0xa220
movq $0x0, -0x8(%rbp)
jmp 0x767e
jmp 0x75e6
movq $0x0, -0x58(%rbp)
jmp 0x7577
jmp 0x75f2
jmp 0x7516
movq -0x80(%rbp), %rdi
callq 0xa220
xorl %eax, %eax
cmpq $0x0, -0x38(%rbp)
movb %al, -0x13a(%rbp)
jne 0x7624
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0xa, %eax
setl %al
movb %al, -0x13a(%rbp)
movb -0x13a(%rbp), %al
testb $0x1, %al
jne 0x7462
movq -0x48(%rbp), %rdi
callq 0x23d0
movq -0x40(%rbp), %rdi
callq 0x23d0
movq -0x78(%rbp), %rdi
callq 0x23d0
cmpq $0x0, -0x38(%rbp)
jne 0x7676
callq 0x2060
cmpl $0x0, (%rax)
jne 0x766c
leaq 0x765e(%rip), %rdi      # 0xecc3
movb $0x0, %al
callq 0x22f0
movq $0x0, -0x8(%rbp)
jmp 0x767e
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopl (%rax,%rax)