// File: /workspace/github_c_makefile_star2_O3/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 $0xa8, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, %r14
movups (%rdi), %xmm0
movdqu 0x10(%rdi), %xmm1
movupd 0x20(%rdi), %xmm2
leaq 0x20(%rsp), %r15
movaps %xmm0, (%r15)
movdqa %xmm1, 0x10(%r15)
movapd %xmm2, 0x20(%r15)
movq %r15, %rdi
callq 0x6ae07
movq %r15, %rdi
callq 0x6af0f
movl $0xfffff80a, %eax       # imm = 0xFFFFF80A
addl 0x8(%r15), %eax
cmpl $-0x44, %eax
ja 0x6ac59
movaps 0x653f(%rip), %xmm0     # 0x71180
movups %xmm0, 0x28(%rsp)
movl $0x0, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
jmp 0x6ac74
movsd 0x40(%rsp), %xmm0
addsd 0x23a1(%rip), %xmm0     # 0x6d008
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movlps %xmm0, 0x40(%rsp)
leaq 0x20(%rsp), %r15
movl $0x0, 0x1c(%r15)
movb $0x0, 0x2a(%r15)
movq %r15, %rdi
callq 0x6a69e
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
movq %rax, 0x18(%rsp)
movb $0x1, %bpl
xorl %r13d, %r13d
cmpl $0x0, 0x1f5c6(%rip)     # 0x8a294
je 0x6acf0
movl $0x2, %edi
callq *0x1f62d(%rip)          # 0x8a308
testq %rax, %rax
je 0x6acf0
movq %rax, %r12
movq %rax, %rdi
callq *0x1f62c(%rip)          # 0x8a318
xorl %ebp, %ebp
jmp 0x6acf3
xorl %r12d, %r12d
leaq 0x18(%rsp), %rdi
callq 0x71d0
cmpl $0x0, 0x1f72c(%rip)     # 0x8a430
sete %cl
testq %rax, %rax
setne %bl
andb %cl, %bl
cmpb $0x1, %bl
jne 0x6ad33
movl 0x4(%rax), %r13d
movq 0x8(%rax), %xmm1
movq 0x10(%rax), %xmm0
paddd 0x6466(%rip), %xmm0     # 0x71190
xorps %xmm2, %xmm2
cvtsi2sdl (%rax), %xmm2
jmp 0x6ad43
pxor %xmm1, %xmm1
movq 0x6451(%rip), %xmm0     # 0x71190
xorpd %xmm2, %xmm2
testb %bpl, %bpl
jne 0x6ad75
movq %r12, %rdi
movsd %xmm2, 0x8(%rsp)
movdqa %xmm1, 0x60(%rsp)
movdqa %xmm0, 0x50(%rsp)
callq *0x1f5c5(%rip)          # 0x8a328
movdqa 0x50(%rsp), %xmm0
movdqa 0x60(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
testb %bl, %bl
je 0x6adb6
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
pshufd $0xe1, %xmm1, %xmm1     # xmm1 = xmm1[1,0,2,3]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
leaq 0x78(%rsp), %r14
movdqu %xmm0, 0x8(%r14)
movl %r13d, 0x18(%r14)
movsd %xmm2, 0x20(%r14)
movl $0x101, 0x28(%r14)      # imm = 0x101
movq %r14, %rdi
callq 0x6a69e
movq (%r14), %rax
subq %r15, %rax
xorl %ebx, %ebx
jmp 0x6adee
movl $0x1, 0x5c(%r14)
movb $0x1, 0x61(%r14)
addq $0x8, %r14
leaq 0xa17b(%rip), %rsi      # 0x74f49
movl $0x1, %ebx
movq %r14, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movq $-0x1, %r8
callq 0xf552
xorl %eax, %eax
movq 0x10(%rsp), %rcx
movl %ebx, (%rcx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq