// File: /workspace/github_c_makefile_star2_O3/rakitzis[P]rc/which.c
// Function: which
extern char *which(char *name, bool verbose) {
	static char *test = NULL;
	static size_t testlen = 0;
	List *path;
	int len;
	struct stat st;
	if (name == NULL)	/* no filename? can happen with "> foo" as a command */
		return NULL;
	if (!initialized) {
		initialized = TRUE;
		uid = geteuid();
		gid = getegid();
#if HAVE_GETGROUPS
#if HAVE_POSIX_GETGROUPS
		ngroups = getgroups(0, (GETGROUPS_T *)0);
		if (ngroups < 0) {
			uerror("getgroups");
			rc_exit(1);
		}
#else
		ngroups = NGROUPS;
#endif
		if (ngroups) {	
			gidset = ealloc(ngroups * sizeof(GETGROUPS_T));
			getgroups(ngroups, gidset);
		}
#endif
	}
	if (isabsolute(name)) /* absolute pathname? */
		return rc_access(name, verbose, &st) ? name : NULL;
	len = strlen(name);
	for (path = varlookup("path"); path != NULL; path = path->n) {
		size_t need = strlen(path->w) + len + 2; /* one for null terminator, one for the '/' */
		if (testlen < need) {
			efree(test);
			test = ealloc(testlen = need);
		}
		if (*path->w == '\0') {
			strcpy(test, name);
		} else {
			strcpy(test, path->w);
			if (!streq(test, "/")) /* "//" is special to POSIX */
				strcat(test, "/");
			strcat(test, name);
		}
		if (rc_access(test, FALSE, &st))
			return test;
	}
	if (verbose)
		fprint(2, RC "cannot find `%s'\n", name);
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
testq %rdi, %rdi
je 0xe031
movl %esi, %ebp
movq %rdi, %rbx
cmpb $0x0, 0xd161(%rip)      # 0x1aff8
jne 0xdf0a
movb $0x1, 0xd158(%rip)      # 0x1aff8
callq 0x3160
movl %eax, 0xd135(%rip)      # 0x1afe0
callq 0x3280
movl %eax, 0xd12e(%rip)      # 0x1afe4
xorl %edi, %edi
xorl %esi, %esi
callq 0x3260
movl %eax, 0xd137(%rip)      # 0x1affc
testl %eax, %eax
jns 0xdee5
leaq 0x68dc(%rip), %rdi      # 0x147ac
callq 0xc6dd
movl $0x1, %edi
callq 0x4eb5
movl 0xd117(%rip), %eax      # 0x1affc
testl %eax, %eax
je 0xdf0a
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0xa00d
movq %rax, 0xd104(%rip)      # 0x1b000
movl 0xd0fa(%rip), %edi      # 0x1affc
movq %rax, %rsi
callq 0x3260
movq %rbx, %rdi
callq 0xc7b8
testl %eax, %eax
je 0xdf33
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0xddc0
xorl %r14d, %r14d
testl %eax, %eax
cmovneq %rbx, %r14
jmp 0xe034
movl %ebp, 0x4(%rsp)
movq %rbx, %rdi
callq 0x30f0
movq %rax, %r15
leaq 0x118e(%rip), %rdi      # 0xf0d7
callq 0xc9da
testq %rax, %rax
je 0xe00f
movq %rax, %r14
movslq %r15d, %rbp
addq $0x2, %rbp
leaq 0x8(%rsp), %r15
movq (%r14), %r13
movq %r13, %rdi
callq 0x30f0
movq %rax, %r12
addq %rbp, %r12
cmpq %r12, 0xd072(%rip)      # 0x1aff0
jae 0xdfa5
movq 0xd061(%rip), %rdi      # 0x1afe8
callq 0x9fde
movq %r12, 0xd05d(%rip)      # 0x1aff0
movq %r12, %rdi
callq 0xa00d
movq %rax, 0xd046(%rip)      # 0x1afe8
movq (%r14), %r13
cmpb $0x0, (%r13)
movq 0xd037(%rip), %r12      # 0x1afe8
movq %r12, %rdi
je 0xdfe9
movq %r13, %rsi
callq 0x3070
cmpb $0x2f, (%r12)
jne 0xdfcd
cmpb $0x0, 0x1(%r12)
je 0xdfdc
movq %r12, %rdi
callq 0x30f0
movw $0x2f, (%r12,%rax)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3310
jmp 0xdff1
movq %rbx, %rsi
callq 0x3070
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0xddc0
testl %eax, %eax
jne 0xe049
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0xdf66
cmpl $0x0, 0x4(%rsp)
je 0xe031
leaq 0x6799(%rip), %rsi      # 0x147b6
xorl %r14d, %r14d
movl $0x2, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xaf8c
jmp 0xe034
xorl %r14d, %r14d
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xcf98(%rip), %r14      # 0x1afe8
jmp 0xe034