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


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


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

    // TODO: Process command line arguments.
    int cutoff = strtol(argv[1], NULL, 10);

    char type;
    char permission[10];
    int link;
    char owner[32];
    char group[32];
    int size;
    char remainder[50];

    int n;
    int eof;

    eof = scanf("%s %d", remainder, &n);

    int count = 0;

    while (eof != EOF){
        eof = scanf("%c%s %d %s %s %d %[^\n]s\n", &type, permission, &link, owner, group, &size, remainder);
        printf("type: %c permission: %s link: %d owner: %s group: %s size: %d remainder: %s", type, permission, link, owner, group, size, remainder);
        if ((type == '-') && ((argc == 2) || (check_permissions(permission, argv[2]) == 0)) && (size > cutoff)){
            count++;
        }
        printf(" COUNT %d\n", count);
    }

    printf("%d\n", count);

    return 0;
}

int check_permissions(char* p1, char* p2){
    for (int i = 0; i < 9; i++){
        if((p2[i] != '-') && (p1[i] == '-')) return 1;
    }
    return 0;
}

parse each line read from the standard input. The first character from each line is not being read correctly.