// File: /workspace/github_cpp_makefile_star2_O3/mukul-mehta[P]meta/builtins.cc
// Function: metash_fetch(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>)
int metash_fetch(unused vector<string> tokens) {
    // Fetch username, hostname and OS Name
    unused string username = getUsername();
    unused string hostname = getHostname();
    unused string OSname = getOSName();

    string kernel_name, kernel_version, machine;

    long uptime = -1;
    long total_memory = -1;
    long free_memory = -1;
    long consumed_memory = -1;

    struct utsname uts;
    // The `uname` call populates the uts struct with system information. Also implemented as the `uname` executable
    if (uname(&uts) < 0) {
        perror("uname error");
    } else {
        kernel_name = uts.sysname;
        kernel_version = uts.release;
        machine = uts.machine;
    }

    struct sysinfo info;
    // The `sysinfo` call populates the `sysinfo` struct. Fills with uptime and memory usage information
    if (sysinfo(&info) < 0)
        perror("sysinfo() error");
    else {
        total_memory = info.totalram;
        free_memory = info.freeram;
        consumed_memory = total_memory - free_memory;
        uptime = info.uptime;
    }

    char* user_host_string = (char*)malloc(BUFSIZE * sizeof(char));
    sprintf(user_host_string, "%s%s@%s%s\n", BLUE, username.c_str(), hostname.c_str(), NORM);
    size_t len = username.size() + hostname.size();

    printf("%s", user_host_string);
    for (size_t i = 0; i <= len; i++)
        printf("-");
    printf("\n");

    printf("%sOS%s:       %s\n", BLUE, NORM, OSname.c_str());
    printf("%sKernel%s:   %s %s\n", BLUE, NORM, kernel_name.c_str(), kernel_version.c_str());
    printf("%sPlatform%s: %s\n", BLUE, NORM, machine.c_str());
    printf("%sMemory%s:   %s / %s\n", BLUE, NORM, parse_memory(consumed_memory),
           parse_memory(total_memory));
    printf("%sUptime%s:   %s\n", BLUE, NORM, parse_time(uptime));
    printf("%sShell%s:    %s %s\n", BLUE, NORM, SHELL, VERSION);
    printf("%sAuthors%s:  %s\n", BLUE, NORM, AUTHORS);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
leaq 0x80(%rsp), %rdi
callq 0x46eb
leaq 0x60(%rsp), %rdi
callq 0x4718
leaq 0xa0(%rsp), %rdi
callq 0x475e
leaq 0x50(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x30(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x10(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x132(%rsp), %rdi
callq 0x2060
testl %eax, %eax
js 0x4f8f
leaq 0x40(%rsp), %rbx
movq 0x8(%rbx), %r14
leaq 0x132(%rsp), %r15
movq %r15, %rdi
callq 0x20f0
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
movq %rax, %r8
callq 0x2440
leaq 0x1b4(%rsp), %rbx
leaq 0x20(%rsp), %r14
movq 0x8(%r14), %r15
movq %rbx, %rdi
callq 0x20f0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x2440
leaq 0x236(%rsp), %rbx
movq %rsp, %r14
movq 0x8(%r14), %r15
movq %rbx, %rdi
callq 0x20f0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x2440
leaq 0xc0(%rsp), %rdi
callq 0x2360
testl %eax, %eax
js 0x4fa0
movq 0xc0(%rsp), %rbx
movq 0xe0(%rsp), %r14
movq %r14, %r15
subq 0xe8(%rsp), %r15
movl $0x1000, %edi           # imm = 0x1000
callq 0x2380
movq %rax, %r12
movq 0x80(%rsp), %rcx
movq 0x60(%rsp), %r8
leaq 0x1af3(%rip), %rsi      # 0x686a
leaq 0x19f5(%rip), %rdx      # 0x6773
leaq 0x140e(%rip), %r9       # 0x6193
xorl %r13d, %r13d
movq %rax, %rdi
xorl %eax, %eax
callq 0x2070
movq 0x68(%rsp), %rbp
addq 0x88(%rsp), %rbp
leaq 0x158a(%rip), %rdi      # 0x6330
movq %r12, %rsi
xorl %eax, %eax
callq 0x2030
movl $0x2d, %edi
callq 0x23b0
incq %r13
cmpq %rbp, %r13
jbe 0x4db0
movl $0xa, %edi
callq 0x23b0
movq 0xa0(%rsp), %rcx
leaq 0x1a9a(%rip), %rdi      # 0x6875
leaq 0x1991(%rip), %r12      # 0x6773
leaq 0x13aa(%rip), %r13      # 0x6193
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq 0x40(%rsp), %rcx
movq 0x20(%rsp), %r8
leaq 0x1a80(%rip), %rdi      # 0x6887
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq (%rsp), %rcx
leaq 0x1a7d(%rip), %rdi      # 0x689c
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq %r15, %rdi
callq 0x44f8
movq %rax, %r15
movq %r14, %rdi
callq 0x44f8
leaq 0x1a68(%rip), %rdi      # 0x68ae
leaq 0x1926(%rip), %rsi      # 0x6773
leaq 0x133f(%rip), %rdx      # 0x6193
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
callq 0x456f
leaq 0x1a55(%rip), %rdi      # 0x68c5
leaq 0x18fc(%rip), %rbx      # 0x6773
leaq 0x1315(%rip), %r14      # 0x6193
movq %rbx, %rsi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2030
leaq 0x1a42(%rip), %rdi      # 0x68d7
leaq 0x1a50(%rip), %rcx      # 0x68ec
leaq 0x1a51(%rip), %r8       # 0x68f4
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2030
leaq 0x1a41(%rip), %rdi      # 0x68f8
leaq 0x1a4c(%rip), %rcx      # 0x690a
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2030
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4ee6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x4f02
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x4f1e
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4f3f
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4f5a
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4f7b
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2290
xorl %eax, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18b8(%rip), %rdi      # 0x684e
callq 0x2210
jmp 0x4d26
leaq 0x18b3(%rip), %rdi      # 0x685a
callq 0x2210
movq $-0x1, %rbx
movq $-0x1, %r14
movq $-0x1, %r15
jmp 0x4d56
movq %rax, %rbx
jmp 0x504f
movq %rax, %rbx
jmp 0x506a
jmp 0x4fd8
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4ff6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5012
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x502e
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x504f
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x506a
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x508b
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x2490