// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rsi, 0x10(%rsp)
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 0x5d9fd
movl $0xfffff80a, %eax       # imm = 0xFFFFF80A
addl 0x8(%r15), %eax
cmpl $-0x44, %eax
ja 0x5d888
movaps 0x588a(%rip), %xmm0     # 0x63100
movups %xmm0, 0x28(%rsp)
andl $0x0, 0x38(%rsp)
andq $0x0, 0x40(%rsp)
jmp 0x5d8a3
movsd 0x40(%rsp), %xmm0
addsd 0x178a(%rip), %xmm0     # 0x5f020
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movlps %xmm0, 0x40(%rsp)
leaq 0x20(%rsp), %r15
andl $0x0, 0x1c(%r15)
movb $0x0, 0x2a(%r15)
movq %r15, %rdi
callq 0x5d31f
movq (%r15), %r15
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rax
cqto
idivq %rcx
movabsq $-0x3118a36940, %rcx    # imm = 0xFFFFFFCEE75C96C0
addq %rax, %rcx
movq %rcx, 0x18(%rsp)
movb $0x1, %bpl
xorl %r13d, %r13d
cmpl $0x0, 0x229bb(%rip)     # 0x802a4
je 0x5d909
pushq $0x2
popq %rdi
callq *0x22a24(%rip)          # 0x80318
testq %rax, %rax
je 0x5d909
movq %rax, %r12
movq %rax, %rdi
callq *0x22a23(%rip)          # 0x80328
xorl %ebp, %ebp
jmp 0x5d90c
xorl %r12d, %r12d
leaq 0x18(%rsp), %rdi
callq 0x71e0
cmpl $0x0, 0x22b23(%rip)     # 0x80440
sete %cl
testq %rax, %rax
setne %r14b
andb %cl, %r14b
cmpb $0x1, %r14b
jne 0x5d94c
movl 0x4(%rax), %r13d
movq 0x8(%rax), %xmm1
movq 0x10(%rax), %xmm0
paddd 0x57ca(%rip), %xmm0     # 0x63110
cvtsi2sdl (%rax), %xmm2
jmp 0x5d95c
pxor %xmm1, %xmm1
movq 0x57b8(%rip), %xmm0     # 0x63110
xorpd %xmm2, %xmm2
testb %bpl, %bpl
jne 0x5d98e
movq %r12, %rdi
movsd %xmm2, 0x8(%rsp)
movdqa %xmm1, 0x60(%rsp)
movdqa %xmm0, 0x50(%rsp)
callq *0x229bc(%rip)          # 0x80338
movdqa 0x50(%rsp), %xmm0
movdqa 0x60(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
testb %r14b, %r14b
je 0x5d9d0
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 0x5d31f
movq (%r14), %rax
subq %r15, %rax
xorl %ecx, %ecx
jmp 0x5d9e9
leaq 0x94f2(%rip), %rsi      # 0x66ec9
pushq $-0x1
popq %rdx
movq 0x10(%rsp), %rdi
callq 0xe87f
pushq $0x1
popq %rcx
xorl %eax, %eax
movl %ecx, (%rbx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq