void gather_vec_double_min(double *restrict out, const double *restrict in,
                           const unsigned vn,
                           const unsigned int *restrict map) {
  unsigned int i, j;
  while ((i = *map++) != -(unsigned int)1) {
    double *restrict p = &out[i * vn], *pe = p + vn;
    j = *map++;
    do {
      const double *restrict q = &in[j * vn];
      double *restrict pk = p;
      do {
        if (*q < *pk)
          *pk = *q;
        ++pk, ++q;
      } while (pk != pe);
    } while ((j = *map++) != -(unsigned int)1);
  }
}


x86 assembly (clang, -O0):
<gather_vec_double_min>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1205 <gather_vec_double_min+0x105>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x14(%rbp),%ecx
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x14(%rbp),%ecx
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x48(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b8 <gather_vec_double_min+0xb8>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x48(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x48(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    118e <gather_vec_double_min+0x8e>
jmp    11e3 <gather_vec_double_min+0xe3>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    116e <gather_vec_double_min+0x6e>
jmp    1113 <gather_vec_double_min+0x13>
pop    %rbp
ret

x86 assembly (clang, -O2):
<gather_vec_double_min>:
mov    (%rcx),%eax
cmp    $0xffffffff,%eax
je     1173 <gather_vec_double_min+0x73>
mov    %edx,%r8d
shl    $0x3,%r8
jmp    1117 <gather_vec_double_min+0x17>
mov    (%rcx),%eax
cmp    $0xffffffff,%eax
je     1173 <gather_vec_double_min+0x73>
imul   %edx,%eax
lea    (%rdi,%rax,8),%r9
mov    0x4(%rcx),%eax
add    $0x8,%rcx
jmp    113b <gather_vec_double_min+0x3b>
nopw   0x0(%rax,%rax,1)
mov    (%rcx),%eax
add    $0x4,%rcx
cmp    $0xffffffff,%eax
je     1110 <gather_vec_double_min+0x10>
imul   %edx,%eax
lea    (%rsi,%rax,8),%r10
xor    %eax,%eax
jmp    1159 <gather_vec_double_min+0x59>
cs nopw 0x0(%rax,%rax,1)
add    $0x8,%rax
cmp    %rax,%r8
je     1130 <gather_vec_double_min+0x30>
movsd  (%r10,%rax,1),%xmm0
movsd  (%r9,%rax,1),%xmm1
ucomisd %xmm0,%xmm1
jbe    1150 <gather_vec_double_min+0x50>
movsd  %xmm0,(%r9,%rax,1)
jmp    1150 <gather_vec_double_min+0x50>
ret

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

LLVM IR (-O2):
define void @gather_vec_double_min(double* noalias %0, double* noalias nocapture %1, i32 %2, i32* noalias nocapture %3) {
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %43, label %7
7: ; preds = %4
%8 = zext i32 %2 to i64
br label %12
9: ; preds = %39
%10 = load i32, i32* %40
%11 = icmp eq i32 %10, -1
br i1 %11, label %43, label %12
12: ; preds = %7, %9
%13 = phi i32 [ %5, %7 ], [ %10, %9 ]
%14 = phi i32* [ %3, %7 ], [ %40, %9 ]
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = mul i32 %13, %2
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = getelementptr inbounds double, double* %18, i64 %8
%20 = getelementptr inbounds i32, i32* %14, i64 2
%21 = load i32, i32* %15
br label %22
22: ; preds = %39, %12
%23 = phi i32 [ %21, %12 ], [ %41, %39 ]
%24 = phi i32* [ %20, %12 ], [ %40, %39 ]
%25 = mul i32 %23, %2
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds double, double* %1, i64 %26
br label %28
28: ; preds = %35, %22
%29 = phi double* [ %27, %22 ], [ %37, %35 ]
%30 = phi double* [ %18, %22 ], [ %36, %35 ]
%31 = load double, double* %29
%32 = load double, double* %30
%33 = fcmp olt double %31, %32
br i1 %33, label %34, label %35
34: ; preds = %28
store double %31, double* %30
br label %35
35: ; preds = %34, %28
%36 = getelementptr inbounds double, double* %30, i64 1
%37 = getelementptr inbounds double, double* %29, i64 1
%38 = icmp eq double* %36, %19
br i1 %38, label %39, label %28
39: ; preds = %35
%40 = getelementptr inbounds i32, i32* %24, i64 1
%41 = load i32, i32* %24
%42 = icmp eq i32 %41, -1
br i1 %42, label %9, label %22
43: ; preds = %9, %4
ret void
}