#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>

uint64_t generate_challenge(){
    time_t tVar1;
    long challenge;
    uint8_t rnds [9];
    tVar1 = time((time_t *)0x0);

    srand((uint)tVar1);
    memset(rnds,0,9);
    challenge = 0;
    for (uint8_t i = 0; i < 8; i = i + 1) {
        rnds[i] = (uint8_t)rand();
        challenge = challenge * 0x100 + (ulong)rnds[i];
    }
    for(uint8_t i=0; i<sizeof(rnds); i++)
        printf("%02X ", rnds[i]);
    printf("\n");
    printf("Challenge: %llX\n",challenge);
    return challenge;
}

unsigned int FUN_001011b0(char *param_1,long param_2)
{
  long start;
  char *next_char_p;
  int i;
  char character;
  unsigned int mask;
  long len;
  char *input_char;
  
  mask = 0xffffffff;
  len = param_2;
  input_char = param_1;
  while (start = len + -1, len != 0) {
    next_char_p = input_char + 1;
    character = *input_char;
    for (i = 0; len = start, input_char = next_char_p, i < 8; i = i + 1) {
      if ((((int)character ^ mask) & 1) == 0) {
        mask = mask >> 1;
      }
      else {
        mask = mask >> 1 ^ 0xedb88320;
      }
      character = character >> 1;
    }
  }
  return mask ^ 0xffffffff;
}

int main(int argc, char** args){
    //uint64_t challenge = generate_challenge();
    uint64_t challenge = 0x84223EB2051265E3;

    uint8_t rnds[9];
    for(uint8_t i=0; i<8; i++){
        rnds[7-i] = challenge & 0xFF;
        challenge>>=8;
    }

    uint64_t resp = FUN_001011b0(rnds, 8);
    printf("%ld", resp);
}
