int digit_10(int *n) {
  int j;
  int sum = 0;
  int i = 0;
  int weight[9] = {2, 4, 8, 5, 10, 9, 7, 3, 6};
  for (i = 0; i < 9; i++) {
    j = n[i] * weight[i];
    sum = sum + j;
  }
  sum = sum % 11;
  if (sum < 10) {
    return sum;
  } else {
    sum = 0;
    return sum;
  }
}


x86 assembly (clang, -O0):
<digit_10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xecb(%rip),%rsi
mov    $0x24,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x9,-0x1c(%rbp)
jge    117e <digit_10+0x6e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
movslq -0x1c(%rbp),%rcx
imul   -0x40(%rbp,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1146 <digit_10+0x36>
mov    -0x18(%rbp),%eax
mov    $0xb,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    11a1 <digit_10+0x91>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <digit_10+0x9e>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digit_10>:
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
add    %eax,%eax
lea    (%rax,%rcx,4),%eax
mov    0x8(%rdi),%ecx
lea    (%rax,%rcx,8),%eax
mov    0xc(%rdi),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    0x10(%rdi),%edx
lea    (%rdx,%rdx,4),%edx
movdqu 0x14(%rdi),%xmm0
movdqa 0xed7(%rip),%xmm1
pmuludq %xmm0,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pshufd $0xf5,%xmm0,%xmm0
pmuludq 0xed1(%rip),%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%esi
lea    (%rsi,%rdx,2),%edx
add    %ecx,%edx
add    %eax,%edx
movslq %edx,%rcx
imul   $0x2e8ba2e9,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rax
add    %edx,%eax
lea    (%rax,%rax,4),%edx
lea    (%rax,%rdx,2),%eax
sub    %eax,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
cmovl  %ecx,%eax
ret

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

LLVM IR (-O2):
define i32 @digit_10(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = shl nsw i32 %2, 1
%4 = getelementptr inbounds i32, i32* %0, i64 1
%5 = load i32, i32* %4
%6 = shl nsw i32 %5, 2
%7 = add nsw i32 %6, %3
%8 = getelementptr inbounds i32, i32* %0, i64 2
%9 = load i32, i32* %8
%10 = shl nsw i32 %9, 3
%11 = add nsw i32 %10, %7
%12 = getelementptr inbounds i32, i32* %0, i64 3
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, 5
%15 = getelementptr inbounds i32, i32* %0, i64 4
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 10
%18 = getelementptr inbounds i32, i32* %0, i64 5
%19 = bitcast i32* %18 to <4 x i32>*
%20 = load <4 x i32>, <4 x i32>* %19
%21 = mul nsw <4 x i32> %20, <i32 9, i32 7, i32 3, i32 6>
%22 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %21)
%23 = add nsw i32 %22, %17
%24 = add nsw i32 %23, %14
%25 = add nsw i32 %24, %11
%26 = srem i32 %25, 11
%27 = icmp slt i32 %26, 10
%28 = select i1 %27, i32 %26, i32 0
ret i32 %28
}