int getControlNumber(char *upn) {
  int i, controlNumber = 0, weights[9] = {2, 4, 8, 5, 10, 9, 7, 3, 6};
  for (i = 0; i < 9; i++) {
    controlNumber += ((upn[i] - '0') * weights[i]);
  }
  controlNumber = controlNumber % 11;
  if (controlNumber == 10) {
    controlNumber = 0;
  }
  return controlNumber;
}


x86 assembly (clang, -O0):
<getControlNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xed2(%rip),%rsi
mov    $0x24,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jge    1175 <getControlNumber+0x65>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
movslq -0xc(%rbp),%rcx
imul   -0x40(%rbp,%rcx,4),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <getControlNumber+0x2f>
mov    -0x10(%rbp),%eax
mov    $0xb,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jne    1194 <getControlNumber+0x84>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getControlNumber>:
movsbl (%rdi),%eax
add    %eax,%eax
movsbl 0x1(%rdi),%ecx
lea    (%rax,%rcx,4),%eax
movsbl 0x2(%rdi),%ecx
lea    (%rax,%rcx,8),%eax
movsbl 0x3(%rdi),%ecx
lea    (%rcx,%rcx,4),%ecx
movsbl 0x4(%rdi),%edx
lea    (%rdx,%rdx,4),%edx
movd   0x5(%rdi),%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
psrad  $0x18,%xmm0
pmaddwd 0xec5(%rip),%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%esi
lea    (%rsi,%rdx,2),%edx
add    %ecx,%edx
add    %edx,%eax
add    $0xfffff5e0,%eax
movslq %eax,%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
cmovne %ecx,%eax
ret

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

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