// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movl %esi, 0x24(%rsp)
movl %edx, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0x6e5c
movl 0x20(%rsp), %eax
movl $0x3f, %ecx
cltd
idivl %ecx
movl %eax, 0x1c(%rsp)
movl 0x20(%rsp), %eax
movl $0x3f, %ecx
cltd
idivl %ecx
movl %edx, 0x18(%rsp)
cmpl $0x0, 0x1c(%rsp)
je 0x6da3
movq 0x28(%rsp), %rdi
movslq 0x1c(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq 0x28(%rsp), %rsi
movl 0x24(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1180
movq 0x28(%rsp), %rdi
movl 0x1c(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movl 0x1c(%rsp), %eax
addl 0x24(%rsp), %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x18(%rsp)
je 0x6e57
movl 0x1c(%rsp), %eax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0x6e2f
movq 0x28(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movl 0x18(%rsp), %eax
movl %eax, %ecx
shlq %cl, %rdx
orq 0x10(%rsp), %rdx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq %rax, %rdx
movq 0x28(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x8(%rsp), %rax
movl $0x3f, %ecx
subl 0x18(%rsp), %ecx
movl %ecx, %ecx
shrq %cl, %rax
movq %rax, 0x10(%rsp)
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x6db6
cmpq $0x0, 0x10(%rsp)
je 0x6e55
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rax
movl 0x24(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x24(%rsp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x6e57
jmp 0x6fe2
cmpl $0x0, 0x20(%rsp)
jge 0x6fe0
xorl %eax, %eax
subl 0x20(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %eax
movl $0x3f, %ecx
cltd
idivl %ecx
movl %eax, 0x1c(%rsp)
movl 0x20(%rsp), %eax
movl $0x3f, %ecx
cltd
idivl %ecx
movl %edx, 0x18(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x24(%rsp), %eax
jl 0x6ebe
movq 0x28(%rsp), %rdi
movl 0x24(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movl $0x1, 0x34(%rsp)
jmp 0x6fea
cmpl $0x0, 0x1c(%rsp)
je 0x6f2f
movq 0x28(%rsp), %rdi
movq 0x28(%rsp), %rsi
movslq 0x1c(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl 0x24(%rsp), %eax
subl 0x1c(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1180
movq 0x28(%rsp), %rdi
movslq 0x24(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movslq 0x1c(%rsp), %rcx
xorl %eax, %eax
subq %rcx, %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x1c(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movl 0x1c(%rsp), %ecx
movl 0x24(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x18(%rsp)
je 0x6fde
movl 0x24(%rsp), %eax
subl $0x1, %eax
movl %eax, (%rsp)
cmpl $0x0, (%rsp)
jl 0x6fb4
movq 0x28(%rsp), %rax
movslq (%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movslq (%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movl 0x18(%rsp), %eax
movl %eax, %ecx
shrq %cl, %rdx
orq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rax
movslq (%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x8(%rsp), %rax
movl $0x3f, %ecx
subl 0x18(%rsp), %ecx
movl %ecx, %ecx
shlq %cl, %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq %rcx, %rax
movq %rax, 0x10(%rsp)
movl (%rsp), %eax
addl $-0x1, %eax
movl %eax, (%rsp)
jmp 0x6f44
movq 0x28(%rsp), %rax
movl 0x24(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x6fdc
cmpl $0x1, 0x24(%rsp)
jle 0x6fdc
movl 0x24(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x6fde
jmp 0x6fe0
jmp 0x6fe2
movl 0x24(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)