void mp_mulhf(int n, int radix, int in1[], int in2[], int out[], int tmp[],
              int nfft, double in1fft[], double tmpfft[]) {
  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(int nfft, double d1[], double d2[]);
  void mp_mul_cmul_nt_d1(int nfft, double d1[], double d2[]);
  void mp_mul_d2i(int n, int radix, int nfft, double din[], int out[]);
  int n_h, shift;
  short int *in2dgt;
  in2dgt = (short int *)&in2[2];
  shift = (nfft >> 1) + 1;
  while (n > shift) {
    if (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, in1fft);
  mp_mul_i2d(n, radix, nfft, 0, in2, tmpfft);
  mp_mul_cmul(nfft, in1fft, tmpfft);
  mp_mul_d2i(n, radix, nfft, tmpfft, tmp);
  mp_mul_i2d(n, radix, nfft, shift, in2, tmpfft);
  mp_mul_cmul_nt_d1(nfft, in1fft, tmpfft);
  mp_mul_d2i(n_h, radix, nfft, tmpfft, out);
  if (out[0] != 0) {
    mp_add(n, radix, out, tmp, out);
  } else {
    mp_copy(n, radix, tmp, out);
  }
}


x86 assembly (clang, -O0):
<mp_mulhf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    0x10(%rbp),%eax
sar    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x30(%rbp),%eax
jle    11d5 <mp_mulhf+0x75>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
movswl (%rax,%rcx,2),%eax
cmp    $0x0,%eax
je     11c7 <mp_mulhf+0x67>
jmp    11d5 <mp_mulhf+0x75>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a1 <mp_mulhf+0x41>
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    1200 <mp_mulhf+0xa0>
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    -0x18(%rbp),%r8
mov    0x20(%rbp),%r9
xor    %ecx,%ecx
call   1040 <mp_mul_i2d@plt>
mov    0x10(%rbp),%edi
mov    0x18(%rbp),%rsi
mov    0x20(%rbp),%rdx
call   1060 <mp_mul_cmul@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x10(%rbp),%edx
mov    0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1080 <mp_mul_d2i@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x10(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    0x20(%rbp),%r9
call   1040 <mp_mul_i2d@plt>
mov    0x10(%rbp),%edi
mov    0x18(%rbp),%rsi
mov    0x20(%rbp),%rdx
call   1030 <mp_mul_cmul_nt_d1@plt>
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x10(%rbp),%edx
mov    0x20(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1080 <mp_mul_d2i@plt>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
je     12be <mp_mulhf+0x15e>
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    12d1 <mp_mulhf+0x171>
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_mulhf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,0x20(%rsp)
mov    %rcx,%r15
mov    %rdx,%r8
mov    0x70(%rsp),%r14
mov    0x68(%rsp),%r9
mov    0x60(%rsp),%r13d
mov    %r13d,%ebp
sar    %ebp
movslq %ebp,%rax
movslq %edi,%rcx
lea    0x1(%rax),%r10d
cmp    %r10d,%ecx
cmovg  %edi,%r10d
add    $0x5,%rax
nopw   0x0(%rax,%rax,1)
lea    -0x4(%rax),%rbx
cmp    %rcx,%rbx
jge    11ca <mp_mulhf+0x6a>
add    $0x1,%ebp
cmpw   $0x0,(%r15,%rax,2)
lea    0x1(%rax),%rax
je     11b0 <mp_mulhf+0x50>
jmp    11cd <mp_mulhf+0x6d>
mov    %r10d,%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    %r13d,%edx
xor    %ecx,%ecx
mov    %esi,%r12d
mov    %r9,0x18(%rsp)
mov    %edi,%ebx
call   1040 <mp_mul_i2d@plt>
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r13d,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r14,%r9
call   1040 <mp_mul_i2d@plt>
mov    %r13d,%edi
mov    0x18(%rsp),%rsi
mov    %r14,%rdx
call   1060 <mp_mul_cmul@plt>
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %r14,%rcx
mov    0x8(%rsp),%r8
call   1080 <mp_mul_d2i@plt>
mov    %ebx,0x4(%rsp)
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %ebp,%ecx
mov    %r15,%r8
mov    %r14,%r9
call   1040 <mp_mul_i2d@plt>
mov    %r13d,%edi
mov    0x18(%rsp),%rsi
mov    %r14,%rdx
call   1030 <mp_mul_cmul_nt_d1@plt>
mov    0x14(%rsp),%edi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %r14,%rcx
mov    0x20(%rsp),%rbx
mov    %rbx,%r8
call   1080 <mp_mul_d2i@plt>
cmpl   $0x0,(%rbx)
je     12a1 <mp_mulhf+0x141>
mov    0x4(%rsp),%edi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    0x8(%rsp),%rcx
mov    %rbx,%r8
add    $0x28,%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    %rbx,%rcx
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <mp_copy@plt>

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

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