unsigned int bar(const unsigned int x[40][2], unsigned int sum) {
  int i;
  for (i = 0; i < 40; i++)
    sum += x[i][0] * x[i][0] + x[i][1] * x[i][1];
  return sum;
}


x86 assembly (clang, -O0):
<bar>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x28,-0x10(%rbp)
jge    1162 <bar+0x62>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
imul   (%rcx,%rdx,8),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
mov    0x4(%rcx,%rdx,8),%ecx
mov    -0x8(%rbp),%rdx
movslq -0x10(%rbp),%rsi
imul   0x4(%rdx,%rsi,8),%ecx
add    %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1112 <bar+0x12>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bar>:
movd   %esi,%xmm2
movups (%rdi),%xmm3
movups 0x10(%rdi),%xmm4
movups 0x20(%rdi),%xmm0
movups 0x30(%rdi),%xmm1
movaps %xmm3,%xmm5
shufps $0x88,%xmm4,%xmm5
movaps %xmm3,%xmm6
shufps $0xaa,%xmm4,%xmm6
pmuludq %xmm6,%xmm6
pshufd $0xe8,%xmm6,%xmm6
pmuludq %xmm5,%xmm5
pshufd $0xe8,%xmm5,%xmm5
punpckldq %xmm6,%xmm5
paddd  %xmm2,%xmm5
movaps %xmm3,%xmm2
shufps $0xdd,%xmm4,%xmm2
shufps $0xff,%xmm4,%xmm3
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pmuludq %xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm4
punpckldq %xmm3,%xmm4
movaps %xmm0,%xmm2
shufps $0x88,%xmm1,%xmm2
movaps %xmm0,%xmm3
shufps $0xaa,%xmm1,%xmm3
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pmuludq %xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm3,%xmm2
paddd  %xmm4,%xmm2
paddd  %xmm5,%xmm2
movaps %xmm0,%xmm3
shufps $0xdd,%xmm1,%xmm3
shufps $0xff,%xmm1,%xmm0
pmuludq %xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm1
punpckldq %xmm0,%xmm1
movups 0x50(%rdi),%xmm0
movups 0x40(%rdi),%xmm3
movaps %xmm3,%xmm4
shufps $0x88,%xmm0,%xmm4
movaps %xmm3,%xmm5
shufps $0xaa,%xmm0,%xmm5
pmuludq %xmm5,%xmm5
pshufd $0xe8,%xmm5,%xmm5
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm5,%xmm4
paddd  %xmm1,%xmm4
movaps %xmm3,%xmm1
shufps $0xdd,%xmm0,%xmm1
shufps $0xff,%xmm0,%xmm3
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm0
pmuludq %xmm1,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm0,%xmm1
paddd  %xmm4,%xmm1
paddd  %xmm2,%xmm1
movups 0x70(%rdi),%xmm0
movups 0x60(%rdi),%xmm2
movaps %xmm2,%xmm3
shufps $0x88,%xmm0,%xmm3
movaps %xmm2,%xmm4
shufps $0xaa,%xmm0,%xmm4
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm4,%xmm3
movaps %xmm2,%xmm4
shufps $0xdd,%xmm0,%xmm4
shufps $0xff,%xmm0,%xmm2
pmuludq %xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm0
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm2
punpckldq %xmm0,%xmm2
paddd  %xmm3,%xmm2
movups 0x90(%rdi),%xmm0
movups 0x80(%rdi),%xmm3
movaps %xmm3,%xmm4
shufps $0x88,%xmm0,%xmm4
movaps %xmm3,%xmm5
shufps $0xaa,%xmm0,%xmm5
pmuludq %xmm5,%xmm5
pshufd $0xe8,%xmm5,%xmm5
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm5,%xmm4
paddd  %xmm2,%xmm4
movaps %xmm3,%xmm2
shufps $0xdd,%xmm0,%xmm2
shufps $0xff,%xmm0,%xmm3
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pmuludq %xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm0
punpckldq %xmm3,%xmm0
paddd  %xmm4,%xmm0
paddd  %xmm1,%xmm0
movups 0xb0(%rdi),%xmm1
movups 0xa0(%rdi),%xmm2
movaps %xmm2,%xmm3
shufps $0x88,%xmm1,%xmm3
movaps %xmm2,%xmm4
shufps $0xaa,%xmm1,%xmm4
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm4,%xmm3
movaps %xmm2,%xmm4
shufps $0xdd,%xmm1,%xmm4
shufps $0xff,%xmm1,%xmm2
pmuludq %xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm1
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm2
punpckldq %xmm1,%xmm2
paddd  %xmm3,%xmm2
movups 0xd0(%rdi),%xmm1
movups 0xc0(%rdi),%xmm3
movaps %xmm3,%xmm4
shufps $0x88,%xmm1,%xmm4
movaps %xmm3,%xmm5
shufps $0xaa,%xmm1,%xmm5
pmuludq %xmm5,%xmm5
pshufd $0xe8,%xmm5,%xmm5
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm5,%xmm4
paddd  %xmm2,%xmm4
movaps %xmm3,%xmm2
shufps $0xdd,%xmm1,%xmm2
shufps $0xff,%xmm1,%xmm3
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm1
pmuludq %xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm1,%xmm2
paddd  %xmm4,%xmm2
movups 0xf0(%rdi),%xmm3
movups 0xe0(%rdi),%xmm4
movaps %xmm4,%xmm1
shufps $0x88,%xmm3,%xmm1
movaps %xmm4,%xmm5
shufps $0xaa,%xmm3,%xmm5
pmuludq %xmm5,%xmm5
pshufd $0xe8,%xmm5,%xmm5
pmuludq %xmm1,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm5,%xmm1
paddd  %xmm2,%xmm1
paddd  %xmm0,%xmm1
movaps %xmm4,%xmm0
shufps $0xdd,%xmm3,%xmm0
shufps $0xff,%xmm3,%xmm4
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm2
pmuludq %xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm2,%xmm0
movups 0x110(%rdi),%xmm2
movups 0x100(%rdi),%xmm3
movaps %xmm3,%xmm4
shufps $0x88,%xmm2,%xmm4
movaps %xmm3,%xmm5
shufps $0xaa,%xmm2,%xmm5
pmuludq %xmm5,%xmm5
pshufd $0xe8,%xmm5,%xmm5
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm5,%xmm4
paddd  %xmm0,%xmm4
movaps %xmm3,%xmm0
shufps $0xdd,%xmm2,%xmm0
shufps $0xff,%xmm2,%xmm3
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm2
pmuludq %xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm2,%xmm0
paddd  %xmm4,%xmm0
movups 0x130(%rdi),%xmm2
movups 0x120(%rdi),%xmm3
movaps %xmm3,%xmm4
shufps $0x88,%xmm2,%xmm4
movaps %xmm3,%xmm5
shufps $0xaa,%xmm2,%xmm5
pmuludq %xmm5,%xmm5
pshufd $0xe8,%xmm5,%xmm5
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm5,%xmm4
paddd  %xmm0,%xmm4
movaps %xmm3,%xmm0
shufps $0xdd,%xmm2,%xmm0
shufps $0xff,%xmm2,%xmm3
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm2
pmuludq %xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm2,%xmm0
paddd  %xmm4,%xmm0
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
ret

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

