void mp_mul(int n, int radix, int in1[], int in2[], int out[], int tmp[],
            int nfft, double tmp1fft[], double tmp2fft[], double tmp3fft[]) {
  void mp_copy(int n, int radix, int in[], int out[]);
  void mp_add(int n, int radix, int in1[], int in2[], int out[]);
  void mp_mul_i2d(int n, int radix, int nfft, int shift, int in[],
                  double dout[]);
  void mp_mul_cmul_nt_out(int nfft, double d1[], double d2[]);
  void mp_mul_cmul_nt_d2(int nfft, double d1[], double d2[]);
  void mp_mul_cmul_nt_d1_add(int nfft, double d1[], double d2[], double d3[]);
  void mp_mul_d2i(int n, int radix, int nfft, double din[], int out[]);
  int n_h, shift;
  short int *in1dgt, *in2dgt;
  in1dgt = (short int *)&in1[2];
  in2dgt = (short int *)&in2[2];
  shift = (nfft >> 1) + 1;
  while (n > shift) {
    if (in1dgt[shift] + in2dgt[shift] != 0) {
      break;
    }
    shift++;
  }
  n_h = n / 2 + 1;
  if (n_h < n - shift) {
    n_h = n - shift;
  }
  mp_mul_i2d(n, radix, nfft, 0, in1, tmp1fft);
  mp_mul_i2d(n, radix, nfft, shift, in2, tmp3fft);
  mp_mul_cmul_nt_out(nfft, tmp1fft, tmp3fft);
  mp_mul_i2d(n, radix, nfft, 0, in2, tmp2fft);
  mp_mul_cmul_nt_d2(nfft, tmp2fft, tmp1fft);
  mp_mul_d2i(n, radix, nfft, tmp1fft, tmp);
  mp_mul_i2d(n, radix, nfft, shift, in1, tmp1fft);
  mp_mul_cmul_nt_d1_add(nfft, tmp2fft, tmp1fft, tmp3fft);
  mp_mul_d2i(n_h, radix, nfft, tmp3fft, out);
  if (out[0] != 0) {
    mp_add(n, radix, out, tmp, out);
  } else {
    mp_copy(n, radix, tmp, out);
  }
}


