// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ecx
movl %esi, %r14d
movq %rdi, %rbx
testl %edx, %edx
jle 0x4175
pushq $0x3f
popq %rsi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %edx, %r15d
movl %eax, %ebp
cmpl $0x3f, %ecx
jb 0x4114
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %eax, %r12d
leal (,%r12,8), %r13d
leaq (%rbx,%r13), %rdi
leal (,%r14,8), %eax
movslq %eax, %rdx
movq %rbx, %rsi
callq 0x1160
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x10e0
addl %r14d, %r12d
movl %r12d, %r14d
testl %r15d, %r15d
je 0x4252
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movl %r15d, %eax
xorl $0x3f, %r15d
movl %ebp, %edi
movslq %r14d, %rdx
xorl %r8d, %r8d
cmpq %rdx, %rdi
jge 0x415f
movq (%rbx,%rdi,8), %r9
movq %r9, %r10
movl %eax, %ecx
shlq %cl, %r10
orq %r8, %r10
movl %r15d, %ecx
shrq %cl, %r9
andq %rsi, %r10
movq %r10, (%rbx,%rdi,8)
incq %rdi
movq %r9, %r8
jmp 0x4136
testq %r8, %r8
je 0x4252
leal 0x1(%rdx), %r14d
movq %r8, (%rbx,%rdx,8)
jmp 0x4252
jns 0x4252
negl %ecx
pushq $0x3f
popq %rsi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %r14d, %r13d
subl %eax, %r13d
jle 0x419b
movl %edx, %r15d
cmpl $0x3f, %ecx
jae 0x41b5
movl %r14d, %r13d
jmp 0x41ed
shll $0x3, %r14d
movslq %r14d, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10e0
pushq $0x1
popq %r14
jmp 0x4252
movl %eax, %r12d
movl %eax, %ebp
leaq (%rbx,%rbp,8), %rsi
shlq $0x3, %rbp
leal (,%r13,8), %eax
movslq %eax, %rdx
movq %rbx, %rdi
callq 0x1160
movl %r14d, %eax
leaq (%rbx,%rax,8), %rdi
subq %rbp, %rdi
shll $0x3, %r12d
xorl %esi, %esi
movq %r12, %rdx
callq 0x10e0
testl %r15d, %r15d
je 0x424f
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
leal -0x1(%r13), %esi
movl %r15d, %eax
xorl $0x3f, %r15d
xorl %r8d, %r8d
movl %esi, %edi
testl %edi, %edi
js 0x4236
movl %edi, %r9d
movq (%rbx,%r9,8), %r10
movq %r10, %r11
movl %eax, %ecx
shrq %cl, %r11
orq %r8, %r11
movl %r15d, %ecx
shlq %cl, %r10
movq %r11, (%rbx,%r9,8)
andq %rdx, %r10
decl %edi
movq %r10, %r8
jmp 0x420c
movslq %esi, %rax
cmpl $0x2, %r13d
movl %eax, %r14d
cmovll %r13d, %r14d
cmpq $0x0, (%rbx,%rax,8)
cmovnel %r13d, %r14d
jmp 0x4252
movl %r13d, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq