#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 */
char *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char *s = malloc(101);
  scanf("%s\n", s);
  int prev = 0, curr, diff, c = 0;
  for (; *s; ++s) {
    curr = *s - 'a';
    diff = curr > prev ? curr - prev : prev - curr;
    c += diff <= 13 ? diff : 26 - diff;
    prev = curr;
  }
  printf("%d", c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x65,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea8(%rip),%rdi
call   1050 <scanf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ee <main+0xbe>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x61,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    119f <main+0x6f>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11a8 <main+0x78>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xd,-0x1c(%rbp)
jg     11c3 <main+0x93>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11ce <main+0x9e>
mov    $0x1a,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    116b <main+0x3b>
mov    -0x20(%rbp),%esi
lea    0xe0c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x65,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xebb(%rip),%rdi
mov    %rax,%rsi
call   1050 <scanf@plt>
mov    (%rbx),%al
test   %al,%al
je     1191 <main+0x61>
add    $0x1,%rbx
xor    %esi,%esi
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movsbl %al,%edx
add    $0xffffff9f,%edx
mov    %edx,%eax
sub    %ecx,%eax
neg    %eax
mov    %edx,%edi
sub    %ecx,%edi
cmovle %eax,%edi
mov    $0x1a,%eax
sub    %edi,%eax
cmp    $0xe,%edi
cmovl  %edi,%eax
add    %eax,%esi
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %edx,%ecx
test   %al,%al
jne    1160 <main+0x30>
jmp    1193 <main+0x63>
xor    %esi,%esi
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(101) i8* @malloc(i32 101)
%2 = tail call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %21, %5 ], [ %3, %0 ]
%7 = phi i32 [ %19, %5 ], [ 0, %0 ]
%8 = phi i8* [ %20, %5 ], [ %1, %0 ]
%9 = phi i32 [ %11, %5 ], [ 0, %0 ]
%10 = sext i8 %6 to i32
%11 = add nsw i32 %10, -97
%12 = icmp sgt i32 %11, %9
%13 = sub nsw i32 %11, %9
%14 = sub nsw i32 %9, %11
%15 = select i1 %12, i32 %13, i32 %14
%16 = icmp slt i32 %15, 14
%17 = sub nsw i32 26, %15
%18 = select i1 %16, i32 %15, i32 %17
%19 = add nsw i32 %18, %7
%20 = getelementptr inbounds i8, i8* %8, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %5, %0
%24 = phi i32 [ 0, %0 ], [ %19, %5 ]
%25 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
ret i32 0
}