#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 *port, int *pin, const char *name) {
  if (strlen(name) < 3) {
    goto failed;
  }
  if (*name == 'P') {
    name++;
  } else {
    goto failed;
  }
  *port = *name++ - 'A';
  *pin = atoi(name);
  return;
failed:
  *port = -1;
  *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    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jge    114b <parse_pin+0x2b>
jmp    11a2 <parse_pin+0x82>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x50,%eax
jne    116c <parse_pin+0x4c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1171 <parse_pin+0x51>
jmp    11a2 <parse_pin+0x82>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%ecx
sub    $0x41,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11b6 <parse_pin+0x96>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pin>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jl     1158 <parse_pin+0x38>
cmpb   $0x50,(%rbx)
jne    1158 <parse_pin+0x38>
movsbl 0x1(%rbx),%eax
add    $0x2,%rbx
add    $0xffffffbf,%eax
mov    %eax,(%r15)
mov    %rbx,%rdi
call   1040 <atoi@plt>
jmp    1164 <parse_pin+0x44>
movl   $0xffffffff,(%r15)
mov    $0xffffffff,%eax
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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