// File: /workspace/github_c_makefile_star2_O2/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
callq 0xdf1e
testq %rax, %rax
je 0x59bb2
movq %rax, %r14
decl %r12d
addq $0x8, %r15
leaq -0x58(%rbp), %rcx
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0x59bf8
testl %eax, %eax
jne 0x59bb2
movq 0x8(%rbx), %rdi
pushq $0x1
popq %rsi
xorl %eax, %eax
leaq 0xe6b1(%rip), %rcx      # 0x67efc
movzbl (%r14,%rax), %edx
cmpl $0x25, %edx
je 0x5985b
testl %edx, %edx
jne 0x598be
jmp 0x598c6
movzbl 0x1(%r14,%rax), %edx
incq %rax
leal -0x64(%rdx), %r8d
cmpl $0x9, %r8d
jbe 0x598a0
cmpl $0x25, %edx
je 0x598be
cmpl $0x48, %edx
je 0x598a9
cmpl $0x4a, %edx
je 0x598b4
cmpl $0x4d, %edx
je 0x598a9
cmpl $0x53, %edx
je 0x598a9
cmpl $0x77, %edx
je 0x598be
cmpl $0x59, %edx
je 0x598ae
cmpl $0x73, %edx
je 0x598b4
cmpl $0x57, %edx
je 0x598a9
jmp 0x59bb2
movslq (%rcx,%r8,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
incq %rsi
jmp 0x598be
addq $0x8, %rsi
jmp 0x598be
addq $0x32, %rsi
jmp 0x598be
addq $0x3, %rsi
incq %rax
incq %rsi
jmp 0x5984b
cmpq $0x64, %rsi
jae 0x598d5
leaq -0x100(%rbp), %r15
jmp 0x598fc
movslq 0x68(%rdi), %rax
cmpq %rax, %rsi
jbe 0x598eb
movq %rbx, %rdi
callq 0xe604
jmp 0x59bb2
callq 0x103b4
movq %rax, %r15
testq %rax, %rax
je 0x59bc4
movq %rbx, -0x60(%rbp)
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0x5a515
movq %r12, %rdi
callq 0x5ab20
xorl %ebx, %ebx
xorl %r13d, %r13d
movzbl (%r14,%r13), %eax
cmpl $0x25, %eax
je 0x59937
testl %eax, %eax
je 0x59b86
movb %al, (%r15,%rbx)
incq %rbx
jmp 0x59b7e
movb 0x1(%r14,%r13), %r12b
incq %r13
movzbl %r12b, %eax
leal -0x64(%rax), %ecx
cmpl $0x9, %ecx
jbe 0x599b9
cmpl $0x48, %eax
je 0x59ac7
cmpl $0x4a, %eax
je 0x59b4b
cmpl $0x4d, %eax
je 0x59ad0
cmpl $0x53, %eax
je 0x59b2b
cmpl $0x57, %eax
je 0x599d5
cmpl $0x59, %eax
je 0x59ad9
cmpl $0x73, %eax
je 0x59af6
cmpl $0x77, %eax
jne 0x59a6f
movq -0x58(%rbp), %rax
movl $0x7b98a00, %ecx        # imm = 0x7B98A00
addq %rcx, %rax
cqto
movl $0x5265c00, %ecx        # imm = 0x5265C00
idivq %rcx
cqto
pushq $0x7
popq %rcx
idivq %rcx
addb $0x30, %dl
movb %dl, (%r15,%rbx)
jmp 0x5992f
leaq 0xe564(%rip), %rdx      # 0x67f24
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
leaq (%r15,%rbx), %rsi
movl -0x48(%rbp), %ecx
jmp 0x59b34
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)
pushq $0x1
popq %rax
movl %eax, -0x84(%rbp)
movl %eax, -0x80(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x5a515
movq -0x58(%rbp), %rsi
movl $0x2932e00, %eax        # imm = 0x2932E00
addq %rax, %rsi
movq %rsi, %rax
subq -0x90(%rbp), %rax
cqto
movl $0x5265c00, %edi        # imm = 0x5265C00
idivq %rdi
movq %rax, %rcx
cmpb $0x57, %r12b
jne 0x59aa8
movq %rsi, %rax
cqto
idivq %rdi
cqto
pushq $0x7
popq %rsi
idivq %rsi
leaq (%r15,%rbx), %rsi
subl %edx, %ecx
addl $0x7, %ecx
movl %ecx, %eax
cltd
pushq $0x7
popq %rcx
idivl %ecx
pushq $0x3
popq %rdi
leaq 0x15535(%rip), %rdx     # 0x6ef97
movl %eax, %ecx
xorl %eax, %eax
callq 0xaf26
pushq $0x2
jmp 0x59ac1
movb $0x25, (%r15,%rbx)
jmp 0x5992f
leaq (%r15,%rbx), %rsi
movl -0x4c(%rbp), %ecx
jmp 0x59b34
movsd 0x1186b(%rip), %xmm0    # 0x6b2f8
minsd -0x38(%rbp), %xmm0
leaq (%r15,%rbx), %r12
pushq $0x7
popq %rdi
movq %r12, %rsi
leaq 0x15517(%rip), %rdx     # 0x6efba
jmp 0x59b6a
leaq (%r15,%rbx), %rsi
incl %ecx
pushq $0x4
popq %rdi
leaq 0x15509(%rip), %rdx     # 0x6efc1
xorl %eax, %eax
callq 0xaf26
pushq $0x3
popq %rax
jmp 0x59b7b
leaq (%r15,%rbx), %rsi
movl -0x44(%rbp), %ecx
jmp 0x59b34
leaq (%r15,%rbx), %rsi
movl -0x40(%rbp), %ecx
jmp 0x59b34
leaq (%r15,%rbx), %r12
movl -0x50(%rbp), %ecx
pushq $0x5
popq %rdi
movq %r12, %rsi
leaq 0x154d9(%rip), %rdx     # 0x6efc6
xorl %eax, %eax
callq 0xaf26
jmp 0x59b71
leaq (%r15,%rbx), %r12
movq -0x58(%rbp), %rax
cqto
movl $0x3e8, %ecx            # imm = 0x3E8
idivq %rcx
movabsq $-0x3118a36940, %rcx    # imm = 0xFFFFFFCEE75C96C0
addq %rax, %rcx
pushq $0x1e
popq %rdi
movq %r12, %rsi
leaq 0x12ee8(%rip), %rdx     # 0x6ca0a
xorl %eax, %eax
callq 0xaf26
jmp 0x59b71
leaq (%r15,%rbx), %rsi
cvttsd2si -0x38(%rbp), %ecx
pushq $0x3
popq %rdi
leaq 0x15459(%rip), %rdx     # 0x6ef97
xorl %eax, %eax
callq 0xaf26
addq $0x2, %rbx
jmp 0x59b7e
leaq (%r15,%rbx), %r12
cvtsi2sdq -0x58(%rbp), %xmm0
divsd 0x11753(%rip), %xmm0    # 0x6b2b0
pushq $0x14
popq %rdi
movq %r12, %rsi
leaq 0x12220(%rip), %rdx     # 0x6bd8a
movb $0x1, %al
callq 0xaf26
movq %r12, %rdi
callq 0x8f8e
movl %eax, %eax
addq %rax, %rbx
incq %r13
jmp 0x59919
movb $0x0, (%r15,%rbx)
leaq -0x100(%rbp), %rax
cmpq %rax, %r15
leaq -0x50825(%rip), %rax    # 0x9377
pushq $-0x1
popq %rcx
cmovneq %rax, %rcx
pushq $-0x1
popq %rdx
movq -0x60(%rbp), %rdi
movq %r15, %rsi
callq 0xe48d
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0xe631
jmp 0x59bb2