// File: /workspace/github_c_makefile_star2_O2/ebiggers[P]mysh/mysh_param.c
// Function: lookup_param
const char *
lookup_param(const char *name, size_t len)
{
	static char buf[20];
	unsigned char char_type = shell_char_type(*name);
	if (char_type & SHELL_PARAM_NUMERIC_CHAR) {
		/* Positional parameter */
		unsigned n = 0;
		do {
			n *= 10;
			n += *name - '0';
		} while (--len);
		if (n > num_positional_parameters)
			return NULL;
		else
			return positional_parameters[n];
	} else if (char_type & SHELL_PARAM_SPECIAL_CHAR) {
		/* Special variable */
		switch (*name) {
		case '$':
			/* $$: Process ID */
			sprintf(buf, "%d", getpid());
			return buf;
		case '?':
			/* $?: Exit status of last command */
			sprintf(buf, "%d", mysh_last_exit_status);
			return buf;
		case '#':
			/* $#: Number of positional parameters */
			sprintf(buf, "%u", num_positional_parameters);
			return buf;
		case '!':
			/* $!: pid of last process in last background pipeline */
			if (mysh_last_background_pid == 0) {
				return NULL;
			} else {
				sprintf(buf, "%d", mysh_last_background_pid);
				return buf;
			}
		case '*':
		case '@': /* Note: $@ does not yet behave correctly (it's treated the same as $*) */
			/* All positional parameters */
			return get_all_positional_params();
		}
	} else {
		/* Regular variable; look it up in the trie. */
		return lookup_shell_param_len(name, len);
	}
	return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movzbl (%rdi), %eax
leaq 0x331a(%rip), %rcx      # 0x7b10
movzbl (%rcx,%rax), %ecx
testb $0x2, %cl
jne 0x4814
testb $0x8, %cl
jne 0x4835
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x4741
movsbl %al, %ecx
addl $-0x30, %ecx
xorl %eax, %eax
imull $0xa, %eax, %eax
addl %ecx, %eax
decq %rsi
jne 0x481c
cmpl 0x6cc8(%rip), %eax      # 0xb4f4
jbe 0x4865
xorl %ebx, %ebx
jmp 0x496f
movzbl %al, %eax
xorl %ebx, %ebx
leal -0x21(%rax), %ecx
cmpl $0x9, %ecx
ja 0x4877
leaq 0x3007(%rip), %rax      # 0x7850
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x69e3(%rip), %rax      # 0xb23c
movl (%rax), %edx
testl %edx, %edx
jne 0x4957
jmp 0x482e
movq 0x6c8c(%rip), %rcx      # 0xb4f8
movl %eax, %eax
movq (%rcx,%rax,8), %rbx
jmp 0x496f
cmpl $0x3f, %eax
je 0x494e
cmpl $0x40, %eax
jne 0x496f
movq 0x6c70(%rip), %rdi      # 0xb500
callq 0x2050
movl 0x6c58(%rip), %r14d     # 0xb4f4
movq 0x6c55(%rip), %r15      # 0xb4f8
pushq $0x1
popq %rbx
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x48c0
movq 0x8(%r15,%r12,8), %rdi
callq 0x2100
addq %rax, %rbx
incq %r12
jmp 0x48a9
addq %r14, %rbx
movq %rbx, %rdi
callq 0x6099
movq %rax, 0x6c2e(%rip)      # 0xb500
movb $0x0, (%rax)
pushq $0x1
popq %rbx
movl 0x6c16(%rip), %ecx      # 0xb4f4
cmpl %ecx, %ebx
ja 0x4915
movq 0x6c0f(%rip), %rcx      # 0xb4f8
movl %ebx, %edx
movq (%rcx,%rdx,8), %rsi
movq %rax, %rdi
callq 0x20f0
cmpl 0x6bf7(%rip), %ebx      # 0xb4f4
jne 0x4903
movl %ebx, %ecx
jmp 0x4911
movw $0x20, (%rax)
incq %rax
movl 0x6be3(%rip), %ecx      # 0xb4f4
incl %ebx
jmp 0x48de
movq 0x6be4(%rip), %rbx      # 0xb500
jmp 0x496f
callq 0x20e0
leaq 0x6bb6(%rip), %rbx      # 0xb4e0
leaq 0x2f60(%rip), %rsi      # 0x7891
movq %rbx, %rdi
movl %eax, %edx
jmp 0x4968
movl 0x6bb6(%rip), %edx      # 0xb4f4
leaq 0x6b9b(%rip), %rbx      # 0xb4e0
leaq 0x2f48(%rip), %rsi      # 0x7894
jmp 0x4965
leaq 0x68cb(%rip), %rax      # 0xb220
movl (%rax), %edx
leaq 0x6b82(%rip), %rbx      # 0xb4e0
leaq 0x2f2c(%rip), %rsi      # 0x7891
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2340
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq