#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*/ fatal_error(char *, char *, int);
int get_file_int(char const);
int get_rank_int(char const);
int strlen(char const *);
int get_sq_from_str(const char *sq_str) {
  int file;
  int rank;
  if ((1) <= 1 && !(sq_str != NULL))
    fatal_error("%s:%u: Assertion '"
                "sq_str != NULL"
                "' failed.",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/cutechess/sloppy/refs/heads/"
                "master/src/notation.c",
                157);
  ;
  if (strlen(sq_str) < 2)
    return -1;
  file = get_file_int(sq_str[0]);
  rank = get_rank_int(sq_str[1]);
  if (file == -1 || rank == -1)
    return -1;
  return (rank * 8) + file;
}


x86 assembly (clang, -O0):
<get_sq_from_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <get_sq_from_str+0x2f>
lea    0xea2(%rip),%rdi
lea    0xec5(%rip),%rsi
mov    $0x9d,%edx
call   1050 <fatal_error@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jge    118d <get_sq_from_str+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <get_sq_from_str+0x98>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <get_file_int@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1060 <get_rank_int@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11c0 <get_sq_from_str+0x80>
cmpl   $0xffffffff,-0x18(%rbp)
jne    11cc <get_sq_from_str+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <get_sq_from_str+0x98>
mov    -0x18(%rbp),%eax
shl    $0x3,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sq_from_str>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1164 <get_sq_from_str+0x24>
lea    0xead(%rip),%rdi
lea    0xed0(%rip),%rsi
mov    $0x9d,%edx
call   1050 <fatal_error@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%ebp
cmp    $0x2,%eax
jl     1199 <get_sq_from_str+0x59>
movsbl (%rbx),%edi
call   1040 <get_file_int@plt>
mov    %eax,%r14d
movsbl 0x1(%rbx),%edi
call   1060 <get_rank_int@plt>
cmp    $0xffffffff,%r14d
je     1199 <get_sq_from_str+0x59>
cmp    $0xffffffff,%eax
je     1199 <get_sq_from_str+0x59>
lea    (%r14,%rax,8),%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"%s:%u: Assertion 'sq_str != NULL' failed.\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cutechess/sloppy/refs/heads/master/src/notation.c\00"
define i32 @get_sq_from_str(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 %10, label %8
8: ; preds = %1
%9 = call i32 @fatal_error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 157)
br label %10
10: ; preds = %8, %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 -1, i32* %2
br label %35
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = call i32 @get_file_int(i8 signext %18)
store i32 %19, i32* %4
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = call i32 @get_rank_int(i8 signext %22)
store i32 %23, i32* %5
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, -1
br i1 %25, label %29, label %26
26: ; preds = %15
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %26, %15
store i32 -1, i32* %2
br label %35
30: ; preds = %26
%31 = load i32, i32* %5
%32 = mul nsw i32 %31, 8
%33 = load i32, i32* %4
%34 = add nsw i32 %32, %33
store i32 %34, i32* %2
br label %35
35: ; preds = %30, %29, %14
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [42 x i8] c"%s:%u: Assertion 'sq_str != NULL' failed.\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cutechess/sloppy/refs/heads/master/src/notation.c\00"
define i32 @get_sq_from_str(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @fatal_error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 157)
br label %5
5: ; preds = %3, %1
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp slt i32 %6, 2
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = load i8, i8* %0
%10 = tail call i32 @get_file_int(i8 signext %9)
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = load i8, i8* %11
%13 = tail call i32 @get_rank_int(i8 signext %12)
%14 = icmp eq i32 %10, -1
%15 = icmp eq i32 %13, -1
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %20, label %17
17: ; preds = %8
%18 = shl nsw i32 %13, 3
%19 = add nsw i32 %18, %10
br label %20
20: ; preds = %8, %5, %17
%21 = phi i32 [ %19, %17 ], [ -1, %5 ], [ -1, %8 ]
ret i32 %21
}