// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/apn/integer/gcd.c
// Function: extgcd_binary
static int extgcd_binary(struct tt_int *g, struct tt_int *u, struct tt_int *v,
		_tt_word *a, int msba, _tt_word *b, int msbb)
{
	struct tt_int *u0 = u, *v0 = v;

	/* w = 0, x = 1 */
	struct tt_int *w = tt_int_alloc();
	struct tt_int *x = tt_int_alloc();
	tt_int_from_uint(x, 1);

	const uint shift = _tt_min(__ctz(a), __ctz(b));
	if (shift) {
		/* Remove common trailing zeros */
		msba = _tt_int_shift_buf(a, msba, -shift);
		msbb = _tt_int_shift_buf(b, msbb, -shift);
	}

	/* Make a odd */
	int swapped = 0;
	if ((a[0] & 0x1) == 0) {
		__tt_swap(a, b);
		__tt_swap(msba, msbb);
		swapped = 1;
	}

	/* Save a0, b0 */
	void *buf = malloc((msba+msbb)*_tt_word_sz);
	if (!buf)
		return TT_ENOMEM;
	_tt_word *a0 = buf;
	_tt_word *b0 = a0 + msba;
	memcpy(a0, a, msba*_tt_word_sz);
	memcpy(b0, b, msbb*_tt_word_sz);
	struct tt_int a0i = _TT_INT_DECL(msba, a0);
	struct tt_int b0i = _TT_INT_DECL(msbb, b0);

	do {
		uint tmpsh;
		b = to_odd(b, &msbb, &tmpsh);
		while (tmpsh--) {
			if (x->buf[0] & 0x1) {
				tt_int_add(w, w, &b0i);
				tt_int_sub(x, x, &a0i);
			}
			tt_int_shift(w, -1);
			tt_int_shift(x, -1);
		}

		if (_tt_int_cmp_buf(a, msba, b, msbb) > 0) {
			__tt_swap(a, b);
			__tt_swap(msba, msbb);
			__tt_swap(u, w);
			__tt_swap(v, x);
		}

		msbb = _tt_int_sub_buf(b, msbb, a, msba);
		tt_int_sub(w, w, u);
		tt_int_sub(x, x, v);
	} while (!(msbb == 1 && b[0] == 0));

	free(buf);

	/* Coefficients */
	if (u != u0) {
		_tt_int_copy(u0, u);
		_tt_int_copy(v0, v);
		tt_int_free(u);
		tt_int_free(v);
	} else {
		tt_int_free(w);
		tt_int_free(x);
	}
	if (swapped)
		__tt_swap(*u0, *v0);

	/* GCD */
	if (g) {
		_tt_int_zero(g);
		int ret = _tt_int_realloc(g, msba +
				(shift+_tt_word_bits-1)/_tt_word_bits);
		if (ret)
			return ret;

		const uint sh_words = shift / _tt_word_bits;
		const uint sh_bits = shift % _tt_word_bits;
		memcpy(g->buf+sh_words, a, msba*_tt_word_sz);
		g->msb = _tt_int_shift_buf(g->buf+sh_words, msba, sh_bits) +
			sh_words;
	}

	return 0;
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movl 0x130(%rsp), %eax
movq %rdi, 0x118(%rsp)
movq %rsi, 0x110(%rsp)
movq %rdx, 0x108(%rsp)
movq %rcx, 0x100(%rsp)
movl %r8d, 0xfc(%rsp)
movq %r9, 0xf0(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0xe0(%rsp)
callq 0x6800
movq %rax, 0xd8(%rsp)
callq 0x6800
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rdi
movl $0x1, %esi
callq 0x86c0
movq 0x100(%rsp), %rdi
callq 0xcb30
movl %eax, 0xc8(%rsp)
movq 0xf0(%rsp), %rdi
callq 0xcb30
movl %eax, 0xc4(%rsp)
movl 0xc8(%rsp), %eax
cmpl 0xc4(%rsp), %eax
jae 0xc40f
movl 0xc8(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0xc41a
movl 0xc4(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0xc0(%rsp)
movl 0xc0(%rsp), %eax
movl %eax, 0xcc(%rsp)
cmpl $0x0, 0xcc(%rsp)
je 0xc485
movq 0x100(%rsp), %rdi
movl 0xfc(%rsp), %esi
xorl %edx, %edx
subl 0xcc(%rsp), %edx
callq 0x6d10
movl %eax, 0xfc(%rsp)
movq 0xf0(%rsp), %rdi
movl 0x130(%rsp), %esi
xorl %edx, %edx
subl 0xcc(%rsp), %edx
callq 0x6d10
movl %eax, 0x130(%rsp)
movl $0x0, 0xbc(%rsp)
movq 0x100(%rsp), %rax
movq (%rax), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0xc50e
jmp 0xc4a7
movq 0x100(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0xf0(%rsp)
jmp 0xc4d9
movl 0xfc(%rsp), %eax
movl %eax, 0xac(%rsp)
movl 0x130(%rsp), %eax
movl %eax, 0xfc(%rsp)
movl 0xac(%rsp), %eax
movl %eax, 0x130(%rsp)
movl $0x1, 0xbc(%rsp)
movl 0xfc(%rsp), %eax
addl 0x130(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1160
movq %rax, 0xa0(%rsp)
cmpq $0x0, 0xa0(%rsp)
jne 0xc54a
movl $0xffffffff, 0x124(%rsp) # imm = 0xFFFFFFFF
jmp 0xca26
movq 0xa0(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rax
movslq 0xfc(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rdi
movq 0x100(%rsp), %rsi
movl 0xfc(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x90(%rsp), %rdi
movq 0xf0(%rsp), %rsi
movl 0x130(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movl $0x0, 0x78(%rsp)
movl 0xfc(%rsp), %eax
movl %eax, 0x7c(%rsp)
movl 0xfc(%rsp), %eax
movl %eax, 0x80(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x88(%rsp)
movl $0x0, 0x60(%rsp)
movl 0x130(%rsp), %eax
movl %eax, 0x64(%rsp)
movl 0x130(%rsp), %eax
movl %eax, 0x68(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xf0(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x5c(%rsp), %rdx
callq 0xca90
movq %rax, 0xf0(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x5c(%rsp)
cmpl $0x0, %eax
je 0xc6c3
movq 0xd0(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xc69a
movq 0xd8(%rsp), %rdi
movq 0xd8(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0xa750
movq 0xd0(%rsp), %rdi
movq 0xd0(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0xa890
movq 0xd8(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7000
movq 0xd0(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7000
jmp 0xc63b
movq 0x100(%rsp), %rdi
movl 0xfc(%rsp), %esi
movq 0xf0(%rsp), %rdx
movl 0x130(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jle 0xc79b
jmp 0xc6f1
movq 0x100(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0xf0(%rsp)
jmp 0xc71d
movl 0xfc(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x130(%rsp), %eax
movl %eax, 0xfc(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x130(%rsp)
jmp 0xc743
movq 0x110(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x110(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0xd8(%rsp)
jmp 0xc76f
movq 0x108(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xd0(%rsp)
jmp 0xc79b
movq 0xf0(%rsp), %rdi
movl 0x130(%rsp), %esi
movq 0x100(%rsp), %rdx
movl 0xfc(%rsp), %ecx
callq 0x8940
movl %eax, 0x130(%rsp)
movq 0xd8(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movq 0x110(%rsp), %rdx
callq 0xa890
movq 0xd0(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0xa890
xorl %eax, %eax
cmpl $0x1, 0x130(%rsp)
movb %al, 0xf(%rsp)
jne 0xc822
movq 0xf0(%rsp), %rax
cmpq $0x0, (%rax)
sete %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xc619
movq 0xa0(%rsp), %rdi
callq 0x1030
movq 0x110(%rsp), %rax
cmpq 0xe8(%rsp), %rax
je 0xc895
movq 0xe8(%rsp), %rdi
movq 0x110(%rsp), %rsi
callq 0x69c0
movq 0xe0(%rsp), %rdi
movq 0x108(%rsp), %rsi
callq 0x69c0
movq 0x110(%rsp), %rdi
callq 0x68b0
movq 0x108(%rsp), %rdi
callq 0x68b0
jmp 0xc8af
movq 0xd8(%rsp), %rdi
callq 0x68b0
movq 0xd0(%rsp), %rdi
callq 0x68b0
cmpl $0x0, 0xbc(%rsp)
je 0xc927
jmp 0xc8bb
movq 0xe8(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x28(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0xe8(%rsp), %rax
movq 0xe0(%rsp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq 0xe0(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rax)
jmp 0xc927
cmpq $0x0, 0x118(%rsp)
je 0xca1b
movq 0x118(%rsp), %rdi
callq 0x6a60
movq 0x118(%rsp), %rdi
movl 0xfc(%rsp), %esi
movl 0xcc(%rsp), %eax
addl $0x3f, %eax
subl $0x1, %eax
movl $0x3f, %ecx
xorl %edx, %edx
divl %ecx
addl %eax, %esi
callq 0x68d0
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
je 0xc98a
movl 0x1c(%rsp), %eax
movl %eax, 0x124(%rsp)
jmp 0xca26
movl 0xcc(%rsp), %eax
movl $0x3f, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, 0x18(%rsp)
movl 0xcc(%rsp), %eax
movl $0x3f, %ecx
xorl %edx, %edx
divl %ecx
movl %edx, 0x14(%rsp)
movq 0x118(%rsp), %rax
movq 0x10(%rax), %rdi
movl 0x18(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movq 0x100(%rsp), %rsi
movl 0xfc(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x118(%rsp), %rax
movq 0x10(%rax), %rdi
movl 0x18(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movl 0xfc(%rsp), %esi
movl 0x14(%rsp), %edx
callq 0x6d10
movl %eax, %ecx
addl 0x18(%rsp), %ecx
movq 0x118(%rsp), %rax
movl %ecx, 0x8(%rax)
movl $0x0, 0x124(%rsp)
movl 0x124(%rsp), %eax
addq $0x128, %rsp            # imm = 0x128
retq
nopw %cs:(%rax,%rax)