#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 /*<<< orphan*/ isdigit(char const);
int /*<<< orphan*/ strcasecmp(char const *, char *);
char toupper(char const);
int dis_reg_from_name(const char *name) {
  int i;
  if (!strcasecmp(name, "pc"))
    return 0;
  if (!strcasecmp(name, "sp"))
    return 1;
  if (!strcasecmp(name, "sr"))
    return 2;
  if (toupper(*name) == 'R')
    name++;
  for (i = 0; name[i]; i++)
    if (!isdigit(name[i]))
      return -1;
  i = atoi(name);
  if (i < 0 || i > 15)
    return -1;
  return i;
}


x86 assembly (clang, -O0):
<dis_reg_from_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1171 <dis_reg_from_name+0x31>
movl   $0x0,-0x4(%rbp)
jmp    1263 <dis_reg_from_name+0x123>
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1196 <dis_reg_from_name+0x56>
movl   $0x1,-0x4(%rbp)
jmp    1263 <dis_reg_from_name+0x123>
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11bb <dis_reg_from_name+0x7b>
movl   $0x2,-0x4(%rbp)
jmp    1263 <dis_reg_from_name+0x123>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <toupper@plt>
movsbl %al,%eax
cmp    $0x52,%eax
jne    11df <dis_reg_from_name+0x9f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1231 <dis_reg_from_name+0xf1>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    121e <dis_reg_from_name+0xde>
movl   $0xffffffff,-0x4(%rbp)
jmp    1263 <dis_reg_from_name+0x123>
jmp    1223 <dis_reg_from_name+0xe3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e6 <dis_reg_from_name+0xa6>
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1251 <dis_reg_from_name+0x111>
cmpl   $0xf,-0x14(%rbp)
jle    125d <dis_reg_from_name+0x11d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1263 <dis_reg_from_name+0x123>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dis_reg_from_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
lea    0xeb1(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11d1 <dis_reg_from_name+0x91>
lea    0xea4(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11d5 <dis_reg_from_name+0x95>
lea    0xe94(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11dc <dis_reg_from_name+0x9c>
movsbl (%r15),%edi
call   1050 <toupper@plt>
xor    %r14d,%r14d
cmp    $0x52,%al
sete   %r14b
mov    (%r15,%r14,1),%al
test   %al,%al
je     11b7 <dis_reg_from_name+0x77>
lea    (%r14,%r15,1),%rbx
add    $0x1,%rbx
movsbl %al,%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     11e3 <dis_reg_from_name+0xa3>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11a0 <dis_reg_from_name+0x60>
add    %r14,%r15
mov    %r15,%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
cmp    $0x10,%eax
mov    $0xffffffff,%eax
cmovb  %ecx,%eax
jmp    11e8 <dis_reg_from_name+0xa8>
xor    %eax,%eax
jmp    11e8 <dis_reg_from_name+0xa8>
mov    $0x1,%eax
jmp    11e8 <dis_reg_from_name+0xa8>
mov    $0x2,%eax
jmp    11e8 <dis_reg_from_name+0xa8>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"pc\00"
@.str.1 = [3 x i8] c"sp\00"
@.str.2 = [3 x i8] c"sr\00"
define i32 @dis_reg_from_name(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strcasecmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 0, i32* %2
br label %60
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strcasecmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9
store i32 1, i32* %2
br label %60
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i32 @strcasecmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14
store i32 2, i32* %2
br label %60
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = load i8, i8* %20
%22 = call signext i8 @toupper(i8 signext %21)
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 82
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
br label %28
28: ; preds = %25, %19
store i32 0, i32* %4
br label %29
29: ; preds = %46, %28
%30 = load i8*, i8** %3
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %49
36: ; preds = %29
%37 = load i8*, i8** %3
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @isdigit(i8 signext %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %36
store i32 -1, i32* %2
br label %60
45: ; preds = %36
br label %46
46: ; preds = %45
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %29
49: ; preds = %29
%50 = load i8*, i8** %3
%51 = call i32 @atoi(i8* %50)
store i32 %51, i32* %4
%52 = load i32, i32* %4
%53 = icmp slt i32 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %49
%55 = load i32, i32* %4
%56 = icmp sgt i32 %55, 15
br i1 %56, label %57, label %58
57: ; preds = %54, %49
store i32 -1, i32* %2
br label %60
58: ; preds = %54
%59 = load i32, i32* %4
store i32 %59, i32* %2
br label %60
60: ; preds = %58, %57, %44, %18, %13, %8
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
@.str = [3 x i8] c"pc\00"
@.str.1 = [3 x i8] c"sp\00"
@.str.2 = [3 x i8] c"sr\00"
define i32 @dis_reg_from_name(i8* nocapture %0) {
%2 = tail call i32 @strcasecmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %32, label %4
4: ; preds = %1
%5 = tail call i32 @strcasecmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %32, label %7
7: ; preds = %4
%8 = tail call i32 @strcasecmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %32, label %10
10: ; preds = %7
%11 = load i8, i8* %0
%12 = tail call signext i8 @toupper(i8 signext %11)
%13 = icmp eq i8 %12, 82
%14 = zext i1 %13 to i64
%15 = getelementptr i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %28, label %22
18: ; preds = %22
%19 = getelementptr inbounds i8, i8* %15, i64 %27
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %10, %18
%23 = phi i64 [ %27, %18 ], [ 0, %10 ]
%24 = phi i8 [ %20, %18 ], [ %16, %10 ]
%25 = tail call i32 @isdigit(i8 signext %24)
%26 = icmp eq i32 %25, 0
%27 = add nuw i64 %23, 1
br i1 %26, label %32, label %18
28: ; preds = %18, %10
%29 = tail call i32 @atoi(i8* %15)
%30 = icmp ugt i32 %29, 15
%31 = select i1 %30, i32 -1, i32 %29
br label %32
32: ; preds = %22, %28, %7, %4, %1
%33 = phi i32 [ 0, %1 ], [ 1, %4 ], [ 2, %7 ], [ %31, %28 ], [ -1, %22 ]
ret i32 %33
}