// File: /workspace/github_c_makefile_star2_O1/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:
testb $0x3, %sil
je 0x4a75
xorl %r8d, %r8d
jmp 0x4a9f
imull $0xc28f5c29, %esi, %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
movl %eax, %r9d
rorl $0x2, %r9d
movb $0x1, %r8b
cmpl $0x28f5c28, %r9d        # imm = 0x28F5C28
ja 0x4a9f
rorl $0x4, %eax
cmpl $0xa3d70b, %eax         # imm = 0xA3D70B
setb %r8b
movl (%rdx), %eax
testl %eax, %eax
je 0x4c7c
cmpl $0x1, %eax
je 0x4c76
cmpl $0x2, %eax
jne 0x4ca7
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
movl 0xc(%rdx), %r9d
leal -0x1(%r9), %eax
movzbl %r8b, %r8d
cmpl $0x2, %r9d
jl 0x4b04
movl %eax, %r10d
movl %r8d, %r11d
shll $0x4, %r11d
leaq (%r11,%r11,2), %r11
xorl %ebx, %ebx
leaq 0x1806(%rip), %r14      # 0x62f0
leaq (%r11,%rbx,4), %r15
movslq (%r14,%r15), %r15
imulq $0x15180, %r15, %r15    # imm = 0x15180
addq %r15, %rdi
incq %rbx
cmpq %rbx, %r10
jne 0x4aea
leal 0x9(%r9), %r10d
movslq %r10d, %r10
imulq $0x2aaaaaab, %r10, %r10 # imm = 0x2AAAAAAB
movq %r10, %r11
shrq $0x3f, %r11
shrq $0x21, %r10
addl %r11d, %r10d
shll $0x2, %r10d
leal (%r10,%r10,2), %r10d
negl %r10d
leal (%r9,%r10), %ebx
addl $0x9, %ebx
xorl %r10d, %r10d
cmpl $0x3, %r9d
setl %r10b
subl %r10d, %esi
movslq %esi, %r10
imulq $-0x51eb851f, %r10, %rsi # imm = 0xAE147AE1
movq %rsi, %r9
shrq $0x3f, %r9
shrq $0x20, %rsi
sarl $0x5, %esi
addl %r9d, %esi
imulq $0x51eb851f, %r10, %r11 # imm = 0x51EB851F
movq %r11, %r9
shrq $0x20, %r9
movl %r9d, %ebp
sarl $0x5, %ebp
shrq $0x3f, %r11
addl %r11d, %ebp
imull $0x64, %ebp, %r14d
movl %r10d, %ebp
subl %r14d, %ebp
leal (%rbx,%rbx,4), %r15d
leal (%r15,%r15,4), %r15d
addl %r15d, %ebx
addl $0x18, %ebx
movslq %ebx, %rbx
imulq $0x66666667, %rbx, %rbx # imm = 0x66666667
movq %rbx, %r15
shrq $0x3f, %r15
shrq $0x20, %rbx
sarl $0x2, %ebx
addl %r15d, %ebx
negl %r14d
addl %r14d, %r10d
addl $0x3, %r10d
testl %ebp, %ebp
cmovnsl %ebp, %r10d
sarl $0x2, %r10d
sarl $0x7, %r9d
addl %r11d, %r9d
addl %ebp, %r9d
addl %r10d, %r9d
addl %ebx, %r9d
leal (%r9,%rsi,2), %r10d
leal (%r9,%rsi,2), %esi
incl %esi
movslq %esi, %rsi
imulq $-0x6db6db6d, %rsi, %rsi # imm = 0x92492493
shrq $0x20, %rsi
addl %r10d, %esi
incl %esi
movl %esi, %r9d
shrl $0x1f, %r9d
sarl $0x2, %esi
addl %r9d, %esi
leal (,%rsi,8), %r9d
subl %r9d, %esi
leal (%rsi,%r10), %r9d
incl %r9d
testl %r9d, %r9d
leal 0x8(%rsi,%r10), %esi
cmovnsl %r9d, %esi
movl 0x4(%rdx), %r10d
subl %esi, %r10d
movl 0x8(%rdx), %esi
leal 0x7(%r10), %r9d
testl %r10d, %r10d
cmovnsl %r10d, %r9d
cmpl $0x2, %esi
popq %rbx
popq %r14
popq %r15
popq %rbp
jl 0x4cab
cltq
leaq (%r8,%r8,2), %r8
shll $0x4, %r8d
leaq 0x16aa(%rip), %r10      # 0x62f0
addq %r8, %r10
movl (%r10,%rax,4), %eax
leal (,%rsi,8), %r8d
subl %esi, %r8d
addl %r9d, %r8d
addl $-0x7, %r8d
decl %esi
movl %r9d, %r10d
leal 0x7(%r10), %r9d
cmpl %eax, %r9d
jge 0x4cae
decl %esi
jne 0x4c61
movl %r8d, %r10d
jmp 0x4cae
movslq 0x4(%rdx), %rax
jmp 0x4cb1
movl 0x4(%rdx), %eax
movslq %eax, %rsi
imulq $0x15180, %rsi, %r9     # imm = 0x15180
leaq (%r9,%rdi), %rax
addq %r9, %rdi
addq $-0x15180, %rdi         # imm = 0xFFFEAE80
cmpl $0x3c, %esi
cmovlq %rdi, %rax
testb %r8b, %r8b
cmoveq %rdi, %rax
jmp 0x4cbb
xorl %eax, %eax
jmp 0x4cbb
movl %r9d, %r10d
movslq %r10d, %rax
imulq $0x15180, %rax, %rax    # imm = 0x15180
addq %rdi, %rax
addq %rcx, %rax
addq 0x10(%rdx), %rax
retq