// File: /workspace/github_cpp_makefile_star2_O2/aquirel[P]reminder/reminder.cpp
// Function: main
int main(int argc, char *argv[])
{
    const char *rc_file_name = ".reminderrc";
    string rc_file_path;

    if (2 <= argc)
    {
        if (0 == strcmp("--help", argv[1]) ||
            0 == strcmp("-h", argv[1]))
        {
            printf("Usage: %s [.reminderrc]\n", argv[0]);
            return 0;
        }
        else
        {
            rc_file_path = argv[1];
        }
    }

    if (0 == rc_file_path.length())
    {
        rc_file_path = getenv("HOME") ?: ".";

        if ('/' != rc_file_path.back())
        {
            rc_file_path.append("/");
        }

        rc_file_path.append(rc_file_name);
    }

    vector<Person> persons;
    unsigned remind_before = 3; // In days.

    ifstream rc_file(rc_file_path);

    string remind_before_prefix = "remind_before",
           buf;

    while (rc_file.good())
    {
        getline(rc_file, buf, '\n');

        if (0 == buf.length() ||
            '#' == buf[0] ||
            ';' == buf[0])
        {
            continue;
        }

        if (equal(remind_before_prefix.begin(), remind_before_prefix.end(), buf.begin()))
        {
            buf = buf.substr(remind_before_prefix.length());
            while (0 < buf.length() && isspace(buf[0]))
            {
                buf.erase(0, 1);
            }

            if (0 < buf.length() && '=' == buf[0])
            {
                buf.erase(0, 1);

                if (0 < buf.length())
                {
                    remind_before = stoul(buf);
                }
            }
        }
        else
        {
            unsigned year, month, day;
            if (3 != sscanf(buf.c_str(), "%4u-%02u-%02u", &year, &month, &day))
            {
                continue;
            }

            tm birthday;
            memset(&birthday, 0, sizeof(birthday));

            birthday.tm_year = year - 1900;
            birthday.tm_mon = month - 1;
            birthday.tm_mday = day;

            if (-1 == mktime(&birthday))
            {
                continue;
            }

            auto delimiter = find_if(buf.begin(), buf.end(), [] (const char c) { return isspace(c); });
            if (buf.end() == delimiter)
            {
                continue;
            }

            buf = buf.substr(delimiter - buf.begin());

            while (0 < buf.length() && isspace(buf[0]))
            {
                buf.erase(0, 1);
            }

            while (0 < buf.length() && isspace(buf.back()))
            {
                buf.erase(buf.length() - 1, 1);
            }

            Person new_person {
                .birthday = birthday,
                .name = buf
            };

            persons.push_back(new_person);
        }
    }

    rc_file.close();

    time_t time_since_epoch = time(nullptr);
    tm now = *localtime(&time_since_epoch);

    for (unsigned shift = 0; shift <= remind_before; ++shift)
    {
        tm birthday = now;
        birthday.tm_mday += shift;
        mktime(&birthday);

        for (auto person = persons.begin(); person != persons.end(); ++person)
        {
            if (birthday.tm_mon == person->birthday.tm_mon &&
                birthday.tm_mday == person->birthday.tm_mday)
            {
                char buf[16];
                strftime(buf, sizeof(buf), "%F", &birthday);

                printf("%s has birthday on %s ", person->name.c_str(), buf);

                if (0 == shift)
                {
                    printf("(TODAY!). ");
                }
                else
                {
                    printf("(in %u days). ", shift);
                }

                printf("He/she becomes %u.\n", birthday.tm_year - person->birthday.tm_year);
            }
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpl $0x2, %edi
jl 0x2421
movq %rsi, %rbx
movq 0x8(%rsi), %r14
leaq 0xc3c(%rip), %rdi       # 0x3010
movq %r14, %rsi
callq 0x2200
testl %eax, %eax
je 0x29e8
movzbl (%r14), %eax
subl $0x2d, %eax
jne 0x23fc
movzbl 0x1(%r14), %eax
subl $0x68, %eax
jne 0x23fc
movzbl 0x2(%r14), %eax
negl %eax
testl %eax, %eax
je 0x29e8
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0x2290
cmpq $0x0, 0x88(%rsp)
jne 0x2487
leaq 0xc08(%rip), %rdi       # 0x3030
callq 0x21c0
testq %rax, %rax
leaq 0xbfe(%rip), %rsi       # 0x3035
cmovneq %rax, %rsi
leaq 0x80(%rsp), %rdi
callq 0x2290
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rcx
cmpb $0x2f, -0x1(%rax,%rcx)
je 0x2473
leaq 0xbd1(%rip), %rsi       # 0x3037
leaq 0x80(%rsp), %rdi
callq 0x2280
leaq 0xb8a(%rip), %rsi       # 0x3004
leaq 0x80(%rsp), %rdi
callq 0x2280
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
andq $0x0, 0xb0(%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x80(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x2230
leaq 0xb7f(%rip), %rsi       # 0x3039
leaq 0x130(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x2aa6
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
pushq $0x3
popq %rax
movq %rax, 0x70(%rsp)
leaq 0x150(%rsp), %r15
leaq 0x8(%rsp), %r12
pushq $0xa
popq %rbp
leaq 0xc0(%rsp), %r14
movq 0x150(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x170(%rsp,%rax)
jne 0x2866
movq %r15, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x2270
cmpq $0x0, 0x10(%rsp)
je 0x2500
movq 0x8(%rsp), %rdx
movzbl (%rdx), %eax
cmpl $0x23, %eax
je 0x2500
cmpl $0x3b, %eax
je 0x2500
movq 0x130(%rsp), %rdi
movq 0x138(%rsp), %rsi
addq %rdi, %rsi
callq 0x2d0a
testb %al, %al
jne 0x27a0
movq 0x8(%rsp), %rdi
leaq 0xada(%rip), %rsi       # 0x3047
leaq 0x120(%rsp), %rdx
leaq 0x78(%rsp), %rcx
leaq 0x2c(%rsp), %r8
xorl %eax, %eax
callq 0x2170
cmpl $0x3, %eax
jne 0x2500
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movl 0x120(%rsp), %eax
movl $0xfffff894, %ecx       # imm = 0xFFFFF894
addl %ecx, %eax
movl %eax, 0x44(%rsp)
movl 0x78(%rsp), %eax
decl %eax
movl %eax, 0x40(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x3c(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x2100
cmpq $-0x1, %rax
je 0x2500
movq %r15, %r14
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %rbp
movq %r13, %rax
addq %rbp, %rax
movq %rax, 0x68(%rsp)
movq %rbp, %r15
sarq $0x2, %r15
movq %r13, 0x118(%rsp)
testq %r15, %r15
jle 0x2658
movq %r13, %rdi
callq 0x2a96
testb %al, %al
jne 0x269c
leaq 0x1(%r13), %rbx
movq %rbx, %rdi
callq 0x2a96
testb %al, %al
jne 0x269f
leaq 0x2(%r13), %rbx
movq %rbx, %rdi
callq 0x2a96
testb %al, %al
jne 0x269f
leaq 0x3(%r13), %rbx
movq %rbx, %rdi
callq 0x2a96
testb %al, %al
jne 0x269f
addq $0x4, %r13
decq %r15
addq $-0x4, %rbp
jmp 0x2606
cmpq $0x1, %rbp
movq %r14, %r15
je 0x280b
cmpq $0x2, %rbp
leaq 0xc0(%rsp), %r14
je 0x27f7
cmpq $0x3, %rbp
pushq $0xa
popq %rbp
jne 0x2500
movq %r13, %rdi
callq 0x2a96
testb %al, %al
jne 0x2826
incq %r13
jmp 0x27fa
movq %r13, %rbx
movq %r14, %r15
pushq $0xa
popq %rbp
leaq 0xc0(%rsp), %r14
cmpq %rbx, 0x68(%rsp)
je 0x2500
subq 0x118(%rsp), %rbx
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
pushq $-0x1
popq %rcx
callq 0x21b0
movq %r12, %rdi
movq %r14, %rsi
callq 0x21d0
movq %r14, %rdi
callq 0x20d0
cmpq $0x0, 0x10(%rsp)
je 0x271d
movq 0x8(%rsp), %rax
movsbl (%rax), %edi
callq 0x2050
testl %eax, %eax
je 0x271d
movq %r12, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x2070
jmp 0x26e4
decq %rbx
movq %r12, %rdi
movq %rbx, %rsi
pushq $0x1
popq %rdx
callq 0x2070
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0x273a
movq 0x8(%rsp), %rax
movsbl -0x1(%rax,%rbx), %edi
callq 0x2050
testl %eax, %eax
jne 0x270c
movq 0x60(%rsp), %rax
movq %rax, 0xf0(%rsp)
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movaps 0x50(%rsp), %xmm2
movaps %xmm2, 0xe0(%rsp)
movaps %xmm1, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
leaq 0xf8(%rsp), %rdi
movq %r12, %rsi
callq 0x21f0
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x2afe
leaq 0xf8(%rsp), %rdi
callq 0x20d0
jmp 0x2500
movq 0x138(%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
pushq $-0x1
popq %rcx
callq 0x21b0
movq %r12, %rdi
movq %r14, %rsi
callq 0x21d0
movq %r14, %rdi
callq 0x20d0
cmpq $0x0, 0x10(%rsp)
je 0x2500
movq 0x8(%rsp), %rax
movb (%rax), %bl
movsbl %bl, %edi
callq 0x2050
testl %eax, %eax
je 0x282e
movq %r12, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x2070
jmp 0x27c9
pushq $0xa
popq %rbp
movq %r13, %rdi
callq 0x2a96
testb %al, %al
jne 0x2826
incq %r13
jmp 0x2816
pushq $0xa
popq %rbp
leaq 0xc0(%rsp), %r14
movq %r13, %rdi
callq 0x2a96
testb %al, %al
cmoveq 0x68(%rsp), %r13
movq %r13, %rbx
jmp 0x26ad
cmpb $0x3d, %bl
jne 0x2500
movq %r12, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x2070
cmpq $0x0, 0x10(%rsp)
je 0x2500
movq %r12, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x2ae1
movq %rax, 0x70(%rsp)
jmp 0x2500
leaq 0x150(%rsp), %rdi
callq 0x2060
xorl %edi, %edi
callq 0x2160
leaq 0x78(%rsp), %rdi
movq %rax, (%rdi)
callq 0x2120
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movaps %xmm0, 0xc0(%rsp)
movaps %xmm1, 0xd0(%rsp)
movaps %xmm2, 0xe0(%rsp)
movq 0x30(%rax), %rax
movq %rax, 0xf0(%rsp)
leaq 0x30(%rsp), %r14
leaq 0x120(%rsp), %r12
leaq 0x78e(%rip), %rbp       # 0x3058
leaq 0x7b8(%rip), %rbx       # 0x3089
xorl %r15d, %r15d
cmpl 0x70(%rsp), %r15d
ja 0x29b5
movaps 0xc0(%rsp), %xmm0
movaps 0xd0(%rsp), %xmm1
movaps 0xe0(%rsp), %xmm2
movaps %xmm0, 0x30(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x60(%rsp)
movaps %xmm2, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
addl %r15d, 0x3c(%rsp)
movq %r14, %rdi
callq 0x2100
movq 0xa0(%rsp), %r13
cmpq 0xa8(%rsp), %r13
je 0x29ad
movl 0x40(%rsp), %eax
cmpl 0x10(%r13), %eax
jne 0x29a4
movl 0x3c(%rsp), %eax
cmpl 0xc(%r13), %eax
jne 0x29a4
movq %r12, %rdi
pushq $0x10
popq %rsi
leaq 0x702(%rip), %rdx       # 0x3055
movq %r14, %rcx
callq 0x2140
movq 0x38(%r13), %rsi
movq %rbp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2040
testl %r15d, %r15d
je 0x2984
leaq 0x702(%rip), %rdi       # 0x307a
movl %r15d, %esi
xorl %eax, %eax
callq 0x2040
jmp 0x2992
leaq 0x6e4(%rip), %rdi       # 0x306f
xorl %eax, %eax
callq 0x2040
movl 0x44(%rsp), %esi
subl 0x14(%r13), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2040
addq $0x58, %r13
jmp 0x2928
incl %r15d
jmp 0x28d4
leaq 0x8(%rsp), %rdi
callq 0x20d0
leaq 0x130(%rsp), %rdi
callq 0x20d0
leaq 0x150(%rsp), %rdi
callq 0x2080
leaq 0xa0(%rsp), %rdi
callq 0x2b2a
jmp 0x29f9
movq (%rbx), %rsi
leaq 0x625(%rip), %rdi       # 0x3017
xorl %eax, %eax
callq 0x2040
leaq 0x80(%rsp), %rdi
callq 0x20d0
xorl %eax, %eax
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a4d
jmp 0x2a4d
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x20d0
jmp 0x2a50
jmp 0x2a4d
jmp 0x2a4d
jmp 0x2a4d
jmp 0x2a4d
jmp 0x2a4d
jmp 0x2a4d
movq %rax, %rbx
jmp 0x2a67
movq %rax, %rbx
jmp 0x2a74
movq %rax, %rbx
jmp 0x2a81
jmp 0x2a4d
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x20d0
leaq 0x130(%rsp), %rdi
callq 0x20d0
leaq 0x150(%rsp), %rdi
callq 0x2080
leaq 0xa0(%rsp), %rdi
callq 0x2b2a
leaq 0x80(%rsp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x2250