int add_mux(int *id, int *mask) {
  int i;
  int result = 0;
  for (i = 0; i < 17; i++)
    result += id[i] * mask[i];
  return result;
}


x86 assembly (clang, -O0):
<add_mux>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x11,-0x14(%rbp)
jge    114f <add_mux+0x4f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
imul   (%rcx,%rdx,4),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    111a <add_mux+0x1a>
mov    -0x18(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_mux>:
mov    (%rsi),%ecx
imul   (%rdi),%ecx
movdqu 0x4(%rdi),%xmm2
movdqu 0x14(%rdi),%xmm8
movdqu 0x24(%rdi),%xmm3
movdqu 0x34(%rdi),%xmm4
movdqu 0x14(%rsi),%xmm1
movdqu 0x34(%rsi),%xmm5
movdqu 0x4(%rsi),%xmm6
movdqu 0x24(%rsi),%xmm7
pshufd $0xf5,%xmm7,%xmm0
pmuludq %xmm3,%xmm7
pshufd $0xe8,%xmm7,%xmm7
pshufd $0xf5,%xmm3,%xmm3
pmuludq %xmm3,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm7
pshufd $0xf5,%xmm6,%xmm0
pmuludq %xmm2,%xmm6
pshufd $0xe8,%xmm6,%xmm3
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm0,%xmm2
pshufd $0xe8,%xmm2,%xmm0
punpckldq %xmm0,%xmm3
paddd  %xmm7,%xmm3
pshufd $0xf5,%xmm5,%xmm0
pmuludq %xmm4,%xmm5
pshufd $0xe8,%xmm5,%xmm2
pshufd $0xf5,%xmm4,%xmm4
pmuludq %xmm0,%xmm4
pshufd $0xe8,%xmm4,%xmm0
punpckldq %xmm0,%xmm2
pshufd $0xf5,%xmm1,%xmm0
pmuludq %xmm8,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pshufd $0xf5,%xmm8,%xmm4
pmuludq %xmm0,%xmm4
pshufd $0xe8,%xmm4,%xmm0
punpckldq %xmm0,%xmm1
paddd  %xmm2,%xmm1
paddd  %xmm3,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
add    %ecx,%eax
ret

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

LLVM IR (-O2):
define i32 @add_mux(i32* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %0
%4 = load i32, i32* %1
%5 = mul nsw i32 %4, %3
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = getelementptr inbounds i32, i32* %1, i64 1
%8 = bitcast i32* %6 to <16 x i32>*
%9 = load <16 x i32>, <16 x i32>* %8
%10 = bitcast i32* %7 to <16 x i32>*
%11 = load <16 x i32>, <16 x i32>* %10
%12 = mul nsw <16 x i32> %11, %9
%13 = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %12)
%14 = add nsw i32 %13, %5
ret i32 %14
}