#include <stdint.h>
#include <stdio.h>

#if defined(__GNUC__)
#define NOINLINE __attribute__((noinline))
#else
#define NOINLINE
#endif

static NOINLINE uint8_t checksum8(const uint8_t *data, unsigned len) {
    uint8_t value = 0x5a;
    for (unsigned i = 0; i < len; i++) {
        value = (uint8_t)((value * 2u) ^ data[i] ^ 0x3d);
    }
    return value;
}

NOINLINE int parse_header(const uint8_t *input, unsigned len) {
    if (len < 4) {
        return -1;
    }
    if (input[0] != 'G' || input[1] != 'A') {
        return -2;
    }
    return checksum8(input, len);
}

int main(void) {
    static const uint8_t payload[] = {'G', 'A', 1, 2, 3};
    printf("tiny=%d\n", parse_header(payload, 5));
    return 0;
}