x86 assembly (clang, -O0):
<mp_mul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x28(%rbp),%rax
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),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
mov    0x10(%rbp),%eax
sar    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x30(%rbp),%eax
jle    1203 <mp_mul+0x93>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
movswl (%rax,%rcx,2),%eax
mov    -0x40(%rbp),%rcx
movslq -0x30(%rbp),%rdx
movswl (%rcx,%rdx,2),%ecx
add    %ecx,%eax
cmp    $0x0,%eax
je     11f5 <mp_mul+0x85>
jmp    1203 <mp_mul+0x93>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c1 <mp_mul+0x51>
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    122e <mp_mul+0xbe>
mov    -0x4(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x10(%rbp),%edx
mov    -0x10(%rbp),%r8
mov    0x18(%rbp),%r9
xor    %ecx,%ecx
call   1040 <mp_mul_i2d@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x10(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    0x28(%rbp),%r9
call   1040 <mp_mul_i2d@plt>
mov    0x10(%rbp),%edi
mov    0x18(%rbp),%rsi
mov    0x28(%rbp),%rdx
call   1080 <mp_mul_cmul_nt_out@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x10(%rbp),%edx
mov    -0x18(%rbp),%r8
mov    0x20(%rbp),%r9
xor    %ecx,%ecx
call   1040 <mp_mul_i2d@plt>
mov    0x10(%rbp),%edi
mov    0x20(%rbp),%rsi
mov    0x18(%rbp),%rdx
call   1030 <mp_mul_cmul_nt_d2@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x10(%rbp),%edx
mov    0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1090 <mp_mul_d2i@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x10(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    0x18(%rbp),%r9
call   1040 <mp_mul_i2d@plt>
mov    0x10(%rbp),%edi
mov    0x20(%rbp),%rsi
mov    0x18(%rbp),%rdx
mov    0x28(%rbp),%rcx
call   1060 <mp_mul_cmul_nt_d1_add@plt>
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x10(%rbp),%edx
mov    0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1090 <mp_mul_d2i@plt>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
je     1319 <mp_mul+0x1a9>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1050 <mp_add@plt>
jmp    132c <mp_mul+0x1bc>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1070 <mp_copy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_mul>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,0x30(%rsp)
mov    %rcx,%r13
mov    %rdx,%r15
mov    0x88(%rsp),%rax
mov    %rax,0x28(%rsp)
mov    0x80(%rsp),%rax
mov    %rax,0x20(%rsp)
mov    0x78(%rsp),%r9
mov    0x70(%rsp),%r14d
mov    %r14d,%ebp
sar    %ebp
movslq %ebp,%rax
movslq %edi,%r10
lea    0x1(%rax),%r8d
cmp    %r8d,%r10d
cmovg  %edi,%r8d
add    $0x5,%rax
nopl   0x0(%rax)
lea    -0x4(%rax),%rbx
cmp    %r10,%rbx
jge    11f1 <mp_mul+0x81>
movswl (%r15,%rax,2),%ebx
movswl 0x0(%r13,%rax,2),%ecx
add    $0x1,%ebp
add    $0x1,%rax
add    %ebx,%ecx
je     11d0 <mp_mul+0x60>
jmp    11f4 <mp_mul+0x84>
mov    %r8d,%ebp
mov    %edi,%eax
shr    $0x1f,%eax
add    %edi,%eax
sar    %eax
add    $0x1,%eax
mov    %edi,%ecx
sub    %ebp,%ecx
cmp    %ecx,%eax
cmovge %eax,%ecx
mov    %ecx,0x14(%rsp)
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %esi,%ebx
mov    %esi,(%rsp)
mov    %edi,%r12d
mov    %r15,%r8
mov    %r9,0x18(%rsp)
call   1040 <mp_mul_i2d@plt>
mov    %r12d,%edi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %r13,%r8
mov    0x28(%rsp),%rbx
mov    %rbx,%r9
call   1040 <mp_mul_i2d@plt>
mov    %r14d,%edi
mov    0x18(%rsp),%rsi
mov    %rbx,%rdx
call   1080 <mp_mul_cmul_nt_out@plt>
mov    %r12d,%edi
mov    (%rsp),%esi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %r13,%r8
mov    0x20(%rsp),%rbx
mov    %rbx,%r9
call   1040 <mp_mul_i2d@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    0x18(%rsp),%rbx
mov    %rbx,%rdx
call   1030 <mp_mul_cmul_nt_d2@plt>
mov    %r12d,%edi
mov    (%rsp),%esi
mov    %r14d,%edx
mov    %rbx,%rcx
mov    0x8(%rsp),%r8
call   1090 <mp_mul_d2i@plt>
mov    %r12d,0x4(%rsp)
mov    %r12d,%edi
mov    (%rsp),%r12d
mov    %r12d,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %r15,%r8
mov    %rbx,%r9
call   1040 <mp_mul_i2d@plt>
mov    %r14d,%edi
mov    0x20(%rsp),%rsi
mov    %rbx,%rdx
mov    0x28(%rsp),%rbx
mov    %rbx,%rcx
call   1060 <mp_mul_cmul_nt_d1_add@plt>
mov    0x14(%rsp),%edi
mov    %r12d,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
mov    0x30(%rsp),%rbp
mov    %rbp,%r8
call   1090 <mp_mul_d2i@plt>
cmpl   $0x0,0x0(%rbp)
je     1311 <mp_mul+0x1a1>
mov    0x4(%rsp),%edi
mov    %r12d,%esi
mov    %rbp,%rdx
mov    0x8(%rsp),%rcx
mov    %rbp,%r8
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mp_add@plt>
mov    0x4(%rsp),%edi
mov    %r12d,%esi
mov    0x8(%rsp),%rdx
mov    %rbp,%rcx
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <mp_copy@plt>

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

LLVM IR (-O2):
define void @mp_mul(i32 %0, i32 %1, i32* %2, i32* %3, i32* %4, i32* %5, i32 %6, double* %7, double* %8, double* %9) {
%11 = getelementptr inbounds i32, i32* %2, i64 2
%12 = bitcast i32* %11 to i16*
%13 = getelementptr inbounds i32, i32* %3, i64 2
%14 = bitcast i32* %13 to i16*
%15 = ashr i32 %6, 1
%16 = sext i32 %15 to i64
%17 = sext i32 %0 to i64
%18 = add nsw i32 %15, 1
%19 = call i32 @llvm.smax.i32(i32 %0, i32 %18)
br label %20
20: ; preds = %24, %10
%21 = phi i64 [ %22, %24 ], [ %16, %10 ]
%22 = add nsw i64 %21, 1
%23 = icmp slt i64 %22, %17
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = getelementptr inbounds i16, i16* %12, i64 %22
%26 = load i16, i16* %25
%27 = sext i16 %26 to i32
%28 = getelementptr inbounds i16, i16* %14, i64 %22
%29 = load i16, i16* %28
%30 = sext i16 %29 to i32
%31 = sub nsw i32 0, %30
%32 = icmp eq i32 %27, %31
br i1 %32, label %20, label %33
33: ; preds = %24
%34 = trunc i64 %22 to i32
br label %35
35: ; preds = %20, %33
%36 = phi i32 [ %34, %33 ], [ %19, %20 ]
%37 = sdiv i32 %0, 2
%38 = add nsw i32 %37, 1
%39 = sub nsw i32 %0, %36
%40 = icmp slt i32 %38, %39
%41 = select i1 %40, i32 %39, i32 %38
tail call void @mp_mul_i2d(i32 %0, i32 %1, i32 %6, i32 0, i32* %2, double* %7)
tail call void @mp_mul_i2d(i32 %0, i32 %1, i32 %6, i32 %36, i32* %3, double* %9)
tail call void @mp_mul_cmul_nt_out(i32 %6, double* %7, double* %9)
tail call void @mp_mul_i2d(i32 %0, i32 %1, i32 %6, i32 0, i32* %3, double* %8)
tail call void @mp_mul_cmul_nt_d2(i32 %6, double* %8, double* %7)
tail call void @mp_mul_d2i(i32 %0, i32 %1, i32 %6, double* %7, i32* %5)
tail call void @mp_mul_i2d(i32 %0, i32 %1, i32 %6, i32 %36, i32* %2, double* %7)
tail call void @mp_mul_cmul_nt_d1_add(i32 %6, double* %8, double* %7, double* %9)
tail call void @mp_mul_d2i(i32 %41, i32 %1, i32 %6, double* %9, i32* %4)
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %35
tail call void @mp_add(i32 %0, i32 %1, i32* %4, i32* %5, i32* %4)
br label %46
45: ; preds = %35
tail call void @mp_copy(i32 %0, i32 %1, i32* %5, i32* %4)
br label %46
46: ; preds = %45, %44
ret void
}