#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*/ abort();
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ strcmp(char const *, char *);
int reg(const char *r) {
  r++;
  if (!strcmp(r, "zero"))
    return 0;
  if (!strcmp(r, "pc"))
    return 1;
  if (!strcmp(r, "sp"))
    return 2;
  if (!strcmp(r, "r0"))
    return 3;
  if (!strcmp(r, "r1"))
    return 4;
  if (!strcmp(r, "r2"))
    return 5;
  if (!strcmp(r, "r3"))
    return 6;
  if (!strcmp(r, "flags"))
    return 7;
  printf("Unkown Register %s\n", r);
  abort();
}


x86 assembly (clang, -O0):
<reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    116d <reg+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1287 <reg+0x157>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1192 <reg+0x62>
movl   $0x1,-0x4(%rbp)
jmp    1287 <reg+0x157>
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11b7 <reg+0x87>
movl   $0x2,-0x4(%rbp)
jmp    1287 <reg+0x157>
mov    -0x10(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11dc <reg+0xac>
movl   $0x3,-0x4(%rbp)
jmp    1287 <reg+0x157>
mov    -0x10(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1201 <reg+0xd1>
movl   $0x4,-0x4(%rbp)
jmp    1287 <reg+0x157>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1226 <reg+0xf6>
movl   $0x5,-0x4(%rbp)
jmp    1287 <reg+0x157>
mov    -0x10(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    124b <reg+0x11b>
movl   $0x6,-0x4(%rbp)
jmp    1287 <reg+0x157>
mov    -0x10(%rbp),%rdi
lea    0xdc1(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1270 <reg+0x140>
movl   $0x7,-0x4(%rbp)
jmp    1287 <reg+0x157>
mov    -0x10(%rbp),%rsi
lea    0xda2(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reg>:
push   %rbx
mov    %rdi,%rbx
add    $0x1,%rbx
lea    0xec1(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11dd <reg+0xad>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11e1 <reg+0xb1>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11e8 <reg+0xb8>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11ef <reg+0xbf>
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11f6 <reg+0xc6>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11fd <reg+0xcd>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1204 <reg+0xd4>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
mov    %eax,%ecx
mov    $0x7,%eax
test   %ecx,%ecx
jne    120b <reg+0xdb>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret
mov    $0x2,%eax
pop    %rbx
ret
mov    $0x3,%eax
pop    %rbx
ret
mov    $0x4,%eax
pop    %rbx
ret
mov    $0x5,%eax
pop    %rbx
ret
mov    $0x6,%eax
pop    %rbx
ret
lea    0xe0b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"zero\00"
@.str.1 = [3 x i8] c"pc\00"
@.str.2 = [3 x i8] c"sp\00"
@.str.3 = [3 x i8] c"r0\00"
@.str.4 = [3 x i8] c"r1\00"
@.str.5 = [3 x i8] c"r2\00"
@.str.6 = [3 x i8] c"r3\00"
@.str.7 = [6 x i8] c"flags\00"
@.str.8 = [20 x i8] c"Unkown Register %s\0A\00"
define i32 @reg(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i32 1
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 0, i32* %2
br label %49
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10
store i32 1, i32* %2
br label %49
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %15
store i32 2, i32* %2
br label %49
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %20
store i32 3, i32* %2
br label %49
25: ; preds = %20
%26 = load i8*, i8** %3
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %25
store i32 4, i32* %2
br label %49
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %30
store i32 5, i32* %2
br label %49
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %35
store i32 6, i32* %2
br label %49
40: ; preds = %35
%41 = load i8*, i8** %3
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %40
store i32 7, i32* %2
br label %49
45: ; preds = %40
%46 = load i8*, i8** %3
%47 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %46)
%48 = call i32 (...) @abort()
unreachable
49: ; preds = %44, %39, %34, %29, %24, %19, %14, %9
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@.str = [5 x i8] c"zero\00"
@.str.1 = [3 x i8] c"pc\00"
@.str.2 = [3 x i8] c"sp\00"
@.str.3 = [3 x i8] c"r0\00"
@.str.4 = [3 x i8] c"r1\00"
@.str.5 = [3 x i8] c"r2\00"
@.str.6 = [3 x i8] c"r3\00"
@.str.7 = [6 x i8] c"flags\00"
@.str.8 = [20 x i8] c"Unkown Register %s\0A\00"
define i32 @reg(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %29, label %5
5: ; preds = %1
%6 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %29, label %8
8: ; preds = %5
%9 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %29, label %11
11: ; preds = %8
%12 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %11
%15 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %14
%18 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %17
%21 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %2)
%28 = tail call i32 (...) @abort()
unreachable
29: ; preds = %23, %20, %17, %14, %11, %8, %5, %1
%30 = phi i32 [ 0, %1 ], [ 1, %5 ], [ 2, %8 ], [ 3, %11 ], [ 4, %14 ], [ 5, %17 ], [ 6, %20 ], [ 7, %23 ]
ret i32 %30
}