// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl 0x135b2(%rip), %eax     # 0x1bf94
addl $0x1, %eax
movslq %eax, %rsi
movl $0x1, %edi
callq 0x57a0
movq %rax, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
cmpl $0x0, 0x13577(%rip)     # 0x1bf7c
jl 0x8a1e
cmpl $0x0, 0x13562(%rip)     # 0x1bf70
jle 0x8a1e
movl 0x1355a(%rip), %eax     # 0x1bf70
subl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x8a27
movl 0x1743c(%rip), %eax     # 0x1fe60
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x17426(%rip), %eax     # 0x1fe5c
jge 0x8a43
movl 0x1741e(%rip), %eax     # 0x1fe5c
movl %eax, -0x38(%rbp)
jmp 0x8a65
movl -0x10(%rbp), %eax
cmpl 0x17414(%rip), %eax     # 0x1fe60
jle 0x8a59
movl 0x1740c(%rip), %eax     # 0x1fe60
movl %eax, -0x3c(%rbp)
jmp 0x8a5f
movl -0x10(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x13513(%rip), %eax     # 0x1bf94
jge 0x8ad8
movq 0x1350e(%rip), %rax     # 0x1bf98
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x7f, (%rax)
jbe 0x8aa4
jmp 0x8acd
movq 0x134ed(%rip), %rax     # 0x1bf98
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movslq -0xc(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x8a78
movq -0x20(%rbp), %rax
movslq 0x134b1(%rip), %rcx     # 0x1bf94
movb $0x0, (%rax,%rcx)
movq -0x20(%rbp), %rdi
leaq 0xbe6b(%rip), %rsi      # 0x1495d
callq 0x5470
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x8b1b
movq -0x20(%rbp), %rdi
leaq 0xbe59(%rip), %rsi      # 0x14965
callq 0x5470
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x8b1d
jmp 0x8b45
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
cmpl 0x17330(%rip), %eax     # 0x1fe5c
jge 0x8b37
movl 0x1732c(%rip), %eax     # 0x1fe60
movl %eax, -0x10(%rbp)
jmp 0x8b39
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x8a71
cmpq $0x0, -0x30(%rbp)
je 0x8c34
callq 0x5eb0
movq -0x20(%rbp), %rdi
callq 0x5360
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
callq 0x5360
movq %rax, %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movl %eax, 0x13401(%rip)     # 0x1bf7c
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x8bc1
movq -0x28(%rbp), %rax
movsbl (%rax), %esi
leaq 0x10973(%rip), %rdi     # 0x19510
callq 0x5550
cmpq $0x0, %rax
jne 0x8bb1
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x8bc1
jmp 0x8bb3
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x8b83
movl $0x1, 0x13395(%rip)     # 0x1bf60
movl $0x1, 0x1338f(%rip)     # 0x1bf64
movslq 0x133a0(%rip), %rax     # 0x1bf7c
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
callq 0x5360
movq %rax, %rcx
movq -0x50(%rbp), %rax
addq %rcx, %rax
subq $0x1, %rax
movl %eax, 0x13387(%rip)     # 0x1bf84
movl -0x10(%rbp), %eax
movl %eax, 0x13382(%rip)     # 0x1bf88
movl %eax, 0x13374(%rip)     # 0x1bf80
callq 0x5ef0
movl 0x13359(%rip), %edi     # 0x1bf70
movl 0x1335b(%rip), %esi     # 0x1bf78
callq 0x60a0
callq 0x63a0
movq %rax, %rdi
callq 0xcb10
callq 0xca80
movq -0x20(%rbp), %rdi
callq 0x5330
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)