#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 *);
int bbb_getIndexByPin(int, int);
int strlen(char *);
int bbb_getIndexByStr(char *str) {
  int size = strlen(str);
  int header = 0;
  int pin = 0;
  if (str[0] == 'P' && size >= 4) {
    if (str[1] == '8') {
      header = 8;
    } else {
      if (str[1] == '9') {
        header = 9;
      } else {
        return -1;
      }
    }
  } else {
    return -1;
  }
  if (str[2] == '_') {
    pin = atoi((str + 3));
  } else {
    return -1;
  }
  return bbb_getIndexByPin(header, pin);
}


x86 assembly (clang, -O0):
<bbb_getIndexByStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x50,%eax
jne    11c0 <bbb_getIndexByStr+0x90>
cmpl   $0x4,-0x14(%rbp)
jl     11c0 <bbb_getIndexByStr+0x90>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x38,%eax
jne    118d <bbb_getIndexByStr+0x5d>
movl   $0x8,-0x18(%rbp)
jmp    11bb <bbb_getIndexByStr+0x8b>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x39,%eax
jne    11aa <bbb_getIndexByStr+0x7a>
movl   $0x9,-0x18(%rbp)
jmp    11b6 <bbb_getIndexByStr+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <bbb_getIndexByStr+0xdc>
jmp    11bb <bbb_getIndexByStr+0x8b>
jmp    11cc <bbb_getIndexByStr+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <bbb_getIndexByStr+0xdc>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x5f,%eax
jne    11f2 <bbb_getIndexByStr+0xc2>
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    11fe <bbb_getIndexByStr+0xce>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <bbb_getIndexByStr+0xdc>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <bbb_getIndexByPin@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bbb_getIndexByStr>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmpb   $0x50,(%rbx)
jne    115b <bbb_getIndexByStr+0x2b>
cmp    $0x4,%eax
jl     115b <bbb_getIndexByStr+0x2b>
mov    0x1(%rbx),%al
cmp    $0x38,%al
je     1167 <bbb_getIndexByStr+0x37>
cmp    $0x39,%al
jne    115b <bbb_getIndexByStr+0x2b>
mov    $0x9,%ebp
cmpb   $0x5f,0x2(%rbx)
je     1172 <bbb_getIndexByStr+0x42>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x8,%ebp
cmpb   $0x5f,0x2(%rbx)
jne    115b <bbb_getIndexByStr+0x2b>
add    $0x3,%rbx
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %ebp,%edi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <bbb_getIndexByPin@plt>

LLVM IR (-O0):
define i32 @bbb_getIndexByStr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 80
br i1 %13, label %14, label %34
14: ; preds = %1
%15 = load i32, i32* %4
%16 = icmp sge i32 %15, 4
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 56
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 8, i32* %5
br label %33
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 57
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 9, i32* %5
br label %32
31: ; preds = %24
store i32 -1, i32* %2
br label %50
32: ; preds = %30
br label %33
33: ; preds = %32, %23
br label %35
34: ; preds = %14, %1
store i32 -1, i32* %2
br label %50
35: ; preds = %33
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 2
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 95
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 3
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %6
br label %46
45: ; preds = %35
store i32 -1, i32* %2
br label %50
46: ; preds = %41
%47 = load i32, i32* %5
%48 = load i32, i32* %6
%49 = call i32 @bbb_getIndexByPin(i32 %47, i32 %48)
store i32 %49, i32* %2
br label %50
50: ; preds = %46, %45, %34, %31
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
define i32 @bbb_getIndexByStr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 80
%5 = icmp sgt i32 %2, 3
%6 = select i1 %4, i1 %5, i1 false
br i1 %6, label %7, label %20
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
switch i8 %9, label %20 [
i8 56, label %11
i8 57, label %10
]
10: ; preds = %7
br label %11
11: ; preds = %7, %10
%12 = phi i32 [ 9, %10 ], [ 8, %7 ]
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 95
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %0, i64 3
%18 = tail call i32 @atoi(i8* %17)
%19 = tail call i32 @bbb_getIndexByPin(i32 %12, i32 %18)
br label %20
20: ; preds = %11, %1, %7, %16
%21 = phi i32 [ %19, %16 ], [ -1, %7 ], [ -1, %1 ], [ -1, %11 ]
ret i32 %21
}