// File: /workspace/github_c_makefile_star2_O1/cyb70289[P]tt/src/apn/decimal/basic.c
// Function: shift_digs
static int shift_digs(uint *dst, uint dst_sz, const uint *src, int msb, int adj)
{
	int uints = (msb + 8) / 9;	/* Valid uints in src */
	int msb_r = msb + adj;		/* Result length for debugging */

	/* Check shift direction */
	int append0;
	if (adj < 0) {
		adj = -adj;
		if (adj >= msb) {
			/* All digits truncated, just fill with 0 */
			if (dst == src)
				memset(dst, 0, uints * 4);
			return 1;
		}
		append0 = 0;	/* Truncate */
	} else if (adj > 0) {
		append0 = 1;	/* Append */
	} else {
		if (dst != src)
			memcpy(dst, src, uints * 4);
		return msb;	/* No shift */
	}

	/* Shift */
	int adj9 = adj / 9;	/* Align to uint */
	adj %= 9;
	int i;
	const uint *cur = src;	/* Current digit buffer */
	if (append0) { /* Left shift */
		/* Align-9 */
		if (adj9) {
			for (i = uints-1; i >= 0; i--)
				dst[i+adj9] = src[i];
			memset(dst, 0, adj9 * 4);

			msb += adj9 * 9;
			uints += adj9;

			cur = dst;
		}

		/* Unaligned */
		if (adj) {	/* adj = 1~8 */
			/* Check digits in first uint */
			int u1_dig = (msb - 1) % 9 + 1;
			if ((u1_dig + adj) > 9)
				uints++;
			msb += adj;

			/* Shift left */
			for (i = uints-1; i > 0; i--) {
				dst[i] = lshift_dig_1_8(cur[i], adj);
				/* Append msb of lower uint */
				dst[i] += cur[i-1] / one_tbl[9-adj];
			}
			dst[0] = lshift_dig_1_8(cur[0], adj);
		}
	} else { /* Right shift */
		/* Align-9 */
		if (adj9) {
			for (i = adj9; i < uints; i++)
				dst[i-adj9] = src[i];
			int remains = dst_sz - (uints - adj9) * 4;
			if (remains > 0)
				memset(dst + uints - adj9, 0, remains);

			msb -= adj9 * 9;
			uints -= adj9;

			cur = dst;
		}

		/* Unaligned */
		if (adj) {	/* adj = 1~8 */
			/* Shift right */
			for (i = 0; i < uints - 1; i++) {
				dst[i] = rshift_dig_1_8(cur[i], adj);
				/* Prepend lsb of higher uint */
				dst[i] += (cur[i+1] % one_tbl[adj]) *
					one_tbl[9-adj];
			}
			dst[uints-1] = rshift_dig_1_8(cur[uints-1], adj);

			/* Check digits in first uint */
			int u1_dig = (msb - 1) % 9 + 1;
			if (u1_dig <= adj)
				uints--;
			msb -= adj;
		}
	}

	tt_assert_fa(msb_r == msb);
	return msb;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebx
movq %rdx, %rcx
movq %rdi, %r14
leal 0x8(%rbx), %eax
cltq
imulq $0x38e38e39, %rax, %r12 # imm = 0x38E38E39
movq %r12, %rax
shrq $0x3f, %rax
sarq $0x21, %r12
addl %eax, %r12d
movl %r8d, %eax
testl %r8d, %r8d
js 0x3b77
jne 0x3b81
cmpq %rcx, %r14
je 0x3e01
shll $0x2, %r12d
movslq %r12d, %rdx
movq %r14, %rdi
movq %rcx, %rsi
callq 0x1120
jmp 0x3e01
negl %eax
cmpl %ebx, %eax
jge 0x3d01
leal (%r8,%rbx), %ebp
movl %eax, %edx
imulq $0x38e38e39, %rdx, %r13 # imm = 0x38E38E39
shrq $0x21, %r13
leal (%r13,%r13,8), %edx
movl %eax, %r15d
subl %edx, %r15d
testl %r8d, %r8d
js 0x3cf0
cmpl $0x9, %eax
jb 0x3bf6
testl %ebx, %ebx
jle 0x3bd5
leal 0x1(%r12), %eax
leal -0x1(%r12), %edx
leaq (%rcx,%rdx,4), %rcx
movl (%rcx), %edx
leal (%rax,%r13), %esi
addl $-0x2, %esi
movl %edx, (%r14,%rsi,4)
decl %eax
addq $-0x4, %rcx
cmpl $0x1, %eax
jg 0x3bbd
leal (,%r13,4), %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x10e0
leal (%r13,%r13,8), %eax
addl %ebx, %eax
addl %r13d, %r12d
movq %r14, %rcx
movl %eax, %ebx
testl %r15d, %r15d
je 0x3dfd
movl %ebp, 0x4(%rsp)
leal -0x1(%rbx), %eax
cltq
imulq $0x38e38e39, %rax, %rax # imm = 0x38E38E39
movq %rax, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rax
addl %edx, %eax
leal (%rax,%rax,8), %eax
negl %eax
addl %ebx, %eax
decl %eax
leal (%r15,%rax), %edx
incl %edx
xorl %eax, %eax
cmpl $0xa, %edx
setge %al
leal (%r12,%rax), %edx
movl %r15d, %edi
movabsq $0x44b82fa09b5a53, %rsi # imm = 0x44B82FA09B5A53
cmpl $0x2, %edx
jl 0x3cbf
leaq 0x7540(%rip), %r8       # 0xb190
movl (%r8,%rdi,4), %r9d
movl $0x9, %r10d
subl %r15d, %r10d
movl (%r8,%r10,4), %r10d
movl %edx, %r11d
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
addq %r11, %r13
leal (%r12,%rax), %ebp
incl %ebp
decq %r11
movl %r11d, %r12d
shlq $0x2, %r12
movl (%rcx,%r12), %r8d
imulq %r9, %r8
movq %r8, %rax
shrq $0x9, %rax
mulq %rsi
shrq $0xb, %rdx
imull $0x3b9aca00, %edx, %eax # imm = 0x3B9ACA00
subl %eax, %r8d
movl %r8d, (%r14,%r12)
movl %r13d, %eax
movl (%rcx,%rax,4), %eax
xorl %edx, %edx
divl %r10d
addl %r8d, %eax
movl %eax, (%r14,%r12)
decq %r13
decl %ebp
decq %r11
cmpl $0x2, %ebp
jg 0x3c76
addl %r15d, %ebx
movl (%rcx), %eax
leaq 0x74c5(%rip), %rcx      # 0xb190
movl (%rcx,%rdi,4), %ecx
imulq %rax, %rcx
movq %rcx, %rax
shrq $0x9, %rax
mulq %rsi
shrq $0xb, %rdx
imull $0x3b9aca00, %edx, %eax # imm = 0x3B9ACA00
subl %eax, %ecx
movl %ecx, (%r14)
jmp 0x3df9
movl %ebp, 0x4(%rsp)
cmpl $0x9, %eax
jae 0x3d25
movl %r12d, %ebp
jmp 0x3d81
movl $0x1, %ebx
cmpq %rcx, %r14
jne 0x3e01
shll $0x2, %r12d
movslq %r12d, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x10e0
jmp 0x3e01
movl %r12d, %ebp
subl %r13d, %ebp
jle 0x3d4f
movl %r13d, %edx
leal (%r12,%r13), %eax
subl %r13d, %eax
leaq (%rcx,%rdx,4), %rcx
subq %rdx, %rax
xorl %edx, %edx
movl (%rcx,%rdx,4), %edi
movl %edi, (%r14,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x3d40
leal (,%rbp,4), %eax
subl %eax, %esi
testl %esi, %esi
jle 0x3d77
movslq %r12d, %rax
leaq (%r14,%rax,4), %rdi
leal (,%r13,4), %eax
subq %rax, %rdi
movl %esi, %edx
xorl %esi, %esi
callq 0x10e0
leal (%r13,%r13,8), %eax
subl %eax, %ebx
movq %r14, %rcx
testl %r15d, %r15d
je 0x3df9
leal -0x1(%rbp), %edi
cmpl $0x2, %ebp
jl 0x3ddd
movl %r15d, %eax
leaq 0x73f8(%rip), %rdx      # 0xb190
movl (%rdx,%rax,4), %r8d
movl $0x9, %eax
subl %r15d, %eax
movl (%rdx,%rax,4), %r9d
movl %edi, %r10d
xorl %r11d, %r11d
movl (%rcx,%r11,4), %eax
xorl %edx, %edx
divl %r8d
movl %eax, %esi
movl %eax, (%r14,%r11,4)
movl 0x4(%rcx,%r11,4), %eax
xorl %edx, %edx
divl %r8d
imull %r9d, %edx
addl %esi, %edx
movl %edx, (%r14,%r11,4)
leaq 0x1(%r11), %rax
movq %rax, %r11
cmpq %rax, %r10
jne 0x3dae
movslq %edi, %rsi
movl (%rcx,%rsi,4), %eax
movl %r15d, %ecx
leaq 0x73a3(%rip), %rdi      # 0xb190
xorl %edx, %edx
divl (%rdi,%rcx,4)
movl %eax, (%r14,%rsi,4)
subl %r15d, %ebx
movl 0x4(%rsp), %ebp
cmpl %ebx, %ebp
jne 0x3e12
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x143c