// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/apn/integer/gcd.c
// Function: gcd_binary
static int gcd_binary(struct tt_int *g, _tt_word *a, int msba,
		_tt_word *b, int msbb)
{
	if (msba == 1 && msbb == 1) {
		tt_int_from_uint(g, gcd_naive(*a, *b));
		return 0;
	}

	uint shifta, shiftb;
	a = to_odd(a, &msba, &shifta);
	b = to_odd(b, &msbb, &shiftb);
	const uint shift = _tt_min(shifta, shiftb);

	int cmp;
	while ((cmp = _tt_int_cmp_buf(a, msba, b, msbb))) {
		if (cmp < 0) {
			__tt_swap(a, b);
			__tt_swap(msba, msbb);
		}
		msba = _tt_int_sub_buf(a, msba, b, msbb);
		a = to_odd(a, &msba, &shifta);
	}

	_tt_int_zero(g);
	int ret = _tt_int_realloc(g,
			msba + (shift+_tt_word_bits-1)/_tt_word_bits);
	if (ret)
		return ret;

	const uint sh_words = shift / _tt_word_bits;
	const uint sh_bits = shift % _tt_word_bits;
	memcpy(g->buf+sh_words, a, msba*_tt_word_sz);
	g->msb = _tt_int_shift_buf(g->buf+sh_words, msba, sh_bits) + sh_words;

	return 0;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movl %edx, 0x5c(%rsp)
movq %rcx, 0x50(%rsp)
movl %r8d, 0x4c(%rsp)
cmpl $0x1, 0x5c(%rsp)
jne 0xbf63
cmpl $0x1, 0x4c(%rsp)
jne 0xbf63
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x60(%rsp), %rax
movq (%rax), %rdi
movq 0x50(%rsp), %rax
movq (%rax), %rsi
callq 0xca40
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x86c0
movl $0x0, 0x74(%rsp)
jmp 0xc133
movq 0x60(%rsp), %rdi
leaq 0x5c(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0xca90
movq %rax, 0x60(%rsp)
movq 0x50(%rsp), %rdi
leaq 0x4c(%rsp), %rsi
leaq 0x44(%rsp), %rdx
callq 0xca90
movq %rax, 0x50(%rsp)
movl 0x48(%rsp), %eax
movl %eax, 0x3c(%rsp)
movl 0x44(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x38(%rsp), %eax
jae 0xbfb9
movl 0x3c(%rsp), %eax
movl %eax, 0xc(%rsp)
jmp 0xbfc1
movl 0x38(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
movl %eax, 0x40(%rsp)
movq 0x60(%rsp), %rdi
movl 0x5c(%rsp), %esi
movq 0x50(%rsp), %rdx
movl 0x4c(%rsp), %ecx
callq 0x8ad0
movl %eax, 0x30(%rsp)
cmpl $0x0, %eax
je 0xc06d
cmpl $0x0, 0x30(%rsp)
jge 0xc034
jmp 0xbffa
movq 0x60(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0xc01a
movl 0x5c(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x4c(%rsp)
jmp 0xc034
movq 0x60(%rsp), %rdi
movl 0x5c(%rsp), %esi
movq 0x50(%rsp), %rdx
movl 0x4c(%rsp), %ecx
callq 0x8940
movl %eax, 0x5c(%rsp)
movq 0x60(%rsp), %rdi
leaq 0x5c(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0xca90
movq %rax, 0x60(%rsp)
jmp 0xbfd1
movq 0x68(%rsp), %rdi
callq 0x6a60
movq 0x68(%rsp), %rdi
movl 0x5c(%rsp), %esi
movl 0x40(%rsp), %eax
addl $0x3f, %eax
subl $0x1, %eax
movl $0x3f, %ecx
xorl %edx, %edx
divl %ecx
addl %eax, %esi
callq 0x68d0
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0xc0b2
movl 0x20(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0xc133
movl 0x40(%rsp), %eax
movl $0x3f, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, 0x1c(%rsp)
movl 0x40(%rsp), %eax
movl $0x3f, %ecx
xorl %edx, %edx
divl %ecx
movl %edx, 0x18(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rdi
movl 0x1c(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movq 0x60(%rsp), %rsi
movl 0x5c(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rdi
movl 0x1c(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x5c(%rsp), %esi
movl 0x18(%rsp), %edx
callq 0x6d10
movl %eax, %ecx
addl 0x1c(%rsp), %ecx
movq 0x68(%rsp), %rax
movl %ecx, 0x8(%rax)
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopl (%rax)