// File: /workspace/github_c_makefile_star2_O3/ebiggers[P]mysh/mysh_main.c
// Function: do_get_prompt
static const char *do_get_prompt(const char *var, const char *def)
{
#define MAX_PROMPT_LEN 127
	static char prompt[MAX_PROMPT_LEN + 1];
	const char *psp;
	size_t i;
	const char *ps;

	ps = lookup_shell_param(var);
	if (!ps)
		ps = def;
	for (psp = ps, i = 0; *psp && i < MAX_PROMPT_LEN; psp++) {
		const char *s;
		if (*psp == '\\') {
			switch (*++psp) {
			case '[':
				/* Begin a sequence of non-printing characters.
				 * This is to stop readline() from getting
				 * confused when the prompt contains terminal
				 * control sequences that expand to fewer
				 * on-screen characters than the length of the
				 * prompt string. */
			#ifdef WITH_READLINE
				prompt[i++] = RL_PROMPT_START_IGNORE;
			#endif
				break;
			case ']':
				/* End a sequence of non-printing characters */
			#ifdef WITH_READLINE
				prompt[i++] = RL_PROMPT_END_IGNORE;
			#endif
				break;
			case '0' ... '9':
				/* Literal character given in octal */
				if (*(psp + 1) >= '0' && *(psp + 1) <= '9' &&
				    *(psp + 2) >= '0' && *(psp + 2) <= '9')
				{
					int c = *(psp + 2) - '0'
						+ 8 * (*(psp + 1) - '0')
						+ 64 * (*(psp + 0) - '0');
					prompt[i++] = c;
					psp += 2;
				}
				break;
			case 'h':
				/* Hostname, excluding domain name */
				{
					char *dot;
					prompt[i] = '\0';
					gethostname(&prompt[i], MAX_PROMPT_LEN - i);
					prompt[MAX_PROMPT_LEN] = '\0';
					dot = strchrnul(&prompt[i], '.');
					*dot = '\0';
					i += dot - &prompt[i];
				}
				break;
			case 's':
				/* Name of the shell */
				s = SHELL_NAME;
				goto handle_string;
			case 'u':
				/* Current user name */
				s = lookup_shell_param("USER");
				if (!s)
					s = "I have no name!";
				goto handle_string;
			case 'v':
				/* Version of the shell */
				s = SHELL_VERSION;
				goto handle_string;
			case 'w':
			case 'W':
				/* Absolute path to working directory
				 * TODO: Relative path, replace $HOME with ~  */
				s = lookup_shell_param("PWD");
				goto handle_string;

			handle_string:
				if (s) {
					/* Append a string to the command prompt */
					size_t len = strlen(s);
					if (i + len > MAX_PROMPT_LEN)
						goto out;
					strcpy(&prompt[i], s);
					i += len;
				}
				break;
			case '$':
				/* '#' if root, otherwise '$' */
				prompt[i++] = geteuid() ? '$' : '#';
				break;
			default:
				/* unrecognized meta sequence */
				prompt[i++] = *psp;
				break;
			}
		} else {
			/* not a meta sequence */
			prompt[i++] = *psp;
		}
	}
out:
	prompt[i] = '\0';
	return prompt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
callq 0x4b5a
testq %rax, %rax
cmovneq %rax, %r12
movb (%r12), %al
testb %al, %al
je 0x478a
leaq 0x6c3f(%rip), %rbp      # 0xb240
leaq 0x2e54(%rip), %rbx      # 0x745c
xorl %r15d, %r15d
cmpb $0x5c, %al
jne 0x465b
leaq 0x1(%r12), %r14
movb 0x1(%r12), %al
movzbl %al, %ecx
cmpl $0x56, %ecx
jg 0x4682
leal -0x30(%rcx), %edx
cmpl $0xa, %edx
jae 0x46f0
movb 0x2(%r12), %cl
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x4665
movb 0x3(%r12), %dl
leal -0x30(%rdx), %esi
cmpb $0x9, %sil
ja 0x4665
addq $0x3, %r12
shlb $0x3, %cl
andb $0x78, %cl
shlb $0x6, %al
addb %dl, %al
addb %cl, %al
addb $-0x30, %al
movb %al, (%r15,%rbp)
incq %r15
movq %r12, %r14
movb 0x1(%r14), %al
testb %al, %al
je 0x478d
incq %r14
movq %r14, %r12
cmpq $0x7f, %r15
jb 0x460b
jmp 0x478d
cmpl $0x67, %ecx
jg 0x469d
cmpl $0x57, %ecx
je 0x46d7
cmpl $0x5b, %ecx
je 0x4707
cmpl $0x5d, %ecx
jne 0x4701
movb $0x2, (%r15,%rbp)
jmp 0x470c
leal -0x73(%rcx), %edx
cmpl $0x4, %edx
ja 0x4714
movslq (%rbx,%rdx,4), %rcx
addq %rbx, %rcx
leaq 0x3174(%rip), %r12      # 0x7827
jmpq *%rcx
leaq 0x3170(%rip), %rdi      # 0x782c
callq 0x4b5a
movq %rax, %r12
testq %rax, %rax
leaq 0x3163(%rip), %rax      # 0x7831
cmoveq %rax, %r12
jmp 0x475d
leaq 0x29d1(%rip), %rdi      # 0x70af
callq 0x4b5a
movq %rax, %r12
testq %rax, %rax
jne 0x475d
jmp 0x4665
cmpl $0x24, %ecx
jne 0x4701
callq 0x2190
cmpl $0x1, %eax
movb $0x24, %al
sbbb $0x0, %al
movb %al, (%r15,%rbp)
jmp 0x470c
movb $0x1, (%r15,%rbp)
incq %r15
jmp 0x4665
cmpl $0x68, %ecx
jne 0x4701
leaq (%r15,%rbp), %r12
xorl %r13d, %r13d
movb %r13b, (%r15,%rbp)
movl $0x7f, %esi
subq %r15, %rsi
movq %r12, %rdi
callq 0x2320
movb %r13b, 0x6b84(%rip)     # 0xb2bf
movq %r12, %rdi
movl $0x2e, %esi
callq 0x20b0
movq %rax, %r15
movb %r13b, (%rax)
subq %rbp, %r15
jmp 0x4665
leaq 0x30e4(%rip), %r12      # 0x7841
movq %r12, %rdi
callq 0x2100
movq %rax, %r13
addq %r15, %r13
cmpq $0x80, %r13
jae 0x478d
addq %rbp, %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x2070
movq %r13, %r15
jmp 0x4665
xorl %r15d, %r15d
leaq 0x6aac(%rip), %rax      # 0xb240
movb $0x0, (%r15,%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq