#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 atoi(char const *);
int strlen(char const *);
void parse_pin(int *pin, const char *name) {
  if (strlen(name) < 3) {
    goto failed;
  }
  if (*name == 'P') {
    name++;
  } else {
    goto failed;
  }
  int port = *name++ - 'A';
  int index = atoi(name);
  *pin = port * 32 + index;
  return;
failed:
  *pin = -1;
}


x86 assembly (clang, -O0):
<parse_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jge    1147 <parse_pin+0x27>
jmp    11a5 <parse_pin+0x85>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x50,%eax
jne    1168 <parse_pin+0x48>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    116d <parse_pin+0x4d>
jmp    11a5 <parse_pin+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
sub    $0x41,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
shl    $0x5,%ecx
add    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11af <parse_pin+0x8f>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pin>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%ecx
cmp    $0x3,%eax
jl     1161 <parse_pin+0x41>
cmpb   $0x50,(%rbx)
jne    1161 <parse_pin+0x41>
movsbl 0x1(%rbx),%r15d
add    $0x2,%rbx
mov    %rbx,%rdi
call   1040 <atoi@plt>
shl    $0x5,%r15d
lea    (%rax,%r15,1),%ecx
add    $0xfffff7e0,%ecx
mov    %ecx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @parse_pin(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %11
10: ; preds = %2
br label %33
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 80
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
br label %20
19: ; preds = %11
br label %33
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
%23 = load i8, i8* %21
%24 = sext i8 %23 to i32
%25 = sub nsw i32 %24, 65
store i32 %25, i32* %5
%26 = load i8*, i8** %4
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %6
%28 = load i32, i32* %5
%29 = mul nsw i32 %28, 32
%30 = load i32, i32* %6
%31 = add nsw i32 %29, %30
%32 = load i32*, i32** %3
store i32 %31, i32* %32
br label %35
33: ; preds = %19, %10
%34 = load i32*, i32** %3
store i32 -1, i32* %34
br label %35
35: ; preds = %33, %20
ret void
}

LLVM IR (-O2):
define void @parse_pin(i32* nocapture writeonly %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp slt i32 %3, 3
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 80
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %1, i64 1
%10 = getelementptr inbounds i8, i8* %1, i64 2
%11 = load i8, i8* %9
%12 = sext i8 %11 to i32
%13 = tail call i32 @atoi(i8* %10)
%14 = shl nsw i32 %12, 5
%15 = add i32 %13, -2080
%16 = add i32 %15, %14
br label %17
17: ; preds = %2, %5, %8
%18 = phi i32 [ %16, %8 ], [ -1, %5 ], [ -1, %2 ]
store i32 %18, i32* %0
ret void
}