#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int strlen(char *);
int CheckSum(char *num) {
  int checksum = 0, i = 0;
  for (i = 0; i < strlen(num); i++) {
    checksum += (i % 2 == 1) ? (num[i] - '0') * 3 : (num[i] - '0');
  }
  return 10 - (checksum % 10);
}


x86 assembly (clang, -O0):
<CheckSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11a4 <CheckSum+0x94>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    117b <CheckSum+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
imul   $0x3,%eax,%eax
mov    %eax,-0x18(%rbp)
jmp    118d <CheckSum+0x7d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1131 <CheckSum+0x21>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    $0xa,%eax
sub    %edx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckSum>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    117d <CheckSum+0x6d>
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r14,%rbx,1),%eax
lea    -0x30(%rax),%ecx
test   $0x1,%bl
lea    -0x90(%rax,%rax,2),%eax
cmove  %ecx,%eax
add    %eax,%ebp
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1130 <CheckSum+0x20>
movslq %ebp,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %ecx,%eax
add    $0xa,%eax
jmp    1182 <CheckSum+0x72>
mov    $0xa,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @CheckSum(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %24
4: ; preds = %1, %4
%5 = phi i64 [ %17, %4 ], [ 0, %1 ]
%6 = phi i32 [ %16, %4 ], [ 0, %1 ]
%7 = and i64 %5, 1
%8 = icmp eq i64 %7, 0
%9 = getelementptr inbounds i8, i8* %0, i64 %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = mul nsw i32 %11, 3
%13 = add nsw i32 %12, -144
%14 = add nsw i32 %11, -48
%15 = select i1 %8, i32 %14, i32 %13
%16 = add nsw i32 %15, %6
%17 = add nuw nsw i64 %5, 1
%18 = tail call i32 @strlen(i8* %0)
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %4, label %21
21: ; preds = %4
%22 = srem i32 %16, 10
%23 = sub nsw i32 10, %22
br label %24
24: ; preds = %21, %1
%25 = phi i32 [ 10, %1 ], [ %23, %21 ]
ret i32 %25
}