// File: /workspace/github_c_makefile_star2_O3/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 0x4c67
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 0x4bf4
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
setne %al
cmpl %ebx, %r13d
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4d56
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
movl %r15d, %eax
xorl $0x3f, %r15d
movl %r13d, %esi
leal (%rbx,%r13), %edi
subl %r13d, %edi
xorl %r8d, %r8d
movq (%r14,%rsi,8), %r9
movq %r9, %r10
movl %eax, %ecx
shlq %cl, %r10
orq %r8, %r10
movq %r9, %r8
movl %r15d, %ecx
shrq %cl, %r8
andq %rdx, %r10
movq %r10, (%r14,%rsi,8)
incq %rsi
cmpq %rsi, %rdi
jne 0x4c29
testq %r8, %r8
je 0x4d56
movslq %ebx, %rax
incl %ebx
movq %r8, (%r14,%rax,8)
jmp 0x4d56
jns 0x4d56
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 0x4cad
movl %r12d, %ecx
shll $0x6, %ecx
movl %r12d, %r15d
subl %ecx, %r15d
subl %edx, %r15d
cmpl $0x3f, %eax
jae 0x4cc7
movl %ebx, %r13d
jmp 0x4cf5
shll $0x3, %ebx
movslq %ebx, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x10e0
movl $0x1, %ebx
jmp 0x4d56
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 0x4d53
leal -0x1(%r13), %ebx
testl %r13d, %r13d
jle 0x4d3d
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
movl %r15d, %eax
xorl $0x3f, %r15d
movl %ebx, %esi
xorl %edi, %edi
movq (%r14,%rsi,8), %r8
movq %r8, %r9
movl %eax, %ecx
shrq %cl, %r9
orq %rdi, %r9
movl %r15d, %ecx
shlq %cl, %r8
movq %r9, (%r14,%rsi,8)
andq %rdx, %r8
movq %r8, %rdi
addq $-0x1, %rsi
jb 0x4d18
movslq %ebx, %rax
cmpl $0x2, %r13d
cmovll %r13d, %ebx
cmpq $0x0, (%r14,%rax,8)
cmovnel %r13d, %ebx
jmp 0x4d56
movl %r13d, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq