// File: /workspace/github_c_makefile_star2_O2/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 $0xe8, %rsp
movq %r8, %rbx
movq %rcx, %rbp
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r12
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x4c9c
movq %r13, %rdi
callq 0x3fad
movslq 0x8(%rbp), %r15
cmpq $0x1, %r15
jne 0x6cd7
movq 0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x6ddd
movq %r12, 0x50(%rsp)
movslq 0x8(%rbx), %r12
cmpq $0x1, %r12
jne 0x6cf4
movq 0x10(%rbx), %rax
cmpq $0x0, (%rax)
je 0x71e5
leal (%r12,%r15), %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1140
testq %rax, %rax
je 0x6dd5
movq %r13, 0x38(%rsp)
movq %r14, 0x30(%rsp)
leaq (%rax,%r15,8), %r13
movq %rbp, 0xb8(%rsp)
movq 0x10(%rbp), %rsi
movq %r15, %rdx
shlq $0x3, %rdx
movq %rax, %rbp
movq %rax, %rdi
callq 0x1120
movq %rbx, 0xc0(%rsp)
movq 0x10(%rbx), %rsi
movq %r12, %rdx
shlq $0x3, %rdx
movq %r13, %rdi
callq 0x1120
movl %r12d, 0xc(%rsp)
callq 0x3e50
movq %rax, %r14
callq 0x3e50
movq %rax, %rbx
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x4c9c
movq %rbp, 0x48(%rsp)
movq %rbp, %rdi
callq 0x725a
movl %eax, %ebp
movq %r13, 0x10(%rsp)
movq %r13, %rdi
callq 0x725a
cmpl %eax, %ebp
cmovbl %ebp, %eax
testl %eax, %eax
movq %rax, 0xa8(%rsp)
je 0x6e2a
movl %eax, %ebp
negl %ebp
movq 0x48(%rsp), %r13
movq %r13, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x40ab
movl %eax, %r15d
movq 0x10(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x40ab
movl %eax, %r12d
movl %eax, 0xc(%rsp)
jmp 0x6e2f
pushq $-0x1
popq %rbx
jmp 0x71d1
movq 0x10(%r14), %rax
movq %rax, 0x90(%rsp)
movups (%r14), %xmm0
movaps %xmm0, 0x80(%rsp)
movq 0x10(%r13), %rax
movq %rax, 0x10(%r14)
movups (%r13), %xmm0
movups %xmm0, (%r14)
movq 0x90(%rsp), %rax
movq %rax, 0x10(%r13)
movaps 0x80(%rsp), %xmm0
movups %xmm0, (%r13)
movq %r12, %rdi
movq %rbx, %rsi
jmp 0x71ed
movq 0x48(%rsp), %r13
movq (%r13), %rax
movq %rax, 0xb0(%rsp)
testb $0x1, %al
jne 0x6e56
movl %r15d, 0xc(%rsp)
movl %r15d, %ebp
movq %r13, 0x18(%rsp)
movl %r12d, %eax
movq %rax, 0x28(%rsp)
jmp 0x6e70
movl %r12d, %ebp
movq 0x10(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movl %r15d, %ecx
movq %rcx, 0x28(%rsp)
movq %r13, 0x10(%rsp)
addl %r12d, %r15d
shll $0x3, %r15d
movslq %r15d, %rdi
callq 0x1140
testq %rax, %rax
movq 0x38(%rsp), %rcx
je 0x719e
movslq 0x28(%rsp), %r12
leaq (%rax,%r12,8), %r13
movq %r13, 0x20(%rsp)
movq %rbp, %r15
movq %rax, %rbp
leal (,%r12,8), %eax
movslq %eax, %rdx
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
callq 0x1120
leal (,%r15,8), %eax
movslq %eax, %rdx
movq %r13, %rdi
movq 0x18(%rsp), %r13
movq %r13, %rsi
callq 0x1120
movq %r13, %rdi
leaq 0x80(%rsp), %rcx
andl $0x0, (%rcx)
movl %r12d, 0x4(%rcx)
movl %r12d, 0x8(%rcx)
movq %rbp, 0xa0(%rsp)
movq %rbp, 0x10(%rcx)
movq %rcx, %rbp
leaq 0xd0(%rsp), %r12
andl $0x0, (%r12)
movl %r15d, 0x4(%r12)
movl %r15d, 0x8(%r12)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%r12)
pushq $-0x1
popq %r15
movq 0x38(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xc(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x7203
movq %rax, 0xc8(%rsp)
subl $0x1, 0x60(%rsp)
jb 0x6f8d
movq 0x10(%rbx), %rax
testb $0x1, (%rax)
je 0x6f75
movq %r14, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x606f
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x61ff
movq %r14, %rdi
movl %r15d, %esi
callq 0x4264
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4264
jmp 0x6f49
movl 0xc(%rsp), %ecx
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq 0x28(%rsp), %r13
movl %r13d, %esi
movq 0xc8(%rsp), %r12
movq %r12, %rdx
callq 0x4dca
movl 0xc(%rsp), %ecx
testl %eax, %eax
jle 0x6fe9
movl %r13d, 0xc(%rsp)
movl %r13d, %esi
movq 0x40(%rsp), %rdi
movq 0x20(%rsp), %rax
movq %r12, %rdx
movq %rbp, %r12
movq %rbx, %rbp
movq %r14, %r13
movq %rdi, 0x58(%rsp)
movq %rdi, %rbx
movq %rax, 0x18(%rsp)
movq %rax, %r14
jmp 0x7005
movl %ecx, %esi
movq %rbx, 0x58(%rsp)
movq %r14, 0x18(%rsp)
movq %rbp, %rdx
movq %r13, %rcx
movq 0x40(%rsp), %rbp
movq 0x20(%rsp), %r13
movq %r12, %rdi
movq %rdx, 0x10(%rsp)
movq %rcx, 0x28(%rsp)
callq 0x4d64
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, %rsi
movq %r13, 0x20(%rsp)
movq %r13, %rdx
callq 0x61ff
movq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r13, %rsi
movq %rbp, 0x40(%rsp)
movq %rbp, %rdx
callq 0x61ff
movq %r12, %rdi
cmpl $0x1, 0xc(%rsp)
leaq 0x80(%rsp), %rbp
leaq 0xd0(%rsp), %r12
jne 0x6f32
cmpq $0x0, (%rdi)
movq %r13, %rbx
movq 0x18(%rsp), %r14
jne 0x6f32
movq 0xa0(%rsp), %rdi
callq 0x1030
movq 0x30(%rsp), %r14
movq 0x20(%rsp), %r12
cmpq %r14, %r12
movq 0x38(%rsp), %rbx
movq 0x18(%rsp), %rdi
je 0x70bc
movq %r14, %rdi
movq %r12, %rsi
callq 0x3f47
movq %rbx, %rdi
movq 0x40(%rsp), %r13
movq %r13, %rsi
callq 0x3f47
movq %r12, %rdi
callq 0x3eaa
movq %r13, %rdi
callq 0x3eaa
testb $0x1, 0xb0(%rsp)
movq 0x50(%rsp), %r12
jne 0x710a
movq 0x10(%r14), %rax
movq %rax, 0x70(%rsp)
movups (%r14), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r14)
movups (%rbx), %xmm0
movups %xmm0, (%r14)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rbx)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rbx)
testq %r12, %r12
je 0x7195
movq %r12, %rdi
callq 0x3fad
movq 0xa8(%rsp), %r15
leal 0x3e(%r15), %eax
pushq $0x3f
popq %r13
xorl %edx, %edx
divl %r13d
movq 0x28(%rsp), %rbp
leal (%rax,%rbp), %esi
movq %r12, %rdi
callq 0x3ec0
movl %eax, %ebx
testl %eax, %eax
jne 0x7197
movl %r15d, %eax
xorl %edx, %edx
divl %r13d
movl %edx, %ebx
movl %eax, %r14d
leal (,%r14,8), %r15d
movq 0x10(%r12), %rdi
addq %r15, %rdi
leal (,%rbp,8), %eax
movslq %eax, %rdx
movq 0x10(%rsp), %rsi
callq 0x1120
addq 0x10(%r12), %r15
movq %r15, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x40ab
addl %r14d, %eax
movq 0x30(%rsp), %r14
movl %eax, 0x8(%r12)
xorl %ebx, %ebx
movq 0x38(%rsp), %rcx
jmp 0x71a6
pushq $-0x1
popq %rbx
movq 0x30(%rsp), %r14
movq 0xb8(%rsp), %rax
cmpl $0x0, (%rax)
movq 0x48(%rsp), %rdi
je 0x71bc
xorb $0x1, (%r14)
movq 0xc0(%rsp), %rax
cmpl $0x0, (%rax)
je 0x71cc
xorb $0x1, (%rcx)
callq 0x1030
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rsp), %rdi
movq %rbp, %rsi
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c76