#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 /*<<< orphan*/ assert(int);
int str_sq(const char *sq) {
  assert(sq[0] >= 'a' && sq[0] <= 'h');
  assert(sq[1] >= '1' && sq[1] <= '8');
  return ((8 * (sq[1] - '1' + 1 - 1)) + (sq[0] - 'a' + 1 - 1));
}


x86 assembly (clang, -O0):
<str_sq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x61,%ecx
mov    %al,-0x9(%rbp)
jl     1141 <str_sq+0x31>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
setle  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%ecx
xor    %eax,%eax
cmp    $0x31,%ecx
mov    %al,-0xa(%rbp)
jl     1175 <str_sq+0x65>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x38,%eax
setle  %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x31,%eax
add    $0x1,%eax
sub    $0x1,%eax
shl    $0x3,%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x61,%ecx
add    $0x1,%ecx
sub    $0x1,%ecx
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_sq>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%al
add    $0x9f,%al
xor    %edi,%edi
cmp    $0x8,%al
setb   %dil
call   1030 <assert@plt>
mov    0x1(%rbx),%al
add    $0xcf,%al
xor    %edi,%edi
cmp    $0x8,%al
setb   %dil
call   1030 <assert@plt>
movsbl 0x1(%rbx),%eax
movsbl (%rbx),%ecx
lea    (%rcx,%rax,8),%eax
add    $0xfffffe17,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @str_sq(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = add i8 %2, -97
%4 = icmp ult i8 %3, 8
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = add i8 %8, -49
%10 = icmp ult i8 %9, 8
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = load i8, i8* %7
%14 = sext i8 %13 to i32
%15 = shl nsw i32 %14, 3
%16 = load i8, i8* %0
%17 = sext i8 %16 to i32
%18 = add nsw i32 %17, -489
%19 = add nsw i32 %18, %15
ret i32 %19
}