// File: /workspace/github_c_makefile_star2_O2/lyda[P]tz/localtime.c
// Function: time2sub
static time_t
time2sub(tmp, funcp, offset, okayp, do_norm_secs)
struct tm * const	tmp;
struct tm * (* const	funcp)(const time_t*, long, struct tm*);
const long		offset;
int * const		okayp;
const int		do_norm_secs;
{
	register const struct state *	sp;
	register int			dir;
	register int			i, j;
	register int			saved_seconds;
	register long			li;
	register time_t			lo;
	register time_t			hi;
	long				y;
	time_t				newt;
	time_t				t;
	struct tm			yourtm, mytm;

	*okayp = FALSE;
	yourtm = *tmp;
	if (do_norm_secs) {
		if (normalize_overflow(&yourtm.tm_min, &yourtm.tm_sec,
			SECSPERMIN))
				return WRONG;
	}
	if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR))
		return WRONG;
	if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY))
		return WRONG;
	y = yourtm.tm_year;
	if (long_normalize_overflow(&y, &yourtm.tm_mon, MONSPERYEAR))
		return WRONG;
	/*
	** Turn y into an actual year number for now.
	** It is converted back to an offset from TM_YEAR_BASE later.
	*/
	if (long_increment_overflow(&y, TM_YEAR_BASE))
		return WRONG;
	while (yourtm.tm_mday <= 0) {
		if (long_increment_overflow(&y, -1))
			return WRONG;
		li = y + (1 < yourtm.tm_mon);
		yourtm.tm_mday += year_lengths[isleap(li)];
	}
	while (yourtm.tm_mday > DAYSPERLYEAR) {
		li = y + (1 < yourtm.tm_mon);
		yourtm.tm_mday -= year_lengths[isleap(li)];
		if (long_increment_overflow(&y, 1))
			return WRONG;
	}
	for ( ; ; ) {
		i = mon_lengths[isleap(y)][yourtm.tm_mon];
		if (yourtm.tm_mday <= i)
			break;
		yourtm.tm_mday -= i;
		if (++yourtm.tm_mon >= MONSPERYEAR) {
			yourtm.tm_mon = 0;
			if (long_increment_overflow(&y, 1))
				return WRONG;
		}
	}
	if (long_increment_overflow(&y, -TM_YEAR_BASE))
		return WRONG;
	yourtm.tm_year = y;
	if (yourtm.tm_year != y)
		return WRONG;
	if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN)
		saved_seconds = 0;
	else if (y + TM_YEAR_BASE < EPOCH_YEAR) {
		/*
		** We can't set tm_sec to 0, because that might push the
		** time below the minimum representable time.
		** Set tm_sec to 59 instead.
		** This assumes that the minimum representable time is
		** not in the same minute that a leap second was deleted from,
		** which is a safer assumption than using 58 would be.
		*/
		if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN))
			return WRONG;
		saved_seconds = yourtm.tm_sec;
		yourtm.tm_sec = SECSPERMIN - 1;
	} else {
		saved_seconds = yourtm.tm_sec;
		yourtm.tm_sec = 0;
	}
	/*
	** Do a binary search (this works whatever time_t's type is).
	*/
	if (!TYPE_SIGNED(time_t)) {
		lo = 0;
		hi = lo - 1;
	} else if (!TYPE_INTEGRAL(time_t)) {
		if (sizeof(time_t) > sizeof(float))
			hi = (time_t) DBL_MAX;
		else	hi = (time_t) FLT_MAX;
		lo = -hi;
	} else {
		lo = 1;
		for (i = 0; i < (int) TYPE_BIT(time_t) - 1; ++i)
			lo *= 2;
		hi = -(lo + 1);
	}
	for ( ; ; ) {
		t = lo / 2 + hi / 2;
		if (t < lo)
			t = lo;
		else if (t > hi)
			t = hi;
		if ((*funcp)(&t, offset, &mytm) == NULL) {
			/*
			** Assume that t is too extreme to be represented in
			** a struct tm; arrange things so that it is less
			** extreme on the next pass.
			*/
			dir = (t > 0) ? 1 : -1;
		} else	dir = tmcomp(&mytm, &yourtm);
		if (dir != 0) {
			if (t == lo) {
				++t;
				if (t <= lo)
					return WRONG;
				++lo;
			} else if (t == hi) {
				--t;
				if (t >= hi)
					return WRONG;
				--hi;
			}
			if (lo > hi)
				return WRONG;
			if (dir > 0)
				hi = t;
			else	lo = t;
			continue;
		}
		if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
			break;
		/*
		** Right time, wrong type.
		** Hunt for right time, right type.
		** It's okay to guess wrong since the guess
		** gets checked.
		*/
		sp = (const struct state *)
			((funcp == localsub) ? lclptr : gmtptr);
#ifdef ALL_STATE
		if (sp == NULL)
			return WRONG;
#endif /* defined ALL_STATE */
		for (i = sp->typecnt - 1; i >= 0; --i) {
			if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
				continue;
			for (j = sp->typecnt - 1; j >= 0; --j) {
				if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
					continue;
				newt = t + sp->ttis[j].tt_gmtoff -
					sp->ttis[i].tt_gmtoff;
				if ((*funcp)(&newt, offset, &mytm) == NULL)
					continue;
				if (tmcomp(&mytm, &yourtm) != 0)
					continue;
				if (mytm.tm_isdst != yourtm.tm_isdst)
					continue;
				/*
				** We have a match.
				*/
				t = newt;
				goto label;
			}
		}
		return WRONG;
	}