LLVM IR (-O2):
define i32 @bar([2 x i32]* nocapture %0, i32 %1) {
%3 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %1, i64 0
%4 = bitcast [2 x i32]* %0 to <8 x i32>*
%5 = load <8 x i32>, <8 x i32>* %4
%6 = mul <8 x i32> %5, %5
%7 = shufflevector <8 x i32> %6, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%8 = mul <8 x i32> %5, %5
%9 = shufflevector <8 x i32> %8, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%10 = add <4 x i32> %7, %3
%11 = add <4 x i32> %10, %9
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 4, i64 0
%13 = bitcast i32* %12 to <8 x i32>*
%14 = load <8 x i32>, <8 x i32>* %13
%15 = mul <8 x i32> %14, %14
%16 = shufflevector <8 x i32> %15, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%17 = mul <8 x i32> %14, %14
%18 = shufflevector <8 x i32> %17, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%19 = add <4 x i32> %16, %11
%20 = add <4 x i32> %19, %18
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 8, i64 0
%22 = bitcast i32* %21 to <8 x i32>*
%23 = load <8 x i32>, <8 x i32>* %22
%24 = mul <8 x i32> %23, %23
%25 = shufflevector <8 x i32> %24, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%26 = mul <8 x i32> %23, %23
%27 = shufflevector <8 x i32> %26, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%28 = add <4 x i32> %25, %20
%29 = add <4 x i32> %28, %27
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 12, i64 0
%31 = bitcast i32* %30 to <8 x i32>*
%32 = load <8 x i32>, <8 x i32>* %31
%33 = mul <8 x i32> %32, %32
%34 = shufflevector <8 x i32> %33, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%35 = mul <8 x i32> %32, %32
%36 = shufflevector <8 x i32> %35, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%37 = add <4 x i32> %34, %29
%38 = add <4 x i32> %37, %36
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 16, i64 0
%40 = bitcast i32* %39 to <8 x i32>*
%41 = load <8 x i32>, <8 x i32>* %40
%42 = mul <8 x i32> %41, %41
%43 = shufflevector <8 x i32> %42, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%44 = mul <8 x i32> %41, %41
%45 = shufflevector <8 x i32> %44, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%46 = add <4 x i32> %43, %38
%47 = add <4 x i32> %46, %45
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 20, i64 0
%49 = bitcast i32* %48 to <8 x i32>*
%50 = load <8 x i32>, <8 x i32>* %49
%51 = mul <8 x i32> %50, %50
%52 = shufflevector <8 x i32> %51, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%53 = mul <8 x i32> %50, %50
%54 = shufflevector <8 x i32> %53, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%55 = add <4 x i32> %52, %47
%56 = add <4 x i32> %55, %54
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 24, i64 0
%58 = bitcast i32* %57 to <8 x i32>*
%59 = load <8 x i32>, <8 x i32>* %58
%60 = mul <8 x i32> %59, %59
%61 = shufflevector <8 x i32> %60, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%62 = mul <8 x i32> %59, %59
%63 = shufflevector <8 x i32> %62, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%64 = add <4 x i32> %61, %56
%65 = add <4 x i32> %64, %63
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 28, i64 0
%67 = bitcast i32* %66 to <8 x i32>*
%68 = load <8 x i32>, <8 x i32>* %67
%69 = mul <8 x i32> %68, %68
%70 = shufflevector <8 x i32> %69, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%71 = mul <8 x i32> %68, %68
%72 = shufflevector <8 x i32> %71, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%73 = add <4 x i32> %70, %65
%74 = add <4 x i32> %73, %72
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 32, i64 0
%76 = bitcast i32* %75 to <8 x i32>*
%77 = load <8 x i32>, <8 x i32>* %76
%78 = mul <8 x i32> %77, %77
%79 = shufflevector <8 x i32> %78, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%80 = mul <8 x i32> %77, %77
%81 = shufflevector <8 x i32> %80, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%82 = add <4 x i32> %79, %74
%83 = add <4 x i32> %82, %81
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i64 36, i64 0
%85 = bitcast i32* %84 to <8 x i32>*
%86 = load <8 x i32>, <8 x i32>* %85
%87 = mul <8 x i32> %86, %86
%88 = shufflevector <8 x i32> %87, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
%89 = mul <8 x i32> %86, %86
%90 = shufflevector <8 x i32> %89, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
%91 = add <4 x i32> %88, %83
%92 = add <4 x i32> %91, %90
%93 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %92)
ret i32 %93
}