#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*/ printf(char *);
char get_piece(char *board, char x, char y) {
  x = x - 'a';
  y = 7 - (y - '1');
  if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) {
    printf("DEBUG: Invalid coordinate given\n");
    return -1;
  }
  return board[y * 8 + x];
}


x86 assembly (clang, -O0):
<get_piece>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x10(%rbp)
mov    %cl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
movsbl -0x11(%rbp),%eax
sub    $0x61,%eax
mov    %al,-0x11(%rbp)
movsbl -0x12(%rbp),%ecx
sub    $0x31,%ecx
mov    $0x7,%eax
sub    %ecx,%eax
mov    %al,-0x12(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jl     1176 <get_piece+0x66>
movsbl -0x11(%rbp),%eax
cmp    $0x7,%eax
jg     1176 <get_piece+0x66>
movsbl -0x12(%rbp),%eax
cmp    $0x0,%eax
jl     1176 <get_piece+0x66>
movsbl -0x12(%rbp),%eax
cmp    $0x7,%eax
jle    118b <get_piece+0x7b>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
movb   $0xff,-0x1(%rbp)
jmp    11a5 <get_piece+0x95>
mov    -0x10(%rbp),%rax
movsbl -0x12(%rbp),%ecx
shl    $0x3,%ecx
movsbl -0x11(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_piece>:
push   %rax
add    $0x9f,%sil
mov    $0x38,%al
sub    %dl,%al
mov    %eax,%ecx
or     %sil,%cl
cmp    $0x8,%cl
jae    1133 <get_piece+0x23>
movzbl %al,%eax
movzbl %sil,%ecx
lea    (%rcx,%rax,8),%rax
mov    (%rdi,%rax,1),%al
pop    %rcx
ret
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
mov    $0xff,%al
pop    %rcx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"DEBUG: Invalid coordinate given\0A\00"
define signext i8 @get_piece(i8* %0, i8 signext %1, i8 signext %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8
store i8* %0, i8** %5
store i8 %1, i8* %6
store i8 %2, i8* %7
%8 = load i8, i8* %6
%9 = sext i8 %8 to i32
%10 = sub nsw i32 %9, 97
%11 = trunc i32 %10 to i8
store i8 %11, i8* %6
%12 = load i8, i8* %7
%13 = sext i8 %12 to i32
%14 = sub nsw i32 %13, 49
%15 = sub nsw i32 7, %14
%16 = trunc i32 %15 to i8
store i8 %16, i8* %7
%17 = load i8, i8* %6
%18 = sext i8 %17 to i32
%19 = icmp slt i32 %18, 0
br i1 %19, label %32, label %20
20: ; preds = %3
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = icmp sgt i32 %22, 7
br i1 %23, label %32, label %24
24: ; preds = %20
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
%27 = icmp slt i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
%31 = icmp sgt i32 %30, 7
br i1 %31, label %32, label %34
32: ; preds = %28, %24, %20, %3
%33 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i8 -1, i8* %4
br label %45
34: ; preds = %28
%35 = load i8*, i8** %5
%36 = load i8, i8* %7
%37 = sext i8 %36 to i32
%38 = mul nsw i32 %37, 8
%39 = load i8, i8* %6
%40 = sext i8 %39 to i32
%41 = add nsw i32 %38, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %35, i64 %42
%44 = load i8, i8* %43
store i8 %44, i8* %4
br label %45
45: ; preds = %34, %32
%46 = load i8, i8* %4
ret i8 %46
}

LLVM IR (-O2):
@str = [32 x i8] c"DEBUG: Invalid coordinate given\00"
define signext i8 @get_piece(i8* nocapture %0, i8 signext %1, i8 signext %2) {
%4 = add i8 %1, -97
%5 = sub i8 56, %2
%6 = or i8 %5, %4
%7 = icmp ult i8 %6, 8
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %17
10: ; preds = %3
%11 = zext i8 %5 to i64
%12 = zext i8 %4 to i64
%13 = shl nuw nsw i64 %11, 3
%14 = add nuw nsw i64 %13, %12
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
br label %17
17: ; preds = %10, %8
%18 = phi i8 [ -1, %8 ], [ %16, %10 ]
ret i8 %18
}