#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 */
unsigned int ctoi(unsigned char);
char itoc(unsigned int);
int ustrlen(unsigned char *);
char isbn_check(unsigned char source[]) {
  unsigned int i, weight, sum, check, h;
  char check_char;
  sum = 0;
  weight = 1;
  h = ustrlen(source) - 1;
  for (i = 0; i < h; i++) {
    sum += ctoi(source[i]) * weight;
    weight++;
  }
  check = sum % 11;
  check_char = itoc(check);
  if (check == 10) {
    check_char = 'X';
  }
  return check_char;
}


x86 assembly (clang, -O0):
<isbn_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ustrlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    119d <isbn_check+0x6d>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movzbl (%rax,%rcx,1),%edi
call   1030 <ctoi@plt>
imul   -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1160 <isbn_check+0x30>
mov    -0x14(%rbp),%eax
mov    $0xb,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <itoc@plt>
mov    %al,-0x1d(%rbp)
cmpl   $0xa,-0x18(%rbp)
jne    11c5 <isbn_check+0x95>
movb   $0x58,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isbn_check>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <ustrlen@plt>
add    $0xffffffff,%eax
je     11a1 <isbn_check+0x71>
mov    %eax,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edi
add    $0x1,%rbx
call   1030 <ctoi@plt>
mov    %ebx,%ecx
imul   %eax,%ecx
add    %ecx,%ebp
cmp    %rbx,%r15
jne    1150 <isbn_check+0x20>
mov    %ebp,%eax
mov    $0xba2e8ba3,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,4),%eax
lea    (%rcx,%rax,2),%eax
sub    %eax,%ebp
mov    %ebp,%edi
call   1050 <itoc@plt>
cmp    $0xa,%ebp
movzbl %al,%ecx
mov    $0x58,%eax
cmovne %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <itoc@plt>

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

LLVM IR (-O2):
define signext i8 @isbn_check(i8* %0) {
%2 = tail call i32 @ustrlen(i8* %0)
%3 = add i32 %2, -1
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call signext i8 @itoc(i32 0)
br label %26
7: ; preds = %1
%8 = zext i32 %3 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %19, %9 ]
%11 = phi i32 [ 1, %7 ], [ %18, %9 ]
%12 = phi i32 [ 0, %7 ], [ %17, %9 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %10
%14 = load i8, i8* %13
%15 = tail call i32 @ctoi(i8 zeroext %14)
%16 = mul i32 %15, %11
%17 = add i32 %16, %12
%18 = add i32 %11, 1
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %21, label %9
21: ; preds = %9
%22 = urem i32 %17, 11
%23 = tail call signext i8 @itoc(i32 %22)
%24 = icmp eq i32 %22, 10
%25 = select i1 %24, i8 88, i8 %23
br label %26
26: ; preds = %21, %5
%27 = phi i8 [ %6, %5 ], [ %25, %21 ]
ret i8 %27
}