int mp_inv_newton(int n, int radix, int in[], int inout[], int tmp1[],
                  int tmp2[], int nfft, double tmp1fft[], double tmp2fft[]) {
  void mp_load_1(int n, int radix, int out[]);
  void mp_round(int n, int radix, int m, int inout[]);
  void mp_add(int n, int radix, int in1[], int in2[], int out[]);
  void mp_sub(int n, int radix, int in1[], int in2[], int out[]);
  void mp_mulh(int n, int radix, int in1[], int in2[], int out[], int nfft,
               double in1fft[], double outfft[]);
  void mp_mulh_use_in1fft(int n, int radix, double in1fft[], int shift,
                          int in2[], int out[], int nfft, double outfft[]);
  int n_h, shift, prc;
  shift = (nfft >> 1) + 1;
  n_h = n / 2 + 1;
  if (n_h < n - shift) {
    n_h = n - shift;
  }
  mp_round(n, radix, shift, inout);
  mp_mulh(n, radix, inout, in, tmp1, nfft, tmp1fft, tmp2fft);
  mp_load_1(n, radix, tmp2);
  mp_sub(n, radix, tmp2, tmp1, tmp2);
  mp_mulh_use_in1fft(n, radix, tmp1fft, shift, in, tmp1, nfft, tmp2fft);
  mp_sub(n_h, radix, tmp2, tmp1, tmp2);
  prc = -tmp2[1];
  if (tmp2[0] == 0) {
    prc = nfft + 1;
  }
  mp_mulh_use_in1fft(n_h, radix, tmp1fft, 0, tmp2, tmp2, nfft, tmp2fft);
  if (tmp2[0] != 0) {
    mp_add(n, radix, inout, tmp2, inout);
  }
  return prc;
}


