void outer_prod(double **Z, double x[], double y[], int n, int m) {
  int i, j;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      Z[i][j] = x[i] * y[j];
}


x86 assembly (clang, -O0):
<outer_prod>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    118d <outer_prod+0x8d>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    117a <outer_prod+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1131 <outer_prod+0x31>
jmp    117f <outer_prod+0x7f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111e <outer_prod+0x1e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<outer_prod>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %ecx,%ecx
jle    1332 <outer_prod+0x232>
mov    %ecx,%r12d
mov    %r8d,%r10d
lea    (%rdx,%r10,8),%rax
mov    %rax,-0x8(%rsp)
mov    %r10d,%r11d
and    $0xfffffffc,%r11d
lea    -0x4(%r11),%rax
mov    %rax,-0x10(%rsp)
mov    %rax,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,-0x18(%rsp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,-0x20(%rsp)
mov    %r10d,%r13d
and    $0x3,%r13d
xor    %eax,%eax
jmp    116d <outer_prod+0x6d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    %r12,%rax
je     1332 <outer_prod+0x232>
test   %r8d,%r8d
jle    1160 <outer_prod+0x60>
mov    (%rdi,%rax,8),%rbx
cmp    $0x4,%r8d
jb     1280 <outer_prod+0x180>
lea    (%rsi,%rax,8),%r9
lea    (%rsi,%rax,8),%rbp
add    $0x8,%rbp
lea    (%rbx,%r10,8),%rcx
cmp    %rbp,%rbx
setb   %bpl
cmp    %rcx,%r9
setb   %r15b
cmp    -0x8(%rsp),%rbx
setb   %r9b
cmp    %rdx,%rcx
seta   %r14b
test   %r15b,%bpl
jne    1280 <outer_prod+0x180>
mov    $0x0,%ebp
and    %r14b,%r9b
jne    1282 <outer_prod+0x182>
cmpq   $0x0,-0x10(%rsp)
je     1320 <outer_prod+0x220>
movsd  (%rsi,%rax,8),%xmm0
unpcklpd %xmm0,%xmm0
mov    -0x20(%rsp),%rcx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movupd (%rdx,%rbp,8),%xmm1
movupd 0x10(%rdx,%rbp,8),%xmm2
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,(%rbx,%rbp,8)
movupd %xmm2,0x10(%rbx,%rbp,8)
movupd 0x20(%rdx,%rbp,8),%xmm1
movupd 0x30(%rdx,%rbp,8),%xmm2
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,0x20(%rbx,%rbp,8)
movupd %xmm2,0x30(%rbx,%rbp,8)
add    $0x8,%rbp
add    $0xfffffffffffffffe,%rcx
jne    11f0 <outer_prod+0xf0>
testb  $0x1,-0x18(%rsp)
je     1266 <outer_prod+0x166>
movsd  (%rsi,%rax,8),%xmm0
unpcklpd %xmm0,%xmm0
movupd (%rdx,%rbp,8),%xmm1
movupd 0x10(%rdx,%rbp,8),%xmm2
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,(%rbx,%rbp,8)
movupd %xmm2,0x10(%rbx,%rbp,8)
mov    %r11,%rbp
cmp    %r10,%r11
je     1160 <outer_prod+0x60>
jmp    1282 <outer_prod+0x182>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
mov    %rbp,%r14
not    %r14
add    %r10,%r14
test   %r13,%r13
je     12b9 <outer_prod+0x1b9>
mov    %r13,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rsi,%rax,8),%xmm0
mulsd  (%rdx,%rbp,8),%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
add    $0xffffffffffffffff,%rcx
jne    12a0 <outer_prod+0x1a0>
cmp    $0x3,%r14
jb     1160 <outer_prod+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rsi,%rax,8),%xmm0
mulsd  (%rdx,%rbp,8),%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
movsd  (%rsi,%rax,8),%xmm0
mulsd  0x8(%rdx,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rbp,8)
movsd  (%rsi,%rax,8),%xmm0
mulsd  0x10(%rdx,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rbx,%rbp,8)
movsd  (%rsi,%rax,8),%xmm0
mulsd  0x18(%rdx,%rbp,8),%xmm0
movsd  %xmm0,0x18(%rbx,%rbp,8)
add    $0x4,%rbp
cmp    %rbp,%r10
jne    12d0 <outer_prod+0x1d0>
jmp    1160 <outer_prod+0x60>
xor    %ebp,%ebp
testb  $0x1,-0x18(%rsp)
jne    123f <outer_prod+0x13f>
jmp    1266 <outer_prod+0x166>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @outer_prod(double** nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %155
7: ; preds = %5
%8 = icmp sgt i32 %4, 0
%9 = zext i32 %3 to i64
%10 = zext i32 %4 to i64
%11 = getelementptr double, double* %2, i64 %10
%12 = and i64 %10, 4294967292
%13 = add nsw i64 %12, -4
%14 = lshr exact i64 %13, 2
%15 = add nuw nsw i64 %14, 1
%16 = icmp ult i32 %4, 4
%17 = and i64 %10, 4294967292
%18 = and i64 %15, 1
%19 = icmp eq i64 %13, 0
%20 = and i64 %15, 9223372036854775806
%21 = icmp eq i64 %18, 0
%22 = icmp eq i64 %17, %10
%23 = and i64 %10, 3
%24 = icmp eq i64 %23, 0
br label %25
25: ; preds = %7, %152
%26 = phi i64 [ 0, %7 ], [ %153, %152 ]
%27 = getelementptr double, double* %1, i64 %26
%28 = add nuw i64 %26, 1
%29 = getelementptr double, double* %1, i64 %28
br i1 %8, label %30, label %152
30: ; preds = %25
%31 = getelementptr inbounds double, double* %1, i64 %26
%32 = getelementptr inbounds double*, double** %0, i64 %26
%33 = load double*, double** %32
br i1 %16, label %107, label %34
34: ; preds = %30
%35 = getelementptr double, double* %33, i64 %10
%36 = icmp ult double* %33, %29
%37 = icmp ult double* %27, %35
%38 = and i1 %36, %37
%39 = icmp ult double* %33, %11
%40 = icmp ugt double* %35, %2
%41 = and i1 %39, %40
%42 = or i1 %38, %41
br i1 %42, label %107, label %43
43: ; preds = %34
br i1 %19, label %86, label %44
44: ; preds = %43
%45 = load double, double* %31
%46 = insertelement <2 x double> poison, double %45, i64 0
%47 = shufflevector <2 x double> %46, <2 x double> poison, <2 x i32> zeroinitializer
%48 = insertelement <2 x double> poison, double %45, i64 0
%49 = shufflevector <2 x double> %48, <2 x double> poison, <2 x i32> zeroinitializer
%50 = load double, double* %31
%51 = insertelement <2 x double> poison, double %50, i64 0
%52 = shufflevector <2 x double> %51, <2 x double> poison, <2 x i32> zeroinitializer
%53 = insertelement <2 x double> poison, double %50, i64 0
%54 = shufflevector <2 x double> %53, <2 x double> poison, <2 x i32> zeroinitializer
br label %55
55: ; preds = %55, %44
%56 = phi i64 [ 0, %44 ], [ %83, %55 ]
%57 = phi i64 [ 0, %44 ], [ %84, %55 ]
%58 = getelementptr inbounds double, double* %2, i64 %56
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = getelementptr inbounds double, double* %58, i64 2
%62 = bitcast double* %61 to <2 x double>*
%63 = load <2 x double>, <2 x double>* %62
%64 = fmul <2 x double> %47, %60
%65 = fmul <2 x double> %49, %63
%66 = getelementptr inbounds double, double* %33, i64 %56
%67 = bitcast double* %66 to <2 x double>*
store <2 x double> %64, <2 x double>* %67
%68 = getelementptr inbounds double, double* %66, i64 2
%69 = bitcast double* %68 to <2 x double>*
store <2 x double> %65, <2 x double>* %69
%70 = or i64 %56, 4
%71 = getelementptr inbounds double, double* %2, i64 %70
%72 = bitcast double* %71 to <2 x double>*
%73 = load <2 x double>, <2 x double>* %72
%74 = getelementptr inbounds double, double* %71, i64 2
%75 = bitcast double* %74 to <2 x double>*
%76 = load <2 x double>, <2 x double>* %75
%77 = fmul <2 x double> %52, %73
%78 = fmul <2 x double> %54, %76
%79 = getelementptr inbounds double, double* %33, i64 %70
%80 = bitcast double* %79 to <2 x double>*
store <2 x double> %77, <2 x double>* %80
%81 = getelementptr inbounds double, double* %79, i64 2
%82 = bitcast double* %81 to <2 x double>*
store <2 x double> %78, <2 x double>* %82
%83 = add nuw i64 %56, 8
%84 = add i64 %57, 2
%85 = icmp eq i64 %84, %20
br i1 %85, label %86, label %55
86: ; preds = %55, %43
%87 = phi i64 [ 0, %43 ], [ %83, %55 ]
br i1 %21, label %106, label %88
88: ; preds = %86
%89 = load double, double* %31
%90 = insertelement <2 x double> poison, double %89, i64 0
%91 = shufflevector <2 x double> %90, <2 x double> poison, <2 x i32> zeroinitializer
%92 = insertelement <2 x double> poison, double %89, i64 0
%93 = shufflevector <2 x double> %92, <2 x double> poison, <2 x i32> zeroinitializer
%94 = getelementptr inbounds double, double* %2, i64 %87
%95 = bitcast double* %94 to <2 x double>*
%96 = load <2 x double>, <2 x double>* %95
%97 = getelementptr inbounds double, double* %94, i64 2
%98 = bitcast double* %97 to <2 x double>*
%99 = load <2 x double>, <2 x double>* %98
%100 = fmul <2 x double> %91, %96
%101 = fmul <2 x double> %93, %99
%102 = getelementptr inbounds double, double* %33, i64 %87
%103 = bitcast double* %102 to <2 x double>*
store <2 x double> %100, <2 x double>* %103
%104 = getelementptr inbounds double, double* %102, i64 2
%105 = bitcast double* %104 to <2 x double>*
store <2 x double> %101, <2 x double>* %105
br label %106
106: ; preds = %86, %88
br i1 %22, label %152, label %107
107: ; preds = %34, %30, %106
%108 = phi i64 [ 0, %34 ], [ 0, %30 ], [ %17, %106 ]
%109 = xor i64 %108, -1
%110 = add nsw i64 %109, %10
br i1 %24, label %122, label %111
111: ; preds = %107, %111
%112 = phi i64 [ %119, %111 ], [ %108, %107 ]
%113 = phi i64 [ %120, %111 ], [ 0, %107 ]
%114 = load double, double* %31
%115 = getelementptr inbounds double, double* %2, i64 %112
%116 = load double, double* %115
%117 = fmul double %114, %116
%118 = getelementptr inbounds double, double* %33, i64 %112
store double %117, double* %118
%119 = add nuw nsw i64 %112, 1
%120 = add i64 %113, 1
%121 = icmp eq i64 %120, %23
br i1 %121, label %122, label %111
122: ; preds = %111, %107
%123 = phi i64 [ %108, %107 ], [ %119, %111 ]
%124 = icmp ult i64 %110, 3
br i1 %124, label %152, label %125
125: ; preds = %122, %125
%126 = phi i64 [ %150, %125 ], [ %123, %122 ]
%127 = load double, double* %31
%128 = getelementptr inbounds double, double* %2, i64 %126
%129 = load double, double* %128
%130 = fmul double %127, %129
%131 = getelementptr inbounds double, double* %33, i64 %126
store double %130, double* %131
%132 = add nuw nsw i64 %126, 1
%133 = load double, double* %31
%134 = getelementptr inbounds double, double* %2, i64 %132
%135 = load double, double* %134
%136 = fmul double %133, %135
%137 = getelementptr inbounds double, double* %33, i64 %132
store double %136, double* %137
%138 = add nuw nsw i64 %126, 2
%139 = load double, double* %31
%140 = getelementptr inbounds double, double* %2, i64 %138
%141 = load double, double* %140
%142 = fmul double %139, %141
%143 = getelementptr inbounds double, double* %33, i64 %138
store double %142, double* %143
%144 = add nuw nsw i64 %126, 3
%145 = load double, double* %31
%146 = getelementptr inbounds double, double* %2, i64 %144
%147 = load double, double* %146
%148 = fmul double %145, %147
%149 = getelementptr inbounds double, double* %33, i64 %144
store double %148, double* %149
%150 = add nuw nsw i64 %126, 4
%151 = icmp eq i64 %150, %10
br i1 %151, label %152, label %125
152: ; preds = %122, %125, %106, %25
%153 = add nuw nsw i64 %26, 1
%154 = icmp eq i64 %153, %9
br i1 %154, label %155, label %25
155: ; preds = %152, %5
ret void
}