// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/analyzer.c
// Function: analyze
int analyze(Analyzer a, char const * fn) {
    if(!a)
        return 0;
    struct analyzer * ca = a;
    FILE * file;
    CALLEXIT(!(file = fopen(fn, "r")))

    char * word = 0; //malloc(MAX_WORD_LEN)
    char * prediction;
    CALLEXIT(!(prediction = malloc(ca->markov_tier+1))) //next n characters, \0 terminated
    if(!ca->tlists) {
        CALLEXIT(!(ca->tlists = malloc(CHAR_LEN * sizeof *ca->tlists)))
        for(size_t i = 0; i < CHAR_LEN; i++) {
            ca->tlists[i] = init_token_list();
        }
    }
    if(!ca->start) {
        ca->start = init_token_list();
    }
    size_t len = 0;
    char * start;
    CALLEXIT(!(start = calloc(1, ca->markov_tier+2)))
    while(getline(&word, &len, file) != -1) { //fscanf(file, "%"MAX_WORD_LEN_LITERAL"s", word) != EOF
        word[strlen(word)-1] = '\0';
        char cur_char = word[0];

        //initialize prediction
        size_t i;
        for(i = 0; i < ca->markov_tier && word[i+1] != '\0'; i++) {
            prediction[i] = word[i+1];
        }
        prediction[ca->markov_tier] = '\0';

        //word too short?
        if(i < ca->markov_tier) {
            continue;
        }
        start[0] = word[0];
        strcpy(start+1, prediction);
        inc_token(ca->start, start, 0);

        for(i = 1; prediction[ca->markov_tier-1] != '\0' && cur_char != '\0'; i++) {
            //add markov prediction
            int end = 0;

            if(word[i+ca->markov_tier] == '\0') {
                end = 1;
            }
            inc_token(ca->tlists[(unsigned char)cur_char], prediction, end);
            ca->tokens++;
            //shift prediction
            for(size_t pos = 1; pos < ca->markov_tier; pos++) {
                prediction[pos-1] = prediction[pos];
            }
            prediction[ca->markov_tier-1] = word[i+ca->markov_tier];

            //get next character
            cur_char = word[i];
        }
    }
    fclose(file);
    free(word);
    free(start);
    free(prediction);
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x26d6
movl $0x0, -0x4(%rbp)
jmp 0x2a46
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x1acc6(%rip), %rsi     # 0x1d3af
callq 0x2230
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x270e
leaq 0x17970(%rip), %rdi     # 0x1a06f
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x1, %rdi
callq 0x22b0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x2746
leaq 0x17977(%rip), %rdi     # 0x1a0ae
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x27b9
movl $0x800, %edi            # imm = 0x800
callq 0x22b0
movq -0x20(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x277f
leaq 0x1798e(%rip), %rdi     # 0x1a0fe
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq $0x0, -0x40(%rbp)
cmpq $0x100, -0x40(%rbp)     # imm = 0x100
jae 0x27b7
callq 0x17b30
movq %rax, %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x2787
jmp 0x27b9
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x27d4
callq 0x17b30
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq $0x0, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rsi
addq $0x2, %rsi
movl $0x1, %edi
callq 0x2110
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jne 0x2811
leaq 0x17958(%rip), %rdi     # 0x1a15a
callq 0x2190
movl $0x1, %edi
callq 0x2260
jmp 0x2813
movq -0x28(%rbp), %rdx
leaq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2290
cmpq $-0x1, %rax
je 0x2a1b
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rdi
callq 0x20c0
movq %rax, %rcx
movq -0x78(%rbp), %rax
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rax
movb (%rax), %al
movb %al, -0x51(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x79(%rbp)
jae 0x2887
movq -0x30(%rbp), %rax
movq -0x60(%rbp), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x2890
jmp 0x28b5
movq -0x30(%rbp), %rax
movq -0x60(%rbp), %rcx
movb 0x1(%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x285f
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
movq -0x60(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x28d6
jmp 0x2813
movq -0x30(%rbp), %rax
movb (%rax), %cl
movq -0x50(%rbp), %rax
movb %cl, (%rax)
movq -0x50(%rbp), %rdi
addq $0x1, %rdi
movq -0x38(%rbp), %rsi
callq 0x21c0
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x50(%rbp), %rsi
xorl %edx, %edx
callq 0x17c00
movq $0x1, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x7a(%rbp)
je 0x2938
movsbl -0x51(%rbp), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x7a(%rbp)
movb -0x7a(%rbp), %al
testb $0x1, %al
jne 0x2944
jmp 0x2a16
movl $0x0, -0x64(%rbp)
movq -0x30(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rdx
addq (%rdx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x296a
movl $0x1, -0x64(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movzbl -0x51(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movq -0x38(%rbp), %rsi
movl -0x64(%rbp), %edx
callq 0x17c00
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq $0x1, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x29d3
movq -0x38(%rbp), %rax
movq -0x70(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movq -0x70(%rbp), %rcx
subq $0x1, %rcx
movb %dl, (%rax,%rcx)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x299e
movq -0x30(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rdx
addq (%rdx), %rcx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
movq -0x60(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x51(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x290e
jmp 0x2813
movq -0x28(%rbp), %rdi
callq 0x21f0
movq -0x30(%rbp), %rdi
callq 0x2240
movq -0x50(%rbp), %rdi
callq 0x2240
movq -0x38(%rbp), %rdi
callq 0x2240
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)