#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp_si(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init2(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_si(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_submul(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ mpz_tdiv_qr(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/);
void extend_gcd(mpz_t a, mpz_t b, mpz_t x, mpz_t y, int length) {
  mpz_t m, n, x1, y1, x0, y0, q, r;
  mpz_init2(m, length);
  mpz_init2(n, length);
  mpz_init2(x1, length);
  mpz_init2(y1, length);
  mpz_init2(x0, length);
  mpz_init2(y0, length);
  mpz_init2(q, length);
  mpz_init2(r, length);
  mpz_set(m, a);
  mpz_set(n, b);
  mpz_set_si(x0, 1);
  mpz_set_si(y0, 0);
  mpz_set_si(x1, 0);
  mpz_set_si(y1, 1);
  mpz_set_si(x, 0);
  mpz_set_si(y, 1);
  mpz_tdiv_qr(q, r, m, n);
  while (mpz_cmp_si(r, 0)) {
    mpz_submul(x0, q, x1);
    mpz_submul(y0, q, y1);
    mpz_set(x, x0);
    mpz_set(y, y0);
    mpz_set(x0, x1);
    mpz_set(y0, y1);
    mpz_set(x1, x);
    mpz_set(y1, y);
    mpz_set(m, n);
    mpz_set(n, r);
    mpz_tdiv_qr(q, r, m, n);
  }
  mpz_clear(m);
  mpz_clear(n);
  mpz_clear(x1);
  mpz_clear(y1);
  mpz_clear(x0);
  mpz_clear(y0);
  mpz_clear(q);
  mpz_clear(r);
}


