// File: /workspace/github_c_makefile_star2_O2/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 %r8d, %ebp
movl %ecx, %ebx
movq %rdx, %rcx
movq %rdi, %r14
leal 0x8(%rbx), %eax
pushq $0x9
popq %r12
cltd
idivl %r12d
movl %eax, %r15d
testl %r8d, %r8d
js 0x3065
je 0x308f
movl %ebp, %eax
xorl %edx, %edx
divl %r12d
movl %edx, %r11d
cmpl $0x9, %ebp
jae 0x30af
movl %ebx, %edi
jmp 0x3107
movl %ebp, %edi
negl %edi
cmpl %ebx, %edi
jge 0x3191
movl %edi, %eax
xorl %edx, %edx
divl %r12d
movl %edx, %r9d
cmpl $0x9, %edi
movl %edx, 0x4(%rsp)
jae 0x31b3
movl %ebx, %edi
jmp 0x320a
cmpq %rcx, %r14
je 0x327b
shll $0x2, %r15d
movslq %r15d, %rdx
movq %r14, %rdi
movq %rcx, %rsi
callq 0x1120
jmp 0x327b
movl %eax, %r13d
movl %r15d, %esi
movl %ebp, %eax
pushq $0x9
popq %rdi
xorl %edx, %edx
divq %rdi
decq %rax
testl %esi, %esi
jle 0x30da
leaq -0x1(%rsi), %rdx
movl %edx, %edi
movl (%rcx,%rdi,4), %edi
addl %eax, %esi
movl %edi, (%r14,%rsi,4)
movq %rdx, %rsi
jmp 0x30c2
leal (,%r13,4), %edx
movq %r14, %rdi
xorl %esi, %esi
movl %ebp, 0x4(%rsp)
movq %r11, %rbp
callq 0x10e0
movq %rbp, %r11
movl 0x4(%rsp), %ebp
leal (%r13,%r13,8), %edi
addl %ebx, %edi
addl %r13d, %r15d
movq %r14, %rcx
testl %r11d, %r11d
je 0x3275
leal -0x1(%rdi), %eax
cltd
idivl %r12d
leal (%r11,%rdx), %eax
incl %eax
xorl %edx, %edx
cmpl $0xa, %eax
setge %dl
addl %edx, %r15d
movl %r11d, %r8d
subl %r11d, %r12d
leaq 0x703b(%rip), %r9       # 0xa170
movl $0x3b9aca00, %r10d      # imm = 0x3B9ACA00
cmpl $0x2, %r15d
jl 0x3172
movl -0x4(%rcx,%r15,4), %edx
movl (%r9,%r8,4), %eax
imulq %rdx, %rax
xorl %edx, %edx
divq %r10
movq %rdx, %rsi
movl %esi, -0x4(%r14,%r15,4)
movl -0x8(%rcx,%r15,4), %eax
xorl %edx, %edx
divl (%r9,%r12,4)
addl %esi, %eax
movl %eax, -0x4(%r14,%r15,4)
decq %r15
jmp 0x313b
addl %r11d, %edi
movl (%rcx), %ecx
movl (%r9,%r8,4), %eax
imulq %rcx, %rax
movl $0x3b9aca00, %ecx       # imm = 0x3B9ACA00
xorl %edx, %edx
divq %rcx
movl %edx, (%r14)
jmp 0x3275
pushq $0x1
popq %rbx
cmpq %rcx, %r14
jne 0x327b
shll $0x2, %r15d
movslq %r15d, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x10e0
jmp 0x327b
movl %eax, %r13d
movl %eax, %eax
movslq %r15d, %rdx
leaq (%rcx,%rax,4), %rcx
xorl %edi, %edi
leaq (%rax,%rdi), %r8
cmpq %rdx, %r8
jge 0x31d7
movl (%rcx,%rdi,4), %r8d
movl %r8d, (%r14,%rdi,4)
incq %rdi
jmp 0x31c1
subl %r13d, %r15d
leal (,%r15,4), %ecx
subl %ecx, %esi
testl %esi, %esi
jle 0x3201
leaq (%r14,%rdx,4), %rdi
shlq $0x2, %rax
subq %rax, %rdi
movl %esi, %edx
xorl %esi, %esi
callq 0x10e0
movl 0x4(%rsp), %r9d
imull $-0x9, %r13d, %edi
addl %ebx, %edi
movq %r14, %rcx
testl %r9d, %r9d
je 0x3275
decl %r15d
movl %r9d, %r8d
subl %r9d, %r12d
xorl %r10d, %r10d
testl %r15d, %r15d
movl $0x0, %r11d
cmovgl %r15d, %r11d
leaq 0x6f41(%rip), %r9       # 0xa170
cmpq %r10, %r11
je 0x3261
movl (%rcx,%r10,4), %eax
movl (%r9,%r8,4), %r13d
xorl %edx, %edx
divl %r13d
movl %eax, %esi
movl %eax, (%r14,%r10,4)
movl 0x4(%rcx,%r10,4), %eax
xorl %edx, %edx
divl %r13d
imull (%r9,%r12,4), %edx
addl %esi, %edx
movl %edx, (%r14,%r10,4)
incq %r10
jmp 0x322f
movslq %r15d, %rsi
movl (%rcx,%rsi,4), %eax
xorl %edx, %edx
divl (%r9,%r8,4)
movl %eax, (%r14,%rsi,4)
subl 0x4(%rsp), %edi
addl %ebp, %ebx
cmpl %edi, %ebx
jne 0x328c
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13608(%rip), %rsi     # 0x1689b
leaq 0x6de8(%rip), %rdx      # 0xa082
leaq 0x135b3(%rip), %rcx     # 0x16854
xorl %edi, %edi
movl $0x182, %r8d            # imm = 0x182
xorl %eax, %eax
callq 0x7de8
callq 0x1050