#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 strlen(char *);
int titleToNumber(char *s) {
  if (!s)
    return 0;
  int n, l;
  for (n = 0, l = 0; l < strlen(s); l++) {
    n = n * 26 + s[l] - 'A' + 1;
  }
  return n;
}


x86 assembly (clang, -O0):
<titleToNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <titleToNumber+0x23>
movl   $0x0,-0x4(%rbp)
jmp    118c <titleToNumber+0x7c>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1186 <titleToNumber+0x76>
imul   $0x1a,-0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
sub    $0x41,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1141 <titleToNumber+0x31>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<titleToNumber>:
push   %r15
push   %r14
push   %rbx
xor    %r15d,%r15d
test   %rdi,%rdi
je     115a <titleToNumber+0x4a>
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    115a <titleToNumber+0x4a>
xor    %ebx,%ebx
xor    %r15d,%r15d
xchg   %ax,%ax
lea    (%r15,%r15,4),%eax
lea    (%rax,%rax,4),%eax
add    %r15d,%eax
movsbl (%r14,%rbx,1),%ecx
lea    (%rcx,%rax,1),%r15d
add    $0xffffffc0,%r15d
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1130 <titleToNumber+0x20>
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @titleToNumber(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 0, i32* %2
br label %32
9: ; preds = %1
store i32 0, i32* %4
store i32 0, i32* %5
br label %10
10: ; preds = %27, %9
%11 = load i32, i32* %5
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %30
15: ; preds = %10
%16 = load i32, i32* %4
%17 = mul nsw i32 %16, 26
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = add nsw i32 %17, %23
%25 = sub nsw i32 %24, 65
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %27
27: ; preds = %15
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %10
30: ; preds = %10
%31 = load i32, i32* %4
store i32 %31, i32* %2
br label %32
32: ; preds = %30, %8
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @titleToNumber(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %19
6: ; preds = %3, %6
%7 = phi i64 [ %15, %6 ], [ 0, %3 ]
%8 = phi i32 [ %14, %6 ], [ 0, %3 ]
%9 = mul nsw i32 %8, 26
%10 = getelementptr inbounds i8, i8* %0, i64 %7
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = add i32 %9, -64
%14 = add i32 %13, %12
%15 = add nuw nsw i64 %7, 1
%16 = tail call i32 @strlen(i8* %0)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %6, label %19
19: ; preds = %6, %3, %1
%20 = phi i32 [ 0, %1 ], [ 0, %3 ], [ %14, %6 ]
ret i32 %20
}