x86 assembly (clang, -O0):
<mp_inv_newton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    0x10(%rbp),%eax
sar    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    -0x30(%rbp),%ecx
cmp    %ecx,%eax
jge    11c0 <mp_inv_newton+0x60>
mov    -0x4(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <mp_round@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    0x10(%rbp),%r9d
mov    0x18(%rbp),%r10
mov    0x20(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <mp_mulh@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1070 <mp_load_1@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1080 <mp_sub@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x18(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    0x10(%rbp),%r10d
mov    0x20(%rbp),%rax
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <mp_mulh_use_in1fft@plt>
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1080 <mp_sub@plt>
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
sub    0x4(%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1288 <mp_inv_newton+0x128>
mov    0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x18(%rbp),%rdx
mov    -0x28(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    0x10(%rbp),%r10d
mov    0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <mp_mulh_use_in1fft@plt>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
je     12d6 <mp_inv_newton+0x176>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1050 <mp_add@plt>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_inv_newton>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,0x10(%rsp)
mov    %rcx,%rbx
mov    %rdx,(%rsp)
mov    %esi,%r12d
mov    %edi,%r15d
mov    0x50(%rsp),%eax
mov    %eax,%r13d
sar    %r13d
add    $0x1,%r13d
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
sar    %eax
add    $0x1,%eax
mov    %edi,%ebp
sub    %r13d,%ebp
cmp    %ebp,%eax
cmovge %eax,%ebp
mov    %r13d,%edx
call   1040 <mp_round@plt>
mov    %r15d,%edi
mov    %r12d,%esi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdx
mov    (%rsp),%rcx
mov    0x10(%rsp),%rbx
mov    %rbx,%r8
mov    0x50(%rsp),%r9d
mov    0x60(%rsp),%rax
push   %rax
mov    0x60(%rsp),%rax
push   %rax
call   1030 <mp_mulh@plt>
add    $0x10,%rsp
mov    %r15d,%edi
mov    %r12d,%esi
mov    %r14,%rdx
call   1070 <mp_load_1@plt>
mov    %r15d,%edi
mov    %r12d,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1080 <mp_sub@plt>
mov    %r15d,%edi
mov    %r12d,%esi
mov    0x58(%rsp),%rdx
mov    %r13d,%ecx
mov    (%rsp),%r8
mov    %rbx,%r9
mov    0x60(%rsp),%rax
push   %rax
mov    0x58(%rsp),%r13d
push   %r13
call   1060 <mp_mulh_use_in1fft@plt>
add    $0x10,%rsp
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1080 <mp_sub@plt>
mov    (%r14),%eax
mov    %eax,(%rsp)
mov    0x4(%r14),%ebx
mov    %ebp,%edi
mov    %r12d,%esi
mov    0x58(%rsp),%rdx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r14,%r9
push   0x60(%rsp)
push   %r13
call   1060 <mp_mulh_use_in1fft@plt>
add    $0x10,%rsp
cmpl   $0x0,(%r14)
je     128a <mp_inv_newton+0x12a>
mov    %r15d,%edi
mov    %r12d,%esi
mov    0x8(%rsp),%rdx
mov    %r14,%rcx
mov    %rdx,%r8
call   1050 <mp_add@plt>
add    $0x1,%r13d
neg    %ebx
cmpl   $0x0,(%rsp)
cmove  %r13d,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mp_inv_newton(i32 %0, i32 %1, i32* %2, i32* %3, i32* %4, i32* %5, i32 %6, double* %7, double* %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca double*
%18 = alloca double*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32 %0, i32* %10
store i32 %1, i32* %11
store i32* %2, i32** %12
store i32* %3, i32** %13
store i32* %4, i32** %14
store i32* %5, i32** %15
store i32 %6, i32* %16
store double* %7, double** %17
store double* %8, double** %18
%22 = load i32, i32* %16
%23 = ashr i32 %22, 1
%24 = add nsw i32 %23, 1
store i32 %24, i32* %20
%25 = load i32, i32* %10
%26 = sdiv i32 %25, 2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %19
%28 = load i32, i32* %19
%29 = load i32, i32* %10
%30 = load i32, i32* %20
%31 = sub nsw i32 %29, %30
%32 = icmp slt i32 %28, %31
br i1 %32, label %33, label %37
33: ; preds = %9
%34 = load i32, i32* %10
%35 = load i32, i32* %20
%36 = sub nsw i32 %34, %35
store i32 %36, i32* %19
br label %37
37: ; preds = %33, %9
%38 = load i32, i32* %10
%39 = load i32, i32* %11
%40 = load i32, i32* %20
%41 = load i32*, i32** %13
%42 = load i32, i32* %10
%43 = load i32, i32* %11
%44 = load i32*, i32** %13
%45 = load i32*, i32** %12
%46 = load i32*, i32** %14
%47 = load i32, i32* %16
%48 = load double*, double** %17
%49 = load double*, double** %18
%50 = load i32, i32* %10
%51 = load i32, i32* %11
%52 = load i32*, i32** %15
%53 = load i32, i32* %10
%54 = load i32, i32* %11
%55 = load i32*, i32** %15
%56 = load i32*, i32** %14
%57 = load i32*, i32** %15
%58 = load i32, i32* %10
%59 = load i32, i32* %11
%60 = load double*, double** %17
%61 = load i32, i32* %20
%62 = load i32*, i32** %12
%63 = load i32*, i32** %14
%64 = load i32, i32* %16
%65 = load double*, double** %18
%66 = load i32, i32* %19
%67 = load i32, i32* %11
%68 = load i32*, i32** %15
%69 = load i32*, i32** %14
%70 = load i32*, i32** %15
%71 = load i32*, i32** %15
%72 = getelementptr inbounds i32, i32* %71, i64 1
%73 = load i32, i32* %72
%74 = sub nsw i32 0, %73
store i32 %74, i32* %21
%75 = load i32*, i32** %15
%76 = getelementptr inbounds i32, i32* %75, i64 0
%77 = load i32, i32* %76
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %37
%80 = load i32, i32* %16
%81 = add nsw i32 %80, 1
store i32 %81, i32* %21
br label %82
82: ; preds = %79, %37
%83 = load i32, i32* %19
%84 = load i32, i32* %11
%85 = load double*, double** %17
%86 = load i32*, i32** %15
%87 = load i32*, i32** %15
%88 = load i32, i32* %16
%89 = load double*, double** %18
%90 = load i32*, i32** %15
%91 = getelementptr inbounds i32, i32* %90, i64 0
%92 = load i32, i32* %91
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %100
94: ; preds = %82
%95 = load i32, i32* %10
%96 = load i32, i32* %11
%97 = load i32*, i32** %13
%98 = load i32*, i32** %15
%99 = load i32*, i32** %13
br label %100
100: ; preds = %94, %82
%101 = load i32, i32* %21
ret i32 %101
}

LLVM IR (-O2):
define i32 @mp_inv_newton(i32 %0, i32 %1, i32* %2, i32* %3, i32* %4, i32* %5, i32 %6, double* %7, double* %8) {
%10 = ashr i32 %6, 1
%11 = add nsw i32 %10, 1
%12 = sdiv i32 %0, 2
%13 = add nsw i32 %12, 1
%14 = sub nsw i32 %0, %11
%15 = icmp slt i32 %13, %14
%16 = select i1 %15, i32 %14, i32 %13
tail call void @mp_round(i32 %0, i32 %1, i32 %11, i32* %3)
tail call void @mp_mulh(i32 %0, i32 %1, i32* %3, i32* %2, i32* %4, i32 %6, double* %7, double* %8)
tail call void @mp_load_1(i32 %0, i32 %1, i32* %5)
tail call void @mp_sub(i32 %0, i32 %1, i32* %5, i32* %4, i32* %5)
tail call void @mp_mulh_use_in1fft(i32 %0, i32 %1, double* %7, i32 %11, i32* %2, i32* %4, i32 %6, double* %8)
tail call void @mp_sub(i32 %16, i32 %1, i32* %5, i32* %4, i32* %5)
%17 = getelementptr inbounds i32, i32* %5, i64 1
%18 = load i32, i32* %17
%19 = load i32, i32* %5
tail call void @mp_mulh_use_in1fft(i32 %16, i32 %1, double* %7, i32 0, i32* %5, i32* %5, i32 %6, double* %8)
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %9
tail call void @mp_add(i32 %0, i32 %1, i32* %3, i32* %5, i32* %3)
br label %23
23: ; preds = %22, %9
%24 = icmp eq i32 %19, 0
%25 = add nsw i32 %6, 1
%26 = sub nsw i32 0, %18
%27 = select i1 %24, i32 %25, i32 %26
ret i32 %27
}