void gather_array_double_bpr(double *restrict out, const double *restrict in,
                             unsigned int n) {
  for (; n; --n) {
    double q = *in++, *p = out++;
    do
      if (q != 0) {
        unsigned int a_ = *p;
        unsigned int b_ = q;
        if (a_ == 0) {
          *p = b_;
          break;
        }
        for (;;) {
          if (a_ < b_)
            b_ >>= 1;
          else if (b_ < a_)
            a_ >>= 1;
          else
            break;
        }
        *p = a_;
      }
    while (0);
  }
}


x86 assembly (clang, -O0):
<gather_array_double_bpr>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1205 <gather_array_double_bpr+0x105>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1161 <gather_array_double_bpr+0x61>
jp     1161 <gather_array_double_bpr+0x61>
jmp    11ed <gather_array_double_bpr+0xed>
mov    -0x28(%rbp),%rax
cvttsd2si (%rax),%rax
mov    %eax,-0x2c(%rbp)
cvttsd2si -0x20(%rbp),%rax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1195 <gather_array_double_bpr+0x95>
mov    -0x30(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    11f2 <gather_array_double_bpr+0xf2>
jmp    119a <gather_array_double_bpr+0x9a>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jae    11b4 <gather_array_double_bpr+0xb4>
mov    -0x30(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11d8 <gather_array_double_bpr+0xd8>
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    11ce <gather_array_double_bpr+0xce>
mov    -0x2c(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d3 <gather_array_double_bpr+0xd3>
jmp    11dd <gather_array_double_bpr+0xdd>
jmp    11d8 <gather_array_double_bpr+0xd8>
jmp    119a <gather_array_double_bpr+0x9a>
mov    -0x2c(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    11f2 <gather_array_double_bpr+0xf2>
jmp    11f7 <gather_array_double_bpr+0xf7>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    110f <gather_array_double_bpr+0xf>
pop    %rbp
ret

x86 assembly (clang, -O2):
<gather_array_double_bpr>:
test   %edx,%edx
je     1160 <gather_array_double_bpr+0x60>
xorpd  %xmm0,%xmm0
jmp    112d <gather_array_double_bpr+0x2d>
nopw   0x0(%rax,%rax,1)
mov    %ecx,%eax
mov    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  %xmm1,(%rdi)
add    $0x8,%rsi
add    $0x8,%rdi
add    $0xffffffff,%edx
je     1160 <gather_array_double_bpr+0x60>
movsd  (%rsi),%xmm1
ucomisd %xmm0,%xmm1
jne    1139 <gather_array_double_bpr+0x39>
jnp    1120 <gather_array_double_bpr+0x20>
cvttsd2si (%rdi),%rcx
cvttsd2si %xmm1,%rax
test   %ecx,%ecx
jne    1152 <gather_array_double_bpr+0x52>
jmp    1112 <gather_array_double_bpr+0x12>
nopl   0x0(%rax)
shr    %eax
cmp    %eax,%ecx
jb     1150 <gather_array_double_bpr+0x50>
jbe    1110 <gather_array_double_bpr+0x10>
shr    %ecx
cmp    %eax,%ecx
jb     1150 <gather_array_double_bpr+0x50>
jmp    1156 <gather_array_double_bpr+0x56>
ret

LLVM IR (-O0):
define void @gather_array_double_bpr(double* noalias %0, double* noalias %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
br label %11
11: ; preds = %59, %3
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %62
14: ; preds = %11
%15 = load double*, double** %5
%16 = getelementptr inbounds double, double* %15, i32 1
store double* %16, double** %5
%17 = load double, double* %15
store double %17, double* %7
%18 = load double*, double** %4
%19 = getelementptr inbounds double, double* %18, i32 1
store double* %19, double** %4
store double* %18, double** %8
br label %20
20: ; preds = %14
%21 = load double, double* %7
%22 = fcmp une double %21, 0.000000e+00
br i1 %22, label %23, label %57
23: ; preds = %20
%24 = load double*, double** %8
%25 = load double, double* %24
%26 = fptoui double %25 to i32
store i32 %26, i32* %9
%27 = load double, double* %7
%28 = fptoui double %27 to i32
store i32 %28, i32* %10
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %23
%32 = load i32, i32* %10
%33 = uitofp i32 %32 to double
%34 = load double*, double** %8
store double %33, double* %34
br label %58
35: ; preds = %23
br label %36
36: ; preds = %52, %35
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = icmp ult i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %10
%42 = lshr i32 %41, 1
store i32 %42, i32* %10
br label %52
43: ; preds = %36
%44 = load i32, i32* %10
%45 = load i32, i32* %9
%46 = icmp ult i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* %9
%49 = lshr i32 %48, 1
store i32 %49, i32* %9
br label %51
50: ; preds = %43
br label %53
51: ; preds = %47
br label %52
52: ; preds = %51, %40
br label %36
53: ; preds = %50
%54 = load i32, i32* %9
%55 = uitofp i32 %54 to double
%56 = load double*, double** %8
store double %55, double* %56
br label %57
57: ; preds = %53, %20
br label %58
58: ; preds = %57, %31
br label %59
59: ; preds = %58
%60 = load i32, i32* %6
%61 = add i32 %60, -1
store i32 %61, i32* %6
br label %11
62: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @gather_array_double_bpr(double* noalias nocapture %0, double* noalias nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %36, label %5
5: ; preds = %3, %33
%6 = phi double* [ %11, %33 ], [ %0, %3 ]
%7 = phi double* [ %9, %33 ], [ %1, %3 ]
%8 = phi i32 [ %34, %33 ], [ %2, %3 ]
%9 = getelementptr inbounds double, double* %7, i64 1
%10 = load double, double* %7
%11 = getelementptr inbounds double, double* %6, i64 1
%12 = fcmp une double %10, 0.000000e+00
br i1 %12, label %13, label %33
13: ; preds = %5
%14 = load double, double* %6
%15 = fptoui double %14 to i32
%16 = fptoui double %10 to i32
%17 = icmp eq i32 %15, 0
br i1 %17, label %30, label %18
18: ; preds = %13, %28
%19 = phi i32 [ %29, %28 ], [ %15, %13 ]
%20 = phi i32 [ %22, %28 ], [ %16, %13 ]
br label %21
21: ; preds = %18, %24
%22 = phi i32 [ %25, %24 ], [ %20, %18 ]
%23 = icmp ult i32 %19, %22
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = lshr i32 %22, 1
br label %21
26: ; preds = %21
%27 = icmp ult i32 %22, %19
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = lshr i32 %19, 1
br label %18
30: ; preds = %26, %13
%31 = phi i32 [ %16, %13 ], [ %19, %26 ]
%32 = uitofp i32 %31 to double
store double %32, double* %6
br label %33
33: ; preds = %30, %5
%34 = add i32 %8, -1
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %5
36: ; preds = %33, %3
ret void
}