// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: strftimeFunc
static void strftimeFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  DateTime x;
  u64 n;
  size_t i,j;
  char *z;
  sqlite3 *db;
  const char *zFmt = (const char*)sqlite3_value_text(argv[0]);
  char zBuf[100];
  if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
  db = sqlite3_context_db_handle(context);
  for(i=0, n=1; zFmt[i]; i++, n++){
    if( zFmt[i]=='%' ){
      switch( zFmt[i+1] ){
        case 'd':
        case 'H':
        case 'm':
        case 'M':
        case 'S':
        case 'W':
          n++;
          /* fall thru */
        case 'w':
        case '%':
          break;
        case 'f':
          n += 8;
          break;
        case 'j':
          n += 3;
          break;
        case 'Y':
          n += 8;
          break;
        case 's':
        case 'J':
          n += 50;
          break;
        default:
          return;  /* ERROR.  return a NULL */
      }
      i++;
    }
  }
  testcase( n==sizeof(zBuf)-1 );
  testcase( n==sizeof(zBuf) );
  testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH]+1 );
  testcase( n==(u64)db->aLimit[SQLITE_LIMIT_LENGTH] );
  if( n<sizeof(zBuf) ){
    z = zBuf;
  }else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
    sqlite3_result_error_toobig(context);
    return;
  }else{
    z = sqlite3DbMallocRaw(db, (int)n);
    if( z==0 ){
      sqlite3_result_error_nomem(context);
      return;
    }
  }
  computeJD(&x);
  computeYMD_HMS(&x);
  for(i=j=0; zFmt[i]; i++){
    if( zFmt[i]!='%' ){
      z[j++] = zFmt[i];
    }else{
      i++;
      switch( zFmt[i] ){
        case 'd':  sqlite3_snprintf(3, &z[j],"%02d",x.D); j+=2; break;
        case 'f': {
          double s = x.s;
          if( s>59.999 ) s = 59.999;
          sqlite3_snprintf(7, &z[j],"%06.3f", s);
          j += sqlite3Strlen30(&z[j]);
          break;
        }
        case 'H':  sqlite3_snprintf(3, &z[j],"%02d",x.h); j+=2; break;
        case 'W': /* Fall thru */
        case 'j': {
          int nDay;             /* Number of days since 1st day of year */
          DateTime y = x;
          y.validJD = 0;
          y.M = 1;
          y.D = 1;
          computeJD(&y);
          nDay = (int)((x.iJD-y.iJD+43200000)/86400000);
          if( zFmt[i]=='W' ){
            int wd;   /* 0=Monday, 1=Tuesday, ... 6=Sunday */
            wd = (int)(((x.iJD+43200000)/86400000)%7);
            sqlite3_snprintf(3, &z[j],"%02d",(nDay+7-wd)/7);
            j += 2;
          }else{
            sqlite3_snprintf(4, &z[j],"%03d",nDay+1);
            j += 3;
          }
          break;
        }
        case 'J': {
          sqlite3_snprintf(20, &z[j],"%.16g",x.iJD/86400000.0);
          j+=sqlite3Strlen30(&z[j]);
          break;
        }
        case 'm':  sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;
        case 'M':  sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break;
        case 's': {
          sqlite3_snprintf(30,&z[j],"%lld",
                           (i64)(x.iJD/1000 - 21086676*(i64)10000));
          j += sqlite3Strlen30(&z[j]);
          break;
        }
        case 'S':  sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;
        case 'w': {
          z[j++] = (char)(((x.iJD+129600000)/86400000) % 7) + '0';
          break;
        }
        case 'Y': {
          sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=sqlite3Strlen30(&z[j]);
          break;
        }
        default:   z[j++] = '%'; break;
      }
    }
  }
  z[j] = 0;
  sqlite3_result_text(context, z, -1,
                      z==zBuf ? SQLITE_TRANSIENT : SQLITE_DYNAMIC);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %rbx
