// File: /workspace/github_c_makefile_star2_O0/ebiggers[P]mysh/mysh_param.c
// Function: do_param_expansion
struct string *
do_param_expansion(struct string *s, unsigned char **param_char_map)
{
	const char *var_begin;
	const char *dollar_sign;
	const char *var_end;
	const char *scan_next;
	unsigned char mask;
	unsigned char char_type;
	struct string *tmp;
	size_t len;
	struct list_head string_list;
	bool bracketed;

	*param_char_map = NULL;
	var_end = s->chars;
	dollar_sign = strchr(var_end, '$');
	if (!dollar_sign || *(dollar_sign + 1) == '\0') {
		/* No parameter expansion to be done.
		 * Return the original string. */
		return s;
	}

	/* As a result of doing the expansions, we will produce a list of
	 * strings in the list @string_list, each of which will correspond to
	 * either literal characters or to characters that were produced as a
	 * result of a parameter expansion.  These strings are later joined
	 * together to produce the returned, expanded string. */
	INIT_LIST_HEAD(&string_list);
	do {
		/* Append the literal characters (if any) from after the end of
		 * the previous variable (or the beginning of the string) up
		 * until the dollar sign. */
		if (dollar_sign > var_end)
			append_string(var_end, dollar_sign - var_end, &string_list);

		/* Parse the parameter name.  There are several cases; for
		 * example, the parameter may be specified as ${foo} rather than
		 * $foo.  Parameters beginning with a number are positional
		 * parameters, so they are parsed up until the first non-digit
		 * or closing '}'.  Any invalid sequences, such as the missing
		 * closing '}', are just output literally. */
		var_begin = dollar_sign + 1;
		if (*var_begin == '{') {
			bracketed = true;
			var_begin++;
		} else
			bracketed = false;
		var_end = var_begin;
		char_type = shell_char_type(*var_end);
		mysh_assert(shell_char_type('$') & SHELL_PARAM_SPECIAL_CHAR);
		if (char_type & (SHELL_NORMAL_PARAM_CHAR |
				 SHELL_PARAM_SPECIAL_CHAR))
		{
			if (char_type & SHELL_PARAM_NUMERIC_CHAR) {
				/* positional parameter */
				mask = SHELL_PARAM_NUMERIC_CHAR;
			} else if (char_type & SHELL_PARAM_SPECIAL_CHAR) {
				/* special parameter */
				mask = 0;
			} else {
				/* regular parameter */
				mask = SHELL_NORMAL_PARAM_CHAR;
			}
			do {
				var_end++;
			} while (shell_char_type(*var_end) & mask);
			if (bracketed && *var_end != '}') {
				/* Missing closing brace */

				/* Set var_end to point to dollar sign so it's
				 * output literally */
				var_end = var_begin - 2;
				/* Start scanning at the ? in ${?.  So,
				 * "${$HOME" will expand $HOME. */
				scan_next = var_begin;
			} else {
				/* The parameter name (or special character, or
				 * positional parameter) begins at var_begin and
				 * continues for (var_end - var_begin)
				 * characters.  Look it up and append it to the
				 * string list. */
				append_param(var_begin, var_end - var_begin,
					     &string_list);
				if (bracketed)
					++var_end;
				scan_next = var_end;
			}
		} else {
			scan_next = var_end + 1;
			var_end = dollar_sign;
		}
	} while ((dollar_sign = strchr(scan_next, '$')) && *(dollar_sign + 1) != '\0');

	/* Append any remaining literal characters */
	if (*var_end)
		append_string(var_end, s->len - (var_end - s->chars), &string_list);

	/* Sum the total length of the expanded string */
	len = 0;
	list_for_each_entry(tmp, &string_list, list)
		len += tmp->len;
	if (len == 0) {
		/* The expansions produced the empty string.  Return the
		 * original string.  */
		free_string_list(&string_list);
		s->len = 0;
		s->chars[0] = '\0';
	} else {
		/* The expansions produced one or more strings, which now need
		 * to be joined.  The original string that was passed in must be
		 * freed. */
		int flags;
		size_t pos;

		flags = s->flags;
		free_string(s);
		if (flags & STRING_FLAG_UNQUOTED) {
			*param_char_map = xzalloc(len);
			pos = 0;
			list_for_each_entry(tmp, &string_list, list) {
				if (tmp->flags & STRING_FLAG_WAS_PARAM) {
					size_t i;
					for (i = 0; i < tmp->len; i++)
						(*param_char_map)[pos + i] = 1;
				}
				pos += tmp->len;

			}
		}
		s = join_strings(&string_list);
		s->flags = flags;
	}
	s->flags |= STRING_FLAG_PARAM_EXPANDED;
	return s;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl $0x24, %esi
callq 0x2130
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x656f
movq -0x28(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x657c
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6953
leaq -0x60(%rbp), %rdi
callq 0x6960
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jbe 0x65a7
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rax
subq %rax, %rsi
leaq -0x60(%rbp), %rdx
callq 0x6990
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
jne 0x65d1
movb $0x1, -0x61(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x65d5
movb $0x0, -0x61(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %edi
callq 0x60f0
movb %al, -0x3a(%rbp)
movl $0x24, %edi
callq 0x60f0
andl $0x8, %eax
cmpl $0x0, %eax
je 0x6600
jmp 0x661f
leaq 0x4463(%rip), %rdi      # 0xaa6a
leaq 0x448c(%rip), %rsi      # 0xaa9a
movl $0x205, %edx            # imm = 0x205
leaq 0x448d(%rip), %rcx      # 0xaaa7
callq 0x2160
movzbl -0x3a(%rbp), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x66da
movzbl -0x3a(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x6641
movb $0x2, -0x39(%rbp)
jmp 0x6659
movzbl -0x3a(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x6653
movb $0x0, -0x39(%rbp)
jmp 0x6657
movb $0x7, -0x39(%rbp)
jmp 0x6659
jmp 0x665b
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %edi
callq 0x60f0
movzbl -0x39(%rbp), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x665b
testb $0x1, -0x61(%rbp)
je 0x66a6
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7d, %eax
je 0x66a6
movq -0x20(%rbp), %rax
addq $-0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x66d8
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rax
subq %rax, %rsi
leaq -0x60(%rbp), %rdx
callq 0x69d0
testb $0x1, -0x61(%rbp)
je 0x66d0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x66ee
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x66f0
movq -0x38(%rbp), %rdi
movl $0x24, %esi
callq 0x2130
movq %rax, %rcx
movq %rcx, -0x28(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0xc1(%rbp)
je 0x6727
movq -0x28(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x6585
movq -0x30(%rbp), %rax
cmpb $0x0, (%rax)
je 0x6764
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
subq %rax, %rsi
leaq -0x60(%rbp), %rdx
callq 0x6990
movq $0x0, -0x50(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
addq $-0x18, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x18, %rax
leaq -0x60(%rbp), %rcx
cmpq %rcx, %rax
je 0x67d1
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
addq $-0x18, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x6788
cmpq $0x0, -0x50(%rbp)
jne 0x67fc
leaq -0x60(%rbp), %rdi
callq 0x9050
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb $0x0, (%rax)
jmp 0x693e
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9020
movl -0x8c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6924
movq -0x50(%rbp), %rdi
callq 0x8ea0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x98(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
addq $-0x18, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x18, %rax
leaq -0x60(%rbp), %rcx
cmpq %rcx, %rax
je 0x6922
movq -0x48(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x68db
movq $0x0, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x68d9
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x98(%rbp), %rcx
addq -0xb0(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb0(%rbp)
jmp 0x689b
jmp 0x68db
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
addq $-0x18, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x686a
jmp 0x6924
leaq -0x60(%rbp), %rdi
callq 0x9120
movq %rax, -0x10(%rbp)
movl -0x8c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq