#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) == 'z')
    reg_num = 0;
  else if ((tolower(*reg_name) >= 'a') && (tolower(*reg_name) <= 'g'))
    reg_num = tolower(*reg_name) - 'a' + 1;
  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    $0x7a,%eax
jne    1164 <GetRegNum+0x34>
movl   $0x0,-0x14(%rbp)
jmp    11d0 <GetRegNum+0xa0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x61,%eax
jl     11b1 <GetRegNum+0x81>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x67,%eax
jg     11b1 <GetRegNum+0x81>
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    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>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x7a,%cl
je     1171 <GetRegNum+0x41>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
cmp    $0x61,%al
jl     1179 <GetRegNum+0x49>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
cmp    $0x67,%al
jg     1179 <GetRegNum+0x49>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
add    $0xffffffa0,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe80(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [33 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 eq i32 %9, 122
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %5
br label %36
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = call signext i8 @tolower(i8 signext %14)
%16 = sext i8 %15 to i32
%17 = icmp sge i32 %16, 97
br i1 %17, label %18, label %31
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = call signext i8 @tolower(i8 signext %20)
%22 = sext i8 %21 to i32
%23 = icmp sle i32 %22, 103
br i1 %23, label %24, label %31
24: ; preds = %18
%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 = sub nsw i32 %28, 97
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %35
31: ; preds = %18, %12
%32 = load i8*, i8** %3
%33 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %24
br label %36
36: ; preds = %35, %11
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@.str = [33 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 eq i8 %4, 122
br i1 %5, label %22, label %6
6: ; preds = %2
%7 = load i8, i8* %1
%8 = tail call signext i8 @tolower(i8 signext %7)
%9 = icmp sgt i8 %8, 96
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = load i8, i8* %1
%12 = tail call signext i8 @tolower(i8 signext %11)
%13 = icmp slt i8 %12, 104
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i8, i8* %1
%16 = tail call signext i8 @tolower(i8 signext %15)
%17 = sext i8 %16 to i32
%18 = add nsw i32 %17, -96
br label %22
19: ; preds = %10, %6
%20 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %2, %14
%23 = phi i32 [ %18, %14 ], [ 0, %2 ]
ret i32 %23
}