int mp_inv_newton(int n, int radix, int in[], int inout[], int tmp[],
                  char *f_name_tmp1, int nfft, double tmpfft[],
                  char *f_name_tmp1fft) {
  void f_swap_in(int bytesize, char *f_name, char *in);
  void f_swap_out(int bytesize, char *f_name, char *out);
  void mp_load_0(int n, int radix, int out[]);
  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_f(int n, int radix, int in1[], int in2[], int out[], int nfft,
                 char *f_name_in1fft, double outfft[]);
  void mp_mulh_f_use_in1fft(int n, int radix, char *f_name_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);
  f_swap_out(2 * sizeof(int) + shift * sizeof(short int), f_name_tmp1,
             (char *)inout);
  mp_mulh_f(n, radix, inout, in, tmp, nfft, f_name_tmp1fft, tmpfft);
  mp_load_1(n, radix, inout);
  mp_sub(n, radix, inout, tmp, tmp);
  mp_mulh_f_use_in1fft(n, radix, f_name_tmp1fft, shift, in, inout, nfft,
                       tmpfft);
  mp_sub(n_h, radix, tmp, inout, tmp);
  prc = -tmp[1];
  if (tmp[0] == 0) {
    prc = nfft + 1;
  }
  mp_mulh_f_use_in1fft(n_h, radix, f_name_tmp1fft, 0, tmp, tmp, nfft, tmpfft);
  mp_load_0(n, radix, inout);
  f_swap_in(2 * sizeof(int) + shift * sizeof(short int), f_name_tmp1,
            (char *)inout);
  if (tmp[0] != 0) {
    mp_add(n, radix, inout, tmp, 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    11f0 <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   1030 <mp_round@plt>
movslq -0x30(%rbp),%rax
shl    $0x1,%rax
add    $0x8,%rax
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <f_swap_out@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    0x20(%rbp),%r10
mov    0x18(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <mp_mulh_f@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1080 <mp_load_1@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1090 <mp_sub@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x20(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    0x10(%rbp),%r10d
mov    0x18(%rbp),%rax
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   10a0 <mp_mulh_f_use_in1fft@plt>
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1090 <mp_sub@plt>
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
sub    0x4(%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    12d3 <mp_inv_newton+0x143>
mov    0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x20(%rbp),%rdx
mov    -0x20(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    0x10(%rbp),%r10d
mov    0x18(%rbp),%rax
xor    %ecx,%ecx
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   10a0 <mp_mulh_f_use_in1fft@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   10b0 <mp_load_0@plt>
movslq -0x30(%rbp),%rax
shl    $0x1,%rax
add    $0x8,%rax
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <f_swap_in@plt>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
je     134b <mp_inv_newton+0x1bb>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%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,0x8(%rsp)
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,0x10(%rsp)
mov    %edi,%ebp
mov    0x50(%rsp),%ebx
sar    %ebx
lea    0x1(%rbx),%edx
mov    %edx,(%rsp)
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
sar    %eax
add    $0x1,%eax
mov    %edi,%r15d
sub    %edx,%r15d
cmp    %r15d,%eax
cmovge %eax,%r15d
mov    %esi,%r13d
call   1030 <mp_round@plt>
lea    (%rbx,%rbx,1),%edi
add    $0xa,%edi
mov    %edi,0x4(%rsp)
mov    0x8(%rsp),%rsi
mov    %r14,%rbx
mov    %r14,%rdx
call   1040 <f_swap_out@plt>
mov    %ebp,%edi
mov    %r13d,%esi
mov    %r14,%rdx
mov    0x10(%rsp),%r14
mov    %r14,%rcx
mov    %r12,%r8
mov    0x50(%rsp),%r9d
mov    0x58(%rsp),%rax
push   %rax
mov    0x68(%rsp),%rax
push   %rax
call   1060 <mp_mulh_f@plt>
add    $0x10,%rsp
mov    %ebp,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
call   1080 <mp_load_1@plt>
mov    %ebp,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r12,%r8
call   1090 <mp_sub@plt>
mov    %ebp,%edi
mov    %r13d,%esi
mov    0x60(%rsp),%rdx
mov    (%rsp),%ecx
mov    %r14,%r8
mov    %rbx,%r9
mov    0x58(%rsp),%rax
push   %rax
mov    0x58(%rsp),%eax
push   %rax
call   10a0 <mp_mulh_f_use_in1fft@plt>
add    $0x10,%rsp
mov    %r15d,%edi
mov    %r13d,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
call   1090 <mp_sub@plt>
mov    (%r12),%eax
mov    %eax,(%rsp)
mov    0x4(%r12),%r14d
mov    %r15d,%edi
mov    %r13d,%esi
mov    0x60(%rsp),%rdx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r12,%r9
push   0x58(%rsp)
mov    0x58(%rsp),%eax
mov    %rax,%r15
push   %rax
call   10a0 <mp_mulh_f_use_in1fft@plt>
add    $0x10,%rsp
mov    %ebp,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
call   10b0 <mp_load_0@plt>
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%rsi
mov    %rbx,%rdx
call   1070 <f_swap_in@plt>
cmpl   $0x0,(%r12)
je     12eb <mp_inv_newton+0x15b>
mov    %ebp,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
call   1050 <mp_add@plt>
add    $0x1,%r15d
neg    %r14d
cmpl   $0x0,(%rsp)
cmove  %r15d,%r14d
mov    %r14d,%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, i8* %5, i32 %6, double* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca double*
%18 = alloca i8*
%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 i8* %5, i8** %15
store i32 %6, i32* %16
store double* %7, double** %17
store i8* %8, i8** %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* %20
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 2
%45 = add i64 8, %44
%46 = trunc i64 %45 to i32
%47 = load i8*, i8** %15
%48 = load i32*, i32** %13
%49 = bitcast i32* %48 to i8*
%50 = load i32, i32* %10
%51 = load i32, i32* %11
%52 = load i32*, i32** %13
%53 = load i32*, i32** %12
%54 = load i32*, i32** %14
%55 = load i32, i32* %16
%56 = load i8*, i8** %18
%57 = load double*, double** %17
%58 = load i32, i32* %10
%59 = load i32, i32* %11
%60 = load i32*, i32** %13
%61 = load i32, i32* %10
%62 = load i32, i32* %11
%63 = load i32*, i32** %13
%64 = load i32*, i32** %14
%65 = load i32*, i32** %14
%66 = load i32, i32* %10
%67 = load i32, i32* %11
%68 = load i8*, i8** %18
%69 = load i32, i32* %20
%70 = load i32*, i32** %12
%71 = load i32*, i32** %13
%72 = load i32, i32* %16
%73 = load double*, double** %17
%74 = load i32, i32* %19
%75 = load i32, i32* %11
%76 = load i32*, i32** %14
%77 = load i32*, i32** %13
%78 = load i32*, i32** %14
%79 = load i32*, i32** %14
%80 = getelementptr inbounds i32, i32* %79, i64 1
%81 = load i32, i32* %80
%82 = sub nsw i32 0, %81
store i32 %82, i32* %21
%83 = load i32*, i32** %14
%84 = getelementptr inbounds i32, i32* %83, i64 0
%85 = load i32, i32* %84
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %37
%88 = load i32, i32* %16
%89 = add nsw i32 %88, 1
store i32 %89, i32* %21
br label %90
90: ; preds = %87, %37
%91 = load i32, i32* %19
%92 = load i32, i32* %11
%93 = load i8*, i8** %18
%94 = load i32*, i32** %14
%95 = load i32*, i32** %14
%96 = load i32, i32* %16
%97 = load double*, double** %17
%98 = load i32, i32* %10
%99 = load i32, i32* %11
%100 = load i32*, i32** %13
%101 = load i32, i32* %20
%102 = sext i32 %101 to i64
%103 = mul i64 %102, 2
%104 = add i64 8, %103
%105 = trunc i64 %104 to i32
%106 = load i8*, i8** %15
%107 = load i32*, i32** %13
%108 = bitcast i32* %107 to i8*
%109 = load i32*, i32** %14
%110 = getelementptr inbounds i32, i32* %109, i64 0
%111 = load i32, i32* %110
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %119
113: ; preds = %90
%114 = load i32, i32* %10
%115 = load i32, i32* %11
%116 = load i32*, i32** %13
%117 = load i32*, i32** %14
%118 = load i32*, i32** %13
br label %119
119: ; preds = %113, %90
%120 = load i32, i32* %21
ret i32 %120
}

LLVM IR (-O2):
define i32 @mp_inv_newton(i32 %0, i32 %1, i32* %2, i32* %3, i32* %4, i8* %5, i32 %6, double* %7, i8* %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)
%17 = shl i32 %11, 1
%18 = add i32 %17, 8
%19 = bitcast i32* %3 to i8*
tail call void @f_swap_out(i32 %18, i8* %5, i8* %19)
tail call void @mp_mulh_f(i32 %0, i32 %1, i32* %3, i32* %2, i32* %4, i32 %6, i8* %8, double* %7)
tail call void @mp_load_1(i32 %0, i32 %1, i32* %3)
tail call void @mp_sub(i32 %0, i32 %1, i32* %3, i32* %4, i32* %4)
tail call void @mp_mulh_f_use_in1fft(i32 %0, i32 %1, i8* %8, i32 %11, i32* %2, i32* %3, i32 %6, double* %7)
tail call void @mp_sub(i32 %16, i32 %1, i32* %4, i32* %3, i32* %4)
%20 = getelementptr inbounds i32, i32* %4, i64 1
%21 = load i32, i32* %20
%22 = load i32, i32* %4
tail call void @mp_mulh_f_use_in1fft(i32 %16, i32 %1, i8* %8, i32 0, i32* %4, i32* %4, i32 %6, double* %7)
tail call void @mp_load_0(i32 %0, i32 %1, i32* %3)
tail call void @f_swap_in(i32 %18, i8* %5, i8* %19)
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %9
tail call void @mp_add(i32 %0, i32 %1, i32* %3, i32* %4, i32* %3)
br label %26
26: ; preds = %25, %9
%27 = icmp eq i32 %22, 0
%28 = add nsw i32 %6, 1
%29 = sub nsw i32 0, %21
%30 = select i1 %27, i32 %28, i32 %29
ret i32 %30
}