// File: /workspace/github_cpp_makefile_star2_O1/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 0x48ab
leaq 0x60(%rsp), %rdi
callq 0x48d8
leaq 0xa0(%rsp), %rdi
callq 0x491e
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 0x514f
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 0x5160
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 0x1933(%rip), %rsi      # 0x686a
leaq 0x1835(%rip), %rdx      # 0x6773
leaq 0x124e(%rip), %r9       # 0x6193
xorl %r13d, %r13d
movq %rax, %rdi
xorl %eax, %eax
callq 0x2070
movq 0x68(%rsp), %rbp
addq 0x88(%rsp), %rbp
leaq 0x13ca(%rip), %rdi      # 0x6330
movq %r12, %rsi
xorl %eax, %eax
callq 0x2030
movl $0x2d, %edi
callq 0x23b0
incq %r13
cmpq %rbp, %r13
jbe 0x4f70
movl $0xa, %edi
callq 0x23b0
movq 0xa0(%rsp), %rcx
leaq 0x18da(%rip), %rdi      # 0x6875
leaq 0x17d1(%rip), %r12      # 0x6773
leaq 0x11ea(%rip), %r13      # 0x6193
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq 0x40(%rsp), %rcx
movq 0x20(%rsp), %r8
leaq 0x18c0(%rip), %rdi      # 0x6887
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq (%rsp), %rcx
leaq 0x18bd(%rip), %rdi      # 0x689c
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x2030
movq %r15, %rdi
callq 0x46b8
movq %rax, %r15
movq %r14, %rdi
callq 0x46b8
leaq 0x18a8(%rip), %rdi      # 0x68ae
leaq 0x1766(%rip), %rsi      # 0x6773
leaq 0x117f(%rip), %rdx      # 0x6193
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
callq 0x472f
leaq 0x1895(%rip), %rdi      # 0x68c5
leaq 0x173c(%rip), %rbx      # 0x6773
leaq 0x1155(%rip), %r14      # 0x6193
movq %rbx, %rsi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2030
leaq 0x1882(%rip), %rdi      # 0x68d7
leaq 0x1890(%rip), %rcx      # 0x68ec
leaq 0x1891(%rip), %r8       # 0x68f4
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2030
leaq 0x1881(%rip), %rdi      # 0x68f8
leaq 0x188c(%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 0x50a6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x50c2
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x50de
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x50ff
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x511a
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x513b
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 0x16f8(%rip), %rdi      # 0x684e
callq 0x2210
jmp 0x4ee6
leaq 0x16f3(%rip), %rdi      # 0x685a
callq 0x2210
movq $-0x1, %rbx
movq $-0x1, %r14
movq $-0x1, %r15
jmp 0x4f16
movq %rax, %rbx
jmp 0x520f
movq %rax, %rbx
jmp 0x522a
jmp 0x5198
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x51b6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x51d2
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2290
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x51ee
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x520f
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x522a
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2290
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x524b
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x2490