// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %rbp
movl $0x1, %esi
movq %rbx, %rdi
callq 0x5854
movq %r15, %rdi
callq 0x4a46
movslq 0x8(%r13), %rcx
cmpq $0x1, %rcx
jne 0x7b15
movq 0x10(%r13), %rax
cmpq $0x0, (%rax)
je 0x7c81
movq %rbx, 0x40(%rsp)
movslq 0x8(%r14), %r12
cmpq $0x1, %r12
jne 0x7b32
movq 0x10(%r14), %rax
cmpq $0x0, (%rax)
je 0x808d
movq %rbp, 0xa8(%rsp)
leal (%r12,%rcx), %eax
shll $0x3, %eax
movslq %eax, %rdi
movq %rcx, %rbx
callq 0x1140
testq %rax, %rax
je 0x7c77
movq %rax, %rbp
movq %r15, 0x38(%rsp)
leaq (%rax,%rbx,8), %rax
movq %r13, 0xa0(%rsp)
movq 0x10(%r13), %rsi
movq %rbx, 0x8(%rsp)
leaq (,%rbx,8), %rdx
movq %rax, %rbx
movq %rbp, %rdi
callq 0x1120
movq %r14, 0x48(%rsp)
movq 0x10(%r14), %rsi
movq %r12, %rdx
shlq $0x3, %rdx
movq %rbx, %rdi
callq 0x1120
movq %r12, 0x10(%rsp)
movl %r12d, 0x4(%rsp)
callq 0x48dc
movq %rax, %r14
callq 0x48dc
movq %rax, %r12
movl $0x1, %esi
movq %rax, %rdi
callq 0x5854
movq (%rbp), %rdi
xorl %r15d, %r15d
movl $0x0, %r13d
testq %rdi, %rdi
jne 0x7bed
leaq 0x8(%rbp), %rax
xorl %r13d, %r13d
addl $0x3f, %r13d
movq (%rax), %rdi
addq $0x8, %rax
testq %rdi, %rdi
je 0x7bdd
movq %rbp, 0x28(%rsp)
callq 0x4a7d
movl %eax, %ebp
addl %r13d, %ebp
movq (%rbx), %rdi
testq %rdi, %rdi
jne 0x7c29
movq 0x28(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rax,%rcx,8), %rax
addq $0x8, %rax
xorl %r15d, %r15d
addl $0x3f, %r15d
movq (%rax), %rdi
addq $0x8, %rax
testq %rdi, %rdi
je 0x7c19
callq 0x4a7d
movl %eax, %r13d
addl %r15d, %r13d
cmpl %r13d, %ebp
cmovbl %ebp, %r13d
testl %r13d, %r13d
je 0x7ccd
movl %r13d, %ebp
negl %ebp
movq 0x28(%rsp), %r15
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x4b6a
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %edx
callq 0x4b6a
movl %eax, 0x4(%rsp)
jmp 0x7cd2
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x80a8
movq 0x10(%rbx), %rax
movq %rax, 0x80(%rsp)
movups (%rbx), %xmm0
movaps %xmm0, 0x70(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x10(%rbx)
movups (%r15), %xmm0
movups %xmm0, (%rbx)
movq 0x80(%rsp), %rax
movq %rax, 0x10(%r15)
movaps 0x70(%rsp), %xmm0
movups %xmm0, (%r15)
testq %rbp, %rbp
je 0x80a6
movq %rbp, %rdi
movq %r14, %rsi
jmp 0x8098
movq 0x28(%rsp), %r15
movq (%r15), %rbp
testb $0x1, %bpl
movq %r13, 0x98(%rsp)
jne 0x7cfe
movq %rbx, 0x20(%rsp)
movl 0x4(%rsp), %eax
movq 0x8(%rsp), %rcx
movl %ecx, 0x4(%rsp)
movq %r15, 0x10(%rsp)
movl %eax, %ecx
jmp 0x7d0d
movq %rbx, 0x10(%rsp)
movq %r15, 0x20(%rsp)
movq 0x8(%rsp), %rcx
movl 0x4(%rsp), %ebx
leal (%rbx,%rcx), %eax
shll $0x3, %eax
movslq %eax, %rdi
movq %rcx, %r13
callq 0x1140
testq %rax, %rax
je 0x8052
movq %rbp, 0x90(%rsp)
movslq %ebx, %r15
movq %r13, 0x8(%rsp)
movslq %r13d, %r13
leaq (%rax,%r13,8), %rbp
movq %rbp, 0x18(%rsp)
movq %rax, %rbx
leal (,%r13,8), %eax
movslq %eax, %rdx
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x1120
leaq (,%r15,8), %rdx
movq %rbp, %rdi
movq 0x10(%rsp), %rbp
movq %rbp, %rsi
callq 0x1120
movq %rbp, %rdi
xorl %eax, %eax
leaq 0x70(%rsp), %rcx
movl %eax, (%rcx)
movl %r13d, 0x4(%rcx)
movl %r13d, 0x8(%rcx)
movq %rbx, 0x88(%rsp)
movq %rbx, 0x10(%rcx)
movq %rcx, %rbx
leaq 0xb0(%rsp), %rbp
movl %eax, (%rbp)
movl %r15d, 0x4(%rbp)
movl %r15d, 0x8(%rbp)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbp)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x4(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x80bc
movq %rax, %r15
subl $0x1, 0x50(%rsp)
jb 0x7e28
movq 0x10(%r12), %rax
testb $0x1, (%rax)
je 0x7e0c
movq %r14, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x6e62
movq %r12, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x7004
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4d51
movq %r12, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4d51
jmp 0x7ddf
movl 0x4(%rsp), %ecx
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rbp
movl %ebp, %esi
movq %r15, %rdx
callq 0x59b9
testl %eax, %eax
jle 0x7e74
movl 0x4(%rsp), %eax
movl %ebp, 0x4(%rsp)
movq 0x30(%rsp), %r13
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %r15
movl %eax, %ecx
movq %r12, %rbx
movq %r14, %rbp
movq %r13, %r12
movq %rsi, 0x10(%rsp)
movq %rsi, %r14
jmp 0x7e8c
movq %r12, %r13
movq %r14, 0x10(%rsp)
movq %rbp, %rcx
movq %rbx, %rdx
movq 0x30(%rsp), %rbx
movq 0x18(%rsp), %rbp
movl 0x4(%rsp), %esi
movq %r15, %rdi
movq %rdx, 0x20(%rsp)
movq %rcx, 0x8(%rsp)
callq 0x593d
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rdi
movq %rdi, %rsi
movq %rbp, 0x18(%rsp)
movq %rbp, %rdx
callq 0x7004
movq %r13, %rdi
movq %r13, %rsi
movq %rbx, 0x30(%rsp)
movq %rbx, %rdx
callq 0x7004
movq %r15, %rdi
cmpl $0x1, 0x4(%rsp)
leaq 0x70(%rsp), %rbx
leaq 0xb0(%rsp), %rbp
jne 0x7dcd
cmpq $0x0, (%rdi)
movq %r13, %r12
movq 0x10(%rsp), %r14
jne 0x7dcd
movq 0x88(%rsp), %rdi
callq 0x1030
movq 0x40(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %rbx, %r14
movq 0x38(%rsp), %r12
movq 0x10(%rsp), %rdi
je 0x7f3f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49db
movq %r12, %rdi
movq 0x30(%rsp), %r13
movq %r13, %rsi
callq 0x49db
movq %r14, %rdi
callq 0x493c
movq %r13, %rdi
callq 0x493c
testb $0x1, 0x90(%rsp)
movq 0x48(%rsp), %rbp
jne 0x7f91
movq 0x10(%rbx), %rax
movq %rax, 0x60(%rsp)
movups (%rbx), %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x10(%r12), %rax
movq %rax, 0x10(%rbx)
movups (%r12), %xmm0
movups %xmm0, (%rbx)
movq 0x60(%rsp), %rax
movq %rax, 0x10(%r12)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%r12)
xorl %ebx, %ebx
movq 0xa8(%rsp), %r13
testq %r13, %r13
je 0x8061
movq %r13, %rdi
callq 0x4a46
movq 0x98(%rsp), %r14
leal 0x3e(%r14), %esi
imulq $0x4104105, %rsi, %rax  # imm = 0x4104105
shrq $0x20, %rax
subl %eax, %esi
shrl %esi
addl %eax, %esi
shrl $0x5, %esi
movq 0x8(%rsp), %r15
addl %r15d, %esi
movq %r13, %rdi
callq 0x4952
movl %eax, %ebx
testl %eax, %eax
jne 0x8061
movl %r14d, %eax
imulq $0x4104105, %rax, %rax  # imm = 0x4104105
shrq $0x20, %rax
movq %r15, %rcx
movl %r14d, %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 %r14d, %ebx
leal (,%r15,8), %r14d
movq 0x10(%r13), %rdi
addq %r14, %rdi
leal (,%rcx,8), %eax
movslq %eax, %rdx
movq 0x20(%rsp), %rsi
callq 0x1120
addq 0x10(%r13), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movl %ebx, %edx
callq 0x4b6a
addl %r15d, %eax
movl %eax, 0x8(%r13)
xorl %ebx, %ebx
jmp 0x8061
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x48(%rsp), %rbp
movq 0x38(%rsp), %r12
movq 0xa0(%rsp), %rax
cmpl $0x0, (%rax)
je 0x8076
movq 0x40(%rsp), %rax
xorb $0x1, (%rax)
cmpl $0x0, (%rbp)
je 0x8081
xorb $0x1, (%r12)
movq 0x28(%rsp), %rdi
callq 0x1030
jmp 0x80a8
testq %rbp, %rbp
je 0x80a6
movq %rbp, %rdi
movq %r13, %rsi
callq 0x49db
movl $0x0, (%rbp)
jmp 0x80aa
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq