// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rdi, %r14
movslq 0x8(%rsi), %r12
cmpq $0x1, %r12
jne 0x6a5b
movq 0x10(%r15), %rax
cmpq $0x0, (%rax)
je 0x6c58
movslq 0x8(%rbx), %r13
cmpq $0x1, %r13
jne 0x6a73
movq 0x10(%rbx), %rax
cmpq $0x0, (%rax)
je 0x6c60
leal (%r12,%r13), %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1140
testq %rax, %rax
je 0x6b05
movq %r14, 0x20(%rsp)
movl %r13d, %ebp
xorl $0x1, %ebp
movl %r12d, %r14d
xorl $0x1, %r14d
leaq (%rax,%r12,8), %rcx
movq %rcx, 0x10(%rsp)
movq 0x10(%r15), %rsi
movq %r12, %rdx
shlq $0x3, %rdx
movq %rax, %r15
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, 0xc(%rsp)
movl %r13d, 0x8(%rsp)
orl %ebp, %r14d
movq %r15, 0x28(%rsp)
jne 0x6b0d
movq (%r15), %rax
movq (%rbx), %rdx
movq 0x20(%rsp), %rdi
testq %rdx, %rdx
je 0x6bad
movq %rdx, %rcx
xorl %edx, %edx
divq %rcx
movq %rcx, %rax
jmp 0x6aef
pushq $-0x1
popq %rbp
jmp 0x6c47
leaq 0xc(%rsp), %r13
leaq 0x34(%rsp), %rbp
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x7203
movq %rax, %r12
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x7203
movq %rax, %r15
movl (%rbp), %eax
movl %eax, 0x1c(%rsp)
movl (%r14), %eax
movq %rax, 0x10(%rsp)
movl 0xc(%rsp), %ebx
movl 0x8(%rsp), %r14d
movq %r12, %rdi
movl %ebx, %esi
movq %r15, %rdx
movl %r14d, %ecx
callq 0x4dca
testl %eax, %eax
je 0x6bbc
js 0x6b7c
movl %r14d, %ecx
movl %ebx, %r14d
movq %r15, %rbx
movq %r12, %r15
jmp 0x6b85
movl %ebx, 0x8(%rsp)
movl %ebx, %ecx
movq %r12, %rbx
movq %r15, %rdi
movl %r14d, %esi
movq %rbx, %rdx
callq 0x4d64
movl %eax, 0xc(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x7203
movq %rax, %r12
movq %rbx, %r15
jmp 0x6b4f
movq %rax, %rsi
callq 0x4c9c
xorl %ebp, %ebp
jmp 0x6c3d
movq 0x10(%rsp), %r13
movl 0x1c(%rsp), %eax
cmpl %r13d, %eax
cmovbl %eax, %r13d
movq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x3fad
leal 0x3e(%r13), %eax
pushq $0x3f
popq %r14
xorl %edx, %edx
divl %r14d
leal (%rax,%rbx), %esi
movq %r15, %rdi
callq 0x3ec0
movl %eax, %ebp
testl %eax, %eax
jne 0x6c3d
movl %r13d, %eax
xorl %edx, %edx
divl %r14d
movl %eax, %r14d
movl %edx, 0x10(%rsp)
movslq %ebx, %rdx
leal (,%r14,8), %r13d
movq 0x10(%r15), %rdi
addq %r13, %rdi
shlq $0x3, %rdx
movq %r12, %rsi
callq 0x1120
addq 0x10(%r15), %r13
movq %r13, %rdi
movl %ebx, %esi
movl 0x10(%rsp), %edx
callq 0x40ab
addl %r14d, %eax
movl %eax, 0x8(%r15)
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
movq %r14, %rdi
movq %rbx, %rsi
jmp 0x6c66
movq %r14, %rdi
movq %r15, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c76