label:
	newt = t + saved_seconds;
	if ((newt < t) != (saved_seconds < 0))
		return WRONG;
	t = newt;
	if ((*funcp)(&t, offset, tmp))
		*okayp = TRUE;
	return t;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r14
andl $0x0, (%rsi)
movq %rdi, %r15
movq 0x30(%rdi), %rax
movq %rax, 0x50(%rsp)
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups 0x20(%rdi), %xmm2
movaps %xmm2, 0x40(%rsp)
movaps %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
pushq $-0x1
popq %rbx
testl %edx, %edx
je 0x3d0c
leaq 0x24(%rsp), %rdi
leaq 0x20(%rsp), %rsi
pushq $0x3c
popq %rdx
callq 0x4145
testl %eax, %eax
jne 0x3d84
leaq 0x28(%rsp), %r12
leaq 0x24(%rsp), %rsi
pushq $0x3c
popq %rdx
movq %r12, %rdi
callq 0x4145
testl %eax, %eax
jne 0x3d84
leaq 0x2c(%rsp), %rdi
pushq $0x18
popq %rdx
movq %r12, %rsi
callq 0x4145
testl %eax, %eax
jne 0x3d84
movslq 0x34(%rsp), %rax
movq %rax, (%rsp)
movl 0x30(%rsp), %ebp
pushq $0xc
popq %rcx
movl %ebp, %eax
testl %ebp, %ebp
js 0x3d58
xorl %edx, %edx
divl %ecx
movl %eax, %r12d
jmp 0x3d64
notl %eax
xorl %edx, %edx
divl %ecx
movl %eax, %r12d
notl %r12d
movq %rsp, %rdi
movl %r12d, %esi
callq 0x4170
testl %eax, %eax
jne 0x3d84
movq %rsp, %rdi
movl $0x76c, %esi            # imm = 0x76C
callq 0x4170
testl %eax, %eax
je 0x3d99
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
imull $-0xc, %r12d, %r12d
addl %ebp, %r12d
movl 0x2c(%rsp), %r13d
xorl %ebp, %ebp
cmpl $0x2, %r12d
setge %bpl
testl %r13d, %r13d
jg 0x3e62
movq %rsp, %rdi
pushq $-0x1
popq %rsi
callq 0x4170
testl %eax, %eax
jne 0x3d84
movq (%rsp), %rcx
addq %rbp, %rcx
testb $0x3, %cl
je 0x3dd7
xorl %eax, %eax
jmp 0x3dff
movq %rcx, %rax
cqto
pushq $0x64
popq %rsi
idivq %rsi
pushq $0x1
popq %rax
testq %rdx, %rdx
jne 0x3dff
movq %rcx, %rax
cqto
movl $0x190, %ecx            # imm = 0x190
idivq %rcx
xorl %eax, %eax
testq %rdx, %rdx
sete %al
leaq 0x141a(%rip), %rcx      # 0x5220
addl (%rcx,%rax,4), %r13d
jmp 0x3daf
movq (%rsp), %rcx
addq %rbp, %rcx
testb $0x3, %cl
je 0x3e1c
xorl %eax, %eax
jmp 0x3e44
movq %rcx, %rax
cqto
pushq $0x64
popq %rsi
idivq %rsi
pushq $0x1
popq %rax
testq %rdx, %rdx
jne 0x3e44
movq %rcx, %rax
cqto
movl $0x190, %ecx            # imm = 0x190
idivq %rcx
xorl %eax, %eax
testq %rdx, %rdx
sete %al
leaq 0x13d5(%rip), %rcx      # 0x5220
subl (%rcx,%rax,4), %r13d
movq %rsp, %rdi
pushq $0x1
popq %rsi
callq 0x4170
testl %eax, %eax
jne 0x3d84
cmpl $0x16e, %r13d           # imm = 0x16E
jg 0x3e0c
movq %r12, %rsi
leaq 0x147b(%rip), %rbp      # 0x52f0
movq (%rsp), %rcx
testb $0x3, %cl
je 0x3e82
xorl %eax, %eax
jmp 0x3eaa
movq %rcx, %rax
cqto
pushq $0x64
popq %rdi
idivq %rdi
pushq $0x1
popq %rax
testq %rdx, %rdx
jne 0x3eaa
movq %rcx, %rax
cqto
movl $0x190, %ecx            # imm = 0x190
idivq %rcx
xorl %eax, %eax
testq %rdx, %rdx
sete %al
movslq %esi, %rcx
imulq $0x30, %rax, %rax
addq %rbp, %rax
movl %r13d, %r12d
subl (%rax,%rcx,4), %r12d
jle 0x3ee3
leal 0x1(%rsi), %eax
movl %r12d, %r13d
cmpl $0xb, %esi
movl %eax, %esi
jl 0x3e75
movq %rsp, %rdi
pushq $0x1
popq %rsi
callq 0x4170
xorl %esi, %esi
movl %r12d, %r13d
testl %eax, %eax
je 0x3e75
jmp 0x3d84
movl %esi, 0x30(%rsp)
movl %r13d, 0x2c(%rsp)
movq %rsp, %rdi
movl $0xfffff894, %esi       # imm = 0xFFFFF894
callq 0x4170
testl %eax, %eax
jne 0x3d84
movq (%rsp), %rax
movl %eax, 0x34(%rsp)
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x3d84
movl 0x20(%rsp), %ecx
xorl %edx, %edx
cmpl $0x3c, %ecx
jb 0x3f50
cmpq $0x45, %rax
jg 0x3f49
leaq 0x20(%rsp), %rdi
pushq $-0x3b
popq %rsi
callq 0x3c2a
testl %eax, %eax
jne 0x3d84
movl 0x20(%rsp), %edx
movl $0x3b, 0x20(%rsp)
jmp 0x3f50
andl $0x0, 0x20(%rsp)
movl %ecx, %edx
movl %edx, 0x1c(%rsp)
movabsq $0x7fffffffffffffff, %rdi # imm = 0x7FFFFFFFFFFFFFFF
leaq 0x1(%rdi), %rbp
leaq 0x70(%rsp), %r13
movq %rbp, %rax
cqto
pushq $0x2
popq %rsi
idivq %rsi
movq %rax, %rcx
movq %rdi, %rax
cqto
idivq %rsi
movq %rax, %r12
addq %rcx, %r12
movq %r12, 0x8(%rsp)
cmpq %rbp, %r12
jge 0x3f97
movq %rbp, 0x8(%rsp)
movq %rbp, %r12
jmp 0x3fa4
cmpq %rdi, %r12
jle 0x3fa4
movq %rdi, 0x8(%rsp)
movq %rdi, %r12
movq %rdi, 0x10(%rsp)
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x2eea
testq %rax, %rax
je 0x3fd0
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x41a2
testl %eax, %eax
jne 0x3fdf
jmp 0x402d
xorl %eax, %eax
testq %r12, %r12
setg %al
leal -0x1(,%rax,2), %eax
cmpq %rbp, %r12
jne 0x3ffb
incq %rbp
movq %rbp, 0x8(%rsp)
movq %rbp, %r12
leaq 0x70(%rsp), %r13
movq 0x10(%rsp), %rdi
jmp 0x4015
movq 0x10(%rsp), %rdi
cmpq %rdi, %r12
leaq 0x70(%rsp), %r13
jne 0x4015
decq %rdi
movq %rdi, 0x8(%rsp)
movq %rdi, %r12
cmpq %rdi, %rbp
jg 0x3d84
testl %eax, %eax
cmovleq %r12, %rbp
cmovgq %r12, %rdi
jmp 0x3f67
movl 0x40(%rsp), %ecx
testl %ecx, %ecx
js 0x403e
cmpl %ecx, 0x90(%rsp)
jne 0x4070
movq %r12, %rbp
movslq 0x1c(%rsp), %rbx
addq %rbp, %rbx
leaq 0x8(%rsp), %rdi
movq %rbx, (%rdi)
xorl %esi, %esi
movq %r15, %rdx
callq 0x2eea
testq %rax, %rax
je 0x3d84
movl $0x1, (%r14)
jmp 0x3d84
movl 0x4642(%rip), %edx      # 0x86b8
leaq 0x4633(%rip), %rsi      # 0x86b0
movl %ecx, 0x18(%rsp)
testl %edx, %edx
jle 0x3d84
decq %rdx
imulq $0x18, %rdx, %rax
cmpl %ecx, 0x2a50(%rax,%rsi)
jne 0x4081
movq %rdx, 0x58(%rsp)
addq %rsi, %rax
addq $0x2a48, %rax           # imm = 0x2A48
movq %rax, 0x60(%rsp)
movl 0x4606(%rip), %edx      # 0x86b8
imulq $0x18, %rdx, %rax
leaq (%rax,%rsi), %r13
addq $0x2a38, %r13           # imm = 0x2A38
testl %edx, %edx
jle 0x4134
cmpl %ecx, (%r13)
je 0x412c
movq -0x8(%r13), %rbp
addq %r12, %rbp
movq 0x60(%rsp), %rax
subq (%rax), %rbp
movq %rbp, 0x68(%rsp)
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
movq %rdx, 0x10(%rsp)
leaq 0x70(%rsp), %rdx
callq 0x2eea
movq 0x10(%rsp), %rdx
movl 0x18(%rsp), %ecx
testq %rax, %rax
je 0x412c
leaq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x41a2
movq 0x10(%rsp), %rdx
movl 0x18(%rsp), %ecx
testl %eax, %eax
jne 0x412c
cmpl %ecx, 0x90(%rsp)
je 0x4041
decl %edx
addq $-0x18, %r13
jmp 0x40c1
movq 0x58(%rsp), %rdx
leaq 0x4570(%rip), %rsi      # 0x86b0
jmp 0x4081