// File: /workspace/github_cpp_makefile_star2_O2/Necrelox[P]Auto_Presence/src/automatic_presence.cpp
// Function: automatic_presence::AutomaticPresence()
void automatic_presence::AutomaticPresence()
{
    filehandle handle(this->path);
    std::string buff;
    this->newfile << "login;present" << std::endl;
    while (std::getline(handle.file, buff)) {
        short count = std::count(buff.begin(), buff.end(), '\t');
        if (count == 5) {
            short valid = 0;
            std::stringstream manipule(buff);
            std::vector<std::string> tab;
            std::string push;
            while(getline(manipule, push, ' '))
                tab.push_back(push);

            int key = 0;
            this->time_player_start = 0;
            this->time_player_end = 0;
            for (size_t i = 0, check = 0; i < tab.size(); i++) {
                check = std::count(tab[i].begin(), tab[i].end(), ':');
                if (check == 2) {
                    std::istringstream flux_player(tab[i]);
                    std::string split_player;
                    for (int t = 0, div = 10000; t < 3; t++) {
                        getline(flux_player, split_player, ':');
                        split_player.erase(std::remove(split_player.begin(), split_player.end(), 0), split_player.end()); 
                        split_player.erase(split_player.begin() + 2, split_player.end());
                        for (size_t j = 0; j < split_player.size() ; j++)
                            if (!std::isdigit(split_player[j])) {
                                valid = 1;
                                break;
                            }
                        if (key == 0)
                            this->time_player_start += std::atoi(split_player.c_str()) * div;
                        else 
                            this->time_player_end += std::atoi(split_player.c_str()) * div;
                        div /= 100;

                        if (t == 0 && std::atoi(split_player.c_str()) > 24) {
                            valid = 1;
                            break;
                        }
                        if (t > 0 && std::atoi(split_player.c_str()) > 60) {
                            valid = 1;
                            break;
                        }
                    }
                    if (valid == 1) {
                        valid = 0;
                        break;
                    }
                    key++;
                }
                tab[i].erase(std::remove(tab[i].begin(), tab[i].end(), 0), tab[i].end()); 
                if (tab[i].find("@epitech.eu") != std::string::npos) {
                    tab[i].erase(0, tab[i].find("\t")+1);
                    tab[i].erase(tab[i].find("@epitech.eu")+11);
                    if (tab[i].find("\t") != std::string::npos)
                        tab[i].erase(0, tab[i].find("\t")+1);
                    this->email = tab[i];
                }
            }
            if (key == 2 && !this->email.empty() && this->time_player_start != 0 && this->time_player_end != 0) {
                this->newfile << this->email << ";";
                int presence = 1;
                int hour_p = this->time_player_start / 10000;
                int hour_r = this->time_rules_start / 10000;
                int min_p = (this->time_player_start - (hour_p * 10000))/100;
                int min_r = (this->time_rules_start - (hour_r * 10000))/100;

                if (hour_p <= hour_r) {
                    if (hour_p < hour_r) {
                        hour_p = hour_r;
                        min_p = min_r;
                    }
                    if (min_p > min_r + this->late_authorized)
                        presence = 0;
                }
                else
                    presence = 0;

                if (this->time_player_end < this->time_rules_end)
                    presence = 0;

                if (presence == 0)
                    this->newfile << "absent" << std::endl;
                else
                    this->newfile << "present" << std::endl;
            }

        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5e8, %rsp            # imm = 0x5E8
movq %rdi, %rbx
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3290
leaq 0x3e0(%rsp), %rdi
movq %r14, %rsi
callq 0x49ac
leaq 0xb8(%rsp), %rdi
callq 0x3100
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x20(%rbx), %rdi
leaq 0x1543(%rip), %rsi      # 0x5040
movq %rdi, 0x60(%rsp)
callq 0x3220
movq %rax, %rdi
callq 0x3130
leaq 0x238(%rbx), %rax
movq %rax, 0x68(%rsp)
leaq 0x3e0(%rsp), %r14
leaq 0x98(%rsp), %r15
leaq 0x258(%rsp), %r12
leaq 0x40(%rsp), %rbp
movq %rbx, 0x30(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3030
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3fc7
movq 0x98(%rsp), %rdi
movq 0xa0(%rsp), %rsi
addq %rdi, %rsi
movb $0x9, 0x258(%rsp)
movq %r12, %rdx
callq 0x4381
cmpw $0x5, %ax
jne 0x3b3d
movq %r12, %rdi
movq %r15, %rsi
pushq $0x18
popq %rdx
callq 0x32f0
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
andq $0x0, 0x80(%rsp)
movb $0x0, 0x88(%rsp)
leaq 0x78(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
pushq $0x20
popq %rdx
callq 0x3380
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3bed
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x41f0
jmp 0x3bc2
andq $0x0, 0x228(%rbx)
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rcx, %r14
jae 0x3ea6
movq %r14, 0x70(%rsp)
shlq $0x5, %r14
movq (%rax,%r14), %rdi
movq 0x8(%rax,%r14), %rsi
addq %rdi, %rsi
movb $0x3a, 0xd8(%rsp)
leaq 0xd8(%rsp), %rdx
callq 0x4381
cmpq $0x2, %rax
jne 0x3d92
movq 0x10(%rsp), %rsi
addq %r14, %rsi
leaq 0xd8(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x3320
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
andq $0x0, 0x48(%rsp)
movb $0x0, 0x50(%rsp)
xorl %ebx, %ebx
movl $0x2710, %r13d          # imm = 0x2710
cmpl $0x3, %ebx
je 0x3d6e
leaq 0xd8(%rsp), %rdi
movq %rbp, %rsi
pushq $0x3a
popq %rdx
callq 0x3380
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq %rdi, %rsi
andl $0x0, 0x3c(%rsp)
leaq 0x3c(%rsp), %rdx
callq 0x439c
movq 0x40(%rsp), %rdx
addq 0x48(%rsp), %rdx
movq %rbp, %rdi
movq %rax, %rsi
callq 0x3050
movq 0x40(%rsp), %rdx
leaq 0x2(%rdx), %rsi
addq 0x48(%rsp), %rdx
movq %rbp, %rdi
callq 0x3050
movq %rbp, %r12
movq 0x40(%rsp), %rbp
movq 0x48(%rsp), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x3d12
movsbl (%rbp,%rcx), %edx
addl $-0x30, %edx
incq %rcx
cmpl $0xa, %edx
jb 0x3cf8
movw $0x1, %r15w
movq %rbp, %rdi
callq 0x32e0
imull %r13d, %eax
cmpl $0x0, 0xc(%rsp)
je 0x3d32
movq 0x30(%rsp), %rcx
addl %eax, 0x22c(%rcx)
jmp 0x3d3d
movq 0x30(%rsp), %rcx
addl %eax, 0x228(%rcx)
movl %r13d, %eax
cltd
pushq $0x64
popq %rcx
idivl %ecx
movl %eax, %r13d
movq %rbp, %rdi
callq 0x32e0
testl %ebx, %ebx
je 0x3d5a
cmpl $0x3c, %eax
jmp 0x3d5d
cmpl $0x18, %eax
movq %r12, %rbp
jg 0x3d69
incl %ebx
jmp 0x3c86
movw $0x1, %r15w
movq %rbp, %rdi
callq 0x3100
leaq 0xd8(%rsp), %rdi
callq 0x3110
cmpw $0x1, %r15w
je 0x3ea6
incl 0xc(%rsp)
movq 0x10(%rsp), %r13
movq (%r13,%r14), %rdi
movq 0x8(%r13,%r14), %rsi
addq %rdi, %rsi
andl $0x0, 0xd8(%rsp)
leaq 0xd8(%rsp), %rdx
callq 0x439c
addq %r14, %r13
movq 0x10(%rsp), %rcx
movq (%rcx,%r14), %rdx
addq 0x8(%rcx,%r14), %rdx
movq %r13, %rdi
movq %rax, %rsi
callq 0x3050
movq 0x10(%rsp), %rdi
addq %r14, %rdi
leaq 0x126a(%rip), %rsi      # 0x504e
xorl %edx, %edx
callq 0x33d0
cmpq $-0x1, %rax
je 0x3e99
movq 0x10(%rsp), %r13
addq %r14, %r13
movq %r13, %rdi
leaq 0x1253(%rip), %rsi      # 0x505a
xorl %edx, %edx
callq 0x33d0
leaq 0x1(%rax), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x3060
movq 0x10(%rsp), %r13
addq %r14, %r13
movq %r13, %rdi
leaq 0x1220(%rip), %rsi      # 0x504e
xorl %edx, %edx
callq 0x33d0
leaq 0xb(%rax), %rsi
movq %r13, %rdi
pushq $-0x1
popq %rdx
callq 0x3060
movq 0x10(%rsp), %rdi
addq %r14, %rdi
leaq 0x1207(%rip), %rsi      # 0x505a
xorl %edx, %edx
callq 0x33d0
cmpq $-0x1, %rax
je 0x3e87
movq 0x10(%rsp), %r13
addq %r14, %r13
movq %r13, %rdi
leaq 0x11e8(%rip), %rsi      # 0x505a
xorl %edx, %edx
callq 0x33d0
leaq 0x1(%rax), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x3060
addq 0x10(%rsp), %r14
movq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x3160
movq 0x70(%rsp), %r14
incq %r14
jmp 0x3c03
cmpl $0x2, 0xc(%rsp)
movq 0x30(%rsp), %rbx
leaq 0x3e0(%rsp), %r14
leaq 0x98(%rsp), %r15
leaq 0x258(%rsp), %r12
jne 0x3fa6
cmpq $0x0, 0x240(%rbx)
je 0x3fa6
cmpl $0x0, 0x228(%rbx)
je 0x3fa6
cmpl $0x0, 0x22c(%rbx)
je 0x3fa6
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x3200
movq %rax, %rdi
leaq 0x114d(%rip), %rsi      # 0x505c
callq 0x3220
movl 0x220(%rbx), %r8d
movl 0x228(%rbx), %esi
movl %esi, %eax
cltd
movl $0x2710, %edi           # imm = 0x2710
idivl %edi
movl %eax, %ecx
movl %r8d, %eax
cltd
idivl %edi
movl %eax, %edi
movb $0x1, %al
cmpl %edi, %ecx
jg 0x3f70
imull $0xffffd8f0, %edi, %eax # imm = 0xFFFFD8F0
addl %r8d, %eax
cltd
pushq $0x64
popq %r9
idivl %r9d
movl %eax, %r8d
imull $0xffffd8f0, %ecx, %eax # imm = 0xFFFFD8F0
addl %esi, %eax
cltd
idivl %r9d
cmpl %edi, %ecx
cmovll %r8d, %eax
movswl 0x230(%rbx), %ecx
addl %r8d, %ecx
cmpl %ecx, %eax
setg %al
movl 0x22c(%rbx), %ecx
testb $0x1, %al
leaq 0x10c7(%rip), %rsi      # 0x5046
leaq 0x10d8(%rip), %rax      # 0x505e
cmovneq %rax, %rsi
cmpl 0x224(%rbx), %ecx
cmovlq %rax, %rsi
movq 0x60(%rsp), %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3130
leaq 0x78(%rsp), %rdi
callq 0x3100
leaq 0x10(%rsp), %rdi
callq 0x421c
movq %r12, %rdi
callq 0x31a0
jmp 0x3b3d
leaq 0x98(%rsp), %rdi
callq 0x3100
leaq 0x3e0(%rsp), %rdi
callq 0x49f4
addq $0x5e8, %rsp            # imm = 0x5E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x3100
jmp 0x407e
jmp 0x400f
jmp 0x401e
jmp 0x401e
jmp 0x400f
jmp 0x400f
movq %rax, %rbx
jmp 0x4064
jmp 0x401e
jmp 0x401e
jmp 0x401e
jmp 0x401e
jmp 0x401e
movq %rax, %rbx
jmp 0x4043
jmp 0x4029
jmp 0x4029
jmp 0x4029
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3100
leaq 0xd8(%rsp), %rdi
callq 0x3110
leaq 0x78(%rsp), %rdi
callq 0x3100
leaq 0x10(%rsp), %rdi
callq 0x421c
leaq 0x258(%rsp), %rdi
callq 0x31a0
leaq 0x98(%rsp), %rdi
callq 0x3100
leaq 0x3e0(%rsp), %rdi
callq 0x49f4
movq %rbx, %rdi
callq 0x3350