// File: /workspace/github_c_makefile_star2_O3/System-Glitch[P]ESGILinter-C/src/rules/indent.c
// Function: check_indent
unsigned int check_indent(arraylist_t *file, int indent, char *filename){
    if(!file) return 0;
    unsigned int counter = 0;
    int level = 0;
    int count = 0;
    int adding = 0;
    int special = 0;
    int line_counter = 0;
    int start_switch;
    int mem;
    int brackets;
    size_t j;
    size_t index;
    size_t length;
    size_t tmp_length;
    char c;
    char *tmp;
    char *line = NULL;
    char *trimmed = NULL;

    start_switch = 0;
    brackets = 0;
    mem = 0;

    for(size_t h = 0; h < file->size; h++){
        line = arraylist_get(file, h);
        line_counter++;
        length = strlen(line);
        if(line[0] == '\n' || (length >= 2 && line[0] == '\r' && line[1] == '\n')) continue;
        level += adding;
        adding = 0;
        j = 0;
        count = 0;
        while(line[j] == ' '){
            j++;
            count++;
        }
        for(j = 0; j < length; j++){
            if(line[j] == '{'){
                adding++;
                if(start_switch){
                    brackets++;
                }
            }else if(line[j] == '}'){
                level--;
                if(start_switch){
                    brackets--;
                }
            }
        }
        tmp = strstr(line, "case");
        if(tmp && is_expression(line, tmp)){
            level = mem+1;
        }
        if(brackets == 0 && start_switch == 1){
            start_switch = 0;
            level = mem;
        }
        if(count != (indent*level)){
            trimmed = trim(line);
            print_warning(filename, line_counter, trimmed, "Wrong indentation");
            free(trimmed);
            counter++;
        }
        if(special){
            level--;
            special = 0;
        }
        check_expression(line, "if", &adding, &special);
        check_expression(line, "for", &adding, &special);
        tmp = strstr(line,"case");
        index = 4;
        if(tmp && is_expression(line, tmp)){
            tmp_length = strlen(tmp);
            while(is_whitespace(c = tmp[index]) && index < tmp_length) { index++; };
            if(strchr(tmp, '{') == NULL)
                adding++;
        }

        check_expression(line, "while", &adding, &special);
        tmp = strstr(line, "switch");
        index = 6;
        if(tmp && is_expression(line, tmp)){
            tmp_length = strlen(tmp);
            while(is_whitespace(c = tmp[index]) && index < tmp_length) { index++; };
            if(tmp[index] == '('){
                mem = level;
                start_switch = 1;
                brackets++;
                adding++;
            }
        }
    }
    return counter;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x30(%rsp)
movl %esi, 0x24(%rsp)
testq %rdi, %rdi
je 0x9927
movq %rdi, %r12
xorl %eax, %eax
movl %eax, (%rsp)
movl $0x0, 0xc(%rsp)
movl %eax, 0x8(%rsp)
cmpq $0x0, 0x8(%rdi)
je 0x9921
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %ebx, %ebx
movl $0x0, 0x4(%rsp)
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movq %r12, 0x28(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x6d0c
movq %rax, %rbp
incq %r13
movq %rax, %rdi
callq 0x20b0
movb (%rbp), %dl
cmpb $0xa, %dl
je 0x9916
cmpq $0x2, %rax
setb %cl
cmpb $0xd, %dl
setne %sil
orb %cl, %sil
movq %rbx, 0x10(%rsp)
jne 0x96da
cmpb $0xa, 0x1(%rbp)
je 0x9916
addl (%rsp), %r14d
xorl %ebx, %ebx
jmp 0x96fc
xorl %ecx, %ecx
movl $0x0, %ebx
cmpb $0x20, %dl
jne 0x96f3
xorl %ebx, %ebx
cmpb $0x20, 0x1(%rbp,%rbx)
leaq 0x1(%rbx), %rbx
je 0x96e8
addl (%rsp), %r14d
testq %rax, %rax
je 0x9735
xorl %edx, %edx
cmpl $0x0, 0x4(%rsp)
setne %dl
movl %edx, %esi
negl %esi
xorl %edi, %edi
xorl %ecx, %ecx
movzbl (%rbp,%rdi), %r8d
cmpl $0x7d, %r8d
je 0x9727
cmpl $0x7b, %r8d
jne 0x972d
incl %ecx
addl %edx, %r15d
jmp 0x972d
decl %r14d
addl %esi, %r15d
incq %rdi
cmpq %rdi, %rax
jne 0x970e
movl %ecx, (%rsp)
movq %rbp, %rdi
leaq 0x506a(%rip), %rsi      # 0xe7ac
callq 0x21c0
testq %rax, %rax
je 0x9767
movq %rbp, %rdi
movq %rax, %rsi
callq 0x9938
movq 0x10(%rsp), %rdx
leal 0x1(%rdx), %ecx
testl %eax, %eax
cmovnel %ecx, %r14d
jmp 0x976c
movq 0x10(%rsp), %rdx
movl 0x4(%rsp), %ecx
movl %ecx, %eax
xorl $0x1, %eax
orl %r15d, %eax
cmovel %edx, %r14d
movl $0x0, %eax
cmovel %eax, %ecx
movl %ecx, 0x4(%rsp)
movl %r14d, %eax
imull 0x24(%rsp), %eax
cmpl %eax, %ebx
je 0x97c2
movq %rbp, %rdi
callq 0x8239
movq %rax, %rbx
movq 0x30(%rsp), %rdi
movl %r13d, %esi
movq %rax, %rdx
leaq 0x5228(%rip), %rcx      # 0xe9d9
callq 0x585c
movq %rbx, %rdi
callq 0x2030
incl 0xc(%rsp)
cmpl $0x0, 0x8(%rsp)
movq %r13, 0x18(%rsp)
je 0x97d9
decl %r14d
movl $0x0, 0x8(%rsp)
movq %rbp, %rdi
leaq 0x4ffe(%rip), %rsi      # 0xe7e1
movq %rsp, %rbx
movq %rbx, %rdx
leaq 0x8(%rsp), %r13
movq %r13, %rcx
callq 0x9992
movq %rbp, %rdi
leaq 0x382a(%rip), %rsi      # 0xd02a
movq %rbx, %rdx
movq %r13, %rcx
callq 0x9992
movq %rbp, %rdi
leaq 0x4f97(%rip), %rsi      # 0xe7ac
callq 0x21c0
testq %rax, %rax
je 0x9878
movq %rax, %r13
movq %rbp, %rdi
movq %rax, %rsi
callq 0x9938
testl %eax, %eax
je 0x9878
movq %r13, %rdi
callq 0x20b0
movq %rax, %rbx
movl $0x4, %r12d
movsbl (%r13,%r12), %edi
callq 0x7f3a
testb %al, %al
je 0x985e
leaq 0x1(%r12), %rax
cmpq %rbx, %r12
movq %rax, %r12
jb 0x9842
movq %r13, %rdi
movl $0x7b, %esi
callq 0x20c0
testq %rax, %rax
movq 0x28(%rsp), %r12
jne 0x9878
incl (%rsp)
movq %rbp, %rdi
leaq 0x4fae(%rip), %rsi      # 0xe830
movq %rsp, %rdx
leaq 0x8(%rsp), %rcx
callq 0x9992
movq %rbp, %rdi
leaq 0x4f79(%rip), %rsi      # 0xe812
callq 0x21c0
testq %rax, %rax
je 0x990c
movq %rax, %r13
movq %rbp, %rdi
movq %rax, %rsi
callq 0x9938
testl %eax, %eax
je 0x990c
movq %r13, %rdi
callq 0x20b0
movq %rax, %rbx
movl $0x6, %r12d
movsbl (%r13,%r12), %edi
callq 0x7f3a
leaq 0x1(%r12), %rcx
testb %al, %al
je 0x98e2
cmpq %rbx, %r12
movq %rcx, %r12
jb 0x98c6
cmpb $0x28, -0x1(%r13,%rcx)
movq 0x28(%rsp), %r12
movq 0x10(%rsp), %rbx
jne 0x9905
incl (%rsp)
incl %r15d
movl $0x1, 0x4(%rsp)
movl %r14d, %ebx
movq 0x18(%rsp), %r13
jmp 0x9916
movq 0x18(%rsp), %r13
movq 0x10(%rsp), %rbx
cmpq 0x8(%r12), %r13
jb 0x968b
movl 0xc(%rsp), %eax
jmp 0x9929
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq