#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 atoi(char const *);
int strlen(char const *);
int HTS_name2num(const char *buff) {
  int i;
  for (i = strlen(buff) - 1; '0' <= buff[i] && buff[i] <= '9' && i >= 0; i--)
    ;
  i++;
  return atoi(&buff[i]);
}


x86 assembly (clang, -O0):
<HTS_name2num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
xor    %eax,%eax
mov    $0x30,%ecx
cmp    %edx,%ecx
mov    %al,-0xd(%rbp)
jg     117d <HTS_name2num+0x5d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x39,%ecx
mov    %al,-0xd(%rbp)
jg     117d <HTS_name2num+0x5d>
cmpl   $0x0,-0xc(%rbp)
setge  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    118d <HTS_name2num+0x6d>
jmp    11a0 <HTS_name2num+0x80>
jmp    1192 <HTS_name2num+0x72>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <HTS_name2num+0x1b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
call   1040 <atoi@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HTS_name2num>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
mov    %rax,%rsi
shl    $0x20,%rsi
movabs $0xffffffff00000000,%rdi
ff ff ff
nopl   0x0(%rax)
mov    %rsi,%rdx
movzbl -0x1(%rbx,%rax,1),%ecx
cmp    $0x30,%cl
jl     1162 <HTS_name2num+0x42>
cmp    $0x39,%cl
ja     1162 <HTS_name2num+0x42>
lea    (%rdx,%rdi,1),%rsi
lea    -0x1(%rax),%rcx
test   %rax,%rax
mov    %rcx,%rax
jg     1140 <HTS_name2num+0x20>
sar    $0x20,%rdx
add    %rdx,%rbx
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <atoi@plt>

LLVM IR (-O0):
define i32 @HTS_name2num(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = sub nsw i32 %5, 1
store i32 %6, i32* %3
br label %7
7: ; preds = %29, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp sle i32 48, %13
br i1 %14, label %15, label %26
15: ; preds = %7
%16 = load i8*, i8** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp sle i32 %21, 57
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* %3
%25 = icmp sge i32 %24, 0
br label %26
26: ; preds = %23, %15, %7
%27 = phi i1 [ false, %15 ], [ false, %7 ], [ %25, %23 ]
br i1 %27, label %28, label %32
28: ; preds = %26
br label %29
29: ; preds = %28
%30 = load i32, i32* %3
%31 = add nsw i32 %30, -1
store i32 %31, i32* %3
br label %7
32: ; preds = %26
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
%35 = load i8*, i8** %2
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = call i32 @atoi(i8* %38)
ret i32 %39
}

LLVM IR (-O2):
define i32 @HTS_name2num(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
br label %4
4: ; preds = %10, %1
%5 = phi i64 [ %6, %10 ], [ %3, %1 ]
%6 = add nsw i64 %5, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp sgt i8 %8, 47
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = icmp ult i8 %8, 58
%12 = icmp sgt i64 %5, 0
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %4, label %14
14: ; preds = %4, %10
%15 = shl i64 %5, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = tail call i32 @atoi(i8* %17)
ret i32 %18
}