#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 sscanf(char const *, char *, unsigned int *, unsigned int *);
unsigned compute_pin_index(const char *pinStr) {
  unsigned x;
  unsigned y;
  if ((sscanf(pinStr, "P%u_%u", &x, &y)) == 2) {
    if ((x >= 8) && (x <= 9) && (y >= 1 && y <= 46)) {
      return (x - 8) * 46 + y - 1;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<compute_pin_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed9(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1030 <sscanf@plt>
cmp    $0x2,%eax
jne    1181 <compute_pin_index+0x71>
cmpl   $0x8,-0x14(%rbp)
jb     117c <compute_pin_index+0x6c>
cmpl   $0x9,-0x14(%rbp)
ja     117c <compute_pin_index+0x6c>
cmpl   $0x1,-0x18(%rbp)
jb     117c <compute_pin_index+0x6c>
cmpl   $0x2e,-0x18(%rbp)
ja     117c <compute_pin_index+0x6c>
mov    -0x14(%rbp),%eax
sub    $0x8,%eax
imul   $0x2e,%eax,%eax
add    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1188 <compute_pin_index+0x78>
jmp    1181 <compute_pin_index+0x71>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_pin_index>:
push   %rax
lea    0xee8(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x2,%ecx
jne    1155 <compute_pin_index+0x45>
mov    0x4(%rsp),%ecx
mov    %ecx,%edx
and    $0xfffffffe,%edx
cmp    $0x8,%edx
jne    1155 <compute_pin_index+0x45>
mov    (%rsp),%edx
test   %edx,%edx
je     1155 <compute_pin_index+0x45>
cmp    $0x2e,%edx
ja     1155 <compute_pin_index+0x45>
imul   $0x2e,%ecx,%eax
add    %edx,%eax
add    $0xfffffe8f,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"P%u_%u\00"
define i32 @compute_pin_index(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 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5)
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %29
9: ; preds = %1
%10 = load i32, i32* %4
%11 = icmp uge i32 %10, 8
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = load i32, i32* %4
%14 = icmp ule i32 %13, 9
br i1 %14, label %15, label %28
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp uge i32 %16, 1
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32, i32* %5
%20 = icmp ule i32 %19, 46
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %4
%23 = sub i32 %22, 8
%24 = mul i32 %23, 46
%25 = load i32, i32* %5
%26 = add i32 %24, %25
%27 = sub i32 %26, 1
store i32 %27, i32* %2
br label %30
28: ; preds = %18, %15, %12, %9
br label %29
29: ; preds = %28, %1
store i32 -1, i32* %2
br label %30
30: ; preds = %29, %21
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [7 x i8] c"P%u_%u\00"
define i32 @compute_pin_index(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %21
8: ; preds = %1
%9 = load i32, i32* %2
%10 = and i32 %9, -2
%11 = icmp eq i32 %10, 8
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
%14 = select i1 %11, i1 %13, i1 false
%15 = icmp ult i32 %12, 47
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = mul nuw nsw i32 %9, 46
%19 = add nsw i32 %18, -369
%20 = add nsw i32 %19, %12
br label %21
21: ; preds = %1, %8, %17
%22 = phi i32 [ %20, %17 ], [ -1, %8 ], [ -1, %1 ]
ret i32 %22
}