#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 pow26(int);
int strlen(char *);
char toupper(char);
int titleToNumber(char *s) {
  int number = 0, len = strlen(s) - 1;
  for (int i = len; i >= 0; i--) {
    number += (toupper(s[i]) - 'A' + 1) * pow26(len - i);
  }
  return number;
}


x86 assembly (clang, -O0):
<titleToNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11a9 <titleToNumber+0x79>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
sub    -0x14(%rbp),%edi
call   1050 <pow26@plt>
mov    %al,%cl
mov    -0x18(%rbp),%eax
movsbl %cl,%ecx
imul   %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1158 <titleToNumber+0x28>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<titleToNumber>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %eax,%eax
jle    1190 <titleToNumber+0x60>
mov    %eax,%r14d
add    $0xffffffff,%r14d
add    $0x1,%r14
xor    %ebx,%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl -0x1(%r15,%r14,1),%edi
call   1030 <toupper@plt>
movsbl %al,%ebp
add    $0xffffffc0,%ebp
mov    %ebx,%edi
call   1050 <pow26@plt>
movsbl %al,%eax
imul   %ebp,%eax
add    %eax,%r12d
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
cmp    %rbx,%r14
jne    1160 <titleToNumber+0x30>
jmp    1193 <titleToNumber+0x63>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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