// File: mukul-mehta[P]meta/shell.cc
// Function: getShellPrompt()
const char* getShellPrompt() {
    string username = getUsername();
    string hostname = getHostname();
    char timeBuffer[12];

    auto t = time(nullptr);
    struct tm* ltime = localtime(&t);
    strftime(timeBuffer, sizeof(timeBuffer), "%H:%M:%S", ltime);

    char* prompt = (char*)malloc(BUFSIZE * sizeof(char));

    // Check width of terminal
    // Needed because some part of the prompt is on the right end and need to fill with correct num spaces in between
    struct winsize size;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
    int width = size.ws_col;
    int numSpaces = width - (strlen(__CWD) + 2) - (hostname.size()) - (strlen(timeBuffer));

    string spaces(numSpaces, ' ');
    sprintf(prompt, ": %s%s%s%s%s%s%s [%s%s@%s%s] \n%s@%s ", GREEN, __CWD, NORM, spaces.c_str(),
            GRAY, timeBuffer, NORM, CYAN, username.c_str(), hostname.c_str(), NORM, RED, NORM);
    sprintf(prompt, "%s%s%s: %s%s%s%s%s%s%s\n%s%s%s %s@%s ", YELLOW, hostname.c_str(), NORM,
            GREENIT, __CWD, NORM, spaces.c_str(), GRAY, timeBuffer, NORM, CYAN, username.c_str(),
            NORM, RED, NORM);
    return prompt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
leaq -0x48(%rbp), %rdi
callq 0x89c0
leaq -0x68(%rbp), %rdi
callq 0x8a70
jmp 0x43e8
xorl %eax, %eax
movl %eax, -0xf8(%rbp)
movl %eax, %edi
callq 0x32e0
movq %rax, -0x88(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x3230
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rcx
leaq 0x6d5f(%rip), %rdx      # 0xb17e
leaq -0x80(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
movl $0xc, %esi
callq 0x3290
movl $0x1000, %edi           # imm = 0x1000
callq 0x3460
movq %rax, %rcx
movl -0xf8(%rbp), %eax
movq %rcx, -0x98(%rbp)
movl $0x1, %edi
movl $0x5413, %esi           # imm = 0x5413
leaq -0xa0(%rbp), %rdx
callq 0x34b0
movzwl -0x9e(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xf4(%rbp)
leaq 0xc2bc(%rip), %rdi      # 0x10740
callq 0x3140
movq %rax, %rcx
movl -0xf4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xe8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3200
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl -0xe8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xe4(%rbp)
callq 0x3140
movq %rax, %rcx
movl -0xe4(%rbp), %eax
subl %ecx, %eax
addl $-0x2, %eax
movl %eax, -0xa8(%rbp)
movslq -0xa8(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x3580
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rcx
leaq -0xc8(%rbp), %rdi
movl $0x20, %edx
callq 0x51c0
jmp 0x4516
leaq -0xc9(%rbp), %rdi
callq 0x3350
movq -0x98(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3120
movq %rax, -0x118(%rbp)
leaq -0x80(%rbp), %r15
leaq -0x48(%rbp), %rdi
callq 0x3120
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3120
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %r9
movq %rax, %r11
leaq 0x6c13(%rip), %rsi      # 0xb187
leaq 0x6c31(%rip), %rdx      # 0xb1ac
leaq 0xc1be(%rip), %rcx      # 0x10740
leaq 0x6c29(%rip), %rax      # 0xb1b2
leaq 0x6c27(%rip), %r12      # 0xb1b7
leaq 0x6c26(%rip), %r14      # 0xb1bd
leaq 0x6c25(%rip), %r10      # 0xb1c3
movq %rax, %r8
movq %r12, (%rsp)
movq %r15, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movb $0x0, %al
callq 0x3090
movq -0x98(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3120
movq %rax, -0x108(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3120
movq %rax, %r12
leaq -0x80(%rbp), %r14
leaq -0x48(%rbp), %rdi
callq 0x3120
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rcx
movq %rax, %r11
leaq 0x6ba3(%rip), %rsi      # 0xb1c9
leaq 0x6bc1(%rip), %rdx      # 0xb1ee
leaq 0x6b7e(%rip), %rax      # 0xb1b2
leaq 0x6bb9(%rip), %r9       # 0xb1f4
leaq 0xc0fe(%rip), %r13      # 0x10740
leaq 0x6b6e(%rip), %r15      # 0xb1b7
leaq 0x6b6d(%rip), %rbx      # 0xb1bd
leaq 0x6b6c(%rip), %r10      # 0xb1c3
movq %rax, %r8
movq %r13, (%rsp)
movq %rax, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq %r10, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movb $0x0, %al
callq 0x3090
movq -0x98(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x31e0
leaq -0x68(%rbp), %rdi
callq 0x31e0
leaq -0x48(%rbp), %rdi
callq 0x31e0
movq -0x100(%rbp), %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x470b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xc9(%rbp), %rdi
callq 0x3350
leaq -0x68(%rbp), %rdi
callq 0x31e0
leaq -0x48(%rbp), %rdi
callq 0x31e0
movq -0x70(%rbp), %rdi
callq 0x3570
nopl (%rax)