// File: /workspace/github_c_makefile_star2_O0/mrdotx[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-._~:/?#@!$&'*+,;=%";

	static const char* URLSTRINGS[] = {"http://", "https://"};

	/* remove highlighting from previous selection if any */
	if(sel.ob.x >= 0 && sel.oe.x >= 0)
		tsetcolor(sel.nb.y, sel.ob.x, sel.oe.x + 1, defaultfg, defaultbg);

	int i = 0,
		row = 0, /* row of current URL */
		col = 0, /* column of current URL start */
		startrow = 0, /* row of last occurrence */
		colend = 0, /* column of last occurrence */
		passes = 0; /* how many rows have been scanned */

	char *linestr = calloc(term.col+1, sizeof(Rune));
	char *c = NULL,
		 *match = NULL;

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

	colend = (sel.ob.x >= 0 && sel.nb.y > 0) ? sel.nb.x : term.col;
	LIMIT(colend, 0, term.col);

	/*
 	** Scan from (term.bot,term.col) to (0,0) and find
	** next occurrance of a URL
	*/
	while(passes !=term.bot + 2) {
		/* Read in each column of every row until
 		** we hit previous occurrence of URL
		*/
		for (col = 0, i = 0; col < colend; ++col,++i) {
			linestr[i] = term.line[row][col].u;
		}
		linestr[term.col] = '\0';

		if ((match = findlastany(linestr, URLSTRINGS,
						sizeof(URLSTRINGS)/sizeof(URLSTRINGS[0]))))
			break;

		if (--row < term.top)
			row = term.bot;

		colend = term.col;
		passes++;
	};

	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;
			}

		/* highlight selection by inverting terminal colors */
		tsetcolor(row, sel.ob.x, sel.ob.x + strlen( match ), defaultbg, defaultfg);

		/* 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 $0x70, %rsp
movq %rdi, -0x8(%rbp)
cmpl $0x0, 0x13dd1(%rip)     # 0x1e2b4
jl 0xa51b
cmpl $0x0, 0x13dd0(%rip)     # 0x1e2bc
jl 0xa51b
movl 0x13db4(%rip), %edi     # 0x1e2a8
movl 0x13dba(%rip), %esi     # 0x1e2b4
movl 0x13dbc(%rip), %edx     # 0x1e2bc
addl $0x1, %edx
leaq 0x112b6(%rip), %rax     # 0x1b7c0
movl (%rax), %ecx
leaq 0x112b1(%rip), %rax     # 0x1b7c4
movl (%rax), %r8d
callq 0xa860
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl 0x13d81(%rip), %eax     # 0x1e2cc
addl $0x1, %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x6790
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
cmpl $0x0, 0x13d3e(%rip)     # 0x1e2b4
jl 0xa58c
cmpl $0x0, 0x13d29(%rip)     # 0x1e2a8
jle 0xa58c
movl 0x13d21(%rip), %eax     # 0x1e2a8
movl %eax, -0x3c(%rbp)
jmp 0xa595
movl 0x14d26(%rip), %eax     # 0x1f2b8
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x14d10(%rip), %eax     # 0x1f2b4
jge 0xa5b1
movl 0x14d08(%rip), %eax     # 0x1f2b4
movl %eax, -0x40(%rbp)
jmp 0xa5d3
movl -0x10(%rbp), %eax
cmpl 0x14cfe(%rip), %eax     # 0x1f2b8
jle 0xa5c7
movl 0x14cf6(%rip), %eax     # 0x1f2b8
movl %eax, -0x44(%rbp)
jmp 0xa5cd
movl -0x10(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, 0x13cce(%rip)     # 0x1e2b4
jl 0xa5fc
cmpl $0x0, 0x13cb9(%rip)     # 0x1e2a8
jle 0xa5fc
movl 0x13cad(%rip), %eax     # 0x1e2a4
movl %eax, -0x48(%rbp)
jmp 0xa605
movl 0x13cca(%rip), %eax     # 0x1e2cc
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0xa618
xorl %eax, %eax
movl %eax, -0x4c(%rbp)
jmp 0xa63a
movl -0x1c(%rbp), %eax
cmpl 0x13cab(%rip), %eax     # 0x1e2cc
jle 0xa62e
movl 0x13ca3(%rip), %eax     # 0x1e2cc
movl %eax, -0x50(%rbp)
jmp 0xa634
movl -0x1c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
movl 0x14c6f(%rip), %ecx     # 0x1f2b8
addl $0x2, %ecx
cmpl %ecx, %eax
je 0xa708
movl $0x0, -0x14(%rbp)
movl $0x0, -0xc(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa6a7
movq 0x13c5f(%rip), %rax     # 0x1e2d0
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movslq -0xc(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xa662
movq -0x28(%rbp), %rax
movslq 0x13c1a(%rip), %rcx     # 0x1e2cc
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rdi
leaq 0x10eaf(%rip), %rsi     # 0x1b570
movl $0x2, %edx
callq 0xa8d0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0xa6d7
jmp 0xa708
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
cmpl 0x14bce(%rip), %eax     # 0x1f2b4
jge 0xa6f1
movl 0x14bca(%rip), %eax     # 0x1f2b8
movl %eax, -0x10(%rbp)
movl 0x13bd5(%rip), %eax     # 0x1e2cc
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xa640
cmpq $0x0, -0x38(%rbp)
je 0xa844
callq 0x6f40
movq -0x28(%rbp), %rdi
callq 0x6390
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rdi
callq 0x6390
movq %rax, %rcx
movq -0x58(%rbp), %rax
subq %rcx, %rax
movl %eax, 0x13b76(%rip)     # 0x1e2b4
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xa784
movq -0x30(%rbp), %rax
movsbl (%rax), %esi
leaq 0x10db0(%rip), %rdi     # 0x1b510
callq 0x6550
cmpq $0x0, %rax
jne 0xa774
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
jmp 0xa784
jmp 0xa776
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xa746
movl -0x10(%rbp), %eax
movl %eax, -0x70(%rbp)
movl 0x13b24(%rip), %eax     # 0x1e2b4
movl %eax, -0x6c(%rbp)
movslq 0x13b1a(%rip), %rax     # 0x1e2b4
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rdi
callq 0x6390
movl -0x70(%rbp), %edi
movl -0x6c(%rbp), %esi
movq %rax, %rcx
movq -0x68(%rbp), %rax
addq %rcx, %rax
movl %eax, %edx
leaq 0x11004(%rip), %rax     # 0x1b7c4
movl (%rax), %ecx
leaq 0x10ff7(%rip), %rax     # 0x1b7c0
movl (%rax), %r8d
callq 0xa860
movl $0x1, 0x13abd(%rip)     # 0x1e298
movl $0x1, 0x13ab7(%rip)     # 0x1e29c
movslq 0x13ac8(%rip), %rax     # 0x1e2b4
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rdi
callq 0x6390
movq %rax, %rcx
movq -0x60(%rbp), %rax
addq %rcx, %rax
subq $0x1, %rax
movl %eax, 0x13aaf(%rip)     # 0x1e2bc
movl -0x10(%rbp), %eax
movl %eax, 0x13aaa(%rip)     # 0x1e2c0
movl %eax, 0x13a9c(%rip)     # 0x1e2b8
callq 0x6f80
movl 0x13a81(%rip), %edi     # 0x1e2a8
movl 0x13a83(%rip), %esi     # 0x1e2b0
callq 0x7130
callq 0x7430
movq %rax, %rdi
callq 0xee00
callq 0xed70
movq -0x28(%rbp), %rdi
callq 0x6360
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)