int CalcASBACE(s)
char *s;
{
  int d1, d2;
  char *s2;
  d1 = CalcDV10(s) - 48;
  s2 = malloc(strlen(s) + 4);
  sprintf(s2, "%s%d", s, d1);
  do {
    sprintf(s2, "%s%d", s, d1);
    d2 = _calcDV11(s2, 2, 7) % 11;
    if (d2 == 1) {
      d1 = (d1 + 1) % 10;
      d2 = -1;
    }
  } while (d2 < 0);
  free(s2);
  if (d2)
    d2 = 11 - d2;
  else
    d2 = 0;
  return d1 * 10 + d2;
}


x86 assembly (clang, -O0):
<CalcASBACE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1050 <CalcDV10@plt>
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x4,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2,%esi
mov    $0x7,%edx
mov    $0x0,%al
call   1070 <_calcDV11@plt>
mov    $0xb,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    120a <CalcASBACE+0xaa>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
jmp    120f <CalcASBACE+0xaf>
cmpl   $0x0,-0x10(%rbp)
jl     11af <CalcASBACE+0x4f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x10(%rbp)
je     123c <CalcASBACE+0xdc>
mov    $0xb,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1243 <CalcASBACE+0xe3>
movl   $0x0,-0x10(%rbp)
imul   $0xa,-0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalcASBACE>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <CalcDV10@plt>
mov    %eax,%r13d
add    $0xffffffd0,%r13d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x4(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe6b(%rip),%r12
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r13d,%ecx
xor    %eax,%eax
call   1080 <sprintf@plt>
jmp    11b4 <CalcASBACE+0x54>
nopw   0x0(%rax,%rax,1)
test   %ebx,%ebx
jns    1229 <CalcASBACE+0xc9>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r13d,%ecx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x7,%edx
xor    %eax,%eax
call   1070 <_calcDV11@plt>
movslq %eax,%rbx
imul   $0x2e8ba2e9,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rax,%rcx,2),%eax
sub    %eax,%ebx
cmp    $0x1,%ebx
jne    11b0 <CalcASBACE+0x50>
add    $0x1,%r13d
movslq %r13d,%r13
imul   $0x66666667,%r13,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r13d
mov    $0xffffffff,%ebx
jmp    11b0 <CalcASBACE+0x50>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0xb,%eax
sub    %ebx,%eax
test   %ebx,%ebx
cmove  %ebx,%eax
lea    0x0(%r13,%r13,4),%ecx
lea    (%rax,%rcx,2),%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%d\00"
define i32 @CalcASBACE(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) bitcast (i32 (...)* @CalcDV10 to i32 (i8*, ...)*)(i8* %6)
%8 = sub nsw i32 %7, 48
store i32 %8, i32* %3
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = add i64 %10, 4
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15)
br label %17
17: ; preds = %32, %1
%18 = load i8*, i8** %5
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %19, i32 %20)
%22 = load i8*, i8** %5
%23 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @_calcDV11 to i32 (i8*, i32, i32, ...)*)(i8* %22, i32 2, i32 7)
%24 = srem i32 %23, 11
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %17
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
%30 = srem i32 %29, 10
store i32 %30, i32* %3
store i32 -1, i32* %4
br label %31
31: ; preds = %27, %17
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = icmp slt i32 %33, 0
br i1 %34, label %17, label %35
35: ; preds = %32
%36 = load i8*, i8** %5
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* %4
%41 = sub nsw i32 11, %40
store i32 %41, i32* %4
br label %43
42: ; preds = %35
store i32 0, i32* %4
br label %43
43: ; preds = %42, %39
%44 = load i32, i32* %3
%45 = mul nsw i32 %44, 10
%46 = load i32, i32* %4
%47 = add nsw i32 %45, %46
ret i32 %47
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%d\00"
define i32 @CalcASBACE(i8* %0) {
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @CalcDV10 to i32 (i8*, ...)*)(i8* %0)
%3 = add nsw i32 %2, -48
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add i64 %4, 4
%6 = tail call i8* @malloc(i64 %5)
%7 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %3)
br label %8
8: ; preds = %17, %1
%9 = phi i32 [ %3, %1 ], [ %19, %17 ]
%10 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %9)
%11 = tail call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @_calcDV11 to i32 (i8*, i32, i32, ...)*)(i8* %6, i32 2, i32 7)
%12 = srem i32 %11, 11
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = add nsw i32 %9, 1
%16 = srem i32 %15, 10
br label %17
17: ; preds = %8, %14
%18 = phi i32 [ -1, %14 ], [ %12, %8 ]
%19 = phi i32 [ %16, %14 ], [ %9, %8 ]
%20 = icmp slt i32 %18, 0
br i1 %20, label %8, label %21
21: ; preds = %17
tail call void @free(i8* %6)
%22 = icmp eq i32 %18, 0
%23 = sub nuw nsw i32 11, %18
%24 = select i1 %22, i32 0, i32 %23
%25 = mul nsw i32 %19, 10
%26 = add nsw i32 %25, %24
ret i32 %26
}