// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rsi, %r12
movq %rdi, %r14
movslq 0x8(%rsi), %rbx
cmpq $0x1, %rbx
jne 0x7848
movq 0x10(%r12), %rax
cmpq $0x0, (%rax)
je 0x7a79
movslq 0x8(%r15), %rbp
cmpq $0x1, %rbp
jne 0x7860
movq 0x10(%r15), %rax
cmpq $0x0, (%rax)
je 0x7a86
leal (%rbx,%rbp), %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1140
testq %rax, %rax
je 0x78fe
movq %r14, 0x20(%rsp)
movl %ebp, %r14d
xorl $0x1, %r14d
movl %ebx, %r13d
xorl $0x1, %r13d
leaq (%rax,%rbx,8), %rcx
movq %rcx, 0x18(%rsp)
movq 0x10(%r12), %rsi
movq %rbx, %rdx
shlq $0x3, %rdx
movq %rax, %r12
movq %rax, %rdi
callq 0x1120
movq 0x10(%r15), %rsi
movq %rbp, %rdx
shlq $0x3, %rdx
movq 0x18(%rsp), %rdi
movq %rdi, %r15
callq 0x1120
movl %ebx, 0xc(%rsp)
movl %ebp, 0x10(%rsp)
orl %r14d, %r13d
movq %r12, 0x28(%rsp)
jne 0x7908
movq (%r12), %rax
movq (%r15), %rdx
testq %rdx, %rdx
movq 0x20(%rsp), %rdi
je 0x7aa3
movq %rdx, %rsi
xorl %edx, %edx
divq %rsi
movq %rsi, %rax
testq %rdx, %rdx
jne 0x78e9
jmp 0x7aa6
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x7ab7
leaq 0xc(%rsp), %r13
leaq 0x14(%rsp), %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x80bc
movq %rax, %rbx
leaq 0x10(%rsp), %r14
leaq 0x34(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x80bc
movq %rax, %rbp
leaq 0x14(%rsp), %rax
movl (%rax), %eax
movl (%r12), %ecx
cmpl %ecx, %eax
cmovbl %eax, %ecx
movq %rcx, 0x18(%rsp)
movl (%r13), %esi
movl (%r14), %ecx
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x59b9
testl %eax, %eax
movq 0x20(%rsp), %r14
je 0x79d6
leaq 0xc(%rsp), %r12
leaq 0x14(%rsp), %r13
testl %eax, %eax
js 0x7981
movq %rbp, %r15
movq %rbx, %rbp
jmp 0x7994
movl 0xc(%rsp), %eax
movl 0x10(%rsp), %ecx
movl %ecx, 0xc(%rsp)
movl %eax, 0x10(%rsp)
movq %rbx, %r15
movl 0xc(%rsp), %esi
movl 0x10(%rsp), %ecx
movq %rbp, %rdi
movq %r15, %rdx
callq 0x593d
movl %eax, 0xc(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x80bc
movq %rax, %rbx
movl 0xc(%rsp), %esi
movl 0x10(%rsp), %ecx
movq %rax, %rdi
movq %r15, %rdx
callq 0x59b9
movq %r15, %rbp
testl %eax, %eax
jne 0x7975
movq %r14, %rdi
callq 0x4a46
movslq 0xc(%rsp), %r12
movq 0x18(%rsp), %r15
leal 0x3e(%r15), %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 %r14, %rdi
callq 0x4952
movl %eax, %ebp
testl %eax, %eax
jne 0x7aad
movl %r15d, %eax
imulq $0x4104105, %rax, %rax  # imm = 0x4104105
shrq $0x20, %rax
movl %r15d, %r13d
subl %eax, %r13d
shrl %r13d
addl %eax, %r13d
shrl $0x5, %r13d
movl %r13d, %eax
shll $0x6, %eax
movl %r13d, %ebp
subl %eax, %ebp
addl %r15d, %ebp
leal (,%r13,8), %r15d
movq 0x10(%r14), %rdi
addq %r15, %rdi
movq %r12, %rdx
shlq $0x3, %rdx
movq %rbx, %rsi
callq 0x1120
addq 0x10(%r14), %r15
movq %r15, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x4b6a
addl %r13d, %eax
movl %eax, 0x8(%r14)
jmp 0x7aab
testq %r14, %r14
je 0x7a9f
movq %r14, %rdi
movq %r15, %rsi
jmp 0x7a91
testq %r14, %r14
je 0x7a9f
movq %r14, %rdi
movq %r12, %rsi
callq 0x49db
movl $0x0, (%r14)
jmp 0x7ab9
xorl %ebp, %ebp
jmp 0x7ab7
movq %rax, %rsi
callq 0x5854
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