x86 assembly (clang, -O0):
<extend_gcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <mpz_init2@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <mpz_init2@plt>
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <mpz_init2@plt>
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <mpz_init2@plt>
mov    -0x28(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <mpz_init2@plt>
mov    -0x2c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <mpz_init2@plt>
mov    -0x30(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <mpz_init2@plt>
mov    -0x34(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <mpz_init2@plt>
mov    -0x18(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
mov    -0x2c(%rbp),%edi
xor    %esi,%esi
call   1030 <mpz_set_si@plt>
mov    -0x20(%rbp),%edi
xor    %esi,%esi
call   1030 <mpz_set_si@plt>
mov    -0x24(%rbp),%edi
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1030 <mpz_set_si@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
mov    -0x30(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <mpz_tdiv_qr@plt>
mov    -0x34(%rbp),%edi
xor    %esi,%esi
call   1070 <mpz_cmp_si@plt>
cmp    $0x0,%rax
je     12ea <extend_gcd+0x17a>
mov    -0x28(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1060 <mpz_submul@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1060 <mpz_submul@plt>
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x10(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x2c(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x20(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x1c(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x30(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <mpz_tdiv_qr@plt>
jmp    124c <extend_gcd+0xdc>
mov    -0x18(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x1c(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x24(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x28(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x2c(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x30(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x34(%rbp),%edi
call   1080 <mpz_clear@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extend_gcd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r12d
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %r8d,%esi
call   1090 <mpz_init2@plt>
mov    %r12d,%esi
call   1090 <mpz_init2@plt>
mov    %r12d,%esi
call   1090 <mpz_init2@plt>
mov    %r12d,%esi
call   1090 <mpz_init2@plt>
mov    %r12d,%esi
call   1090 <mpz_init2@plt>
mov    %r12d,%esi
call   1090 <mpz_init2@plt>
mov    %r12d,%esi
call   1090 <mpz_init2@plt>
mov    %r12d,%esi
call   1090 <mpz_init2@plt>
mov    %r15d,%esi
call   1040 <mpz_set@plt>
mov    %r14d,%esi
call   1040 <mpz_set@plt>
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
xor    %esi,%esi
call   1030 <mpz_set_si@plt>
xor    %esi,%esi
call   1030 <mpz_set_si@plt>
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1030 <mpz_set_si@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <mpz_set_si@plt>
nopl   0x0(%rax)
call   1050 <mpz_tdiv_qr@plt>
xor    %esi,%esi
call   1070 <mpz_cmp_si@plt>
test   %rax,%rax
je     125d <extend_gcd+0xed>
call   1060 <mpz_submul@plt>
call   1060 <mpz_submul@plt>
mov    %ebp,%edi
call   1040 <mpz_set@plt>
mov    %ebx,%edi
call   1040 <mpz_set@plt>
call   1040 <mpz_set@plt>
call   1040 <mpz_set@plt>
mov    %ebp,%esi
call   1040 <mpz_set@plt>
mov    %ebx,%esi
call   1040 <mpz_set@plt>
call   1040 <mpz_set@plt>
call   1040 <mpz_set@plt>
jmp    1210 <extend_gcd+0xa0>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <mpz_clear@plt>

LLVM IR (-O0):
define void @extend_gcd(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%19 = load i32, i32* %11
%20 = load i32, i32* %10
%21 = call i32 @mpz_init2(i32 %19, i32 %20)
%22 = load i32, i32* %12
%23 = load i32, i32* %10
%24 = call i32 @mpz_init2(i32 %22, i32 %23)
%25 = load i32, i32* %13
%26 = load i32, i32* %10
%27 = call i32 @mpz_init2(i32 %25, i32 %26)
%28 = load i32, i32* %14
%29 = load i32, i32* %10
%30 = call i32 @mpz_init2(i32 %28, i32 %29)
%31 = load i32, i32* %15
%32 = load i32, i32* %10
%33 = call i32 @mpz_init2(i32 %31, i32 %32)
%34 = load i32, i32* %16
%35 = load i32, i32* %10
%36 = call i32 @mpz_init2(i32 %34, i32 %35)
%37 = load i32, i32* %17
%38 = load i32, i32* %10
%39 = call i32 @mpz_init2(i32 %37, i32 %38)
%40 = load i32, i32* %18
%41 = load i32, i32* %10
%42 = call i32 @mpz_init2(i32 %40, i32 %41)
%43 = load i32, i32* %11
%44 = load i32, i32* %6
%45 = call i32 @mpz_set(i32 %43, i32 %44)
%46 = load i32, i32* %12
%47 = load i32, i32* %7
%48 = call i32 @mpz_set(i32 %46, i32 %47)
%49 = load i32, i32* %15
%50 = call i32 @mpz_set_si(i32 %49, i32 1)
%51 = load i32, i32* %16
%52 = call i32 @mpz_set_si(i32 %51, i32 0)
%53 = load i32, i32* %13
%54 = call i32 @mpz_set_si(i32 %53, i32 0)
%55 = load i32, i32* %14
%56 = call i32 @mpz_set_si(i32 %55, i32 1)
%57 = load i32, i32* %8
%58 = call i32 @mpz_set_si(i32 %57, i32 0)
%59 = load i32, i32* %9
%60 = call i32 @mpz_set_si(i32 %59, i32 1)
%61 = load i32, i32* %17
%62 = load i32, i32* %18
%63 = load i32, i32* %11
%64 = load i32, i32* %12
%65 = call i32 @mpz_tdiv_qr(i32 %61, i32 %62, i32 %63, i32 %64)
br label %66
66: ; preds = %70, %5
%67 = load i32, i32* %18
%68 = call i64 @mpz_cmp_si(i32 %67, i32 0)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %108
70: ; preds = %66
%71 = load i32, i32* %15
%72 = load i32, i32* %17
%73 = load i32, i32* %13
%74 = call i32 @mpz_submul(i32 %71, i32 %72, i32 %73)
%75 = load i32, i32* %16
%76 = load i32, i32* %17
%77 = load i32, i32* %14
%78 = call i32 @mpz_submul(i32 %75, i32 %76, i32 %77)
%79 = load i32, i32* %8
%80 = load i32, i32* %15
%81 = call i32 @mpz_set(i32 %79, i32 %80)
%82 = load i32, i32* %9
%83 = load i32, i32* %16
%84 = call i32 @mpz_set(i32 %82, i32 %83)
%85 = load i32, i32* %15
%86 = load i32, i32* %13
%87 = call i32 @mpz_set(i32 %85, i32 %86)
%88 = load i32, i32* %16
%89 = load i32, i32* %14
%90 = call i32 @mpz_set(i32 %88, i32 %89)
%91 = load i32, i32* %13
%92 = load i32, i32* %8
%93 = call i32 @mpz_set(i32 %91, i32 %92)
%94 = load i32, i32* %14
%95 = load i32, i32* %9
%96 = call i32 @mpz_set(i32 %94, i32 %95)
%97 = load i32, i32* %11
%98 = load i32, i32* %12
%99 = call i32 @mpz_set(i32 %97, i32 %98)
%100 = load i32, i32* %12
%101 = load i32, i32* %18
%102 = call i32 @mpz_set(i32 %100, i32 %101)
%103 = load i32, i32* %17
%104 = load i32, i32* %18
%105 = load i32, i32* %11
%106 = load i32, i32* %12
%107 = call i32 @mpz_tdiv_qr(i32 %103, i32 %104, i32 %105, i32 %106)
br label %66
108: ; preds = %66
%109 = load i32, i32* %11
%110 = call i32 @mpz_clear(i32 %109)
%111 = load i32, i32* %12
%112 = call i32 @mpz_clear(i32 %111)
%113 = load i32, i32* %13
%114 = call i32 @mpz_clear(i32 %113)
%115 = load i32, i32* %14
%116 = call i32 @mpz_clear(i32 %115)
%117 = load i32, i32* %15
%118 = call i32 @mpz_clear(i32 %117)
%119 = load i32, i32* %16
%120 = call i32 @mpz_clear(i32 %119)
%121 = load i32, i32* %17
%122 = call i32 @mpz_clear(i32 %121)
%123 = load i32, i32* %18
%124 = call i32 @mpz_clear(i32 %123)
ret void
}

LLVM IR (-O2):
define void @extend_gcd(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 @mpz_init2(i32 undef, i32 %4)
%7 = tail call i32 @mpz_init2(i32 undef, i32 %4)
%8 = tail call i32 @mpz_init2(i32 undef, i32 %4)
%9 = tail call i32 @mpz_init2(i32 undef, i32 %4)
%10 = tail call i32 @mpz_init2(i32 undef, i32 %4)
%11 = tail call i32 @mpz_init2(i32 undef, i32 %4)
%12 = tail call i32 @mpz_init2(i32 undef, i32 %4)
%13 = tail call i32 @mpz_init2(i32 undef, i32 %4)
%14 = tail call i32 @mpz_set(i32 undef, i32 %0)
%15 = tail call i32 @mpz_set(i32 undef, i32 %1)
%16 = tail call i32 @mpz_set_si(i32 undef, i32 1)
%17 = tail call i32 @mpz_set_si(i32 undef, i32 0)
%18 = tail call i32 @mpz_set_si(i32 undef, i32 0)
%19 = tail call i32 @mpz_set_si(i32 undef, i32 1)
%20 = tail call i32 @mpz_set_si(i32 %2, i32 0)
%21 = tail call i32 @mpz_set_si(i32 %3, i32 1)
%22 = tail call i32 @mpz_tdiv_qr(i32 undef, i32 undef, i32 undef, i32 undef)
%23 = tail call i64 @mpz_cmp_si(i32 undef, i32 0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %39, label %25
25: ; preds = %5, %25
%26 = tail call i32 @mpz_submul(i32 undef, i32 undef, i32 undef)
%27 = tail call i32 @mpz_submul(i32 undef, i32 undef, i32 undef)
%28 = tail call i32 @mpz_set(i32 %2, i32 undef)
%29 = tail call i32 @mpz_set(i32 %3, i32 undef)
%30 = tail call i32 @mpz_set(i32 undef, i32 undef)
%31 = tail call i32 @mpz_set(i32 undef, i32 undef)
%32 = tail call i32 @mpz_set(i32 undef, i32 %2)
%33 = tail call i32 @mpz_set(i32 undef, i32 %3)
%34 = tail call i32 @mpz_set(i32 undef, i32 undef)
%35 = tail call i32 @mpz_set(i32 undef, i32 undef)
%36 = tail call i32 @mpz_tdiv_qr(i32 undef, i32 undef, i32 undef, i32 undef)
%37 = tail call i64 @mpz_cmp_si(i32 undef, i32 0)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %25
39: ; preds = %25, %5
%40 = tail call i32 @mpz_clear(i32 undef)
%41 = tail call i32 @mpz_clear(i32 undef)
%42 = tail call i32 @mpz_clear(i32 undef)
%43 = tail call i32 @mpz_clear(i32 undef)
%44 = tail call i32 @mpz_clear(i32 undef)
%45 = tail call i32 @mpz_clear(i32 undef)
%46 = tail call i32 @mpz_clear(i32 undef)
%47 = tail call i32 @mpz_clear(i32 undef)
ret void
}