#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 */
size_t strlen(char *);
char tolower(char);
int rank_name(char *name) {
  int result = strlen(name);
  for (size_t i = 0; i < strlen(name); ++i)
    result += tolower(name[i]) - 'a' + 1;
  return result;
}


x86 assembly (clang, -O0):
<rank_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jae    1192 <rank_name+0x72>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
sub    $0x61,%eax
add    $0x1,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1140 <rank_name+0x20>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rank_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r15
mov    (%r14),%al
test   %al,%al
je     1185 <rank_name+0x65>
movsbl %al,%edi
call   1040 <tolower@plt>
movsbl %al,%eax
add    %eax,%r15d
add    $0xffffffa0,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%rax
jb     1185 <rank_name+0x65>
mov    $0x1,%ebx
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
add    %eax,%r15d
add    $0xffffffa0,%r15d
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbx
jb     1160 <rank_name+0x40>
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @rank_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = trunc i64 %6 to i32
store i32 %7, i32* %3
store i64 0, i64* %4
br label %8
8: ; preds = %24, %1
%9 = load i64, i64* %4
%10 = load i8*, i8** %2
%11 = call i64 @strlen(i8* %10)
%12 = icmp ult i64 %9, %11
br i1 %12, label %13, label %27
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i64, i64* %4
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = call signext i8 @tolower(i8 signext %17)
%19 = sext i8 %18 to i32
%20 = sub nsw i32 %19, 97
%21 = add nsw i32 %20, 1
%22 = load i32, i32* %3
%23 = add nsw i32 %22, %21
store i32 %23, i32* %3
br label %24
24: ; preds = %13
%25 = load i64, i64* %4
%26 = add i64 %25, 1
store i64 %26, i64* %4
br label %8
27: ; preds = %8
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @rank_name(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = tail call signext i8 @tolower(i8 signext %4)
%8 = sext i8 %7 to i32
%9 = add i32 %3, -96
%10 = add i32 %9, %8
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = icmp ugt i64 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %15, %6, %1
%14 = phi i32 [ %3, %1 ], [ %10, %6 ], [ %23, %15 ]
ret i32 %14
15: ; preds = %6, %15
%16 = phi i64 [ %24, %15 ], [ 1, %6 ]
%17 = phi i32 [ %23, %15 ], [ %10, %6 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %16
%19 = load i8, i8* %18
%20 = tail call signext i8 @tolower(i8 signext %19)
%21 = sext i8 %20 to i32
%22 = add i32 %17, -96
%23 = add i32 %22, %21
%24 = add nuw i64 %16, 1
%25 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%26 = icmp ult i64 %24, %25
br i1 %26, label %15, label %13
}