// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movl %esi, 0x44(%rsp)
movq %rdx, 0x38(%rsp)
movl %ecx, 0x34(%rsp)
movl %r8d, 0x30(%rsp)
movl 0x34(%rsp), %eax
addl $0x8, %eax
movl $0x9, %ecx
cltd
idivl %ecx
movl %eax, 0x2c(%rsp)
movl 0x34(%rsp), %eax
addl 0x30(%rsp), %eax
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x30(%rsp)
jge 0x4b7e
xorl %eax, %eax
subl 0x30(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x34(%rsp), %eax
jl 0x4b74
movq 0x48(%rsp), %rax
cmpq 0x38(%rsp), %rax
jne 0x4b67
movq 0x48(%rsp), %rdi
movl 0x2c(%rsp), %eax
shll $0x2, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movl $0x1, 0x54(%rsp)
jmp 0x4f73
movl $0x0, 0x24(%rsp)
jmp 0x4bc3
cmpl $0x0, 0x30(%rsp)
jle 0x4b8f
movl $0x1, 0x24(%rsp)
jmp 0x4bc1
movq 0x48(%rsp), %rax
cmpq 0x38(%rsp), %rax
je 0x4bb4
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x2c(%rsp), %eax
shll $0x2, %eax
movslq %eax, %rdx
callq 0x1140
movl 0x34(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0x4f73
jmp 0x4bc3
movl 0x30(%rsp), %eax
movl $0x9, %ecx
cltd
idivl %ecx
movl %eax, 0x20(%rsp)
movl 0x30(%rsp), %eax
movl $0x9, %ecx
cltd
idivl %ecx
movl %edx, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x4d5a
cmpl $0x0, 0x20(%rsp)
je 0x4c77
movl 0x2c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jl 0x4c3e
movq 0x38(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x48(%rsp), %rax
movl 0x1c(%rsp), %ecx
addl 0x20(%rsp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x4c0a
movq 0x48(%rsp), %rdi
movl 0x20(%rsp), %eax
shll $0x2, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
imull $0x9, 0x20(%rsp), %eax
addl 0x34(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x20(%rsp), %eax
addl 0x2c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x30(%rsp)
je 0x4d55
movl 0x34(%rsp), %eax
subl $0x1, %eax
movl $0x9, %ecx
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, 0xc(%rsp)
movl 0xc(%rsp), %eax
addl 0x30(%rsp), %eax
cmpl $0x9, %eax
jle 0x4cb0
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl 0x30(%rsp), %eax
addl 0x34(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x2c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jle 0x4d3c
movq 0x10(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %edi
movl 0x30(%rsp), %esi
callq 0x6670
movl %eax, %edx
movq 0x48(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
movl 0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl $0x9, %ecx
subl 0x30(%rsp), %ecx
movslq %ecx, %rsi
leaq 0xd4a8(%rip), %rcx      # 0x121c0
xorl %edx, %edx
divl (%rcx,%rsi,4)
movl %eax, %edx
movq 0x48(%rsp), %rax
movslq 0x1c(%rsp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x4cc7
movq 0x10(%rsp), %rax
movl (%rax), %edi
movl 0x30(%rsp), %esi
callq 0x6670
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, (%rax)
jmp 0x4f20
cmpl $0x0, 0x20(%rsp)
je 0x4e15
movl 0x20(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0x4da4
movq 0x38(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x48(%rsp), %rax
movl 0x1c(%rsp), %ecx
subl 0x20(%rsp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x4d6d
movl 0x44(%rsp), %eax
movl 0x2c(%rsp), %ecx
subl 0x20(%rsp), %ecx
shll $0x2, %ecx
subl %ecx, %eax
movl %eax, 0x8(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x4dee
movq 0x48(%rsp), %rdi
movslq 0x2c(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movslq 0x20(%rsp), %rcx
xorl %eax, %eax
subq %rcx, %rax
shlq $0x2, %rax
addq %rax, %rdi
movslq 0x8(%rsp), %rdx
xorl %esi, %esi
callq 0x10e0
imull $0x9, 0x20(%rsp), %ecx
movl 0x34(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x34(%rsp)
movl 0x20(%rsp), %ecx
movl 0x2c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x2c(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x30(%rsp)
je 0x4f1e
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl 0x2c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4eb6
movq 0x10(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %edi
movl 0x30(%rsp), %esi
callq 0x66b0
movl %eax, %edx
movq 0x48(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
movl 0x1c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movslq 0x30(%rsp), %rsi
leaq 0xd346(%rip), %rcx      # 0x121c0
xorl %edx, %edx
divl (%rcx,%rsi,4)
movl $0x9, %eax
subl 0x30(%rsp), %eax
movslq %eax, %rcx
leaq 0xd32e(%rip), %rax      # 0x121c0
imull (%rax,%rcx,4), %edx
movq 0x48(%rsp), %rax
movslq 0x1c(%rsp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x4e28
movq 0x10(%rsp), %rax
movl 0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edi
movl 0x30(%rsp), %esi
callq 0x66b0
movl %eax, %edx
movq 0x48(%rsp), %rax
movl 0x2c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x34(%rsp), %eax
subl $0x1, %eax
movl $0x9, %ecx
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, 0x4(%rsp)
movl 0x4(%rsp), %eax
cmpl 0x30(%rsp), %eax
jg 0x4f10
movl 0x2c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x2c(%rsp)
movl 0x30(%rsp), %ecx
movl 0x34(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x34(%rsp)
jmp 0x4f20
jmp 0x4f22
movl 0x28(%rsp), %eax
cmpl 0x34(%rsp), %eax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x4f69
xorl %edi, %edi
leaq 0x1987a(%rip), %rsi     # 0x1e7c3
leaq 0xd18e(%rip), %rdx      # 0x120de
leaq 0x19825(%rip), %rcx     # 0x1e77c
movl $0x182, %r8d            # imm = 0x182
movb $0x0, %al
callq 0xe010
callq 0x1060
jmp 0x4f6b
movl 0x34(%rsp), %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopl (%rax)