// File: gossterrible[P]Calendar-/Calendar.cpp
// Function: Calendar::Draw()
void Calendar::Draw() {
    int year = currentDate.getYear();
    int month = currentDate.getMonth();

    cout << "    " << Date::MonthNames[month - 1];
    cout << "    " << year << endl;

    cout << "**************************" << endl;


    //Print all the startingDay days Mon-Sun 
    for (int i = 0; i < sizeof Date::DayNames / sizeof Date::DayNames[0]; ++i) {
        cout << Date::DayNames[i] << " ";
    }
    cout << endl;


    /**********************************************/
    /*  Calculate the starting day for each month  */
    /*********************************************/


    //  Tomohiko Sakamoto's Algorithm

    int y = year - (month < 3);
    static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
    int startingDay;
    int d = 1;
    //Nasty trick to solve febuary starting day
    if (month == 2) {
        d = 0;
    }
    startingDay = ((year + year / 4 - year / 100 + year / 400 + t[month - 1] + d) % 7);
    cout << startingDay << endl;
    int dayCount = Date::MonthDays[month - 1];
    cout << dayCount << endl;


    /**********************************************/
    /*          Printing the calendar            */
    /*********************************************/

    //Print and empty space if the day doesn't have a corresponding day 
    for (int x = 0; x < startingDay; ++x) {
        cout << "    ";
    }


    //Print the date corresponding with the day 
    for (int d = 0; d < dayCount; ++d) {
        if (d < 9)

            cout << "0" << d + 1 << "  ";
        else
            cout << d + 1 << "  ";
        ++startingDay;
        if (startingDay == 7) {
            startingDay = 0;
            cout << endl;
        }
    }

    cout << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x38(%rbp)
callq 0x64f0
movq -0x38(%rbp), %rdi
movl %eax, -0xc(%rbp)
callq 0x64d0
movl %eax, -0x10(%rbp)
movq 0x5cf9(%rip), %rdi      # 0x9fc8
leaq 0x2e5b(%rip), %rsi      # 0x7131
callq 0x3200
movq %rax, %rdi
movl -0x10(%rbp), %eax
subl $0x1, %eax
cltq
leaq 0x6093(%rip), %rsi      # 0xa380
shlq $0x5, %rax
addq %rax, %rsi
callq 0x31d0
movq 0x5cc8(%rip), %rdi      # 0x9fc8
leaq 0x2e2a(%rip), %rsi      # 0x7131
callq 0x3200
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x33b0
movq %rax, %rdi
movq 0x5c97(%rip), %rsi      # 0x9fb8
callq 0x3230
movq 0x5c9b(%rip), %rdi      # 0x9fc8
leaq 0x2e02(%rip), %rsi      # 0x7136
callq 0x3200
movq %rax, %rdi
movq 0x5c75(%rip), %rsi      # 0x9fb8
callq 0x3230
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
cmpq $0x7, %rax
jae 0x4391
movslq -0x14(%rbp), %rax
leaq 0x5f3c(%rip), %rsi      # 0xa2a0
shlq $0x5, %rax
addq %rax, %rsi
movq 0x5c56(%rip), %rdi      # 0x9fc8
callq 0x31d0
movq %rax, %rdi
leaq 0x2db3(%rip), %rsi      # 0x7134
callq 0x3200
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x434f
movq 0x5c30(%rip), %rdi      # 0x9fc8
movq 0x5c19(%rip), %rsi      # 0x9fb8
callq 0x3230
movl -0xc(%rbp), %eax
cmpl $0x3, -0x10(%rbp)
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl $0x1, -0x20(%rbp)
cmpl $0x2, -0x10(%rbp)
jne 0x43cd
movl $0x0, -0x20(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0xc(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x44(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0xc(%rbp), %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x40(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0xc(%rbp), %eax
movl $0x190, %ecx            # imm = 0x190
cltd
idivl %ecx
movl %eax, %ecx
movl -0x3c(%rbp), %eax
addl %ecx, %eax
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rdx
leaq 0x5e21(%rip), %rcx      # 0xa240
addl (%rcx,%rdx,4), %eax
addl -0x20(%rbp), %eax
movl $0x7, %ecx
cltd
idivl %ecx
movl %edx, -0x1c(%rbp)
movl -0x1c(%rbp), %esi
movq 0x5b8e(%rip), %rdi      # 0x9fc8
callq 0x33b0
movq %rax, %rdi
movq 0x5b6f(%rip), %rsi      # 0x9fb8
callq 0x3230
movl -0x10(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x2e92(%rip), %rax      # 0x72f0
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %esi
movq 0x5b5a(%rip), %rdi      # 0x9fc8
callq 0x33b0
movq %rax, %rdi
movq 0x5b3b(%rip), %rsi      # 0x9fb8
callq 0x3230
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x44af
movq 0x5b30(%rip), %rdi      # 0x9fc8
leaq 0x2c92(%rip), %rsi      # 0x7131
callq 0x3200
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x4489
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x4554
cmpl $0x9, -0x2c(%rbp)
jge 0x44fa
movq 0x5af9(%rip), %rdi      # 0x9fc8
leaq 0x2c7b(%rip), %rsi      # 0x7151
callq 0x3200
movq %rax, %rdi
movl -0x2c(%rbp), %esi
addl $0x1, %esi
callq 0x33b0
movq %rax, %rdi
leaq 0x2c40(%rip), %rsi      # 0x7133
callq 0x3200
jmp 0x451b
movl -0x2c(%rbp), %esi
addl $0x1, %esi
movq 0x5ac1(%rip), %rdi      # 0x9fc8
callq 0x33b0
movq %rax, %rdi
leaq 0x2c1d(%rip), %rsi      # 0x7133
callq 0x3200
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x7, -0x1c(%rbp)
jne 0x4544
movl $0x0, -0x1c(%rbp)
movq 0x5a90(%rip), %rdi      # 0x9fc8
movq 0x5a79(%rip), %rsi      # 0x9fb8
callq 0x3230
jmp 0x4546
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x44b6
movq 0x5a6d(%rip), %rdi      # 0x9fc8
movq 0x5a56(%rip), %rsi      # 0x9fb8
callq 0x3230
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)