// File: /workspace/github_c_makefile_star2_O2/andys8[P]st/st.c
// Function: copyurl
void
copyurl(const Arg *arg) {
	/* () and [] can appear in urls, but excluding them here will reduce false
	 * positives when figuring out where a given url ends.
	 */
	static char URLCHARS[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		"abcdefghijklmnopqrstuvwxyz"
		"0123456789-._~:/?#@!$&'*+,;=%";

	int i, row, startrow;
	char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
	char *c, *match = NULL;

	row = (sel.ob.x >= 0 && sel.nb.y > 0) ? sel.nb.y-1 : term.bot;
	LIMIT(row, term.top, term.bot);
	startrow = row;

	/* find the start of the last url before selection */
	do {
		for (i = 0; i < term.col; ++i) {
			if (term.line[row][i].u > 127) /* assume ascii */
				continue;
			linestr[i] = term.line[row][i].u;
		}
		linestr[term.col] = '\0';
		if ((match = strstr(linestr, "http://"))
				|| (match = strstr(linestr, "https://")))
			break;
		if (--row < term.top)
			row = term.bot;
	} while (row != startrow);

	if (match) {
		/* must happen before trim */
		selclear();
		sel.ob.x = strlen(linestr) - strlen(match);

		/* trim the rest of the line from the url match */
		for (c = match; *c != '\0'; ++c)
			if (!strchr(URLCHARS, *c)) {
				*c = '\0';
				break;
			}

		/* select and copy */
		sel.mode = 1;
		sel.type = SEL_REGULAR;
		sel.oe.x = sel.ob.x + strlen(match)-1;
		sel.ob.y = sel.oe.y = row;
		selnormalize();
		tsetdirt(sel.nb.y, sel.ne.y);
		xsetsel(getsel());
		xclipcopy();
	}

	free(linestr);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movslq 0xf9a0(%rip), %r14      # 0x171c4
leaq 0x1(%r14), %rsi
pushq $0x1
popq %rdi
callq 0x5790
movl 0xf96a(%rip), %ecx      # 0x171a0
leal -0x1(%rcx), %edx
testl %ecx, %ecx
movl 0x1384e(%rip), %r12d    # 0x1b090
cmovlel %r12d, %edx
cmpl $0x0, 0xf95f(%rip)      # 0x171ac
movq %rax, %rbx
cmovsl %r12d, %edx
movl 0x13832(%rip), %eax     # 0x1b08c
cmpl %r12d, %edx
movl %r12d, 0xc(%rsp)
cmovll %edx, %r12d
cmpl %eax, %edx
movl %eax, 0x8(%rsp)
cmovll %eax, %r12d
movq 0xf951(%rip), %r15      # 0x171c8
xorl %ebp, %ebp
testl %r14d, %r14d
movq %r14, 0x10(%rsp)
cmovgl %r14d, %ebp
shlq $0x4, %rbp
movl %r12d, %r13d
movslq %r13d, %rax
movq %rbx, %rcx
xorl %edx, %edx
cmpq %rdx, %rbp
je 0x78b1
movq (%r15,%rax,8), %rsi
movl (%rsi,%rdx), %esi
cmpl $0x7f, %esi
ja 0x78a8
movb %sil, (%rcx)
addq $0x10, %rdx
incq %rcx
jmp 0x7894
movq 0x10(%rsp), %rax
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
leaq 0x7de7(%rip), %rsi      # 0xf6ab
callq 0x5470
testq %rax, %rax
jne 0x78fd
movq %rbx, %rdi
leaq 0x7ddb(%rip), %rsi      # 0xf6b3
callq 0x5470
testq %rax, %rax
jne 0x78fd
cmpl 0x8(%rsp), %r13d
leal -0x1(%r13), %eax
cmovlel 0xc(%rsp), %eax
movl %eax, %r13d
cmpl %r12d, %eax
jne 0x788c
jmp 0x79ab
movq %rax, %r14
callq 0x5d16
movq %rbx, %rdi
callq 0x5360
movq %rax, %r15
movq %r14, %rdi
callq 0x5360
subl %eax, %r15d
movl %r15d, 0xf88a(%rip)     # 0x171ac
leaq 0xebd7(%rip), %r12      # 0x16500
movq %r14, %rbp
movsbl (%rbp), %esi
testl %esi, %esi
je 0x7951
movq %r12, %rdi
callq 0x5550
testq %rax, %rax
je 0x7946
incq %rbp
jmp 0x792c
movb $0x0, (%rbp)
movl 0xf85b(%rip), %r15d     # 0x171ac
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0xf82e(%rip)      # 0x17190
movq %r14, %rdi
callq 0x5360
addl %r15d, %eax
decl %eax
movl %eax, 0xf83f(%rip)      # 0x171b4
movl %r13d, 0xf83c(%rip)     # 0x171b8
movl %r13d, 0xf82d(%rip)     # 0x171b0
callq 0x5d3f
movl 0xf812(%rip), %edi      # 0x171a0
movl 0xf814(%rip), %esi      # 0x171a8
callq 0x5e37
callq 0x5feb
movq %rax, %rdi
callq 0xa0ef
callq 0xa090
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5330