// File: /workspace/github_c_makefile_star2_O2/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 0x4cb83
movq %rdx, %r15
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x4cb93
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x2987c
jmp 0x4cd87
movl %esi, %r12d
leaq -0x34(%rbp), %r13
movq %r13, %rsi
callq 0x297ed
movq %rax, %r14
cmpl $0x0, (%r13)
jg 0x4cbb7
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x2987c
cmpl $0x1, %r12d
jne 0x4cbce
leaq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0xc850
movq %r15, %rdi
jmp 0x4cbfb
movq 0x8(%r15), %rdi
testb $0x2, 0x8(%rdi)
je 0x4cbee
callq 0x297ae
leaq -0x30(%rbp), %rdi
movq %rax, (%rdi)
callq 0xc7a0
testq %rax, %rax
jne 0x4cbf7
leaq -0x30(%rbp), %rdi
callq 0xc850
leaq -0x30(%rbp), %rdi
callq 0xc7a0
movq %rax, %rcx
movl 0x8(%rax), %eax
movl (%rcx), %r9d
movl 0x4(%rcx), %r10d
movl 0x10(%rcx), %esi
movl 0xc(%rcx), %r8d
movl 0x14(%rcx), %edi
movl 0x1c(%rcx), %r15d
movl 0x18(%rcx), %edx
movl 0x20(%rcx), %r11d
leal 0x76c(%rdi), %ecx
movzbl (%r14), %r14d
leal -0x68(%r14), %r12d
cmpl $0x12, %r12d
ja 0x4cc51
leaq 0x15d6f(%rip), %r8      # 0x629ac
movslq (%r8,%r12,4), %r11
addq %r8, %r11
jmpq *%r11
pushq $0xc
popq %rcx
cltd
idivl %ecx
incl %edx
jmp 0x4ccbe
leal -0x55(%r14), %esi
cmpl $0x5, %esi
ja 0x4cc79
leaq 0x15d33(%rip), %rax     # 0x62994
movslq (%rax,%rsi,4), %rsi
addq %rax, %rsi
jmpq *%rsi
xorl %edi, %edi
callq 0xc850
movq %rax, %rsi
jmp 0x4cd7f
cmpl $0x48, %r14d
je 0x4cd77
cmpl $0x49, %r14d
je 0x4cd48
cmpl $0x4c, %r14d
je 0x4cd4d
cmpl $0x64, %r14d
je 0x4cd1c
leaq 0x1a42e(%rip), %rdx     # 0x670d2
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
xorl %esi, %esi
jmp 0x4cd7f
pushq $0x64
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
movslq %edx, %rsi
jmp 0x4cd7f
movslq %esi, %rsi
jmp 0x4cd7f
movslq %r9d, %rsi
jmp 0x4cd7f
pushq $0xc
popq %r8
movl %esi, %eax
cltd
idivl %r8d
movslq %edx, %rax
leaq 0x16266(%rip), %rdx     # 0x62f50
movl (%rdx,%rax,4), %r8d
movl $0x190, %r9d            # imm = 0x190
movl %ecx, %eax
cltd
idivl %r9d
cmpl $0x1, %esi
jne 0x4cd1c
testl %edx, %edx
je 0x4cd1c
pushq $0x64
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
testb $0x3, %dil
pushq $0x1c
popq %rax
cmovnel %eax, %r8d
testl %edx, %edx
cmovel %eax, %r8d
movslq %r8d, %rsi
jmp 0x4cd7f
movslq %r10d, %rsi
jmp 0x4cd7f
movslq %r15d, %rsi
jmp 0x4cd7f
pushq $0x7
popq %rcx
movl %edx, %eax
cltd
idivl %ecx
movslq %edx, %rax
leaq 0x16243(%rip), %rcx     # 0x62f80
movslq (%rcx,%rax,4), %rsi
jmp 0x4cd7f
movslq %ecx, %rsi
jmp 0x4cd7f
movslq %r11d, %rsi
jmp 0x4cd7f
movl $0x190, %esi            # imm = 0x190
movl %ecx, %eax
cltd
idivl %esi
testl %edx, %edx
je 0x4cd7c
pushq $0x64
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
testl %edx, %edx
je 0x4ccaf
xorl %esi, %esi
testb $0x3, %dil
sete %sil
jmp 0x4cd7f
movslq %eax, %rsi
jmp 0x4cd7f
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x29897
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq