void py_vec_func2d(double *dst, double (*func)(double, double),
                   const double *arg_x, const long size_x, const double *arg_y,
                   const long size_y) {
  for (long ii = 0; ii < size_x; ++ii)
    for (long jj = 0; jj < size_y; ++jj)
      dst[ii + jj * size_x] = func(arg_x[ii], arg_y[jj]);
}


x86 assembly (clang, -O0):
<py_vec_func2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    11ac <py_vec_func2d+0xac>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1196 <py_vec_func2d+0x96>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x38(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
mov    -0x28(%rbp),%rcx
mov    -0x40(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm1
call   *%rax
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rdx
imul   -0x20(%rbp),%rdx
add    %rdx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    113e <py_vec_func2d+0x3e>
jmp    119b <py_vec_func2d+0x9b>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1128 <py_vec_func2d+0x28>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<py_vec_func2d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x10(%rsp)
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
test   %rcx,%rcx
jle    11ac <py_vec_func2d+0xac>
mov    %r9,%rbx
mov    %r8,%r13
mov    %rdx,%r15
mov    %rsi,%rbp
mov    0x8(%rsp),%rax
lea    0x0(,%rax,8),%rax
xor    %ecx,%ecx
mov    %rax,0x18(%rsp)
jmp    1161 <py_vec_func2d+0x61>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rcx
addq   $0x8,0x10(%rsp)
cmp    0x8(%rsp),%rcx
je     11ac <py_vec_func2d+0xac>
test   %rbx,%rbx
jle    1150 <py_vec_func2d+0x50>
mov    0x10(%rsp),%r14
xor    %r12d,%r12d
mov    %rcx,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%r15,%rcx,8),%xmm0
movsd  0x0(%r13,%r12,8),%xmm1
call   *%rbp
mov    0x20(%rsp),%rcx
mov    0x18(%rsp),%rax
movsd  %xmm0,(%r14)
add    $0x1,%r12
add    %rax,%r14
cmp    %r12,%rbx
jne    1180 <py_vec_func2d+0x80>
jmp    1150 <py_vec_func2d+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @py_vec_func2d(double* %0, double (double, double)* %1, double* %2, i64 %3, double* %4, i64 %5) {
%7 = alloca double*
%8 = alloca double (double, double)*
%9 = alloca double*
%10 = alloca i64
%11 = alloca double*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
store double* %0, double** %7
store double (double, double)* %1, double (double, double)** %8
store double* %2, double** %9
store i64 %3, i64* %10
store double* %4, double** %11
store i64 %5, i64* %12
store i64 0, i64* %13
br label %15
15: ; preds = %46, %6
%16 = load i64, i64* %13
%17 = load i64, i64* %10
%18 = icmp slt i64 %16, %17
br i1 %18, label %19, label %49
19: ; preds = %15
store i64 0, i64* %14
br label %20
20: ; preds = %42, %19
%21 = load i64, i64* %14
%22 = load i64, i64* %12
%23 = icmp slt i64 %21, %22
br i1 %23, label %24, label %45
24: ; preds = %20
%25 = load double (double, double)*, double (double, double)** %8
%26 = load double*, double** %9
%27 = load i64, i64* %13
%28 = getelementptr inbounds double, double* %26, i64 %27
%29 = load double, double* %28
%30 = load double*, double** %11
%31 = load i64, i64* %14
%32 = getelementptr inbounds double, double* %30, i64 %31
%33 = load double, double* %32
%34 = call double %25(double %29, double %33)
%35 = load double*, double** %7
%36 = load i64, i64* %13
%37 = load i64, i64* %14
%38 = load i64, i64* %10
%39 = mul nsw i64 %37, %38
%40 = add nsw i64 %36, %39
%41 = getelementptr inbounds double, double* %35, i64 %40
store double %34, double* %41
br label %42
42: ; preds = %24
%43 = load i64, i64* %14
%44 = add nsw i64 %43, 1
store i64 %44, i64* %14
br label %20
45: ; preds = %20
br label %46
46: ; preds = %45
%47 = load i64, i64* %13
%48 = add nsw i64 %47, 1
store i64 %48, i64* %13
br label %15
49: ; preds = %15
ret void
}

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