// File: /workspace/github_c_makefile_star2_O1/skeeto[P]flappy/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 ){
    /* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only
    ** works for years between 1970 and 2037. For dates outside this range,
    ** SQLite attempts to map the year into an equivalent year within this
    ** range, do the calculation, then map the year back.
    */
    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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, %r13
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups 0x20(%rdi), %xmm2
leaq 0x30(%rsp), %r15
movaps %xmm0, (%r15)
movaps %xmm1, 0x10(%r15)
movaps %xmm2, 0x20(%r15)
movq %r15, %rdi
callq 0x6a7a0
movq %r15, %rdi
callq 0x6a8b6
movl $0xfffff80a, %eax       # imm = 0xFFFFF80A
addl 0x8(%r15), %eax
cmpl $-0x44, %eax
ja 0x6a5ee
movapd 0x5b1b(%rip), %xmm0     # 0x700f0
movupd %xmm0, 0x38(%rsp)
movl $0x0, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
jmp 0x6a60a
movsd 0x50(%rsp), %xmm0
addsd 0x1a0c(%rip), %xmm0     # 0x6c008
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movlpd %xmm0, 0x50(%rsp)
leaq 0x30(%rsp), %r15
movl $0x0, 0x1c(%r15)
movb $0x0, 0x2a(%r15)
movq %r15, %rdi
callq 0x6a016
movq (%r15), %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
movq %rax, 0x20(%rsp)
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
movabsq $-0x3118a36940, %rax    # imm = 0xFFFFFFCEE75C96C0
addq %rdx, %rax
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x1ec34(%rip)     # 0x89294
je 0x6a672
movl $0x2, %edi
callq *0x1ec9b(%rip)          # 0x89308
movq %rax, %r12
jmp 0x6a675
xorl %r12d, %r12d
testq %r12, %r12
je 0x6a683
movq %r12, %rdi
callq *0x1ec95(%rip)          # 0x89318
leaq 0x28(%rsp), %rdi
callq 0x71d0
cmpl $0x0, 0x1ed9c(%rip)     # 0x89430
sete %cl
testq %rax, %rax
setne %bpl
andb %cl, %bpl
cmpb $0x1, %bpl
jne 0x6a6c7
movl 0x4(%rax), %ecx
movl 0x8(%rax), %edx
movl 0xc(%rax), %r15d
movl $0x76c, %edi            # imm = 0x76C
addl 0x14(%rax), %edi
movl 0x10(%rax), %ebx
incl %ebx
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
jmp 0x6a6dc
movl $0x76c, %edi            # imm = 0x76C
movl $0x1, %ebx
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
xorl %edx, %edx
xorl %r15d, %r15d
testq %r12, %r12
je 0x6a70a
movl %edi, 0xc(%rsp)
movq %r12, %rdi
movl %ecx, %r12d
movl %edx, %r14d
movsd %xmm0, 0x18(%rsp)
callq *0x1ec2e(%rip)          # 0x89328
movsd 0x18(%rsp), %xmm0
movl 0xc(%rsp), %edi
movl %r14d, %edx
movl %r12d, %ecx
testb %bpl, %bpl
je 0x6a753
leaq 0x68(%rsp), %r14
movl %edi, 0x8(%r14)
movl %ebx, 0xc(%r14)
movl %r15d, 0x10(%r14)
movl %edx, 0x14(%r14)
movl %ecx, 0x18(%r14)
movsd %xmm0, 0x20(%r14)
movl $0x101, 0x28(%r14)      # imm = 0x101
movq %r14, %rdi
callq 0x6a016
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
movq (%r14), %rax
subq 0x20(%rsp), %rax
jmp 0x6a78e
movl $0x1, %ebx
movl %ebx, 0x5c(%r13)
movb $0x1, 0x61(%r13)
addq $0x8, %r13
leaq 0x973d(%rip), %rsi      # 0x73ea9
movq %r13, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movq $-0x1, %r8
callq 0xf40a
movq 0x10(%rsp), %rax
movl %ebx, (%rax)
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq