// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: localtimeOffset
static sqlite3_int64 localtimeOffset(
  DateTime *p,                    /* Date at which to calculate offset */
  sqlite3_context *pCtx,          /* Write error here if one occurs */
  int *pRc                        /* OUT: Error code. SQLITE_OK or ERROR */
){
  DateTime x, y;
  time_t t;
  struct tm sLocal;

  /* Initialize the contents of sLocal to avoid a compiler warning. */
  memset(&sLocal, 0, sizeof(sLocal));

  x = *p;
  computeYMD_HMS(&x);
  if( x.Y<1971 || x.Y>=2038 ){
    x.Y = 2000;
    x.M = 1;
    x.D = 1;
    x.h = 0;
    x.m = 0;
    x.s = 0.0;
  } else {
    int s = (int)(x.s + 0.5);
    x.s = s;
  }
  x.tz = 0;
  x.validJD = 0;
  computeJD(&x);
  t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
  if( osLocaltime(&t, &sLocal) ){
    sqlite3_result_error(pCtx, "local time unavailable", -1);
    *pRc = SQLITE_ERROR;
    return 0;
  }
  y.Y = sLocal.tm_year + 1900;
  y.M = sLocal.tm_mon + 1;
  y.D = sLocal.tm_mday;
  y.h = sLocal.tm_hour;
  y.m = sLocal.tm_min;
  y.s = sLocal.tm_sec;
  y.validYMD = 1;
  y.validHMS = 1;
  y.validJD = 0;
  y.validTZ = 0;
  computeJD(&y);
  *pRc = SQLITE_OK;
  return y.iJD - x.iJD;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups 0x20(%rdi), %xmm2
leaq -0x50(%rbp), %r15
movaps %xmm0, (%r15)
movaps %xmm1, 0x10(%r15)
movaps %xmm2, 0x20(%r15)
movq %r15, %rdi
callq 0x66bfb
movq %r15, %rdi
callq 0x66d16
movl $0xfffff80a, %eax       # imm = 0xFFFFF80A
addl 0x8(%r15), %eax
cmpl $-0x44, %eax
ja 0x66abd
movapd 0x12929(%rip), %xmm0    # 0x793d0
movupd %xmm0, -0x48(%rbp)
movl $0x0, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
jmp 0x66ad7
movsd -0x30(%rbp), %xmm0
addsd 0x127a6(%rip), %xmm0    # 0x79270
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movlpd %xmm0, -0x30(%rbp)
movl $0x0, 0x1c(%r15)
movb $0x0, 0x2a(%r15)
movq %r15, %rdi
callq 0x6655d
movq (%r15), %r15
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
movq %r15, %rax
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movabsq $-0x3118a36940, %rax    # imm = 0xFFFFFFCEE75C96C0
addq %rdx, %rax
leaq -0x58(%rbp), %rdi
movq %rax, (%rdi)
callq 0x82b0
cmpl $0x0, 0x2da6b(%rip)     # 0x94598
sete %dl
testq %rax, %rax
setne %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x66b5f
movl 0x4(%rax), %edx
movl 0x8(%rax), %esi
movl 0xc(%rax), %r8d
movl $0x76c, %edi            # imm = 0x76C
addl 0x14(%rax), %edi
movl 0x10(%rax), %r9d
incl %r9d
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
jmp 0x66b75
movl $0x76c, %edi            # imm = 0x76C
movl $0x1, %r9d
xorl %edx, %edx
xorpd %xmm0, %xmm0
xorl %esi, %esi
xorl %r8d, %r8d
testb %cl, %cl
je 0x66bb8
leaq -0x88(%rbp), %r14
movl %edi, 0x8(%r14)
movl %r9d, 0xc(%r14)
movl %r8d, 0x10(%r14)
movl %esi, 0x14(%r14)
movl %edx, 0x18(%r14)
movsd %xmm0, 0x20(%r14)
movl $0x101, 0x28(%r14)      # imm = 0x101
movq %r14, %rdi
callq 0x6655d
movl $0x0, (%rbx)
movq (%r14), %rax
subq %r15, %rax
jmp 0x66bf0
movl $0x1, %r15d
movl %r15d, 0x5c(%r14)
movb $0x1, 0x61(%r14)
addq $0x8, %r14
leaq 0x16384(%rip), %rsi     # 0x7cf56
movq %r14, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movq $-0x1, %r8
callq 0xeff4
movl %r15d, (%rbx)
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq