// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
movzbl (%rdi), %eax
leaq 0x2d2c(%rip), %rcx      # 0x7b10
movzbl (%rcx,%rax), %ecx
testb $0x2, %cl
jne 0x4e02
testb $0x8, %cl
jne 0x4e24
xorl %edx, %edx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4d1b
movsbl %al, %ecx
addl $-0x30, %ecx
xorl %eax, %eax
leal (%rax,%rax,4), %eax
leal (%rcx,%rax,2), %eax
decq %rsi
jne 0x4e0a
cmpl 0x66d9(%rip), %eax      # 0xb4f4
jbe 0x4e54
xorl %ebx, %ebx
jmp 0x4f89
movzbl %al, %eax
xorl %ebx, %ebx
leal -0x21(%rax), %ecx
cmpl $0x9, %ecx
ja 0x4e66
leaq 0x2a18(%rip), %rax      # 0x7850
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x63f4(%rip), %rax      # 0xb23c
movl (%rax), %edx
testl %edx, %edx
jne 0x4f0b
jmp 0x4e1d
movq 0x669d(%rip), %rcx      # 0xb4f8
movl %eax, %eax
movq (%rcx,%rax,8), %rbx
jmp 0x4f89
cmpl $0x3f, %eax
je 0x4f02
cmpl $0x40, %eax
jne 0x4f89
movq 0x6681(%rip), %rdi      # 0xb500
testq %rdi, %rdi
je 0x4e89
callq 0x2050
movl 0x6664(%rip), %r14d     # 0xb4f4
testq %r14, %r14
je 0x4f25
movq 0x6658(%rip), %r15      # 0xb4f8
leal 0x1(%r14), %eax
cmpl $0x3, %eax
movl $0x2, %r12d
cmovael %eax, %r12d
movl $0x1, %r13d
movl $0x1, %ebx
movq (%r15,%r13,8), %rdi
callq 0x2100
addq %rax, %rbx
incq %r13
cmpq %r13, %r12
jne 0x4ebc
jmp 0x4f2a
callq 0x20e0
leaq 0x6602(%rip), %rbx      # 0xb4e0
leaq 0x29ac(%rip), %rsi      # 0x7891
movq %rbx, %rdi
movl %eax, %edx
jmp 0x4f1c
movl 0x6602(%rip), %edx      # 0xb4f4
leaq 0x65e7(%rip), %rbx      # 0xb4e0
leaq 0x2994(%rip), %rsi      # 0x7894
jmp 0x4f19
leaq 0x6317(%rip), %rax      # 0xb220
movl (%rax), %edx
leaq 0x65ce(%rip), %rbx      # 0xb4e0
leaq 0x2978(%rip), %rsi      # 0x7891
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2340
jmp 0x4f89
movl $0x1, %ebx
addq %r14, %rbx
movq %rbx, %rdi
callq 0x6540
movq %rax, 0x65c4(%rip)      # 0xb500
movb $0x0, (%rax)
cmpl $0x0, 0x65ae(%rip)      # 0xb4f4
je 0x4f82
movl $0x1, %ebx
movq 0x65a4(%rip), %rcx      # 0xb4f8
movl %ebx, %edx
movq (%rcx,%rdx,8), %rsi
movq %rax, %rdi
callq 0x20f0
cmpl 0x658c(%rip), %ebx      # 0xb4f4
jne 0x4f6e
movl %ebx, %ecx
jmp 0x4f7c
movw $0x20, (%rax)
incq %rax
movl 0x6578(%rip), %ecx      # 0xb4f4
incl %ebx
cmpl %ecx, %ebx
jbe 0x4f4d
movq 0x6577(%rip), %rbx      # 0xb500
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq