// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r8, %rbx
movq %rcx, %rbp
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %r12
movl $0x1, %esi
movq %r13, %rdi
callq 0x5804
movq %r14, %rdi
callq 0x4a77
movslq 0x8(%rbp), %r15
cmpq $0x1, %r15
jne 0x7afa
movq 0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x7c79
movq %r12, 0x58(%rsp)
movslq 0x8(%rbx), %r12
cmpq $0x1, %r12
jne 0x7b17
movq 0x10(%rbx), %rax
cmpq $0x0, (%rax)
je 0x8097
leal (%r12,%r15), %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1140
testq %rax, %rax
je 0x7c6f
movq %r15, %rcx
movq %rax, %r15
movq %r13, 0x28(%rsp)
movq %r14, 0x40(%rsp)
leaq (%rax,%rcx,8), %r14
movq %rbp, 0x38(%rsp)
movq 0x10(%rbp), %rsi
movq %rcx, 0x8(%rsp)
leaq (,%rcx,8), %rdx
movq %rax, %rdi
callq 0x1120
movq %rbx, 0xa8(%rsp)
movq 0x10(%rbx), %rsi
movq %r12, %rdx
shlq $0x3, %rdx
movq %r14, 0x18(%rsp)
movq %r14, %rdi
callq 0x1120
movq %r12, 0x10(%rsp)
movl %r12d, 0x4(%rsp)
callq 0x4910
movq %rax, %r13
callq 0x4910
movq %rax, %r14
movl $0x1, %esi
movq %rax, %rdi
callq 0x5804
movq %r15, 0x50(%rsp)
movq (%r15), %rax
xorl %r15d, %r15d
movl $0x0, %ebx
movq %rax, %rdi
movq %rax, 0x48(%rsp)
testq %rax, %rax
jne 0x7bdf
movq 0x50(%rsp), %rax
addq $0x8, %rax
xorl %ebx, %ebx
addl $0x3f, %ebx
movq (%rax), %rdi
addq $0x8, %rax
testq %rdi, %rdi
je 0x7bd0
callq 0x4aae
movl %eax, %ebp
addl %ebx, %ebp
movq 0x18(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
movq 0x50(%rsp), %rbx
jne 0x7c1a
movq 0x8(%rsp), %rax
leaq (%rbx,%rax,8), %rax
addq $0x8, %rax
xorl %r15d, %r15d
addl $0x3f, %r15d
movq (%rax), %rdi
addq $0x8, %rax
testq %rdi, %rdi
je 0x7c0a
callq 0x4aae
addl %r15d, %eax
cmpl %eax, %ebp
cmovbl %ebp, %eax
testl %eax, %eax
movq %rax, 0xa0(%rsp)
je 0x7cdc
movl %eax, %ebp
negl %ebp
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x4b7f
movl %eax, %r15d
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %edx
callq 0x4b7f
movl %eax, 0x4(%rsp)
movq (%rbx), %rcx
movq 0x38(%rsp), %rbp
jmp 0x7cf0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x80b6
movq 0x10(%r13), %rax
movq %rax, 0x90(%rsp)
movups (%r13), %xmm0
movaps %xmm0, 0x80(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%r13)
movups (%r14), %xmm0
movups %xmm0, (%r13)
movq 0x90(%rsp), %rax
movq %rax, 0x10(%r14)
movaps 0x80(%rsp), %xmm0
movups %xmm0, (%r14)
testq %r12, %r12
je 0x80b4
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4a0f
movl $0x0, (%r12)
jmp 0x80b8
movq 0x38(%rsp), %rbp
movq 0x48(%rsp), %rcx
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %r15
testb $0x1, %cl
movq %rcx, 0x48(%rsp)
jne 0x7d15
movl %r15d, 0x4(%rsp)
movl %r15d, %ecx
movq %rcx, 0x20(%rsp)
movq %rbx, 0x8(%rsp)
movl %eax, %edx
movq %rdx, 0x10(%rsp)
jmp 0x7d33
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movl %r15d, %edx
movq %rdx, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
addl %eax, %r15d
shll $0x3, %r15d
movslq %r15d, %rdi
callq 0x1140
testq %rax, %rax
je 0x8062
movslq 0x10(%rsp), %rbp
leaq (%rax,%rbp,8), %r12
movq %r12, 0x30(%rsp)
movq %rax, %r15
leal (,%rbp,8), %eax
movslq %eax, %rdx
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x1120
movq 0x20(%rsp), %rbx
leal (,%rbx,8), %eax
movslq %eax, %rdx
movq %r12, %rdi
movq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0x1120
movq %r12, %rdi
xorl %eax, %eax
leaq 0x80(%rsp), %rcx
movl %eax, (%rcx)
movl %ebp, 0x4(%rcx)
movl %ebp, 0x8(%rcx)
movq %r15, 0x98(%rsp)
movq %r15, 0x10(%rcx)
leaq 0xb0(%rsp), %rcx
movl %eax, (%rcx)
movl %ebx, 0x4(%rcx)
movl %ebx, 0x8(%rcx)
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rcx)
movq 0x40(%rsp), %rbp
movq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %rbp, 0x30(%rsp)
leaq 0x4(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x80ca
movq %rax, %r15
subl $0x1, 0x60(%rsp)
movq 0x10(%rsp), %rbx
leaq 0x80(%rsp), %r12
leaq 0xb0(%rsp), %rbp
jb 0x7e54
movq 0x10(%r14), %rax
testb $0x1, (%rax)
je 0x7e33
movq %r13, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x6e1a
movq %r14, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x6fc0
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4d62
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4d62
subl $0x1, 0x60(%rsp)
jae 0x7e0e
movl 0x4(%rsp), %ecx
movq 0x18(%rsp), %r12
movq %r12, %rdi
movl %ebx, %esi
movq %r15, %rdx
callq 0x5974
movl 0x4(%rsp), %ecx
testl %eax, %eax
movq %r15, %rdx
jle 0x7e9b
movl %ebx, 0x4(%rsp)
movl %ebx, %esi
movq 0x30(%rsp), %r15
movq 0x20(%rsp), %rdi
movq %r12, %rbx
movq %r14, %rbp
movq %r13, %r12
movq %r15, %r14
movq %rdi, 0x8(%rsp)
movq %rdi, %r13
jmp 0x7eb8
movl %ecx, %esi
movq %r14, %r15
movq %rbx, %rcx
movq %r13, 0x8(%rsp)
movq %rdx, %rbx
movq %r12, %rdx
movq 0x30(%rsp), %rbp
movq 0x20(%rsp), %r12
movq %rbx, %rdi
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
callq 0x58f2
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rdi
movq %rdi, %rsi
movq %r12, 0x20(%rsp)
movq %r12, %rdx
callq 0x6fc0
movq %r15, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x6fc0
movq %rbx, %rdi
cmpl $0x1, 0x4(%rsp)
jne 0x7ddb
cmpq $0x0, (%rdi)
movq %r15, %r14
movq 0x8(%rsp), %r13
jne 0x7ddb
movq 0x98(%rsp), %rdi
callq 0x1030
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r12
cmpq %rdi, %r12
movq 0x40(%rsp), %r14
movq 0x8(%rsp), %rax
je 0x7f50
movq %r12, %rsi
callq 0x4a0f
movq %r14, %rdi
movq %rbp, %r15
movq %rbp, %rsi
callq 0x4a0f
movq %r12, %rax
movq %rax, %rdi
callq 0x4970
movq %r15, %rdi
callq 0x4970
testb $0x1, 0x48(%rsp)
movq 0x58(%rsp), %r13
jne 0x7fa3
movq 0x28(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x70(%rsp)
movups (%rcx), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rcx)
movups (%r14), %xmm0
movups %xmm0, (%rcx)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%r14)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%r14)
xorl %ebx, %ebx
testq %r13, %r13
movq 0x38(%rsp), %rbp
movq 0x10(%rsp), %r15
je 0x806c
movq %r13, %rdi
callq 0x4a77
movq 0xa0(%rsp), %r12
leal 0x3e(%r12), %esi
imulq $0x4104105, %rsi, %rax  # imm = 0x4104105
shrq $0x20, %rax
subl %eax, %esi
shrl %esi
addl %eax, %esi
shrl $0x5, %esi
addl %r15d, %esi
movq %r13, %rdi
callq 0x4986
movl %eax, %ebx
testl %eax, %eax
jne 0x806c
movl %r12d, %eax
imulq $0x4104105, %rax, %rax  # imm = 0x4104105
shrq $0x20, %rax
movq %r15, %rcx
movl %r12d, %r15d
subl %eax, %r15d
shrl %r15d
addl %eax, %r15d
shrl $0x5, %r15d
movl %r15d, %eax
shll $0x6, %eax
movl %r15d, %ebx
subl %eax, %ebx
addl %r12d, %ebx
leal (,%r15,8), %r12d
movq 0x10(%r13), %rdi
addq %r12, %rdi
leal (,%rcx,8), %eax
movslq %eax, %rdx
movq 0x18(%rsp), %rsi
callq 0x1120
addq 0x10(%r13), %r12
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movl %ebx, %edx
callq 0x4b7f
addl %r15d, %eax
movl %eax, 0x8(%r13)
xorl %ebx, %ebx
jmp 0x806c
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x40(%rsp), %r14
cmpl $0x0, (%rbp)
movq 0x28(%rsp), %rax
je 0x807a
xorb $0x1, (%rax)
movq 0xa8(%rsp), %rax
cmpl $0x0, (%rax)
je 0x808b
xorb $0x1, (%r14)
movq 0x50(%rsp), %rdi
callq 0x1030
jmp 0x80b6
movq 0x58(%rsp), %rbx
testq %rbx, %rbx
je 0x80b4
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4a0f
movl $0x0, (%rbx)
jmp 0x80b8
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq