// File: /workspace/github_c_makefile_star2_O1/cyb70289[P]tt/src/apn/integer/integer.c
// Function: tt_int_shift_buf
int _tt_int_shift_buf(_tt_word *buf, int msb, int shift)
{
	int sh_words, sh_bits;
	_tt_word tmp = 0, tmp2;

	if (shift > 0) {
		sh_words = shift / _tt_word_bits;
		sh_bits = shift % _tt_word_bits;

		if (sh_words) {
			memmove(buf+sh_words, buf, msb*_tt_word_sz);
			memset(buf, 0, sh_words*_tt_word_sz);
			msb += sh_words;
		}

		if (sh_bits) {
			for (int i = sh_words; i < msb; i++) {
				tmp2 = buf[i];
				buf[i] = ((buf[i] << sh_bits) | tmp) &
					~_tt_word_top_bit;
				tmp = tmp2 >> (_tt_word_bits-sh_bits);
			}
			if (tmp)
				buf[msb++] = tmp;
		}
	} else if (shift < 0) {
		shift = -shift;
		sh_words = shift / _tt_word_bits;
		sh_bits = shift % _tt_word_bits;

		if (sh_words >= msb) {
			memset(buf, 0, msb*_tt_word_sz);
			return 1;
		}

		if (sh_words) {
			memmove(buf, buf+sh_words, (msb-sh_words)*_tt_word_sz);
			memset(buf+msb-sh_words, 0, sh_words*_tt_word_sz);
			msb -= sh_words;
		}

		if (sh_bits) {
			for (int i = msb-1; i >= 0; i--) {
				tmp2 = buf[i];
				buf[i] = (buf[i] >> sh_bits) | tmp;
				tmp = (tmp2 << (_tt_word_bits-sh_bits)) &
					~_tt_word_top_bit;
			}
			if (buf[msb-1] == 0 && msb > 1)
				msb--;
		}
	}

	return msb;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
testl %edx, %edx
jle 0x4c38
movl %edx, %eax
imulq $0x4104105, %rax, %rax  # imm = 0x4104105
shrq $0x20, %rax
movl %edx, %r13d
subl %eax, %r13d
shrl %r13d
addl %eax, %r13d
shrl $0x5, %r13d
movl %r13d, %eax
shll $0x6, %eax
movl %r13d, %r15d
subl %eax, %r15d
addl %edx, %r15d
cmpl $0x3f, %edx
jb 0x4bdf
leal (,%r13,8), %r12d
leaq (%r14,%r12), %rdi
leal (,%rbx,8), %eax
movslq %eax, %rdx
movq %r14, %rsi
callq 0x1160
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x10e0
addl %r13d, %ebx
testl %r15d, %r15d
je 0x4d45
cmpl %ebx, %r13d
jge 0x4c7e
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
movl %r15d, %eax
xorl $0x3f, %r15d
movl %r13d, %esi
leal (%rbx,%r13), %edi
subl %r13d, %edi
xorl %r9d, %r9d
movq (%r14,%rsi,8), %r8
movq %r8, %r10
movl %eax, %ecx
shlq %cl, %r10
orq %r9, %r10
andq %rdx, %r10
movl %r15d, %ecx
shrq %cl, %r8
movq %r10, (%r14,%rsi,8)
incq %rsi
movq %r8, %r9
cmpq %rsi, %rdi
jne 0x4c0f
jmp 0x4c81
jns 0x4d45
movl %edx, %eax
negl %eax
imulq $0x4104105, %rax, %rcx  # imm = 0x4104105
shrq $0x20, %rcx
movl %eax, %r12d
subl %ecx, %r12d
shrl %r12d
addl %ecx, %r12d
shrl $0x5, %r12d
movl %ebx, %r13d
subl %r12d, %r13d
jle 0x4c98
movl %r12d, %ecx
shll $0x6, %ecx
movl %r12d, %r15d
subl %ecx, %r15d
subl %edx, %r15d
cmpl $0x3f, %eax
jae 0x4cb2
movl %ebx, %r13d
jmp 0x4ce0
xorl %r8d, %r8d
testq %r8, %r8
je 0x4d45
movslq %ebx, %rax
incl %ebx
movq %r8, (%r14,%rax,8)
jmp 0x4d45
shll $0x3, %ebx
movslq %ebx, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x10e0
movl $0x1, %ebx
jmp 0x4d45
shll $0x3, %r12d
leaq (%r14,%r12), %rsi
leal (,%r13,8), %eax
movslq %eax, %rdx
movq %r14, %rdi
callq 0x1160
movl %ebx, %eax
leaq (%r14,%rax,8), %rdi
subq %r12, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x10e0
testl %r15d, %r15d
je 0x4d42
leal -0x1(%r13), %ebx
testl %r13d, %r13d
jle 0x4d2c
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
movl %r15d, %eax
xorl $0x3f, %r15d
movl %ebx, %esi
incq %rsi
xorl %edi, %edi
movq -0x8(%r14,%rsi,8), %r8
movq %r8, %r9
movl %eax, %ecx
shrq %cl, %r9
orq %rdi, %r9
movl %r15d, %ecx
shlq %cl, %r8
movq %r9, -0x8(%r14,%rsi,8)
andq %rdx, %r8
movq %r8, %rdi
decq %rsi
jg 0x4d06
movslq %ebx, %rax
cmpl $0x2, %r13d
cmovll %r13d, %ebx
cmpq $0x0, (%r14,%rax,8)
cmovnel %r13d, %ebx
jmp 0x4d45
movl %r13d, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq