// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_idate
static int jx9Builtin_idate(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zFormat;
	jx9_int64 iVal = 0;
	int nLen;
	Sytm sTm;
	if( nArg < 1 || !jx9_value_is_string(apArg[0]) ){
		/* Missing/Invalid argument, return -1 */
		jx9_result_int(pCtx, -1);
		return JX9_OK;
	}
	zFormat = jx9_value_to_string(apArg[0], &nLen);
	if( nLen < 1 ){
		/* Don't bother processing return -1*/
		jx9_result_int(pCtx, -1);
	}
	if( nArg < 2 ){
#ifdef __WINNT__
		SYSTEMTIME sOS;
		GetSystemTime(&sOS);
		SYSTEMTIME_TO_SYTM(&sOS, &sTm);
#else
		struct tm *pTm;
		time_t t;
		time(&t);
		pTm = localtime(&t);
		STRUCT_TM_TO_SYTM(pTm, &sTm);
#endif
	}else{
		/* Use the given timestamp */
		time_t t;
		struct tm *pTm;
		if( jx9_value_is_int(apArg[1]) ){
			t = (time_t)jx9_value_to_int64(apArg[1]);
			pTm = localtime(&t);
			if( pTm == 0 ){
				time(&t);
			}
		}else{
			time(&t);
		}
		pTm = localtime(&t);
		STRUCT_TM_TO_SYTM(pTm, &sTm);
	}
	/* Perform the requested operation */
	switch(zFormat[0]){
	case 'd':
		/* Day of the month */
		iVal = sTm.tm_mday;
		break;
	case 'h':
		/*	Hour (12 hour format)*/
		iVal = 1 + (sTm.tm_hour % 12);
		break;
	case 'H':
		/* Hour (24 hour format)*/
		iVal = sTm.tm_hour;
		break;
	case 'i':
		/*Minutes*/
		iVal = sTm.tm_min;
		break;
	case 'I':
		/*	returns 1 if DST is activated, 0 otherwise */
#ifdef __WINNT__
#ifdef _MSC_VER
#ifndef _WIN32_WCE
			_get_daylight(&sTm.tm_isdst);
#endif
#endif
#endif
		iVal = sTm.tm_isdst;
		break;
	case 'L':
		/* 	returns 1 for leap year, 0 otherwise */
		iVal = IS_LEAP_YEAR(sTm.tm_year);
		break;
	case 'm':
		/* Month number*/
		iVal = sTm.tm_mon;
		break;
	case 's':
		/*Seconds*/
		iVal = sTm.tm_sec;
		break;
	case 't':{
		/*Days in current month*/
		static const int aMonDays[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
		int nDays = aMonDays[sTm.tm_mon % 12 ];
		if( sTm.tm_mon == 1 /* 'February' */ && !IS_LEAP_YEAR(sTm.tm_year) ){
			nDays = 28;
		}
		iVal = nDays;
		break;
			 }
	case 'U':
		/*Seconds since the Unix Epoch*/
		iVal = (jx9_int64)time(0);
		break;
	case 'w':
		/*	Day of the week (0 on Sunday) */
		iVal = sTm.tm_wday;
		break;
	case 'W': {
		/* ISO-8601 week number of year, weeks starting on Monday */
		static const int aISO8601[] = { 7 /* Sunday */, 1 /* Monday */, 2, 3, 4, 5, 6 };
		iVal = aISO8601[sTm.tm_wday % 7 ];
		break;
			  }
	case 'y':
		/* Year (2 digits) */
		iVal = sTm.tm_year % 100;
		break;
	case 'Y':
		/* Year (4 digits) */
		iVal = sTm.tm_year;
		break;
	case 'z':
		/* Day of the year */
		iVal = sTm.tm_yday;
		break;
	case 'Z':
		/*Timezone offset in seconds*/
		iVal = sTm.tm_gmtoff;
		break;
	default:
		/* unknown format, throw a warning */
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "Unknown date format token");
		break;
	}
	/* Return the time value */
	jx9_result_int64(pCtx, iVal);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x58f33
movq %rdx, %r15
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x58f4b
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq $-0x1, (%rbx)
jmp 0x59218
movl %esi, %r12d
leaq -0x34(%rbp), %r13
movq %r13, %rsi
callq 0x30577
movq %rax, %r14
cmpl $0x0, (%r13)
jg 0x58f88
movq 0x8(%rbx), %r13
movq %r13, %rdi
callq 0x30465
movq $-0x1, (%r13)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r13), %eax
orl $0x2, %eax
movl %eax, 0x8(%r13)
cmpl $0x1, %r12d
jne 0x58f9f
leaq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0xc820
movq %r15, %rdi
jmp 0x58fd3
movq 0x8(%r15), %r15
testb $0x2, 0x8(%r15)
je 0x58fc6
movq %r15, %rdi
callq 0x3f362
movq (%r15), %rax
leaq -0x30(%rbp), %rdi
movq %rax, (%rdi)
callq 0xc770
testq %rax, %rax
jne 0x58fcf
leaq -0x30(%rbp), %rdi
callq 0xc820
leaq -0x30(%rbp), %rdi
callq 0xc770
movl 0x8(%rax), %edx
movl (%rax), %edi
movl 0x4(%rax), %r8d
movl 0x10(%rax), %r9d
movl 0xc(%rax), %r10d
movl 0x14(%rax), %ecx
movl 0x1c(%rax), %r11d
movl 0x18(%rax), %esi
movl 0x20(%rax), %r15d
leal 0x76c(%rcx), %eax
movzbl (%r14), %r14d
cmpl $0x63, %r14d
jg 0x5903a
cmpl $0x54, %r14d
jle 0x59081
addl $-0x55, %r14d
cmpl $0x5, %r14d
ja 0x59129
leaq 0x1998e(%rip), %rcx     # 0x729b0
movslq (%rcx,%r14,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
xorl %edi, %edi
callq 0xc820
movq %rax, %r14
jmp 0x59209
leal -0x68(%r14), %r15d
cmpl $0x12, %r15d
ja 0x5911b
leaq 0x19979(%rip), %r10     # 0x729c8
movslq (%r10,%r15,4), %r14
addq %r10, %r14
jmpq *%r14
movslq %edx, %rax
imulq $0x2aaaaaab, %rax, %rax # imm = 0x2AAAAAAB
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x21, %rax
addl %ecx, %eax
shll $0x2, %eax
leal (%rax,%rax,2), %eax
negl %eax
addl %edx, %eax
incl %eax
jmp 0x591e5
cmpl $0x48, %r14d
je 0x59113
cmpl $0x49, %r14d
je 0x5910b
cmpl $0x4c, %r14d
jne 0x59129
imull $0xc28f5c29, %eax, %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
movl %eax, %edx
rorl $0x4, %edx
cmpl $0xa3d70b, %edx         # imm = 0xA3D70B
jb 0x59203
rorl $0x2, %eax
cmpl $0x28f5c29, %eax        # imm = 0x28F5C29
jb 0x59145
xorl %r14d, %r14d
testb $0x3, %cl
sete %r14b
jmp 0x59209
movslq %esi, %rax
imulq $-0x6db6db6d, %rax, %rax # imm = 0x92492493
shrq $0x20, %rax
addl %esi, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0x2, %eax
addl %ecx, %eax
leal (,%rax,8), %ecx
subl %ecx, %eax
addl %esi, %eax
cltq
leaq 0x19e9e(%rip), %rcx     # 0x72fa0
movslq (%rcx,%rax,4), %r14
jmp 0x59209
movslq %r15d, %r14
jmp 0x59209
movslq %edx, %r14
jmp 0x59209
cmpl $0x64, %r14d
jne 0x59129
movslq %r10d, %r14
jmp 0x59209
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x1dfb7(%rip), %rcx     # 0x770f2
movl $0x2, %edx
callq 0x40afa
xorl %r14d, %r14d
jmp 0x59209
movslq %r9d, %rsi
imulq $0x2aaaaaab, %rsi, %rdx # imm = 0x2AAAAAAB
movq %rdx, %rdi
shrq $0x3f, %rdi
shrq $0x21, %rdx
addl %edi, %edx
shll $0x2, %edx
leal (%rdx,%rdx,2), %edx
movl %esi, %edi
subl %edx, %edi
movslq %edi, %rdx
leaq 0x19df8(%rip), %rdi     # 0x72f70
movl (%rdi,%rdx,4), %edx
cmpl $0x1, %esi
jne 0x591c4
movslq %eax, %rsi
imulq $0x51eb851f, %rsi, %rsi # imm = 0x51EB851F
movq %rsi, %rdi
shrq $0x3f, %rdi
sarq $0x27, %rsi
addl %edi, %esi
imull $0x190, %esi, %esi      # imm = 0x190
movl %eax, %edi
subl %esi, %edi
je 0x591c4
imull $0xc28f5c29, %eax, %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
rorl $0x2, %eax
testb $0x3, %cl
movl $0x1c, %ecx
cmovnel %ecx, %edx
cmpl $0x28f5c29, %eax        # imm = 0x28F5C29
cmovbl %ecx, %edx
movslq %edx, %r14
jmp 0x59209
movslq %eax, %rcx
imulq $0x51eb851f, %rcx, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
imull $0x64, %ecx, %ecx
subl %ecx, %eax
movslq %eax, %r14
jmp 0x59209
movslq %r8d, %r14
jmp 0x59209
movslq %esi, %r14
jmp 0x59209
movslq %r9d, %r14
jmp 0x59209
movslq %edi, %r14
jmp 0x59209
movslq %r11d, %r14
jmp 0x59209
movl $0x1, %r14d
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq %r14, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x2, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq