#include <stdio.h>
#include <stdlib.h>
#include <string.h>


// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(const char *input_permissions, const char *required_permissions) {

    for (int i = 0; i < 9; i++) {
        if (required_permissions[i] == '-') {
            continue;
        }
        if (required_permissions[i] != input_permissions[i]) {
            return 0;
        }
    }

    return 1;

}


int main(int argc, char **argv) {
    if (!(argc == 2 || argc == 3)) {
        fprintf(stderr, "USAGE: count_large size [permissions]\n");
        return 1;
    }

    // Process the command line arguments
    long size = strtol(argv[1], NULL, 10);
    char *required_permissions = argv[2];

    // Initialize the variables used in the loop
    int count = 0;
    char input_permissions[10];
    char input_size_str[10];
    long input_size;
//    int i = 0;
    int permissions;

    // Skip the first line of ls -l
    scanf("%*s %*d");

    // Scan each value from ls -l
    while (scanf("%s %*d %*s %*s %s %*s %*d %*s %*s", input_permissions, input_size_str) != EOF) {
        // Check if there are two command line arguments
        // Therefore checking permissions and size
        input_size = strtol(input_size_str, NULL, 10);
        if (argc == 3) {
            // Check if it is the first item of a line
//            if (i % 9 == 0) {
            if (check_permissions(&input_permissions[1], required_permissions) == 1) {
                permissions = 1;
            } else {
                permissions = 0;
            }
//            }
            //Check if it is the fifth item of a line
//            if (i % 9 == 4) {
            // Check if the permissions pass
            if (permissions == 1) {
                if (input_size > size) {
                    count++;
                }
                permissions = 0;
            }
//            }
        } else {
            // Only checking if the size is larger than the input
            // Check if it is the fifth item of a line
//            if (i % 9 == 4) {
//                printf("%s\n", input_permissions);
            if (input_size > size) {
                count++;
            }
//            }
        }
//        i++;
    }

    printf("%d\n", count);
    return 0;
}

take input from ls -l terminal command as well as one or two command line arguments and return the number of files greater in size
