// File: /workspace/github_c_makefile_star2_O3/cyb70289[P]tt/src/apn/integer/gcd.c
// Function: tt_int_gcd
int tt_int_gcd(struct tt_int *g, const struct tt_int *a, const struct tt_int *b)
{
	if (_tt_int_is_zero(a))
		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 = gcd_binary(g, _a, a->msb, _b, b->msb);

	free(buf);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movslq 0x8(%rsi), %r12
cmpq $0x1, %r12
jne 0x7827
movq 0x10(%r14), %rax
cmpq $0x0, (%rax)
je 0x7a5e
movslq 0x8(%rbx), %r13
cmpq $0x1, %r13
jne 0x783f
movq 0x10(%rbx), %rax
cmpq $0x0, (%rax)
je 0x7a6b
leal (%r12,%r13), %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1140
testq %rax, %rax
je 0x78dd
movq %r15, 0x18(%rsp)
movl %r13d, %ebp
xorl $0x1, %ebp
movl %r12d, %r15d
xorl $0x1, %r15d
leaq (%rax,%r12,8), %rcx
movq %rcx, 0x10(%rsp)
movq 0x10(%r14), %rsi
movq %r12, %rdx
shlq $0x3, %rdx
movq %rax, %r14
movq %rax, %rdi
callq 0x1120
movq 0x10(%rbx), %rsi
movq %r13, %rdx
shlq $0x3, %rdx
movq 0x10(%rsp), %rdi
movq %rdi, %rbx
callq 0x1120
movl %r12d, 0x8(%rsp)
movl %r13d, 0xc(%rsp)
orl %ebp, %r15d
movq %r14, 0x28(%rsp)
jne 0x78e7
movq (%r14), %rax
movq (%rbx), %rdx
testq %rdx, %rdx
movq 0x18(%rsp), %rdi
je 0x7a88
movq %rdx, %rsi
xorl %edx, %edx
divq %rsi
movq %rsi, %rax
testq %rdx, %rdx
jne 0x78c8
jmp 0x7a8b
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x7a9c
leaq 0x8(%rsp), %rsi
leaq 0x24(%rsp), %rdx
movq %r14, %rdi
movq %rdx, %r14
callq 0x80ca
movq %rax, %r13
leaq 0xc(%rsp), %rbp
leaq 0x34(%rsp), %r12
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x80ca
movq %rax, %r15
movl (%r14), %eax
movl (%r12), %ecx
cmpl %ecx, %eax
cmovbl %eax, %ecx
movq %rcx, 0x10(%rsp)
leaq 0x8(%rsp), %rax
movl (%rax), %r12d
movl (%rbp), %ebx
movq %r13, %rdi
movl %r12d, %esi
movq %r15, %rdx
movl %ebx, %ecx
callq 0x5974
testl %eax, %eax
je 0x79af
leaq 0x24(%rsp), %rbp
testl %eax, %eax
js 0x7960
movl %ebx, %ecx
movl %r12d, %ebx
movq %r15, %r14
movq %r13, %r15
jmp 0x796b
movl %r12d, 0xc(%rsp)
movl %r12d, %ecx
movq %r13, %r14
movq %r15, %rdi
movl %ebx, %esi
movq %r14, %rdx
callq 0x58f2
movl %eax, 0x8(%rsp)
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x80ca
movq %rax, %r13
movl 0x8(%rsp), %r12d
movl 0xc(%rsp), %ebx
movq %rax, %rdi
movl %r12d, %esi
movq %r14, %rdx
movl %ebx, %ecx
callq 0x5974
movq %r14, %r15
testl %eax, %eax
jne 0x794f
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x4a77
movq 0x10(%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
addl %r12d, %esi
movq %rbx, %rdi
callq 0x4986
movl %eax, %ebp
testl %eax, %eax
jne 0x7a92
movl %r14d, %eax
imulq $0x4104105, %rax, %rax  # imm = 0x4104105
shrq $0x20, %rax
movq %rbx, %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(%rcx), %rdi
addq %r14, %rdi
leal (,%r12,8), %eax
movslq %eax, %rdx
movq %r13, %rsi
callq 0x1120
movq 0x18(%rsp), %r13
addq 0x10(%r13), %r14
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x4b7f
addl %r15d, %eax
movl %eax, 0x8(%r13)
jmp 0x7a92
testq %r15, %r15
je 0x7a84
movq %r15, %rdi
movq %rbx, %rsi
jmp 0x7a76
testq %r15, %r15
je 0x7a84
movq %r15, %rdi
movq %r14, %rsi
callq 0x4a0f
movl $0x0, (%r15)
jmp 0x7a9e
xorl %ebp, %ebp
jmp 0x7a9c
movq %rax, %rsi
callq 0x5804
xorl %ebp, %ebp
movq 0x28(%rsp), %rdi
callq 0x1030
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq