// File: /workspace/github_c_makefile_star2_O1/Paxa[P]fast_excel/libxlsxwriter/src/utility.c
// Function: lxw_datetime_to_excel_date_epoch
double
lxw_datetime_to_excel_date_epoch(lxw_datetime *datetime, uint8_t date_1904)
{
    int year = datetime->year;
    int month = datetime->month;
    int day = datetime->day;
    int hour = datetime->hour;
    int min = datetime->min;
    double sec = datetime->sec;
    double seconds;
    int epoch = date_1904 ? 1904 : 1900;
    int offset = date_1904 ? 4 : 0;
    int norm = 300;
    int range;
    /* Set month days and check for leap year. */
    int mdays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    int leap = 0;
    int days = 0;
    int i;

    /* For times without dates set the default date for the epoch. */
    if (!year) {
        if (!date_1904) {
            year = 1899;
            month = 12;
            day = 31;
        }
        else {
            year = 1904;
            month = 1;
            day = 1;
        }
    }

    /* Convert the Excel seconds to a fraction of the seconds in 24 hours. */
    seconds = (hour * 60 * 60 + min * 60 + sec) / (24 * 60 * 60.0);

    /* Special cases for Excel dates in the 1900 epoch. */
    if (!date_1904) {
        /* Excel 1900 epoch. */
        if (year == 1899 && month == 12 && day == 31)
            return seconds;

        /* Excel 1900 epoch. */
        if (year == 1900 && month == 1 && day == 0)
            return seconds;

        /* Excel false leapday */
        if (year == 1900 && month == 2 && day == 29)
            return 60 + seconds;
    }

    /* We calculate the date by calculating the number of days since the */
    /* epoch and adjust for the number of leap days. We calculate the */
    /* number of leap days by normalizing the year in relation to the */
    /* epoch. Thus the year 2000 becomes 100 for 4-year and 100-year */
    /* leapdays and 400 for 400-year leapdays. */
    range = year - epoch;

    if (year % 4 == 0 && (year % 100 > 0 || year % 400 == 0)) {
        leap = 1;
        mdays[2] = 29;
    }

    /*
     * Calculate the serial date by accumulating the number of days
     * since the epoch.
     */

    /* Add days for previous months. */
    for (i = 0; i < month; i++) {
        days += mdays[i];
    }
    /* Add days for current month. */
    days += day;
    /* Add days for all previous years.  */
    days += range * 365;
    /* Add 4 year leapdays. */
    days += range / 4;
    /* Remove 100 year leapdays. */
    days -= (range + offset) / 100;
    /* Add 400 year leapdays. */
    days += (range + offset + norm) / 400;
    /* Remove leap days already counted. */
    days -= leap;

    /* Adjust for Excel erroneously treating 1900 as a leap year. */
    if (!date_1904 && days > 59)
        days++;

    return days + seconds;
}

// Assembly:
movl (%rdi), %edx
xorl %ecx, %ecx
testl %esi, %esi
setne %cl
movl $0x1f, %eax
movl $0x1, %r9d
cmovnel %r9d, %eax
movl $0xc, %r8d
cmovnel %r9d, %r8d
testl %edx, %edx
je 0x268b9
movl 0x8(%rdi), %eax
movl 0x4(%rdi), %r8d
jmp 0x268c2
leal (%rcx,%rcx,4), %edx
addl $0x76b, %edx            # imm = 0x76B
pushq %rbp
pushq %rbx
imull $0xe10, 0xc(%rdi), %r9d # imm = 0xE10
imull $0x3c, 0x10(%rdi), %r10d
addl %r9d, %r10d
cvtsi2sd %r10d, %xmm0
addsd 0x18(%rdi), %xmm0
xorl %edi, %edi
movaps 0x1e9b9(%rip), %xmm1    # 0x452a0
movaps %xmm1, -0x18(%rsp)
movaps 0x1e99d(%rip), %xmm1    # 0x45290
movaps %xmm1, -0x28(%rsp)
movapd 0x1e980(%rip), %xmm1    # 0x45280
movapd %xmm1, -0x38(%rsp)
movl $0x1f, -0x8(%rsp)
divsd 0x1e402(%rip), %xmm0    # 0x44d18
testl %esi, %esi
sete %r9b
je 0x26a29
movb %r9b, %dil
leal -0x770(,%rdi,4), %r10d
xorl %edi, %edi
movl $0x0, %r9d
testb $0x3, %dl
jne 0x26989
movslq %edx, %r9
imulq $0x51eb851f, %r9, %r9   # imm = 0x51EB851F
movq %r9, %rbx
sarq $0x25, %rbx
movq %r9, %r11
shrq $0x3f, %r11
addl %r11d, %ebx
imull $0x64, %ebx, %ebx
movl %edx, %ebp
subl %ebx, %ebp
testl %ebp, %ebp
jg 0x2697b
sarq $0x27, %r9
addl %r11d, %r9d
imull $0x190, %r9d, %r11d     # imm = 0x190
movl %edx, %ebx
movl $0x0, %r9d
subl %r11d, %ebx
jne 0x26989
movl $0x1d, -0x30(%rsp)
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
shll $0x2, %ecx
addl %r10d, %edx
testl %r8d, %r8d
jle 0x269a9
movl %r8d, %r8d
xorl %r10d, %r10d
xorl %edi, %edi
addl -0x38(%rsp,%r10,4), %edi
incq %r10
cmpq %r10, %r8
jne 0x2699c
testb %sil, %sil
sete %r8b
imull $0x16d, %edx, %esi      # imm = 0x16D
leal 0x3(%rdx), %r10d
testl %edx, %edx
cmovnsl %edx, %r10d
sarl $0x2, %r10d
leal (%rdx,%rcx), %r11d
movslq %r11d, %r11
imulq $-0x51eb851f, %r11, %r11 # imm = 0xAE147AE1
movq %r11, %rbx
shrq $0x3f, %rbx
sarq $0x25, %r11
addl %ebx, %r11d
addl %edx, %ecx
addl $0x12c, %ecx            # imm = 0x12C
movslq %ecx, %rcx
imulq $0x51eb851f, %rcx, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x27, %rcx
addl %edx, %ecx
addl %r9d, %ecx
addl %eax, %esi
addl %r10d, %esi
addl %r11d, %esi
addl %ecx, %esi
addl %edi, %esi
cmpl $0x3c, %esi
setge %al
andb %r8b, %al
movzbl %al, %eax
addl %esi, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd %xmm1, %xmm0
jmp 0x26a84
movl %edx, %r10d
xorl $0x76b, %r10d           # imm = 0x76B
movl %r8d, %r11d
xorl $0xc, %r11d
orl %r10d, %r11d
movl %eax, %r10d
xorl $0x1f, %r10d
orl %r11d, %r10d
je 0x26a84
movl %edx, %r10d
xorl $0x76c, %r10d           # imm = 0x76C
movl %r8d, %r11d
xorl $0x1, %r11d
orl %r10d, %r11d
orl %eax, %r11d
je 0x26a84
movl %r8d, %r11d
xorl $0x2, %r11d
orl %r11d, %r10d
movl %eax, %r11d
xorl $0x1d, %r11d
orl %r10d, %r11d
jne 0x26922
addsd 0x1e29c(%rip), %xmm0    # 0x44d20
popq %rbx
popq %rbp
retq