int totalHammingDistance(int *nums, int numsSize) {
  int cnt[32][2];
  for (int i = 0; i < 32; i++) {
    cnt[i][0] = 0;
    cnt[i][1] = 0;
  }
  int mask = 0x1;
  for (int i = 0; i < numsSize; i++) {
    int tmp = nums[i];
    for (int j = 0; j < 32; j++) {
      if ((tmp & mask) == 0) {
        cnt[j][0]++;
      } else {
        cnt[j][1]++;
      }
      tmp >>= 1;
    }
  }
  int res = 0;
  for (int i = 0; i < 32; i++) {
    res += cnt[i][0] * cnt[i][1];
  }
  return res;
}


x86 assembly (clang, -O0):
<totalHammingDistance>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x114(%rbp)
cmpl   $0x20,-0x114(%rbp)
jge    1161 <totalHammingDistance+0x61>
movslq -0x114(%rbp),%rax
movl   $0x0,-0x110(%rbp,%rax,8)
movslq -0x114(%rbp),%rax
movl   $0x0,-0x10c(%rbp,%rax,8)
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    111c <totalHammingDistance+0x1c>
movl   $0x1,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
mov    -0x11c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1235 <totalHammingDistance+0x135>
mov    -0x8(%rbp),%rax
movslq -0x11c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x120(%rbp)
movl   $0x0,-0x124(%rbp)
cmpl   $0x20,-0x124(%rbp)
jge    121c <totalHammingDistance+0x11c>
mov    -0x120(%rbp),%eax
and    -0x118(%rbp),%eax
cmp    $0x0,%eax
jne    11e1 <totalHammingDistance+0xe1>
movslq -0x124(%rbp),%rax
mov    -0x110(%rbp,%rax,8),%ecx
add    $0x1,%ecx
mov    %ecx,-0x110(%rbp,%rax,8)
jmp    11f9 <totalHammingDistance+0xf9>
movslq -0x124(%rbp),%rax
mov    -0x10c(%rbp,%rax,8),%ecx
add    $0x1,%ecx
mov    %ecx,-0x10c(%rbp,%rax,8)
mov    -0x120(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x120(%rbp)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11a2 <totalHammingDistance+0xa2>
jmp    1221 <totalHammingDistance+0x121>
mov    -0x11c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x11c(%rbp)
jmp    1175 <totalHammingDistance+0x75>
movl   $0x0,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
cmpl   $0x20,-0x12c(%rbp)
jge    1293 <totalHammingDistance+0x193>
movslq -0x12c(%rbp),%rax
mov    -0x110(%rbp,%rax,8),%eax
movslq -0x12c(%rbp),%rcx
imul   -0x10c(%rbp,%rcx,8),%eax
ff
add    -0x128(%rbp),%eax
mov    %eax,-0x128(%rbp)
mov    -0x12c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x12c(%rbp)
jmp    1249 <totalHammingDistance+0x149>
mov    -0x128(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<totalHammingDistance>:
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,-0x10(%rsp)
movaps %xmm0,-0x20(%rsp)
movaps %xmm0,-0x30(%rsp)
movaps %xmm0,-0x40(%rsp)
movaps %xmm0,-0x50(%rsp)
movaps %xmm0,-0x60(%rsp)
movaps %xmm0,-0x70(%rsp)
movaps %xmm0,-0x80(%rsp)
test   %esi,%esi
jle    119d <totalHammingDistance+0x9d>
mov    %esi,%eax
xor    %ecx,%ecx
jmp    1179 <totalHammingDistance+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rcx
cmp    %rax,%rcx
je     119d <totalHammingDistance+0x9d>
mov    (%rdi,%rcx,4),%edx
xor    %esi,%esi
jmp    1191 <totalHammingDistance+0x91>
addl   $0x1,-0x7c(%rsp,%rsi,8)
sar    %edx
add    $0x1,%rsi
cmp    $0x20,%rsi
je     1170 <totalHammingDistance+0x70>
test   $0x1,%dl
jne    1180 <totalHammingDistance+0x80>
addl   $0x1,-0x80(%rsp,%rsi,8)
jmp    1185 <totalHammingDistance+0x85>
movaps -0x80(%rsp),%xmm0
movaps -0x70(%rsp),%xmm1
movaps -0x60(%rsp),%xmm2
movaps -0x50(%rsp),%xmm3
movaps %xmm0,%xmm4
movlhps %xmm1,%xmm4
movaps %xmm0,%xmm5
shufps $0xdd,%xmm1,%xmm5
pmuludq %xmm4,%xmm5
movaps %xmm0,%xmm4
unpckhpd %xmm1,%xmm4
shufps $0xff,%xmm1,%xmm0
pmuludq %xmm4,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pshufd $0xe8,%xmm5,%xmm4
punpckldq %xmm0,%xmm4
movaps %xmm2,%xmm0
movlhps %xmm3,%xmm0
movaps %xmm2,%xmm1
shufps $0xdd,%xmm3,%xmm1
pmuludq %xmm0,%xmm1
movaps %xmm2,%xmm0
unpckhpd %xmm3,%xmm0
shufps $0xff,%xmm3,%xmm2
pmuludq %xmm0,%xmm2
pshufd $0xe8,%xmm2,%xmm0
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm0,%xmm1
paddd  %xmm4,%xmm1
movaps -0x30(%rsp),%xmm0
movaps -0x40(%rsp),%xmm2
movaps %xmm2,%xmm3
movlhps %xmm0,%xmm3
movaps %xmm2,%xmm4
shufps $0xdd,%xmm0,%xmm4
pmuludq %xmm3,%xmm4
movaps %xmm2,%xmm3
unpckhpd %xmm0,%xmm3
shufps $0xff,%xmm0,%xmm2
pmuludq %xmm3,%xmm2
pshufd $0xe8,%xmm2,%xmm0
pshufd $0xe8,%xmm4,%xmm2
punpckldq %xmm0,%xmm2
movaps -0x10(%rsp),%xmm0
movaps -0x20(%rsp),%xmm3
movaps %xmm3,%xmm4
movlhps %xmm0,%xmm4
movaps %xmm3,%xmm5
shufps $0xdd,%xmm0,%xmm5
pmuludq %xmm4,%xmm5
movaps %xmm3,%xmm4
unpckhpd %xmm0,%xmm4
shufps $0xff,%xmm0,%xmm3
pmuludq %xmm4,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pshufd $0xe8,%xmm5,%xmm0
punpckldq %xmm3,%xmm0
paddd  %xmm2,%xmm0
paddd  %xmm1,%xmm0
movaps 0x10(%rsp),%xmm1
movaps (%rsp),%xmm2
movaps %xmm2,%xmm3
movlhps %xmm1,%xmm3
movaps %xmm2,%xmm4
shufps $0xdd,%xmm1,%xmm4
pmuludq %xmm3,%xmm4
movaps %xmm2,%xmm3
unpckhpd %xmm1,%xmm3
shufps $0xff,%xmm1,%xmm2
pmuludq %xmm3,%xmm2
pshufd $0xe8,%xmm2,%xmm1
pshufd $0xe8,%xmm4,%xmm2
punpckldq %xmm1,%xmm2
movaps 0x30(%rsp),%xmm1
movaps 0x20(%rsp),%xmm3
movaps %xmm3,%xmm4
movlhps %xmm1,%xmm4
movaps %xmm3,%xmm5
shufps $0xdd,%xmm1,%xmm5
pmuludq %xmm4,%xmm5
movaps %xmm3,%xmm4
unpckhpd %xmm1,%xmm4
shufps $0xff,%xmm1,%xmm3
pmuludq %xmm4,%xmm3
pshufd $0xe8,%xmm3,%xmm1
pshufd $0xe8,%xmm5,%xmm3
punpckldq %xmm1,%xmm3
paddd  %xmm2,%xmm3
movaps 0x50(%rsp),%xmm1
movaps 0x40(%rsp),%xmm2
movaps %xmm2,%xmm4
movlhps %xmm1,%xmm4
movaps %xmm2,%xmm5
shufps $0xdd,%xmm1,%xmm5
pmuludq %xmm4,%xmm5
movaps %xmm2,%xmm4
unpckhpd %xmm1,%xmm4
shufps $0xff,%xmm1,%xmm2
pmuludq %xmm4,%xmm2
pshufd $0xe8,%xmm2,%xmm1
pshufd $0xe8,%xmm5,%xmm2
punpckldq %xmm1,%xmm2
paddd  %xmm3,%xmm2
paddd  %xmm0,%xmm2
movaps 0x70(%rsp),%xmm0
movaps 0x60(%rsp),%xmm1
movaps %xmm1,%xmm3
movlhps %xmm0,%xmm3
movaps %xmm1,%xmm4
shufps $0xdd,%xmm0,%xmm4
pmuludq %xmm3,%xmm4
movaps %xmm1,%xmm3
unpckhpd %xmm0,%xmm3
shufps $0xff,%xmm0,%xmm1
pmuludq %xmm3,%xmm1
pshufd $0xe8,%xmm1,%xmm0
pshufd $0xe8,%xmm4,%xmm1
punpckldq %xmm0,%xmm1
paddd  %xmm2,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
add    $0x88,%rsp
ret

LLVM IR (-O0):
define i32 @totalHammingDistance(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [32 x [2 x i32]]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %6
br label %13
13: ; preds = %25, %2
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 32
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [32 x [2 x i32]], [32 x [2 x i32]]* %5, i64 0, i64 %18
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 0
store i32 0, i32* %20
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [32 x [2 x i32]], [32 x [2 x i32]]* %5, i64 0, i64 %22
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 1
store i32 0, i32* %24
br label %25
25: ; preds = %16
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %13
28: ; preds = %13
store i32 1, i32* %7
store i32 0, i32* %8
br label %29
29: ; preds = %68, %28
%30 = load i32, i32* %8
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %71
33: ; preds = %29
%34 = load i32*, i32** %3
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
store i32 %38, i32* %9
store i32 0, i32* %10
br label %39
39: ; preds = %64, %33
%40 = load i32, i32* %10
%41 = icmp slt i32 %40, 32
br i1 %41, label %42, label %67
42: ; preds = %39
%43 = load i32, i32* %9
%44 = load i32, i32* %7
%45 = and i32 %43, %44
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %42
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [32 x [2 x i32]], [32 x [2 x i32]]* %5, i64 0, i64 %49
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %50, i64 0, i64 0
%52 = load i32, i32* %51
%53 = add nsw i32 %52, 1
store i32 %53, i32* %51
br label %61
54: ; preds = %42
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [32 x [2 x i32]], [32 x [2 x i32]]* %5, i64 0, i64 %56
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %57, i64 0, i64 1
%59 = load i32, i32* %58
%60 = add nsw i32 %59, 1
store i32 %60, i32* %58
br label %61
61: ; preds = %54, %47
%62 = load i32, i32* %9
%63 = ashr i32 %62, 1
store i32 %63, i32* %9
br label %64
64: ; preds = %61
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %39
67: ; preds = %39
br label %68
68: ; preds = %67
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
br label %29
71: ; preds = %29
store i32 0, i32* %11
store i32 0, i32* %12
br label %72
72: ; preds = %89, %71
%73 = load i32, i32* %12
%74 = icmp slt i32 %73, 32
br i1 %74, label %75, label %92
75: ; preds = %72
%76 = load i32, i32* %12
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [32 x [2 x i32]], [32 x [2 x i32]]* %5, i64 0, i64 %77
%79 = getelementptr inbounds [2 x i32], [2 x i32]* %78, i64 0, i64 0
%80 = load i32, i32* %79
%81 = load i32, i32* %12
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [32 x [2 x i32]], [32 x [2 x i32]]* %5, i64 0, i64 %82
%84 = getelementptr inbounds [2 x i32], [2 x i32]* %83, i64 0, i64 1
%85 = load i32, i32* %84
%86 = mul nsw i32 %80, %85
%87 = load i32, i32* %11
%88 = add nsw i32 %87, %86
store i32 %88, i32* %11
br label %89
89: ; preds = %75
%90 = load i32, i32* %12
%91 = add nsw i32 %90, 1
store i32 %91, i32* %12
br label %72
92: ; preds = %72
%93 = load i32, i32* %11
ret i32 %93
}

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