#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 conVertToInt32(char);
int strlen(char *);
int checkSum(char *isbn) {
  int counter = 0;
  int position = counter + 1;
  int sum = 0;
  for (counter = 0; counter < strlen(isbn) - 1; counter++) {
    if (isbn[counter] != '-') {
      if (position % 2 == 0) {
        sum = sum + conVertToInt32(isbn[counter]) * 3;
      } else
        sum = sum + conVertToInt32(isbn[counter]) * 1;
      position = position + 1;
    }
  }
  return 10 - (sum % 10);
}


x86 assembly (clang, -O0):
<checkSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11fb <checkSum+0xdb>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
je     11e8 <checkSum+0xc8>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11bb <checkSum+0x9b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <conVertToInt32@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   $0x3,%ecx,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    11df <checkSum+0xbf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <conVertToInt32@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
shl    $0x0,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ed <checkSum+0xcd>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <checkSum+0x2a>
mov    -0x14(%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   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    $0x2,%eax
jl     1189 <checkSum+0x69>
mov    $0x1,%r15d
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1166 <checkSum+0x46>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbp
jge    1189 <checkSum+0x69>
movzbl (%rbx,%rbp,1),%eax
cmp    $0x2d,%al
je     1150 <checkSum+0x30>
movsbl %al,%edi
call   1040 <conVertToInt32@plt>
test   $0x1,%r15b
lea    (%rax,%rax,2),%ecx
cmovne %eax,%ecx
add    %ecx,%r14d
add    $0x1,%r15d
jmp    1150 <checkSum+0x30>
movslq %r14d,%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
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @checkSum(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i32, i32* %3
%7 = add nsw i32 %6, 1
store i32 %7, i32* %4
store i32 0, i32* %5
store i32 0, i32* %3
br label %8
8: ; preds = %50, %1
%9 = load i32, i32* %3
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = sub nsw i32 %11, 1
%13 = icmp slt i32 %9, %12
br i1 %13, label %14, label %53
14: ; preds = %8
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%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 = icmp ne i32 %20, 45
br i1 %21, label %22, label %49
22: ; preds = %14
%23 = load i32, i32* %4
%24 = srem i32 %23, 2
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = load i32, i32* %5
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = call i32 @conVertToInt32(i8 signext %32)
%34 = mul nsw i32 %33, 3
%35 = add nsw i32 %27, %34
store i32 %35, i32* %5
br label %46
36: ; preds = %22
%37 = load i32, i32* %5
%38 = load i8*, i8** %2
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = call i32 @conVertToInt32(i8 signext %42)
%44 = mul nsw i32 %43, 1
%45 = add nsw i32 %37, %44
store i32 %45, i32* %5
br label %46
46: ; preds = %36, %26
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %49
49: ; preds = %46, %14
br label %50
50: ; preds = %49
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %8
53: ; preds = %8
%54 = load i32, i32* %5
%55 = srem i32 %54, 10
%56 = sub nsw i32 10, %55
ret i32 %56
}

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