// File: /workspace/github_c_makefile_star2_O3/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 0x66a08
movq %r15, %rdi
callq 0x66b15
movl $0xfffff80a, %eax       # imm = 0xFFFFF80A
addl 0x8(%r15), %eax
cmpl $-0x44, %eax
ja 0x668ea
movapd 0x12afc(%rip), %xmm0    # 0x793d0
movupd %xmm0, -0x48(%rbp)
movl $0x0, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
jmp 0x66904
movsd -0x30(%rbp), %xmm0
addsd 0x12979(%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 0x663a5
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, 0x2dc3e(%rip)     # 0x94598
setne %cl
testq %rax, %rax
sete %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x669a5
movl $0x1, 0x5c(%r14)
movb $0x1, 0x61(%r14)
addq $0x8, %r14
leaq 0x165d4(%rip), %rsi     # 0x7cf56
movl $0x1, %r15d
movq %r14, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movq $-0x1, %r8
callq 0xf0d7
xorl %eax, %eax
jmp 0x669fa
movq 0x4(%rax), %rcx
rolq $0x20, %rcx
movl 0xc(%rax), %edx
movl 0x10(%rax), %esi
movl $0x76c, %edi            # imm = 0x76C
addl 0x14(%rax), %edi
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
leaq -0x88(%rbp), %r14
movl %edi, 0x8(%r14)
incl %esi
movl %esi, 0xc(%r14)
movl %edx, 0x10(%r14)
movq %rcx, 0x14(%r14)
movsd %xmm0, 0x20(%r14)
movl $0x101, 0x28(%r14)      # imm = 0x101
movq %r14, %rdi
callq 0x663a5
movq (%r14), %rax
subq %r15, %rax
xorl %r15d, %r15d
movl %r15d, (%rbx)
addq $0x78, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq