// File: /workspace/github_cpp_makefile_star2_O2/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 $0x2c8, %rsp            # imm = 0x2C8
leaq 0x90(%rsp), %rdi
callq 0x4093
leaq 0x70(%rsp), %rdi
callq 0x40c0
leaq 0xb0(%rsp), %rdi
callq 0x4106
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq 0x40(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x142(%rsp), %rdi
callq 0x2060
testl %eax, %eax
js 0x47d8
leaq 0x50(%rsp), %rdi
leaq 0x142(%rsp), %rsi
callq 0x24e0
leaq 0x1c4(%rsp), %rsi
leaq 0x30(%rsp), %rdi
callq 0x24e0
leaq 0x246(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x24e0
leaq 0xd0(%rsp), %rdi
callq 0x2380
testl %eax, %eax
js 0x47e9
movq 0xd0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xf0(%rsp), %r14
movq %r14, %r15
subq 0xf8(%rsp), %r15
movl $0x1000, %edi           # imm = 0x1000
callq 0x23a0
movq %rax, %r12
movq 0x90(%rsp), %rcx
movq 0x70(%rsp), %r8
leaq 0x1237(%rip), %rsi      # 0x5862
leaq 0x1139(%rip), %rdx      # 0x576b
leaq 0xb69(%rip), %r9        # 0x51a2
xorl %r13d, %r13d
movq %rax, %rdi
xorl %eax, %eax
callq 0x2070
movq 0x78(%rsp), %rbx
addq 0x98(%rsp), %rbx
leaq 0xcce(%rip), %rdi       # 0x5328
movq %r12, %rsi
xorl %eax, %eax
callq 0x2030
pushq $0x2d
popq %rbp
cmpq %rbx, %r13
ja 0x4678
movl %ebp, %edi
callq 0x23e0
incq %r13
jmp 0x4667
pushq $0xa
popq %rdi
callq 0x23e0
movq 0xb0(%rsp), %rcx
leaq 0x11de(%rip), %rdi      # 0x586d
leaq 0x10d5(%rip), %r12      # 0x576b
leaq 0xb05(%rip), %r13       # 0x51a2
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq 0x50(%rsp), %rcx
movq 0x30(%rsp), %r8
leaq 0x11c4(%rip), %rdi      # 0x587f
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq 0x10(%rsp), %rcx
leaq 0x11c0(%rip), %rdi      # 0x5894
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq %r15, %rdi
callq 0x3edc
movq %rax, %r15
movq %r14, %rdi
callq 0x3edc
leaq 0x11ab(%rip), %rdi      # 0x58a6
leaq 0x1069(%rip), %rsi      # 0x576b
leaq 0xa99(%rip), %rdx       # 0x51a2
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2030
movq 0x8(%rsp), %rdi
callq 0x3f53
leaq 0x1196(%rip), %rdi      # 0x58bd
leaq 0x103d(%rip), %rbx      # 0x576b
leaq 0xa6d(%rip), %r14       # 0x51a2
movq %rbx, %rsi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2030
leaq 0x1183(%rip), %rdi      # 0x58cf
leaq 0x1191(%rip), %rcx      # 0x58e4
leaq 0x1192(%rip), %r8       # 0x58ec
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2030
leaq 0x1182(%rip), %rdi      # 0x58f0
leaq 0x118d(%rip), %rcx      # 0x5902
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2030
leaq 0x10(%rsp), %rdi
callq 0x2120
leaq 0x30(%rsp), %rdi
callq 0x2120
leaq 0x50(%rsp), %rdi
callq 0x2120
leaq 0xb0(%rsp), %rdi
callq 0x2120
leaq 0x70(%rsp), %rdi
callq 0x2120
leaq 0x90(%rsp), %rdi
callq 0x2120
xorl %eax, %eax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1067(%rip), %rdi      # 0x5846
callq 0x2240
jmp 0x45d5
leaq 0x1062(%rip), %rdi      # 0x5852
callq 0x2240
pushq $-0x1
popq %r15
movq %r15, %r14
movq %r15, 0x8(%rsp)
jmp 0x460a
movq %rax, %rbx
jmp 0x4840
movq %rax, %rbx
jmp 0x484a
jmp 0x4812
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2120
leaq 0x30(%rsp), %rdi
callq 0x2120
leaq 0x50(%rsp), %rdi
callq 0x2120
leaq 0xb0(%rsp), %rdi
callq 0x2120
leaq 0x70(%rsp), %rdi
callq 0x2120
leaq 0x90(%rsp), %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x24a0