// File: /workspace/github_c_makefile_star2_O1/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 0x1028a(%rip), %r14d    # 0x181c4
movslq %r14d, %rcx
movq %rcx, 0x18(%rsp)
leaq 0x1(%rcx), %rsi
movl $0x1, %edi
callq 0x57a0
movq %rax, %rbx
movl 0x10253(%rip), %edx     # 0x181ac
movl 0x10241(%rip), %ecx     # 0x181a0
leal -0x1(%rcx), %eax
movq %rcx, 0x10(%rsp)
testl %ecx, %ecx
movl 0x14120(%rip), %r12d    # 0x1c090
cmovlel %r12d, %eax
movl %edx, 0x4(%rsp)
testl %edx, %edx
cmovsl %r12d, %eax
movl 0x14108(%rip), %ecx     # 0x1c08c
cmpl %r12d, %eax
movl %r12d, 0xc(%rsp)
cmovll %eax, %r12d
cmpl %ecx, %eax
movl %ecx, 0x8(%rsp)
cmovll %ecx, %r12d
movq 0x10227(%rip), %r13     # 0x181c8
movq %r14, 0x20(%rsp)
shlq $0x4, %r14
movl %r12d, %ebp
cmpl $0x0, 0x20(%rsp)
jle 0x7fd8
movslq %ebp, %rax
xorl %ecx, %ecx
movq %rbx, %rdx
movq (%r13,%rax,8), %rsi
movl (%rsi,%rcx), %esi
cmpl $0x7f, %esi
ja 0x7fcc
movb %sil, (%rdx)
incq %rdx
addq $0x10, %rcx
cmpq %rcx, %r14
jne 0x7fbc
movq 0x18(%rsp), %rax
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
leaq 0x86c2(%rip), %rsi      # 0x106ad
callq 0x5470
testq %rax, %rax
jne 0x8021
movq %rbx, %rdi
leaq 0x86b6(%rip), %rsi      # 0x106b5
callq 0x5470
testq %rax, %rax
jne 0x8021
cmpl 0x8(%rsp), %ebp
leal -0x1(%rbp), %eax
movl %eax, %ebp
cmovlel 0xc(%rsp), %ebp
cmpl %r12d, %ebp
jne 0x7fad
xorl %r15d, %r15d
jmp 0x8024
movq %rax, %r15
testq %r15, %r15
je 0x8109
cmpl $-0x1, 0x4(%rsp)
je 0x8058
movl $0x0, 0x10152(%rip)     # 0x18190
movl $0xffffffff, 0x10164(%rip) # imm = 0xFFFFFFFF
movl 0x1015a(%rip), %esi     # 0x181a8
movq 0x10(%rsp), %rdi
callq 0x629b
movq %rbx, %rdi
callq 0x5360
movq %rax, %r14
movq %r15, %rdi
callq 0x5360
subl %eax, %r14d
movl %r14d, 0x10137(%rip)    # 0x181ac
movb (%r15), %al
testb %al, %al
je 0x80aa
leaq 0x1(%r15), %r12
leaq 0xf479(%rip), %r14      # 0x17500
movsbl %al, %esi
movq %r14, %rdi
callq 0x5550
testq %rax, %rax
je 0x80a4
movb (%r12), %al
incq %r12
testb %al, %al
jne 0x8087
jmp 0x80aa
movb $0x0, -0x1(%r12)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x100d5(%rip)     # 0x18190
movl 0x100ea(%rip), %r14d    # 0x181ac
movq %r15, %rdi
callq 0x5360
addl %r14d, %eax
decl %eax
movl %eax, 0x100df(%rip)     # 0x181b4
movl %ebp, 0x100dd(%rip)     # 0x181b8
movl %ebp, 0x100cf(%rip)     # 0x181b0
callq 0x619f
movl 0x100b4(%rip), %edi     # 0x181a0
movl 0x100b6(%rip), %esi     # 0x181a8
callq 0x629b
callq 0x6484
movq %rax, %rdi
callq 0xa99a
callq 0xa938
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5330