// File: /workspace/github_c_makefile_star2_O3/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 0x38ec
xorl %r8d, %r8d
jmp 0x3916
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 0x3916
rorl $0x4, %eax
cmpl $0xa3d70b, %eax         # imm = 0xA3D70B
setb %r8b
movl (%rdx), %eax
testl %eax, %eax
je 0x3ae4
cmpl $0x1, %eax
je 0x3ade
cmpl $0x2, %eax
jne 0x3b0f
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
movl 0xc(%rdx), %r9d
leal -0x1(%r9), %eax
movzbl %r8b, %r8d
cmpl $0x2, %r9d
jl 0x397b
movl %eax, %r10d
movl %r8d, %r11d
shll $0x4, %r11d
leaq (%r11,%r11,2), %r11
xorl %ebx, %ebx
leaq 0x198f(%rip), %r14      # 0x52f0
leaq (%r11,%rbx,4), %r15
movslq (%r14,%r15), %r15
imulq $0x15180, %r15, %r15    # imm = 0x15180
addq %r15, %rdi
incq %rbx
cmpq %rbx, %r10
jne 0x3961
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, %r9
imulq $-0x51eb851f, %r9, %rsi # imm = 0xAE147AE1
movq %rsi, %r10
shrq $0x3f, %r10
shrq $0x20, %rsi
sarl $0x5, %esi
addl %r10d, %esi
imulq $0x51eb851f, %r9, %r11  # imm = 0x51EB851F
movq %r11, %r10
shrq $0x20, %r10
movl %r10d, %ebp
sarl $0x5, %ebp
shrq $0x3f, %r11
addl %r11d, %ebp
imull $0x64, %ebp, %ebp
subl %ebp, %r9d
leal (%rbx,%rbx,4), %r14d
leal (%r14,%r14,4), %r14d
addl %r14d, %ebx
addl $0x18, %ebx
movswl %bx, %ebx
imull $0x6667, %ebx, %ebx     # imm = 0x6667
movl %ebx, %r14d
sarl $0x12, %r14d
shrl $0x1f, %ebx
addl %r14d, %ebx
incl %ebx
movswl %bx, %ebx
movl %r9d, %ebp
sarb $0x7, %bpl
shrb $0x6, %bpl
addb %r9b, %bpl
sarb $0x2, %bpl
movsbl %bpl, %ebp
sarl $0x7, %r10d
addl %r11d, %r10d
addl %r9d, %r10d
leal (%r10,%rsi,2), %esi
addl %ebp, %esi
addl %ebx, %esi
movslq %esi, %rsi
imulq $-0x6db6db6d, %rsi, %r9 # imm = 0x92492493
shrq $0x20, %r9
addl %esi, %r9d
movl %r9d, %r10d
shrl $0x1f, %r10d
sarl $0x2, %r9d
addl %r10d, %r9d
leal (,%r9,8), %r10d
subl %r10d, %r9d
leal (%r9,%rsi), %r10d
addl $0x7, %r10d
addl %r9d, %esi
cmovnsl %esi, %r10d
movl 0x4(%rdx), %r11d
subl %r10d, %r11d
movl 0x8(%rdx), %esi
leal 0x7(%r11), %r9d
testl %r11d, %r11d
cmovnsl %r11d, %r9d
cmpl $0x2, %esi
popq %rbx
popq %r14
popq %r15
popq %rbp
jl 0x3b13
cltq
leaq (%r8,%r8,2), %r8
shll $0x4, %r8d
leaq 0x1842(%rip), %r10      # 0x52f0
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 0x3b16
decl %esi
jne 0x3ac9
movl %r8d, %r10d
jmp 0x3b16
movslq 0x4(%rdx), %rax
jmp 0x3b19
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 0x3b23
xorl %eax, %eax
jmp 0x3b23
movl %r9d, %r10d
movslq %r10d, %rax
imulq $0x15180, %rax, %rax    # imm = 0x15180
addq %rdi, %rax
addq %rcx, %rax
addq 0x10(%rdx), %rax
retq