// File: /workspace/github_c_makefile_star2_O2/lyda[P]tz/localtime.c
// Function: transtime
static time_t
transtime(janfirst, year, rulep, offset)
const time_t				janfirst;
const int				year;
register const struct rule * const	rulep;
const long				offset;
{
	register int	leapyear;
	register time_t	value;
	register int	i;
	int		d, m1, yy0, yy1, yy2, dow;

	INITIALIZE(value);
	leapyear = isleap(year);
	switch (rulep->r_type) {

	case JULIAN_DAY:
		/*
		** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
		** years.
		** In non-leap years, or if the day number is 59 or less, just
		** add SECSPERDAY times the day number-1 to the time of
		** January 1, midnight, to get the day.
		*/
		value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
		if (leapyear && rulep->r_day >= 60)
			value += SECSPERDAY;
		break;

	case DAY_OF_YEAR:
		/*
		** n - day of year.
		** Just add SECSPERDAY times the day number to the time of
		** January 1, midnight, to get the day.
		*/
		value = janfirst + rulep->r_day * SECSPERDAY;
		break;

	case MONTH_NTH_DAY_OF_WEEK:
		/*
		** Mm.n.d - nth "dth day" of month m.
		*/
		value = janfirst;
		for (i = 0; i < rulep->r_mon - 1; ++i)
			value += mon_lengths[leapyear][i] * SECSPERDAY;

		/*
		** Use Zeller's Congruence to get day-of-week of first day of
		** month.
		*/
		m1 = (rulep->r_mon + 9) % 12 + 1;
		yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
		yy1 = yy0 / 100;
		yy2 = yy0 % 100;
		dow = ((26 * m1 - 2) / 10 +
			1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
		if (dow < 0)
			dow += DAYSPERWEEK;

		/*
		** "dow" is the day-of-week of the first day of the month. Get
		** the day-of-month (zero-origin) of the first "dow" day of the
		** month.
		*/
		d = rulep->r_day - dow;
		if (d < 0)
			d += DAYSPERWEEK;
		for (i = 1; i < rulep->r_week; ++i) {
			if (d + DAYSPERWEEK >=
				mon_lengths[leapyear][rulep->r_mon - 1])
					break;
			d += DAYSPERWEEK;
		}

		/*
		** "d" is the day-of-month (zero-origin) of the day we want.
		*/
		value += d * SECSPERDAY;
		break;
	}

	/*
	** "value" is the Epoch-relative time of 00:00:00 UTC on the day in
	** question. To get the Epoch-relative time of the specified local
	** time on that day, add the transition time and the current offset
	** from UTC.
	*/
	return value + rulep->r_time + offset;
}

// Assembly:
movq %rdx, %r8
movl $0x64, %r10d
testb $0x3, %sil
je 0x34e8
xorl %r11d, %r11d
jmp 0x3507
movl %esi, %eax
cltd
idivl %r10d
movb $0x1, %r11b
testl %edx, %edx
jne 0x3507
movl $0x190, %r9d            # imm = 0x190
movl %esi, %eax
cltd
idivl %r9d
testl %edx, %edx
sete %r11b
movl (%r8), %eax
testl %eax, %eax
je 0x3578
cmpl $0x1, %eax
je 0x3565
cmpl $0x2, %eax
jne 0x35a7
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movslq 0xc(%r8), %r9
movq %r9, %rbx
decq %rbx
movzbl %r11b, %r11d
xorl %eax, %eax
testl %ebx, %ebx
movl $0x0, %edx
cmovgl %ebx, %edx
imulq $0x30, %r11, %r14
leaq 0x1da7(%rip), %r15      # 0x52f0
cmpq %rax, %rdx
je 0x35ae
leaq (%r14,%rax,4), %r11
movslq (%r15,%r11), %r11
imulq $0x15180, %r11, %r11    # imm = 0x15180
addq %r11, %rdi
incq %rax
jmp 0x3549
movslq 0x4(%r8), %rax
imulq $0x15180, %rax, %rax    # imm = 0x15180
addq %rdi, %rax
jmp 0x3679
movl 0x4(%r8), %eax
movslq %eax, %rdx
imulq $0x15180, %rdx, %rsi    # imm = 0x15180
leaq (%rsi,%rdi), %rax
addq %rdi, %rsi
addq $-0x15180, %rsi         # imm = 0xFFFEAE80
cmpl $0x3c, %edx
cmovlq %rsi, %rax
testb %r11b, %r11b
cmoveq %rsi, %rax
jmp 0x3679
xorl %eax, %eax
jmp 0x3679
leal 0x9(%r9), %eax
movl $0xc, %r11d
cltd
idivl %r11d
movl %edx, %r11d
xorl %eax, %eax
cmpl $0x3, %r9d
setl %al
subl %eax, %esi
movl $0xffffff9c, %r9d       # imm = 0xFFFFFF9C
movl %esi, %eax
cltd
idivl %r9d
movl %eax, %r9d
movl %esi, %eax
cltd
idivl %r10d
movl %edx, %r10d
imull $0x1a, %r11d, %eax
addl $0x18, %eax
movw $0xa, %r11w
cwtd
idivw %r11w
incl %eax
movswl %ax, %r11d
movsbl %r10b, %eax
movb $0x4, %dl
idivb %dl
movsbl %al, %ebp
movl $0x190, %r12d           # imm = 0x190
movl %esi, %eax
cltd
idivl %r12d
addl %r10d, %eax
leal (%rax,%r9,2), %eax
addl %ebp, %eax
addl %r11d, %eax
movl $0x7, %esi
cltd
idivl %esi
leal 0x7(%rdx), %eax
testl %edx, %edx
cmovnsl %edx, %eax
movl 0x4(%r8), %r9d
subl %eax, %r9d
movl 0x8(%r8), %edx
leal 0x7(%r9), %esi
testl %r9d, %r9d
cmovnsl %r9d, %esi
addq %r14, %r15
leaq (%r15,%rbx,4), %r9
movslq %esi, %rax
imulq $0x15180, %rax, %r10    # imm = 0x15180
addq %rdi, %r10
xorl %edi, %edi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
movq %r10, %rax
incl %edi
cmpl %edx, %edi
jge 0x3679
leaq 0x93a80(%rax), %r10
addl $0x7, %esi
cmpl (%r9), %esi
jl 0x3661
addq %rcx, %rax
addq 0x10(%r8), %rax
retq