// File: /workspace/github_c_makefile_star2_O0/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
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x10350
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x8778d
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
subl $0x1, %esi
movq -0x18(%rbp), %rdx
addq $0x8, %rdx
leaq -0x48(%rbp), %rcx
callq 0x87e10
cmpl $0x0, %eax
je 0x87792
jmp 0x87d77
movq -0x8(%rbp), %rdi
callq 0x117b0
movq %rax, -0x70(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x1, -0x50(%rbp)
movq -0x78(%rbp), %rax
movq -0x58(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x87881
movq -0x78(%rbp), %rax
movq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x25, %eax
jne 0x87862
movq -0x78(%rbp), %rcx
movq -0x58(%rbp), %rax
movsbl 0x1(%rax,%rcx), %eax
addl $-0x25, %eax
movl %eax, %ecx
movq %rcx, -0x130(%rbp)
subl $0x52, %eax
ja 0x87851
movq -0x130(%rbp), %rax
leaq 0x22fb6(%rip), %rcx     # 0xaa7b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x87856
movq -0x50(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x50(%rbp)
jmp 0x87856
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x50(%rbp)
jmp 0x87856
movq -0x50(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x50(%rbp)
jmp 0x87856
movq -0x50(%rbp), %rax
addq $0x32, %rax
movq %rax, -0x50(%rbp)
jmp 0x87856
jmp 0x87d77
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x87864
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x877af
cmpq $0x64, -0x50(%rbp)
jae 0x87895
leaq -0xe0(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x878e0
movq -0x50(%rbp), %rax
movq -0x70(%rbp), %rcx
movslq 0x68(%rcx), %rcx
cmpq %rcx, %rax
jbe 0x878b4
movq -0x8(%rbp), %rdi
callq 0x110d0
jmp 0x87d77
movq -0x70(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %esi
callq 0x134e0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x878dc
movq -0x8(%rbp), %rdi
callq 0x11120
jmp 0x87d77
jmp 0x878de
jmp 0x878e0
leaq -0x48(%rbp), %rdi
callq 0x87f50
leaq -0x48(%rbp), %rdi
callq 0x89690
movq $0x0, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x78(%rbp), %rax
movq -0x58(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x87d39
movq -0x78(%rbp), %rax
movq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x25, %eax
je 0x8794b
movq -0x78(%rbp), %rax
movq -0x58(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x60(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x87d26
movq -0x58(%rbp), %rax
incq %rax
movq %rax, -0x58(%rbp)
movq -0x78(%rbp), %rax
movq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
addl $-0x48, %eax
movl %eax, %ecx
movq %rcx, -0x138(%rbp)
subl $0x2f, %eax
ja 0x87d0d
movq -0x138(%rbp), %rax
leaq 0x22d73(%rip), %rcx     # 0xaa6f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movl -0x38(%rbp), %ecx
movl $0x3, %edi
leaq 0x2a0db(%rip), %rdx     # 0xb1a80
movb $0x0, %al
callq 0xc540
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
movsd -0xe8(%rbp), %xmm0
movsd 0x2648e(%rip), %xmm1    # 0xade68
ucomisd %xmm1, %xmm0
jbe 0x879f0
movsd 0x26480(%rip), %xmm0    # 0xade68
movsd %xmm0, -0xe8(%rbp)
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movsd -0xe8(%rbp), %xmm0
movl $0x7, %edi
leaq 0x2a097(%rip), %rdx     # 0xb1aa3
movb $0x1, %al
callq 0xc540
movq -0x68(%rbp), %rdi
addq -0x60(%rbp), %rdi
callq 0x92f0
cltq
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movl -0x34(%rbp), %ecx
movl $0x3, %edi
leaq 0x2a03a(%rip), %rdx     # 0xb1a80
movb $0x0, %al
callq 0xc540
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
leaq -0x120(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0x30, %edx
callq 0x82f0
movb $0x0, -0xf6(%rbp)
movl $0x1, -0x114(%rbp)
movl $0x1, -0x110(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x87f50
movq -0x48(%rbp), %rax
subq -0x120(%rbp), %rax
addq $0x2932e00, %rax        # imm = 0x2932E00
movl $0x5265c00, %ecx        # imm = 0x5265C00
cqto
idivq %rcx
movl %eax, -0xec(%rbp)
movq -0x78(%rbp), %rax
movq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x57, %eax
jne 0x87b34
movq -0x48(%rbp), %rax
addq $0x2932e00, %rax        # imm = 0x2932E00
movl $0x5265c00, %ecx        # imm = 0x5265C00
cqto
idivq %rcx
movl $0x7, %ecx
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0x124(%rbp)
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movl -0xec(%rbp), %eax
addl $0x7, %eax
subl -0x124(%rbp), %eax
movl $0x7, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0x3, %edi
leaq 0x29f61(%rip), %rdx     # 0xb1a80
movb $0x0, %al
callq 0xc540
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
jmp 0x87b64
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movl -0xec(%rbp), %ecx
addl $0x1, %ecx
movl $0x4, %edi
leaq 0x29f59(%rip), %rdx     # 0xb1aaa
movb $0x0, %al
callq 0xc540
movq -0x60(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
cvtsi2sdq -0x48(%rbp), %xmm0
movsd 0x26299(%rip), %xmm1    # 0xade18
divsd %xmm1, %xmm0
movl $0x14, %edi
leaq 0x26cd7(%rip), %rdx     # 0xae866
movb $0x1, %al
callq 0xc540
movq -0x68(%rbp), %rdi
addq -0x60(%rbp), %rdi
callq 0x92f0
cltq
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movl -0x3c(%rbp), %ecx
movl $0x3, %edi
leaq 0x29eb7(%rip), %rdx     # 0xb1a80
movb $0x0, %al
callq 0xc540
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movl -0x30(%rbp), %ecx
movl $0x3, %edi
leaq 0x29e88(%rip), %rdx     # 0xb1a80
movb $0x0, %al
callq 0xc540
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movq -0x48(%rbp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, %rcx
movabsq $0x3118a36940, %rax     # imm = 0x3118A36940
subq %rax, %rcx
movl $0x1e, %edi
leaq 0x278a4(%rip), %rdx     # 0xaf4e6
movb $0x0, %al
callq 0xc540
movq -0x68(%rbp), %rdi
addq -0x60(%rbp), %rdi
callq 0x92f0
cltq
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
cvttsd2si -0x28(%rbp), %ecx
movl $0x3, %edi
leaq 0x29e02(%rip), %rdx     # 0xb1a80
movb $0x0, %al
callq 0xc540
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
movq -0x48(%rbp), %rax
addq $0x7b98a00, %rax        # imm = 0x7B98A00
movl $0x5265c00, %ecx        # imm = 0x5265C00
cqto
idivq %rcx
movl $0x7, %ecx
cqto
idivq %rcx
movb %dl, %al
movsbl %al, %eax
addl $0x30, %eax
movb %al, %dl
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x60(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x87d24
movq -0x68(%rbp), %rsi
addq -0x60(%rbp), %rsi
movl -0x40(%rbp), %ecx
movl $0x5, %edi
leaq 0x29dc2(%rip), %rdx     # 0xb1aaf
movb $0x0, %al
callq 0xc540
movq -0x68(%rbp), %rdi
addq -0x60(%rbp), %rdi
callq 0x92f0
cltq
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x87d24
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x60(%rbp)
movb $0x25, (%rax,%rcx)
jmp 0x87d26
jmp 0x87d28
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x87902
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0xe0(%rbp), %r8
leaq -0x7e3cf(%rip), %rcx    # 0x9990
movq $-0x1, %rax
cmpq %r8, %rdx
cmoveq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x10d80
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq