#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int regnum(char *r) {
  if (r[0] != 'r') {
    fprintf(stderr, "%s is not register\n", r);
    return -1;
  }
  if (strcmp(r, "rsp") == 0) {
    return 30;
  }
  if (strcmp(r, "rbp") == 0) {
    return 31;
  }
  return atoi(r + 1);
}


x86 assembly (clang, -O0):
<regnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
je     1171 <regnum+0x41>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xea0(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cd <regnum+0x9d>
mov    -0x10(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1197 <regnum+0x67>
movl   $0x1e,-0x4(%rbp)
jmp    11cd <regnum+0x9d>
mov    -0x10(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11bd <regnum+0x8d>
movl   $0x1f,-0x4(%rbp)
jmp    11cd <regnum+0x9d>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regnum>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x72,(%rdi)
jne    116e <regnum+0x3e>
lea    0xed4(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     118d <regnum+0x5d>
lea    0xec4(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1194 <regnum+0x64>
add    $0x1,%rbx
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <atoi@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
mov    $0x1e,%eax
pop    %rbx
ret
mov    $0x1f,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"%s is not register\0A\00"
@.str.1 = [4 x i8] c"rsp\00"
@.str.2 = [4 x i8] c"rbp\00"
define i32 @regnum(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 114
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 -1, i32* %2
br label %27
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 30, i32* %2
br label %27
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 31, i32* %2
br label %27
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %2
br label %27
27: ; preds = %23, %22, %17, %9
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"%s is not register\0A\00"
@.str.1 = [4 x i8] c"rsp\00"
@.str.2 = [4 x i8] c"rbp\00"
define i32 @regnum(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 114
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %16
7: ; preds = %1
%8 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %0, i64 1
%15 = tail call i32 @atoi(i8* %14)
br label %16
16: ; preds = %10, %7, %13, %4
%17 = phi i32 [ -1, %4 ], [ %15, %13 ], [ 30, %7 ], [ 31, %10 ]
ret i32 %17
}