// File: /workspace/github_c_makefile_star2_O1/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 0xee49
testq %rax, %rax
je 0x65a7a
movq %rax, %r14
decl %r12d
addq $0x8, %r15
leaq -0x58(%rbp), %rcx
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0x65ad3
testl %eax, %eax
jne 0x65a7a
leaq 0x8(%rbx), %r12
movq 0x8(%rbx), %rdi
movl $0x1, %esi
xorl %eax, %eax
leaq 0x1097f(%rip), %rcx     # 0x75f08
movzbl (%r14,%rax), %edx
cmpl $0x25, %edx
je 0x655a0
testl %edx, %edx
jne 0x65620
jmp 0x6562b
movzbl 0x1(%r14,%rax), %edx
incq %rax
cmpl $0x63, %edx
jg 0x655c7
cmpl $0x4c, %edx
jle 0x655e0
cmpl $0x56, %edx
jg 0x65603
cmpl $0x4d, %edx
je 0x65617
cmpl $0x53, %edx
je 0x65617
jmp 0x65a7a
leal -0x64(%rdx), %r8d
cmpl $0x9, %r8d
ja 0x655f4
movslq (%rcx,%r8,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
addq $0x3, %rsi
jmp 0x65620
cmpl $0x25, %edx
je 0x65620
cmpl $0x48, %edx
je 0x65617
cmpl $0x4a, %edx
je 0x6561c
jmp 0x65a7a
cmpl $0x73, %edx
je 0x6561c
cmpl $0x77, %edx
je 0x65620
jmp 0x65a7a
cmpl $0x57, %edx
je 0x65617
cmpl $0x59, %edx
jne 0x65a7a
addq $0x8, %rsi
jmp 0x65620
incq %rsi
jmp 0x65620
addq $0x32, %rsi
incq %rax
incq %rsi
jmp 0x65589
cmpq $0x64, %rsi
jae 0x6563a
leaq -0x100(%rbp), %r15
jmp 0x65680
movslq 0x68(%rdi), %rax
cmpq %rax, %rsi
jbe 0x6566f
movl $0x12, 0x5c(%rbx)
movb $0x1, 0x61(%rbx)
leaq 0x13e21(%rip), %rsi     # 0x79476
movq %r12, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0xeff4
jmp 0x65a7a
callq 0x115e9
movq %rax, %r15
testq %rax, %rax
je 0x65a8c
movq %rbx, -0x60(%rbp)
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0x6655d
movq %r12, %rdi
callq 0x66bfb
movq %r12, %rdi
callq 0x66d16
movabsq $0x636ba875fd33dc87, %rsi # imm = 0x636BA875FD33DC87
xorl %r12d, %r12d
xorl %ebx, %ebx
movzbl (%r14,%rbx), %eax
cmpl $0x25, %eax
je 0x656cd
testl %eax, %eax
je 0x65a43
movb %al, (%r15,%r12)
incq %r12
jmp 0x65a3b
movb 0x1(%r14,%rbx), %r13b
incq %rbx
movzbl %r13b, %eax
cmpl $0x63, %eax
jg 0x6570a
cmpl $0x52, %eax
jg 0x6572e
cmpl $0x48, %eax
je 0x6595b
cmpl $0x4a, %eax
je 0x65993
cmpl $0x4d, %eax
jne 0x658e6
leaq (%r15,%r12), %rsi
movl -0x40(%rbp), %ecx
jmp 0x6596d
leal -0x64(%rax), %ecx
cmpl $0x9, %ecx
ja 0x6577e
leaq 0x10817(%rip), %rdx     # 0x75f30
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
leaq (%r15,%r12), %rsi
movl -0x48(%rbp), %ecx
jmp 0x6596d
cmpl $0x53, %eax
je 0x65964
cmpl $0x57, %eax
je 0x657e2
cmpl $0x59, %eax
jne 0x658e6
leaq (%r15,%r12), %r13
movl -0x50(%rbp), %ecx
movl $0x5, %edi
movq %r13, %rsi
leaq 0x17847(%rip), %rdx     # 0x7cfa6
xorl %eax, %eax
callq 0xb859
movq $-0x1, %rax
cmpb $0x0, 0x1(%r13,%rax)
leaq 0x1(%rax), %rax
jne 0x6576d
jmp 0x65a29
cmpl $0x73, %eax
je 0x659d3
cmpl $0x77, %eax
jne 0x658e6
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 0x656c5
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 0x6655d
movabsq $0x636ba875fd33dc87, %rdi # imm = 0x636BA875FD33DC87
movq -0x58(%rbp), %rsi
movq -0x90(%rbp), %rax
negq %rax
addq %rsi, %rax
addq $0x2932e00, %rax        # imm = 0x2932E00
imulq %rdi
movq %rdx, %rcx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x19, %rcx
addl %eax, %ecx
cmpb $0x57, %r13b
jne 0x65938
addq $0x2932e00, %rsi        # imm = 0x2932E00
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 0x176a2(%rip), %rdx     # 0x7cf77
xorl %eax, %eax
callq 0xb859
movl $0x2, %eax
jmp 0x65a2e
movb $0x25, (%r15,%r12)
jmp 0x656c5
leaq (%r15,%r12), %rsi
movl -0x4c(%rbp), %ecx
jmp 0x6596d
movsd 0x139e7(%rip), %xmm0    # 0x792e8
minsd -0x38(%rbp), %xmm0
leaq (%r15,%r12), %r13
movl $0x7, %edi
movq %r13, %rsi
leaq 0x17681(%rip), %rdx     # 0x7cf9a
movb $0x1, %al
callq 0xb859
movq $-0x1, %rax
cmpb $0x0, 0x1(%r13,%rax)
leaq 0x1(%rax), %rax
jne 0x65927
jmp 0x65a29
leaq (%r15,%r12), %rsi
incl %ecx
movl $0x4, %edi
leaq 0x17657(%rip), %rdx     # 0x7cfa1
xorl %eax, %eax
callq 0xb859
movl $0x3, %eax
jmp 0x65a2e
leaq (%r15,%r12), %rsi
movl -0x44(%rbp), %ecx
jmp 0x6596d
leaq (%r15,%r12), %rsi
cvttsd2si -0x38(%rbp), %ecx
movl $0x3, %edi
leaq 0x175fe(%rip), %rdx     # 0x7cf77
xorl %eax, %eax
callq 0xb859
movabsq $0x636ba875fd33dc87, %rsi # imm = 0x636BA875FD33DC87
addq $0x2, %r12
jmp 0x65a3b
leaq (%r15,%r12), %r13
xorps %xmm0, %xmm0
cvtsi2sdq -0x58(%rbp), %xmm0
divsd 0x138f8(%rip), %xmm0    # 0x792a0
movl $0x14, %edi
movq %r13, %rsi
leaq 0x143b3(%rip), %rdx     # 0x79d6a
movb $0x1, %al
callq 0xb859
movq $-0x1, %rax
cmpb $0x0, 0x1(%r13,%rax)
leaq 0x1(%rax), %rax
jne 0x659c5
jmp 0x65a29
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 0x14fdb(%rip), %rdx     # 0x7a9ea
xorl %eax, %eax
callq 0xb859
movq $-0x1, %rax
cmpb $0x0, 0x1(%r13,%rax)
leaq 0x1(%rax), %rax
jne 0x65a1d
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
addq %rax, %r12
movabsq $0x636ba875fd33dc87, %rsi # imm = 0x636BA875FD33DC87
incq %rbx
jmp 0x656af
movb $0x0, (%r15,%r12)
leaq -0x100(%rbp), %rax
cmpq %rax, %r15
leaq -0x5c185(%rip), %rax    # 0x98d4
movq $-0x1, %r8
cmovneq %rax, %r8
movq -0x60(%rbp), %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0xef1b
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0xf2d0
movl $0x7, 0x5c(%rbx)
movb $0x1, %al
movb %al, 0x61(%rbx)
movq 0x8(%rbx), %rcx
movb %al, 0x50(%rcx)
jmp 0x65a7a