movq (%rdx), %rdi
movl $0x1, %esi
callq 0xef29
testq %rax, %rax
je 0x658dc
movq %rax, %r14
decl %r12d
addq $0x8, %r15
leaq -0x58(%rbp), %rcx
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0x65935
testl %eax, %eax
jne 0x658dc
leaq 0x8(%rbx), %r12
movq 0x8(%rbx), %rdi
movl $0x1, %esi
xorl %eax, %eax
leaq 0x10b4d(%rip), %rcx     # 0x75f40
movzbl (%r14,%rax), %edx
cmpl $0x25, %edx
je 0x6540a
testl %edx, %edx
jne 0x6548a
jmp 0x65495
movzbl 0x1(%r14,%rax), %edx
incq %rax
cmpl $0x63, %edx
jg 0x65431
cmpl $0x4c, %edx
jle 0x6544a
cmpl $0x56, %edx
jg 0x6546d
cmpl $0x4d, %edx
je 0x65481
cmpl $0x53, %edx
je 0x65481
jmp 0x658dc
leal -0x64(%rdx), %r8d
cmpl $0x9, %r8d
ja 0x6545e
movslq (%rcx,%r8,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
addq $0x3, %rsi
jmp 0x6548a
cmpl $0x25, %edx
je 0x6548a
cmpl $0x48, %edx
je 0x65481
cmpl $0x4a, %edx
je 0x65486
jmp 0x658dc
cmpl $0x73, %edx
je 0x65486
cmpl $0x77, %edx
je 0x6548a
jmp 0x658dc
cmpl $0x57, %edx
je 0x65481
cmpl $0x59, %edx
jne 0x658dc
addq $0x8, %rsi
jmp 0x6548a
incq %rsi
jmp 0x6548a
addq $0x32, %rsi
incq %rax
incq %rsi
jmp 0x653f3
cmpq $0x64, %rsi
jae 0x654a4
leaq -0x100(%rbp), %r15
jmp 0x654ea
movslq 0x68(%rdi), %rax
cmpq %rax, %rsi
jbe 0x654d9
movl $0x12, 0x5c(%rbx)
movb $0x1, 0x61(%rbx)
leaq 0x13fb7(%rip), %rsi     # 0x79476
movq %r12, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0xf0d7
jmp 0x658dc
callq 0x11721
movq %rax, %r15
testq %rax, %rax
je 0x658ee
movq %rbx, -0x60(%rbp)
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0x663a5
movq %r12, %rdi
callq 0x66a08
movq %r12, %rdi
callq 0x66b15
movabsq $0x636ba875fd33dc87, %rsi # imm = 0x636BA875FD33DC87
xorl %r12d, %r12d
xorl %ebx, %ebx
movzbl (%r14,%rbx), %eax
cmpl $0x25, %eax
je 0x65537
testl %eax, %eax
je 0x658a5
movb %al, (%r15,%r12)
incq %r12
jmp 0x6589d
movb 0x1(%r14,%rbx), %r13b
incq %rbx
movzbl %r13b, %eax
cmpl $0x63, %eax
jg 0x65574
cmpl $0x52, %eax
jg 0x65598
cmpl $0x48, %eax
je 0x657bd
cmpl $0x4a, %eax
je 0x657f5
cmpl $0x4d, %eax
jne 0x65748
leaq (%r15,%r12), %rsi
movl -0x40(%rbp), %ecx
jmp 0x657cf
leal -0x64(%rax), %ecx
cmpl $0x9, %ecx
ja 0x655e8
leaq 0x109e5(%rip), %rdx     # 0x75f68
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
leaq (%r15,%r12), %rsi
movl -0x48(%rbp), %ecx
jmp 0x657cf
cmpl $0x53, %eax
je 0x657c6
cmpl $0x57, %eax
je 0x6564c
cmpl $0x59, %eax
jne 0x65748
leaq (%r15,%r12), %r13
movl -0x50(%rbp), %ecx
movl $0x5, %edi
movq %r13, %rsi
leaq 0x179dd(%rip), %rdx     # 0x7cfa6
xorl %eax, %eax
callq 0xb954
movq $-0x1, %rax
cmpb $0x0, 0x1(%r13,%rax)
leaq 0x1(%rax), %rax
jne 0x655d7
jmp 0x6588b
cmpl $0x73, %eax
je 0x65835
cmpl $0x77, %eax
jne 0x65748
movq -0x58(%rbp), %rax
movl $0x7b98a00, %ecx        # imm = 0x7B98A00
addq %rcx, %rax
imulq %rsi
movq %rdx, %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x19, %rcx
addq %rax, %rcx
movq %rcx, %rax
movabsq $0x4924924924924925, %rdx # imm = 0x4924924924924925
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
shrl %edx
addl %eax, %edx
leal (,%rdx,8), %eax
subl %eax, %edx
addl %edx, %ecx
addb $0x30, %cl
movb %cl, (%r15,%r12)
jmp 0x6552f
movupd -0x58(%rbp), %xmm0
movups -0x48(%rbp), %xmm1
movups -0x38(%rbp), %xmm2
movaps %xmm2, -0x70(%rbp)
movapd %xmm0, -0x90(%rbp)
movaps %xmm1, -0x80(%rbp)
movb $0x0, -0x66(%rbp)
movl $0x1, %eax
movl %eax, -0x84(%rbp)
movl %eax, -0x80(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x663a5
movabsq $0x636ba875fd33dc87, %rdi # imm = 0x636BA875FD33DC87
movq -0x58(%rbp), %rsi
movl $0x2932e00, %eax        # imm = 0x2932E00
addq %rax, %rsi
movq %rsi, %rax
subq -0x90(%rbp), %rax
imulq %rdi
movq %rdx, %rcx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x19, %rcx
addl %eax, %ecx
cmpb $0x57, %r13b
jne 0x6579a
movq %rsi, %rax
imulq %rdi
movq %rdx, %rdi
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x19, %rdi
addq %rax, %rdi
movq %rdi, %rax
movabsq $0x4924924924924925, %rdx # imm = 0x4924924924924925
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
shrq %rdx
addl %eax, %edx
leal (,%rdx,8), %eax
subl %edx, %eax
leaq (%r15,%r12), %rsi
subl %edi, %eax
leal (%rcx,%rax), %edx
addl $0x7, %edx
addl %ecx, %eax
movslq %edx, %rcx
imulq $-0x6db6db6d, %rcx, %rcx # imm = 0x92492493
shrq $0x20, %rcx
addl %eax, %ecx
addl $0x7, %ecx
movl %ecx, %eax
shrl $0x1f, %eax
sarl $0x2, %ecx
addl %eax, %ecx
movl $0x3, %edi
leaq 0x17840(%rip), %rdx     # 0x7cf77
xorl %eax, %eax
callq 0xb954
movl $0x2, %eax
jmp 0x65890
movb $0x25, (%r15,%r12)
jmp 0x6552f
leaq (%r15,%r12), %rsi
movl -0x4c(%rbp), %ecx
jmp 0x657cf
movsd 0x13b85(%rip), %xmm0    # 0x792e8
minsd -0x38(%rbp), %xmm0
leaq (%r15,%r12), %r13
movl $0x7, %edi
movq %r13, %rsi
leaq 0x1781f(%rip), %rdx     # 0x7cf9a
movb $0x1, %al
callq 0xb954
movq $-0x1, %rax
cmpb $0x0, 0x1(%r13,%rax)
leaq 0x1(%rax), %rax
jne 0x65789
jmp 0x6588b
leaq (%r15,%r12), %rsi
incl %ecx
movl $0x4, %edi
leaq 0x177f5(%rip), %rdx     # 0x7cfa1
xorl %eax, %eax
callq 0xb954
movl $0x3, %eax
jmp 0x65890
leaq (%r15,%r12), %rsi
movl -0x44(%rbp), %ecx
jmp 0x657cf
leaq (%r15,%r12), %rsi
cvttsd2si -0x38(%rbp), %ecx
movl $0x3, %edi
leaq 0x1779c(%rip), %rdx     # 0x7cf77
xorl %eax, %eax
callq 0xb954
movabsq $0x636ba875fd33dc87, %rsi # imm = 0x636BA875FD33DC87
addq $0x2, %r12
jmp 0x6589d
leaq (%r15,%r12), %r13
xorps %xmm0, %xmm0
cvtsi2sdq -0x58(%rbp), %xmm0
divsd 0x13a96(%rip), %xmm0    # 0x792a0
movl $0x14, %edi
movq %r13, %rsi
leaq 0x14551(%rip), %rdx     # 0x79d6a
movb $0x1, %al
callq 0xb954
movq $-0x1, %rax
cmpb $0x0, 0x1(%r13,%rax)
leaq 0x1(%rax), %rax
jne 0x65827
jmp 0x6588b
movabsq $0x20c49ba5e353f7cf, %rax # imm = 0x20C49BA5E353F7CF
imulq -0x58(%rbp)
leaq (%r15,%r12), %r13
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0x7, %rdx
addq %rdx, %rcx
movabsq $-0x3118a36940, %rax    # imm = 0xFFFFFFCEE75C96C0
addq %rax, %rcx
movl $0x1e, %edi
movq %r13, %rsi
leaq 0x15179(%rip), %rdx     # 0x7a9ea
xorl %eax, %eax
callq 0xb954
movq $-0x1, %rax
cmpb $0x0, 0x1(%r13,%rax)
leaq 0x1(%rax), %rax
jne 0x6587f
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
addq %rax, %r12
movabsq $0x636ba875fd33dc87, %rsi # imm = 0x636BA875FD33DC87
incq %rbx
jmp 0x65519
movb $0x0, (%r15,%r12)
leaq -0x100(%rbp), %rax
cmpq %rax, %r15
leaq -0x5bfab(%rip), %rax    # 0x9910
movq $-0x1, %r8
cmovneq %rax, %r8
movq -0x60(%rbp), %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0xeffe
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0xf373
movl $0x7, 0x5c(%rbx)
movb $0x1, %al
movb %al, 0x61(%rbx)
movq 0x8(%rbx), %rcx
movb %al, 0x50(%rcx)
jmp 0x658dc