#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*/ const mpz_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_add(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/ const);
scalar_t__ mpz_cmp(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_div(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/ const);
int /*<<< orphan*/ mpz_mod(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ mpz_sub(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
void mod_inv(mpz_t result, const mpz_t a, const mpz_t n) {
  int i;
  mpz_t tmp;
  mpz_t num;
  mpz_t den;
  mpz_t quot[3];
  mpz_t p[2];
  mpz_init(tmp);
  mpz_init(num);
  mpz_init(den);
  mpz_init(quot[0]);
  mpz_init(quot[1]);
  mpz_init(quot[2]);
  mpz_init(p[0]);
  mpz_init(p[1]);
  mpz_set_ui(quot[0], 1);
  mpz_set_ui(quot[1], 1);
  mpz_set_ui(quot[2], 1);
  mpz_set_ui(p[0], 0);
  mpz_set_ui(p[1], 1);
  if (mpz_cmp(a, n) > 0) {
    mpz_set(num, a);
    mpz_set(den, n);
  } else {
    mpz_set(num, n);
    mpz_set(den, a);
  }
  for (i = 0; mpz_cmp_ui(den, 0); i++) {
    mpz_div(quot[i % 3], num, den);
    mpz_mod(tmp, num, den);
    mpz_set(num, den);
    mpz_set(den, tmp);
    if (i >= 2) {
      mpz_mul(tmp, quot[(i - 2) % 3], p[(i - 1) % 2]);
      mpz_sub(tmp, p[(i - 2) % 2], tmp);
      if (mpz_cmp_ui(tmp, 0) < 0) {
        mpz_add(tmp, tmp, n);
      }
      mpz_set(p[i % 2], tmp);
    }
  }
  mpz_mul(tmp, quot[(i - 2) % 3], p[(i - 1) % 2]);
  mpz_sub(tmp, p[(i - 2) % 2], tmp);
  if (mpz_cmp_ui(tmp, 0) < 0) {
    mpz_add(tmp, tmp, n);
  }
  mpz_set(result, tmp);
  mpz_clear(tmp);
  mpz_clear(num);
  mpz_clear(den);
  mpz_clear(quot[0]);
  mpz_clear(quot[1]);
  mpz_clear(quot[2]);
  mpz_clear(p[0]);
  mpz_clear(p[1]);
}


x86 assembly (clang, -O0):
<mod_inv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x18(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x1c(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x28(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x24(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x20(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x30(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x2c(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   10b0 <mpz_set_ui@plt>
mov    -0x24(%rbp),%edi
mov    $0x1,%esi
call   10b0 <mpz_set_ui@plt>
mov    -0x20(%rbp),%edi
mov    $0x1,%esi
call   10b0 <mpz_set_ui@plt>
mov    -0x30(%rbp),%edi
xor    %esi,%esi
call   10b0 <mpz_set_ui@plt>
mov    -0x2c(%rbp),%edi
mov    $0x1,%esi
call   10b0 <mpz_set_ui@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   10a0 <mpz_cmp@plt>
cmp    $0x0,%rax
jle    126f <mod_inv+0xbf>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <mpz_set@plt>
jmp    1285 <mod_inv+0xd5>
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <mpz_set@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1090 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
je     138c <mod_inv+0x1dc>
mov    -0x10(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x28(%rbp,%rax,4),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <mpz_div@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   10c0 <mpz_mod@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <mpz_set@plt>
cmpl   $0x2,-0x10(%rbp)
jl     1379 <mod_inv+0x1c9>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x28(%rbp,%rax,4),%esi
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x30(%rbp,%rax,4),%edx
call   1080 <mpz_mul@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x30(%rbp,%rax,4),%esi
mov    -0x14(%rbp),%edx
call   1050 <mpz_sub@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1090 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jge    135f <mod_inv+0x1af>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <mpz_add@plt>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x30(%rbp,%rax,4),%edi
mov    -0x14(%rbp),%esi
call   1040 <mpz_set@plt>
jmp    137e <mod_inv+0x1ce>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    128c <mod_inv+0xdc>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x28(%rbp,%rax,4),%esi
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x30(%rbp,%rax,4),%edx
call   1080 <mpz_mul@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x30(%rbp,%rax,4),%esi
mov    -0x14(%rbp),%edx
call   1050 <mpz_sub@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1090 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jge    1400 <mod_inv+0x250>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <mpz_add@plt>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x14(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x18(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x1c(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x28(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x24(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x30(%rbp),%edi
call   10d0 <mpz_clear@plt>
mov    -0x2c(%rbp),%edi
call   10d0 <mpz_clear@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_inv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r14d
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
call   1060 <mpz_init@plt>
mov    $0x1,%esi
call   10b0 <mpz_set_ui@plt>
mov    $0x1,%esi
call   10b0 <mpz_set_ui@plt>
mov    $0x1,%esi
call   10b0 <mpz_set_ui@plt>
xor    %ebx,%ebx
xor    %esi,%esi
call   10b0 <mpz_set_ui@plt>
mov    $0x1,%esi
call   10b0 <mpz_set_ui@plt>
mov    %ebp,%edi
mov    %r15d,%esi
call   10a0 <mpz_cmp@plt>
test   %rax,%rax
mov    %r15d,%esi
cmovg  %ebp,%esi
cmovg  %r15d,%ebp
call   1040 <mpz_set@plt>
mov    %ebp,%esi
call   1040 <mpz_set@plt>
xor    %esi,%esi
call   1090 <mpz_cmp_ui@plt>
test   %rax,%rax
je     1349 <mod_inv+0x199>
lea    0xc(%rsp),%rbp
xor    %ebx,%ebx
movabs $0xaaaaaaaaaaaaaaab,%r12
aa aa aa
jmp    1296 <mod_inv+0xe6>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%eax
and    $0x1,%eax
mov    0x4(%rsp,%rax,4),%edi
call   1040 <mpz_set@plt>
add    $0x1,%rbx
xor    %esi,%esi
call   1090 <mpz_cmp_ui@plt>
add    $0x4,%rbp
test   %rax,%rax
je     1349 <mod_inv+0x199>
mov    %rbx,%rax
mul    %r12
add    %rdx,%rdx
and    $0xfffffffffffffffc,%rdx
lea    (%rdx,%rdx,2),%rax
mov    %rbp,%rcx
sub    %rax,%rcx
mov    (%rcx),%edi
call   1030 <mpz_div@plt>
call   10c0 <mpz_mod@plt>
call   1040 <mpz_set@plt>
call   1040 <mpz_set@plt>
cmp    $0x2,%ebx
jb     127e <mod_inv+0xce>
lea    -0x2(%rbx),%eax
movslq %eax,%r13
imul   $0x55555556,%r13,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
neg    %eax
add    %ebx,%eax
add    $0xfffffffe,%eax
mov    0xc(%rsp,%rax,4),%esi
lea    -0x1(%rbx),%eax
shr    $0x1f,%eax
add    %ebx,%eax
add    $0xffffffff,%eax
and    $0xfffffffe,%eax
neg    %eax
add    %ebx,%eax
add    $0xffffffff,%eax
mov    0x4(%rsp,%rax,4),%edx
call   1080 <mpz_mul@plt>
shr    $0x1f,%r13d
lea    (%rbx,%r13,1),%eax
add    $0xfffffffe,%eax
and    $0xfffffffe,%eax
neg    %eax
add    %ebx,%eax
add    $0xfffffffe,%eax
mov    0x4(%rsp,%rax,4),%esi
call   1050 <mpz_sub@plt>
xor    %esi,%esi
call   1090 <mpz_cmp_ui@plt>
test   %rax,%rax
jns    1270 <mod_inv+0xc0>
mov    %r15d,%edx
call   1070 <mpz_add@plt>
jmp    1270 <mod_inv+0xc0>
lea    -0x2(%rbx),%eax
movslq %eax,%rbp
imul   $0x55555556,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
neg    %eax
add    %ebx,%eax
add    $0xfffffffe,%eax
cltq
mov    0xc(%rsp,%rax,4),%esi
mov    %ebx,%eax
add    $0xffffffff,%eax
shr    $0x1f,%eax
add    %ebx,%eax
add    $0xffffffff,%eax
and    $0xfffffffe,%eax
neg    %eax
add    %ebx,%eax
add    $0xffffffff,%eax
cltq
mov    0x4(%rsp,%rax,4),%edx
call   1080 <mpz_mul@plt>
shr    $0x1f,%ebp
lea    (%rbx,%rbp,1),%eax
add    $0xfffffffe,%eax
and    $0xfffffffe,%eax
neg    %eax
add    %ebx,%eax
add    $0xfffffffe,%eax
cltq
mov    0x4(%rsp,%rax,4),%esi
call   1050 <mpz_sub@plt>
xor    %esi,%esi
call   1090 <mpz_cmp_ui@plt>
test   %rax,%rax
jns    13c7 <mod_inv+0x217>
mov    %r15d,%edx
call   1070 <mpz_add@plt>
mov    %r14d,%edi
call   1040 <mpz_set@plt>
call   10d0 <mpz_clear@plt>
call   10d0 <mpz_clear@plt>
call   10d0 <mpz_clear@plt>
call   10d0 <mpz_clear@plt>
call   10d0 <mpz_clear@plt>
call   10d0 <mpz_clear@plt>
call   10d0 <mpz_clear@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10d0 <mpz_clear@plt>

LLVM IR (-O0):
define void @mod_inv(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [3 x i32]
%12 = alloca [2 x i32]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* %8
%14 = call i32 @mpz_init(i32 %13)
%15 = load i32, i32* %9
%16 = call i32 @mpz_init(i32 %15)
%17 = load i32, i32* %10
%18 = call i32 @mpz_init(i32 %17)
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 0
%20 = load i32, i32* %19
%21 = call i32 @mpz_init(i32 %20)
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @mpz_init(i32 %23)
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 2
%26 = load i32, i32* %25
%27 = call i32 @mpz_init(i32 %26)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%29 = load i32, i32* %28
%30 = call i32 @mpz_init(i32 %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @mpz_init(i32 %32)
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 0
%35 = load i32, i32* %34
%36 = call i32 @mpz_set_ui(i32 %35, i32 1)
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @mpz_set_ui(i32 %38, i32 1)
%40 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 2
%41 = load i32, i32* %40
%42 = call i32 @mpz_set_ui(i32 %41, i32 1)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%44 = load i32, i32* %43
%45 = call i32 @mpz_set_ui(i32 %44, i32 0)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @mpz_set_ui(i32 %47, i32 1)
%49 = load i32, i32* %5
%50 = load i32, i32* %6
%51 = call i64 @mpz_cmp(i32 %49, i32 %50)
%52 = icmp sgt i64 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %3
%54 = load i32, i32* %9
%55 = load i32, i32* %5
%56 = call i32 @mpz_set(i32 %54, i32 %55)
%57 = load i32, i32* %10
%58 = load i32, i32* %6
%59 = call i32 @mpz_set(i32 %57, i32 %58)
br label %67
60: ; preds = %3
%61 = load i32, i32* %9
%62 = load i32, i32* %6
%63 = call i32 @mpz_set(i32 %61, i32 %62)
%64 = load i32, i32* %10
%65 = load i32, i32* %5
%66 = call i32 @mpz_set(i32 %64, i32 %65)
br label %67
67: ; preds = %60, %53
store i32 0, i32* %7
br label %68
68: ; preds = %134, %67
%69 = load i32, i32* %10
%70 = call i64 @mpz_cmp_ui(i32 %69, i32 0)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %137
72: ; preds = %68
%73 = load i32, i32* %7
%74 = srem i32 %73, 3
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 %75
%77 = load i32, i32* %76
%78 = load i32, i32* %9
%79 = load i32, i32* %10
%80 = call i32 @mpz_div(i32 %77, i32 %78, i32 %79)
%81 = load i32, i32* %8
%82 = load i32, i32* %9
%83 = load i32, i32* %10
%84 = call i32 @mpz_mod(i32 %81, i32 %82, i32 %83)
%85 = load i32, i32* %9
%86 = load i32, i32* %10
%87 = call i32 @mpz_set(i32 %85, i32 %86)
%88 = load i32, i32* %10
%89 = load i32, i32* %8
%90 = call i32 @mpz_set(i32 %88, i32 %89)
%91 = load i32, i32* %7
%92 = icmp sge i32 %91, 2
br i1 %92, label %93, label %133
93: ; preds = %72
%94 = load i32, i32* %8
%95 = load i32, i32* %7
%96 = sub nsw i32 %95, 2
%97 = srem i32 %96, 3
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 %98
%100 = load i32, i32* %99
%101 = load i32, i32* %7
%102 = sub nsw i32 %101, 1
%103 = srem i32 %102, 2
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %104
%106 = load i32, i32* %105
%107 = call i32 @mpz_mul(i32 %94, i32 %100, i32 %106)
%108 = load i32, i32* %8
%109 = load i32, i32* %7
%110 = sub nsw i32 %109, 2
%111 = srem i32 %110, 2
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %112
%114 = load i32, i32* %113
%115 = load i32, i32* %8
%116 = call i32 @mpz_sub(i32 %108, i32 %114, i32 %115)
%117 = load i32, i32* %8
%118 = call i64 @mpz_cmp_ui(i32 %117, i32 0)
%119 = icmp slt i64 %118, 0
br i1 %119, label %120, label %125
120: ; preds = %93
%121 = load i32, i32* %8
%122 = load i32, i32* %8
%123 = load i32, i32* %6
%124 = call i32 @mpz_add(i32 %121, i32 %122, i32 %123)
br label %125
125: ; preds = %120, %93
%126 = load i32, i32* %7
%127 = srem i32 %126, 2
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %128
%130 = load i32, i32* %129
%131 = load i32, i32* %8
%132 = call i32 @mpz_set(i32 %130, i32 %131)
br label %133
133: ; preds = %125, %72
br label %134
134: ; preds = %133
%135 = load i32, i32* %7
%136 = add nsw i32 %135, 1
store i32 %136, i32* %7
br label %68
137: ; preds = %68
%138 = load i32, i32* %8
%139 = load i32, i32* %7
%140 = sub nsw i32 %139, 2
%141 = srem i32 %140, 3
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 %142
%144 = load i32, i32* %143
%145 = load i32, i32* %7
%146 = sub nsw i32 %145, 1
%147 = srem i32 %146, 2
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %148
%150 = load i32, i32* %149
%151 = call i32 @mpz_mul(i32 %138, i32 %144, i32 %150)
%152 = load i32, i32* %8
%153 = load i32, i32* %7
%154 = sub nsw i32 %153, 2
%155 = srem i32 %154, 2
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 %156
%158 = load i32, i32* %157
%159 = load i32, i32* %8
%160 = call i32 @mpz_sub(i32 %152, i32 %158, i32 %159)
%161 = load i32, i32* %8
%162 = call i64 @mpz_cmp_ui(i32 %161, i32 0)
%163 = icmp slt i64 %162, 0
br i1 %163, label %164, label %169
164: ; preds = %137
%165 = load i32, i32* %8
%166 = load i32, i32* %8
%167 = load i32, i32* %6
%168 = call i32 @mpz_add(i32 %165, i32 %166, i32 %167)
br label %169
169: ; preds = %164, %137
%170 = load i32, i32* %4
%171 = load i32, i32* %8
%172 = call i32 @mpz_set(i32 %170, i32 %171)
%173 = load i32, i32* %8
%174 = call i32 @mpz_clear(i32 %173)
%175 = load i32, i32* %9
%176 = call i32 @mpz_clear(i32 %175)
%177 = load i32, i32* %10
%178 = call i32 @mpz_clear(i32 %177)
%179 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 0
%180 = load i32, i32* %179
%181 = call i32 @mpz_clear(i32 %180)
%182 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 1
%183 = load i32, i32* %182
%184 = call i32 @mpz_clear(i32 %183)
%185 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 2
%186 = load i32, i32* %185
%187 = call i32 @mpz_clear(i32 %186)
%188 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%189 = load i32, i32* %188
%190 = call i32 @mpz_clear(i32 %189)
%191 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%192 = load i32, i32* %191
%193 = call i32 @mpz_clear(i32 %192)
ret void
}

LLVM IR (-O2):
define void @mod_inv(i32 %0, i32 %1, i32 %2) {
%4 = alloca [3 x i32]
%5 = alloca [2 x i32]
%6 = bitcast [3 x i32]* %4 to i8*
%7 = bitcast [2 x i32]* %5 to i8*
%8 = tail call i32 @mpz_init(i32 undef)
%9 = tail call i32 @mpz_init(i32 undef)
%10 = tail call i32 @mpz_init(i32 undef)
%11 = tail call i32 @mpz_init(i32 undef)
%12 = tail call i32 @mpz_init(i32 undef)
%13 = tail call i32 @mpz_init(i32 undef)
%14 = tail call i32 @mpz_init(i32 undef)
%15 = tail call i32 @mpz_init(i32 undef)
%16 = tail call i32 @mpz_set_ui(i32 undef, i32 1)
%17 = tail call i32 @mpz_set_ui(i32 undef, i32 1)
%18 = tail call i32 @mpz_set_ui(i32 undef, i32 1)
%19 = tail call i32 @mpz_set_ui(i32 undef, i32 0)
%20 = tail call i32 @mpz_set_ui(i32 undef, i32 1)
%21 = tail call i64 @mpz_cmp(i32 %1, i32 %2)
%22 = icmp sgt i64 %21, 0
%23 = select i1 %22, i32 %1, i32 %2
%24 = select i1 %22, i32 %2, i32 %1
%25 = tail call i32 @mpz_set(i32 undef, i32 %23)
%26 = tail call i32 @mpz_set(i32 undef, i32 %24)
%27 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %71, label %29
29: ; preds = %3, %67
%30 = phi i32 [ %68, %67 ], [ 0, %3 ]
%31 = urem i32 %30, 3
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = tail call i32 @mpz_div(i32 %34, i32 undef, i32 undef)
%36 = tail call i32 @mpz_mod(i32 undef, i32 undef, i32 undef)
%37 = tail call i32 @mpz_set(i32 undef, i32 undef)
%38 = tail call i32 @mpz_set(i32 undef, i32 undef)
%39 = icmp ugt i32 %30, 1
br i1 %39, label %40, label %67
40: ; preds = %29
%41 = add nsw i32 %30, -2
%42 = srem i32 %41, 3
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = add nsw i32 %30, -1
%47 = srem i32 %46, 2
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = tail call i32 @mpz_mul(i32 undef, i32 %45, i32 %50)
%52 = srem i32 %41, 2
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = tail call i32 @mpz_sub(i32 undef, i32 %55, i32 undef)
%57 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %40
%60 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 %2)
br label %61
61: ; preds = %59, %40
%62 = and i32 %30, 1
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = tail call i32 @mpz_set(i32 %65, i32 undef)
br label %67
67: ; preds = %29, %61
%68 = add nuw nsw i32 %30, 1
%69 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %29
71: ; preds = %67, %3
%72 = phi i32 [ 0, %3 ], [ %68, %67 ]
%73 = add nsw i32 %72, -2
%74 = srem i32 %73, 3
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 %75
%77 = load i32, i32* %76
%78 = add nsw i32 %72, -1
%79 = srem i32 %78, 2
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 %80
%82 = load i32, i32* %81
%83 = tail call i32 @mpz_mul(i32 undef, i32 %77, i32 %82)
%84 = srem i32 %73, 2
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 %85
%87 = load i32, i32* %86
%88 = tail call i32 @mpz_sub(i32 undef, i32 %87, i32 undef)
%89 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %93
91: ; preds = %71
%92 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 %2)
br label %93
93: ; preds = %91, %71
%94 = tail call i32 @mpz_set(i32 %0, i32 undef)
%95 = tail call i32 @mpz_clear(i32 undef)
%96 = tail call i32 @mpz_clear(i32 undef)
%97 = tail call i32 @mpz_clear(i32 undef)
%98 = tail call i32 @mpz_clear(i32 undef)
%99 = tail call i32 @mpz_clear(i32 undef)
%100 = tail call i32 @mpz_clear(i32 undef)
%101 = tail call i32 @mpz_clear(i32 undef)
%102 = tail call i32 @mpz_clear(i32 undef)
ret void
}