// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/apn/integer/gcd.c
// Function: tt_int_extgcd
int tt_int_extgcd(struct tt_int *g, struct tt_int *u, struct tt_int *v,
		const struct tt_int *a, const struct tt_int *b)
{
	/* u = 1, v = 0 */
	tt_int_from_uint(u, 1);
	_tt_int_zero(v);

	if (_tt_int_is_zero(a)) {
		__tt_swap(*u, *v);
		return copy_abs(g, b);
	} else if (_tt_int_is_zero(b)) {
		return copy_abs(g, a);
	}

	/* Copy int buffer */
	void *buf = malloc((a->msb+b->msb)*_tt_word_sz);
	if (!buf)
		return TT_ENOMEM;
	_tt_word *_a = buf;
	_tt_word *_b = _a + a->msb;
	memcpy(_a, a->buf, a->msb*_tt_word_sz);
	memcpy(_b, b->buf, b->msb*_tt_word_sz);

	int ret = extgcd_binary(g, u, v, _a, a->msb, _b, b->msb);

	/* Adjust coefficient sign */
	if (a->sign)
		u->sign ^= 1;
	if (b->sign)
		v->sign ^= 1;

	free(buf);
	return ret;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0x86c0
movq 0x58(%rsp), %rdi
callq 0x6a60
movq 0x50(%rsp), %rdi
callq 0xbe70
testb $0x1, %al
jne 0xc186
jmp 0xc1fe
jmp 0xc188
movq 0x60(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0x60(%rsp), %rax
movq 0x58(%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 0x58(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, (%rax)
movq 0x38(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x68(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0xbeb0
movl %eax, 0x74(%rsp)
jmp 0xc337
movq 0x48(%rsp), %rdi
callq 0xbe70
testb $0x1, %al
jne 0xc20e
jmp 0xc226
movq 0x68(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0xbeb0
movl %eax, 0x74(%rsp)
jmp 0xc337
jmp 0xc228
movq 0x50(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x48(%rsp), %rcx
addl 0x8(%rcx), %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1160
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0xc25d
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0xc337
movq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x50(%rsp), %rcx
movslq 0x8(%rcx), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x50(%rsp), %rax
movl 0x8(%rax), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x18(%rsp), %rdi
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x48(%rsp), %rax
movl 0x8(%rax), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x50(%rsp), %rax
movl 0x8(%rax), %r8d
movq 0x18(%rsp), %r9
movq 0x48(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, (%rsp)
callq 0xc340
movl %eax, 0x14(%rsp)
movq 0x50(%rsp), %rax
cmpl $0x0, (%rax)
je 0xc30f
movq 0x60(%rsp), %rax
movl (%rax), %ecx
xorl $0x1, %ecx
movl %ecx, (%rax)
movq 0x48(%rsp), %rax
cmpl $0x0, (%rax)
je 0xc325
movq 0x58(%rsp), %rax
movl (%rax), %ecx
xorl $0x1, %ecx
movl %ecx, (%rax)
movq 0x28(%rsp), %rdi
callq 0x1030
movl 0x14(%rsp), %eax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq