// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
movq %rdi, %r8
movl $0x0, (%rsi)
movl (%rdi), %r9d
movl 0x4(%rdi), %eax
movl 0x8(%rdi), %r11d
movl 0xc(%rdi), %ecx
movl 0x10(%rdi), %ebx
movslq 0x14(%rdi), %rbp
movl 0x20(%rdi), %r14d
testl %edx, %edx
je 0x42cb
testl %r9d, %r9d
js 0x427d
movl %r9d, %edi
movl $0x88888889, %edx       # imm = 0x88888889
imulq %rdi, %rdx
shrq $0x25, %rdx
jmp 0x4291
movl %r9d, %edi
notl %edi
movl $0x88888889, %edx       # imm = 0x88888889
imulq %rdi, %rdx
shrq $0x25, %rdx
notl %edx
testl %eax, %eax
js 0x42ad
movl %eax, %edi
xorl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq $-0x1, %r13
cmpl %edx, %edi
jge 0x42c3
jmp 0x48f1
movl $0x80000000, %edi       # imm = 0x80000000
subl %eax, %edi
movq $-0x1, %r13
cmpl %edx, %edi
jg 0x48f1
imull $-0x3c, %edx, %edi
addl %edi, %r9d
addl %edx, %eax
testl %eax, %eax
js 0x42e0
movl %eax, %edi
movl $0x88888889, %edx       # imm = 0x88888889
imulq %rdi, %rdx
shrq $0x25, %rdx
jmp 0x42f3
movl %eax, %edi
notl %edi
movl $0x88888889, %edx       # imm = 0x88888889
imulq %rdi, %rdx
shrq $0x25, %rdx
notl %edx
testl %r11d, %r11d
js 0x4311
movl %r11d, %edi
xorl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq $-0x1, %r13
cmpl %edx, %edi
jge 0x4328
jmp 0x48f1
movl $0x80000000, %edi       # imm = 0x80000000
subl %r11d, %edi
movq $-0x1, %r13
cmpl %edx, %edi
jg 0x48f1
addl %edx, %r11d
js 0x4340
movl %r11d, %edi
movl $0xaaaaaaab, %r10d      # imm = 0xAAAAAAAB
imulq %rdi, %r10
shrq $0x24, %r10
jmp 0x4356
movl %r11d, %edi
notl %edi
movl $0xaaaaaaab, %r10d      # imm = 0xAAAAAAAB
imulq %rdi, %r10
shrq $0x24, %r10
notl %r10d
testl %ecx, %ecx
js 0x436c
movl %ecx, %edi
xorl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
cmpl %r10d, %edi
jge 0x437c
jmp 0x48f1
movl $0x80000000, %edi       # imm = 0x80000000
subl %ecx, %edi
cmpl %r10d, %edi
jg 0x48f1
addl %r10d, %ecx
testl %ebx, %ebx
movq %rsi, 0x70(%rsp)
movq %r8, 0x78(%rsp)
movl %r9d, 0x8(%rsp)
movl %r14d, 0x14(%rsp)
js 0x43a9
movl %ebx, %r8d
movl $0xaaaaaaab, %edi       # imm = 0xAAAAAAAB
imulq %r8, %rdi
shrq $0x23, %rdi
jmp 0x43be
movl %ebx, %r8d
notl %r8d
movl $0xaaaaaaab, %edi       # imm = 0xAAAAAAAB
imulq %r8, %rdi
shrq $0x23, %rdi
notl %edi
movabsq $0x7fffffffffffffff, %r12 # imm = 0x7FFFFFFFFFFFFFFF
leal (,%rdi,4), %r8d
leal (%r8,%r8,2), %r8d
subl %r8d, %ebx
movslq %edi, %r15
testl %ecx, %ecx
jle 0x43ed
addq %rbp, %r15
addq $0x76c, %r15            # imm = 0x76C
jmp 0x44ab
movl %r11d, 0x4(%rsp)
xorl %edi, %edi
cmpl $0x2, %ebx
setge %dil
leaq (%r15,%rbp), %r8
negq %rbp
leaq (%rdi,%r8), %r11
addq $0x76b, %r11            # imm = 0x76B
leaq (%r12,%r15), %r14
addq $0x76d, %r14            # imm = 0x76D
movabsq $0x28f5c28f5c28f5c, %rsi # imm = 0x28F5C28F5C28F5C
leaq 0xdf7(%rip), %r8        # 0x5220
cmpq %rbp, %r14
je 0x48ea
testb $0x3, %r11b
je 0x443d
xorl %r9d, %r9d
jmp 0x4490
movq %r11, %rdi
movabsq $-0x70a3d70a3d70a3d7, %r9 # imm = 0x8F5C28F5C28F5C29
imulq %r9, %rdi
movabsq $0x51eb851eb851eb8, %r9 # imm = 0x51EB851EB851EB8
leaq (%rdi,%r9), %r13
rorq $0x2, %r13
movl $0x1, %r9d
cmpq %rsi, %r13
ja 0x4490
movabsq $0x51eb851eb851eb0, %r9 # imm = 0x51EB851EB851EB0
addq %r9, %rdi
rorq $0x4, %rdi
xorl %r9d, %r9d
movabsq $0xa3d70a3d70a3d7, %r13 # imm = 0xA3D70A3D70A3D7
cmpq %r13, %rdi
setb %r9b
incq %rbp
decq %r11
addl (%r8,%r9,4), %ecx
jle 0x4429
subq %rbp, %r15
addq $0x76c, %r15            # imm = 0x76C
movl 0x4(%rsp), %r11d
movl %r11d, %ebp
cmpl $0x16f, %ecx            # imm = 0x16F
jb 0x454b
xorl %esi, %esi
cmpl $0x2, %ebx
setge %sil
movabsq $0x51eb851eb851eb8, %r11 # imm = 0x51EB851EB851EB8
movabsq $0x28f5c28f5c28f5c, %r8 # imm = 0x28F5C28F5C28F5C
leaq 0xd42(%rip), %r14       # 0x5220
leaq (%rsi,%r15), %r13
testb $0x3, %r13b
je 0x44ed
xorl %r9d, %r9d
jmp 0x4533
movabsq $-0x70a3d70a3d70a3d7, %rdi # imm = 0x8F5C28F5C28F5C29
imulq %rdi, %r13
leaq (%r11,%r13), %rdi
rorq $0x2, %rdi
movl $0x1, %r9d
cmpq %r8, %rdi
ja 0x4533
movabsq $0x51eb851eb851eb0, %rdi # imm = 0x51EB851EB851EB0
addq %rdi, %r13
rorq $0x4, %r13
xorl %r9d, %r9d
movabsq $0xa3d70a3d70a3d7, %rdi # imm = 0xA3D70A3D70A3D7
cmpq %rdi, %r13
setb %r9b
cmpq %r15, %r12
je 0x48ea
subl (%r14,%r9,4), %ecx
incq %r15
cmpl $0x16e, %ecx            # imm = 0x16E
jg 0x44de
shll $0x3, %r10d
imull $-0x3c, %edx, %r14d
leal (%r10,%r10,2), %edx
addl %eax, %r14d
movl %ebp, %r9d
subl %edx, %r9d
movabsq $-0x5c28f5c28f5c28f5, %rsi # imm = 0xA3D70A3D70A3D70B
leaq 0xd7f(%rip), %r10       # 0x52f0
xorl %r11d, %r11d
movq %r15, %rax
imulq %rsi
addq %r15, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x6, %rdx
addq %rax, %rdx
imulq $0x64, %rdx, %rdx
movq %r15, %rax
subq %rdx, %rax
movq %r15, %rdi
movabsq $-0x70a3d70a3d70a3d7, %rdx # imm = 0x8F5C28F5C28F5C29
imulq %rdx, %rdi
movabsq $0x51eb851eb851eb0, %rdx # imm = 0x51EB851EB851EB0
addq %rdx, %rdi
rorq $0x4, %rdi
xorl %edx, %edx
movabsq $0xa3d70a3d70a3d7, %r8  # imm = 0xA3D70A3D70A3D7
cmpq %r8, %rdi
setb %dl
movslq %ebx, %rdi
leaq (%r10,%rdi,4), %r8
movl %ecx, %ebp
testq %rax, %rax
movl $0x1, %edi
cmoveq %rdx, %rdi
testb $0x3, %r15b
cmovneq %r11, %rdi
leaq (%rdi,%rdi,2), %rdi
shll $0x4, %edi
subl (%r8,%rdi), %ecx
jle 0x4616
leal 0x1(%rbx), %edi
addq $0x4, %r8
movl %ecx, %ebp
cmpl $0xb, %ebx
movl %edi, %ebx
jl 0x45d2
cmpq %r12, %r15
je 0x48ea
incq %r15
xorl %ebx, %ebx
jmp 0x4574
leaq 0x76d(%r12), %rax
movq $-0x1, %r13
cmpq %rax, %r15
jl 0x48f1
leaq 0x7ffff894(%r15), %rax
shrq $0x20, %rax
jne 0x48f1
movl 0x8(%rsp), %eax
cmpl $0x3c, %eax
jae 0x4660
movl %r14d, 0x10(%rsp)
movl %r9d, 0x4(%rsp)
movl %eax, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
jmp 0x46a5
cmpq $0x7b1, %r15            # imm = 0x7B1
jg 0x4693
movl 0x8(%rsp), %eax
cmpl $0x8000003b, %eax       # imm = 0x8000003B
jl 0x48f1
movl %r14d, 0x10(%rsp)
movl %r9d, 0x4(%rsp)
addl $-0x3b, %eax
movl %eax, 0x8(%rsp)
movl $0x3b, 0xc(%rsp)
jmp 0x46a5
movl %r14d, 0x10(%rsp)
movl %r9d, 0x4(%rsp)
movl $0x0, 0xc(%rsp)
addl $0xfffff894, %r15d      # imm = 0xFFFFF894
movl %ebx, %eax
negl %eax
movl %eax, 0x20(%rsp)
leaq 0x1(%r12), %r14
movq %r14, %rax
shrq $0x3f, %rax
addq %r14, %rax
sarq %rax
movq %r12, %r13
shrq $0x3f, %r13
addq %r12, %r13
sarq %r13
addq %rax, %r13
movq %r13, 0x18(%rsp)
cmpq %r14, %r13
jge 0x46ea
movq %r14, 0x18(%rsp)
movq %r14, %r13
jmp 0x46f7
cmpq %r12, %r13
jle 0x46f7
movq %r12, 0x18(%rsp)
movq %r12, %r13
leaq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3222
testq %rax, %rax
je 0x4744
movl 0x3c(%rsp), %eax
subl %r15d, %eax
jne 0x4759
movl 0x38(%rsp), %eax
cmpl %ebx, %eax
jne 0x4755
movl 0x34(%rsp), %eax
subl %ebp, %eax
jne 0x4759
movl 0x30(%rsp), %eax
subl 0x4(%rsp), %eax
jne 0x4759
movl 0x2c(%rsp), %eax
subl 0x10(%rsp), %eax
jne 0x4759
movl 0x28(%rsp), %eax
subl 0xc(%rsp), %eax
jne 0x4759
jmp 0x4798
xorl %eax, %eax
testq %r13, %r13
setg %al
leal -0x1(,%rax,2), %eax
jmp 0x4759
addl 0x20(%rsp), %eax
cmpq %r14, %r13
jne 0x476b
incq %r14
movq %r14, 0x18(%rsp)
movq %r14, %r13
jmp 0x477b
cmpq %r12, %r13
jne 0x477b
decq %r12
movq %r12, 0x18(%rsp)
movq %r12, %r13
cmpq %r12, %r14
jg 0x48ea
testl %eax, %eax
jg 0x4790
movq %r13, %r14
jmp 0x46b9
movq %r13, %r12
jmp 0x46b9
movl 0x14(%rsp), %eax
testl %eax, %eax
js 0x47a6
cmpl %eax, 0x48(%rsp)
jne 0x47e0
movq %r13, 0x20(%rsp)
movslq 0x8(%rsp), %r13
addq 0x20(%rsp), %r13
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
movq 0x78(%rsp), %rsi
callq 0x3222
testq %rax, %rax
je 0x48f1
movq 0x70(%rsp), %rax
movl $0x1, (%rax)
jmp 0x48f1
movslq 0x2ee1(%rip), %rcx      # 0x76c8
testq %rcx, %rcx
jle 0x48ea
movq %rcx, %rax
movq %rax, 0x60(%rsp)
leaq (%rax,%rax,2), %rax
movl 0x14(%rsp), %ecx
leaq 0x2eb9(%rip), %rdx      # 0x76c0
cmpl %ecx, 0x2a38(%rdx,%rax,8)
jne 0x48d7
movslq 0x2ead(%rip), %r12      # 0x76c8
testq %r12, %r12
jle 0x48d7
leaq 0x2e95(%rip), %rcx      # 0x76c0
leaq (%rcx,%rax,8), %rax
addq $0x2a30, %rax           # imm = 0x2A30
movq %rax, 0x68(%rsp)
leaq (%r12,%r12,2), %rax
incq %r12
leaq (%rcx,%rax,8), %r14
addq $0x2a38, %r14           # imm = 0x2A38
movl 0x14(%rsp), %eax
cmpl %eax, (%r14)
jne 0x4864
decq %r12
addq $-0x18, %r14
cmpq $0x1, %r12
ja 0x484c
jmp 0x48d7
movq -0x8(%r14), %rcx
addq %r13, %rcx
movq 0x68(%rsp), %rax
subq (%rax), %rcx
movq %rcx, 0x20(%rsp)
movq %rcx, 0x80(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3222
testq %rax, %rax
je 0x4855
cmpl %r15d, 0x3c(%rsp)
jne 0x4855
cmpl %ebx, 0x38(%rsp)
jne 0x4855
cmpl %ebp, 0x34(%rsp)
jne 0x4855
movl 0x4(%rsp), %eax
cmpl %eax, 0x30(%rsp)
jne 0x4855
movl 0x10(%rsp), %eax
cmpl %eax, 0x2c(%rsp)
jne 0x4855
movl 0xc(%rsp), %eax
cmpl %eax, 0x28(%rsp)
jne 0x4855
movl 0x14(%rsp), %eax
cmpl %eax, 0x48(%rsp)
jne 0x4855
jmp 0x47ab
movq 0x60(%rsp), %rcx
leaq -0x1(%rcx), %rax
cmpq $0x1, %rcx
jg 0x47f3
movq $-0x1, %r13
movq %r13, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop