// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl 0xfde0(%rip), %r14d     # 0x181c4
movslq %r14d, %rcx
movq %rcx, 0x20(%rsp)
leaq 0x1(%rcx), %rsi
movl $0x1, %edi
callq 0x5790
movq %rax, %rbx
movl 0xfd9d(%rip), %ecx      # 0x181a0
leal -0x1(%rcx), %eax
movq %rcx, 0x10(%rsp)
testl %ecx, %ecx
movl 0x13c7c(%rip), %r13d    # 0x1c090
cmovlel %r13d, %eax
movl 0xfd8e(%rip), %ecx      # 0x181ac
movl %ecx, 0x8(%rsp)
testl %ecx, %ecx
cmovsl %r13d, %eax
cmpl %r13d, %eax
movl %r13d, %r12d
cmovll %eax, %r12d
movl 0x13c54(%rip), %ecx     # 0x1c08c
cmpl %ecx, %eax
movl %ecx, 0xc(%rsp)
cmovll %ecx, %r12d
movq 0xfd7f(%rip), %rax      # 0x181c8
movq %rax, 0x18(%rsp)
movl %r12d, %ebp
testl %r14d, %r14d
jle 0x847a
movslq %ebp, %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rax
xorl %ecx, %ecx
movl (%rax), %edx
cmpl $0x7f, %edx
ja 0x846e
movb %dl, (%rbx,%rcx)
incq %rcx
addq $0x10, %rax
cmpq %rcx, %r14
jne 0x8464
movq 0x20(%rsp), %rax
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
leaq 0x824e(%rip), %rsi      # 0x106db
callq 0x5470
testq %rax, %rax
jne 0x84c2
movq %rbx, %rdi
leaq 0x8242(%rip), %rsi      # 0x106e3
callq 0x5470
testq %rax, %rax
jne 0x84c2
cmpl 0xc(%rsp), %ebp
leal -0x1(%rbp), %eax
cmovlel %r13d, %eax
movl %eax, %ebp
cmpl %r12d, %eax
jne 0x8451
jmp 0x85a0
movq %rax, %r15
cmpl $-0x1, 0x8(%rsp)
je 0x84f0
movl $0x0, 0xfcba(%rip)      # 0x18190
movl $0xffffffff, 0xfccc(%rip) # imm = 0xFFFFFFFF
movl 0xfcc2(%rip), %esi      # 0x181a8
movq 0x10(%rsp), %rdi
callq 0x628b
movq %rbx, %rdi
callq 0x5360
movq %rax, %r14
movq %r15, %rdi
callq 0x5360
subl %eax, %r14d
movl %r14d, 0xfc9f(%rip)     # 0x181ac
movb (%r15), %al
testb %al, %al
je 0x8548
leaq 0x1(%r15), %r13
leaq 0xefe1(%rip), %r12      # 0x17500
movsbl %al, %esi
movq %r12, %rdi
callq 0x5550
testq %rax, %rax
je 0x853c
movb (%r13), %al
incq %r13
testb %al, %al
jne 0x851f
jmp 0x8548
movb $0x0, -0x1(%r13)
movl 0xfc64(%rip), %r14d     # 0x181ac
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0xfc37(%rip)      # 0x18190
movq %r15, %rdi
callq 0x5360
addl %r14d, %eax
decl %eax
movl %eax, 0xfc48(%rip)      # 0x181b4
movl %ebp, 0xfc46(%rip)      # 0x181b8
movl %ebp, 0xfc38(%rip)      # 0x181b0
callq 0x618f
movl 0xfc1d(%rip), %edi      # 0x181a0
movl 0xfc1f(%rip), %esi      # 0x181a8
callq 0x628b
callq 0x655a
movq %rax, %rdi
callq 0xb01a
callq 0xafb8
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5330