// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movzbl -0x11(%rbp), %edx
movl $0x76c, %eax            # imm = 0x76C
movl $0x770, %ecx            # imm = 0x770
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x3c(%rbp)
movzbl -0x11(%rbp), %edx
xorl %eax, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x40(%rbp)
movl $0x12c, -0x44(%rbp)     # imm = 0x12C
leaq -0x80(%rbp), %rdi
leaq 0x3384f(%rip), %rsi     # 0x6afa0
movl $0x34, %edx
callq 0xc980
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x377a9
cmpb $0x0, -0x11(%rbp)
jne 0x37792
movl $0x76b, -0x18(%rbp)     # imm = 0x76B
movl $0xc, -0x1c(%rbp)
movl $0x1f, -0x20(%rbp)
jmp 0x377a7
movl $0x770, -0x18(%rbp)     # imm = 0x770
movl $0x1, -0x1c(%rbp)
movl $0x1, -0x20(%rbp)
jmp 0x377a9
imull $0x3c, -0x24(%rbp), %eax
imull $0x3c, %eax, %eax
imull $0x3c, -0x28(%rbp), %ecx
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
addsd -0x30(%rbp), %xmm0
movsd 0x33271(%rip), %xmm1    # 0x6aa38
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
cmpb $0x0, -0x11(%rbp)
jne 0x3784c
cmpl $0x76b, -0x18(%rbp)     # imm = 0x76B
jne 0x377fa
cmpl $0xc, -0x1c(%rbp)
jne 0x377fa
cmpl $0x1f, -0x20(%rbp)
jne 0x377fa
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x3798b
cmpl $0x76c, -0x18(%rbp)     # imm = 0x76C
jne 0x3781e
cmpl $0x1, -0x1c(%rbp)
jne 0x3781e
cmpl $0x0, -0x20(%rbp)
jne 0x3781e
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x3798b
cmpl $0x76c, -0x18(%rbp)     # imm = 0x76C
jne 0x3784a
cmpl $0x2, -0x1c(%rbp)
jne 0x3784a
cmpl $0x1d, -0x20(%rbp)
jne 0x3784a
movsd 0x33205(%rip), %xmm0    # 0x6aa40
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x3798b
jmp 0x3784c
movl -0x18(%rbp), %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x18(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x37896
movl -0x18(%rbp), %eax
movl $0x64, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jg 0x37885
movl -0x18(%rbp), %eax
movl $0x190, %ecx            # imm = 0x190
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x37896
movl $0x1, -0x84(%rbp)
movl $0x1d, -0x78(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x378d3
movslq -0x8c(%rbp), %rax
movl -0x80(%rbp,%rax,4), %eax
addl -0x88(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x378a0
movl -0x20(%rbp), %eax
addl -0x88(%rbp), %eax
movl %eax, -0x88(%rbp)
imull $0x16d, -0x48(%rbp), %eax # imm = 0x16D
addl -0x88(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x48(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
addl -0x88(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x48(%rbp), %eax
addl -0x40(%rbp), %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x88(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x88(%rbp)
movl -0x48(%rbp), %eax
addl -0x40(%rbp), %eax
addl -0x44(%rbp), %eax
movl $0x190, %ecx            # imm = 0x190
cltd
idivl %ecx
addl -0x88(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x84(%rbp), %ecx
movl -0x88(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x88(%rbp)
cmpb $0x0, -0x11(%rbp)
jne 0x37979
cmpl $0x3b, -0x88(%rbp)
jle 0x37979
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
cvtsi2sdl -0x88(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)