#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
char tolower(char);
int GetRegNum(char *instr_line, char *reg_name) {
  int reg_num;
  if ((tolower(*reg_name) >= 'a') && (tolower(*reg_name) <= 'g')) {
    reg_num = tolower(*reg_name) - 'a' + 1;
  } else if (tolower(*reg_name) == 'z') {
    reg_num = 0;
  } else {
    printf("ERROR:bad register name in %s!\n", instr_line);
    exit(-1);
  }
  return reg_num;
}


x86 assembly (clang, -O0):
<GetRegNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x61,%eax
jl     118d <GetRegNum+0x5d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x67,%eax
jg     118d <GetRegNum+0x5d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
sub    $0x61,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d0 <GetRegNum+0xa0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x7a,%eax
jne    11b1 <GetRegNum+0x81>
movl   $0x0,-0x14(%rbp)
jmp    11cb <GetRegNum+0x9b>
mov    -0x8(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
jmp    11d0 <GetRegNum+0xa0>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetRegNum>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movsbl (%rsi),%edi
call   1040 <tolower@plt>
cmp    $0x61,%al
jl     1162 <GetRegNum+0x32>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
cmp    $0x67,%al
jg     1162 <GetRegNum+0x32>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
add    $0xffffffa0,%eax
jmp    1173 <GetRegNum+0x43>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x7a,%cl
jne    117b <GetRegNum+0x4b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe7e(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"ERROR:bad register name in %s!\0A\00"
define i32 @GetRegNum(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = call signext i8 @tolower(i8 signext %7)
%9 = sext i8 %8 to i32
%10 = icmp sge i32 %9, 97
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = call signext i8 @tolower(i8 signext %13)
%15 = sext i8 %14 to i32
%16 = icmp sle i32 %15, 103
br i1 %16, label %17, label %24
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = call signext i8 @tolower(i8 signext %19)
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, 97
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %36
24: ; preds = %11, %2
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = call signext i8 @tolower(i8 signext %26)
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 122
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 0, i32* %5
br label %35
31: ; preds = %24
%32 = load i8*, i8** %3
%33 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %30
br label %36
36: ; preds = %35, %17
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@.str = [32 x i8] c"ERROR:bad register name in %s!\0A\00"
define i32 @GetRegNum(i8* %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = tail call signext i8 @tolower(i8 signext %3)
%5 = icmp sgt i8 %4, 96
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = load i8, i8* %1
%8 = tail call signext i8 @tolower(i8 signext %7)
%9 = icmp slt i8 %8, 104
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i8, i8* %1
%12 = tail call signext i8 @tolower(i8 signext %11)
%13 = sext i8 %12 to i32
%14 = add nsw i32 %13, -96
br label %22
15: ; preds = %6, %2
%16 = load i8, i8* %1
%17 = tail call signext i8 @tolower(i8 signext %16)
%18 = icmp eq i8 %17, 122
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %15, %10
%23 = phi i32 [ %14, %10 ], [ 0, %15 ]
ret i32 %23
}