void zip(double (*f)(double, double), double *v1, double *v2, int s,
         double *res) {
  for (int i = 0; i < s; ++i) {
    res[i] = (*f)(v1[i], v2[i]);
  }
}


x86 assembly (clang, -O0):
<zip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1169 <zip+0x69>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm1
call   *%rax
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1122 <zip+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    113e <zip+0x3e>
mov    %r8,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    %ecx,%ebx
xor    %ebp,%ebp
nop
movsd  (%r12,%rbp,8),%xmm0
movsd  (%r15,%rbp,8),%xmm1
call   *%r13
movsd  %xmm0,(%r14,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1120 <zip+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @zip(double (double, double)* %0, double* %1, double* %2, i32 %3, double* %4) {
%6 = alloca double (double, double)*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
store double (double, double)* %0, double (double, double)** %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store double* %4, double** %10
store i32 0, i32* %11
br label %12
12: ; preds = %33, %5
%13 = load i32, i32* %11
%14 = load i32, i32* %9
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = load double (double, double)*, double (double, double)** %6
%18 = load double*, double** %7
%19 = load i32, i32* %11
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %8
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = call double %17(double %22, double %27)
%29 = load double*, double** %10
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
store double %28, double* %32
br label %33
33: ; preds = %16
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %12
36: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @zip(double (double, double)* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3, double* nocapture writeonly %4) {
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = zext i32 %3 to i64
br label %10
9: ; preds = %10, %5
ret void
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %18, %10 ]
%12 = getelementptr inbounds double, double* %1, i64 %11
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %2, i64 %11
%15 = load double, double* %14
%16 = tail call double %0(double %13, double %15)
%17 = getelementptr inbounds double, double* %4, i64 %11
store double %16, double* %17
%18 = add nuw nsw i64 %11, 1
%19 = icmp eq i64 %18, %8
br i1 %19, label %9, label %10
}