#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 *, int *, char *, int *);
int strlen(char const *);
void parse_pin(int *npin, const char *name) {
  if (strlen(name) < 4) {
    goto failed;
  }
  if (*name != 'P') {
    goto failed;
  }
  int p1, p3;
  char p2;
  name++;
  int n = sscanf(name, "%d%c%d", &p1, &p2, &p3);
  if (n != 3) {
    goto failed;
  }
  int pp1 = p1 * 32 - 8;
  if (pp1 < 0) {
    pp1 = 0;
  }
  int pp2 = (p2 - 'A') * 8 + p3;
  *npin = pp1 + pp2;
  return;
failed:
  *npin = -1;
}


x86 assembly (clang, -O0):
<parse_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
jge    1147 <parse_pin+0x27>
jmp    11d4 <parse_pin+0xb4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x50,%eax
je     115c <parse_pin+0x3c>
jmp    11d4 <parse_pin+0xb4>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x19(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1040 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
je     1196 <parse_pin+0x76>
jmp    11d4 <parse_pin+0xb4>
mov    -0x14(%rbp),%eax
shl    $0x5,%eax
sub    $0x8,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11b3 <parse_pin+0x93>
movl   $0x0,-0x24(%rbp)
movsbl -0x19(%rbp),%eax
sub    $0x41,%eax
shl    $0x3,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11de <parse_pin+0xbe>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pin>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%ebp
cmp    $0x4,%eax
jl     1190 <parse_pin+0x70>
cmpb   $0x50,(%rbx)
jne    1190 <parse_pin+0x70>
add    $0x1,%rbx
lea    0xeb0(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x7(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    1190 <parse_pin+0x70>
mov    0xc(%rsp),%eax
shl    $0x5,%eax
cmp    $0x9,%eax
mov    $0x8,%ecx
cmovge %eax,%ecx
movsbl 0x7(%rsp),%eax
add    0x8(%rsp),%ecx
lea    (%rcx,%rax,8),%ebp
add    $0xfffffdf0,%ebp
mov    %ebp,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%d%c%d\00"
define void @parse_pin(i32* nocapture writeonly %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp slt i32 %6, 4
br i1 %7, label %27, label %8
8: ; preds = %2
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 80
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %1, i64 1
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %5, i32* %4)
%14 = icmp eq i32 %13, 3
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i32, i32* %3
%17 = shl nsw i32 %16, 5
%18 = icmp sgt i32 %17, 8
%19 = select i1 %18, i32 %17, i32 8
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = shl nsw i32 %21, 3
%23 = load i32, i32* %4
%24 = add i32 %23, -528
%25 = add i32 %24, %19
%26 = add i32 %25, %22
br label %27
27: ; preds = %2, %8, %11, %15
%28 = phi i32 [ %26, %15 ], [ -1, %11 ], [ -1, %8 ], [ -1, %2 ]
store i32 %28, i32* %0
ret void
}