#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*/ delete (char *, int);
int /*<<< orphan*/ error(char *);
char *insert(char *, char *);
scalar_t__ is_sparc_r(char);
scalar_t__ isdigit(char);
char *skipParens(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *rewrite_sparc_reg(char *arg) {
  if (!strncmp(arg, "fp", 2)) {
    delete (arg, 2);
    return insert(arg, "30");
  }
  if (!strncmp(arg, "sp", 2)) {
    delete (arg, 2);
    return insert(arg, "14");
  }
  if (is_sparc_r(arg[0]) &&
      (((arg[1] >= '0') && (arg[1] <= '7')) || (arg[1] == '('))) {
    switch (*arg) {
    case 'r':
      delete (arg, 1);
      arg = insert(arg, "0+");
      break;
    case 'g':
      delete (arg, 1);
      arg = insert(arg, "0+");
      break;
    case 'o':
      delete (arg, 1);
      arg = insert(arg, "8+");
      break;
    case 'l':
      delete (arg, 1);
      arg = insert(arg, "16+");
      break;
    case 'i':
      delete (arg, 1);
      arg = insert(arg, "24+");
      break;
    default:
      error("THIS CANNOT HAPPEN");
    }
  }
  if (*arg == '(')
    return skipParens(arg);
  while (isdigit(*arg))
    ++arg;
  return arg;
}


x86 assembly (clang, -O0):
<rewrite_sparc_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11c1 <rewrite_sparc_reg+0x51>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1080 <delete@plt>
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1070 <insert@plt>
mov    %rax,-0x8(%rbp)
jmp    13a6 <rewrite_sparc_reg+0x236>
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1206 <rewrite_sparc_reg+0x96>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1080 <delete@plt>
mov    -0x10(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1070 <insert@plt>
mov    %rax,-0x8(%rbp)
jmp    13a6 <rewrite_sparc_reg+0x236>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <is_sparc_r@plt>
cmp    $0x0,%rax
je     1350 <rewrite_sparc_reg+0x1e0>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x30,%eax
jl     123e <rewrite_sparc_reg+0xce>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x37,%eax
jle    124f <rewrite_sparc_reg+0xdf>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x28,%eax
jne    1350 <rewrite_sparc_reg+0x1e0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffff99,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0xb,%eax
ja     133f <rewrite_sparc_reg+0x1cf>
mov    -0x18(%rbp),%rax
lea    0xd8d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1080 <delete@plt>
mov    -0x10(%rbp),%rdi
lea    0xda7(%rip),%rsi
call   1070 <insert@plt>
mov    %rax,-0x10(%rbp)
jmp    134b <rewrite_sparc_reg+0x1db>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1080 <delete@plt>
mov    -0x10(%rbp),%rdi
lea    0xd80(%rip),%rsi
call   1070 <insert@plt>
mov    %rax,-0x10(%rbp)
jmp    134b <rewrite_sparc_reg+0x1db>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1080 <delete@plt>
mov    -0x10(%rbp),%rdi
lea    0xd5c(%rip),%rsi
call   1070 <insert@plt>
mov    %rax,-0x10(%rbp)
jmp    134b <rewrite_sparc_reg+0x1db>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1080 <delete@plt>
mov    -0x10(%rbp),%rdi
lea    0xd38(%rip),%rsi
call   1070 <insert@plt>
mov    %rax,-0x10(%rbp)
jmp    134b <rewrite_sparc_reg+0x1db>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1080 <delete@plt>
mov    -0x10(%rbp),%rdi
lea    0xd15(%rip),%rsi
call   1070 <insert@plt>
mov    %rax,-0x10(%rbp)
jmp    134b <rewrite_sparc_reg+0x1db>
lea    0xd04(%rip),%rdi
call   1060 <error@plt>
jmp    1350 <rewrite_sparc_reg+0x1e0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    1372 <rewrite_sparc_reg+0x202>
mov    -0x10(%rbp),%rdi
call   1090 <skipParens@plt>
mov    %rax,-0x8(%rbp)
jmp    13a6 <rewrite_sparc_reg+0x236>
jmp    1377 <rewrite_sparc_reg+0x207>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     139e <rewrite_sparc_reg+0x22e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1377 <rewrite_sparc_reg+0x207>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewrite_sparc_reg>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11f7 <rewrite_sparc_reg+0x87>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     120d <rewrite_sparc_reg+0x9d>
movsbl (%rbx),%edi
call   1050 <is_sparc_r@plt>
test   %rax,%rax
je     1283 <rewrite_sparc_reg+0x113>
mov    0x1(%rbx),%al
cmp    $0x28,%al
je     11c3 <rewrite_sparc_reg+0x53>
and    $0xf8,%al
cmp    $0x30,%al
jne    1283 <rewrite_sparc_reg+0x113>
movsbl (%rbx),%eax
add    $0xffffff99,%eax
cmp    $0xb,%eax
ja     122a <rewrite_sparc_reg+0xba>
lea    0xe2b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <delete@plt>
lea    0xe4a(%rip),%rsi
jmp    1278 <rewrite_sparc_reg+0x108>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1080 <delete@plt>
lea    0xe28(%rip),%rsi
jmp    1221 <rewrite_sparc_reg+0xb1>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1080 <delete@plt>
lea    0xe18(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1070 <insert@plt>
lea    0xe19(%rip),%rdi
call   1060 <error@plt>
jmp    1283 <rewrite_sparc_reg+0x113>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <delete@plt>
lea    0xdfa(%rip),%rsi
jmp    1278 <rewrite_sparc_reg+0x108>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <delete@plt>
lea    0xde0(%rip),%rsi
jmp    1278 <rewrite_sparc_reg+0x108>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <delete@plt>
lea    0xdc7(%rip),%rsi
mov    %rbx,%rdi
call   1070 <insert@plt>
mov    %rax,%rbx
mov    (%rbx),%al
cmp    $0x28,%al
jne    1292 <rewrite_sparc_reg+0x122>
mov    %rbx,%rdi
pop    %rbx
jmp    1090 <skipParens@plt>
movsbl %al,%edi
cs nopw 0x0(%rax,%rax,1)
nop
call   1040 <isdigit@plt>
test   %rax,%rax
je     12b4 <rewrite_sparc_reg+0x144>
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
jmp    12a0 <rewrite_sparc_reg+0x130>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"fp\00"
@.str.1 = [3 x i8] c"30\00"
@.str.2 = [3 x i8] c"sp\00"
@.str.3 = [3 x i8] c"14\00"
@.str.4 = [3 x i8] c"0+\00"
@.str.5 = [3 x i8] c"8+\00"
@.str.6 = [4 x i8] c"16+\00"
@.str.7 = [4 x i8] c"24+\00"
@.str.8 = [19 x i8] c"THIS CANNOT HAPPEN\00"
define i8* @rewrite_sparc_reg(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%6 = icmp ne i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i32 @delete(i8* %8, i32 2)
%10 = load i8*, i8** %3
%11 = call i8* @insert(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %2
br label %96
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = call i32 @delete(i8* %17, i32 2)
%19 = load i8*, i8** %3
%20 = call i8* @insert(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %20, i8** %2
br label %96
21: ; preds = %12
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = call i64 @is_sparc_r(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %77
27: ; preds = %21
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp sge i32 %31, 48
br i1 %32, label %33, label %39
33: ; preds = %27
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp sle i32 %37, 55
br i1 %38, label %45, label %39
39: ; preds = %33, %27
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 40
br i1 %44, label %45, label %77
45: ; preds = %39, %33
%46 = load i8*, i8** %3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
switch i32 %48, label %74 [
i32 114, label %49
i32 103, label %54
i32 111, label %59
i32 108, label %64
i32 105, label %69
]
49: ; preds = %45
%50 = load i8*, i8** %3
%51 = call i32 @delete(i8* %50, i32 1)
%52 = load i8*, i8** %3
%53 = call i8* @insert(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i8* %53, i8** %3
br label %76
54: ; preds = %45
%55 = load i8*, i8** %3
%56 = call i32 @delete(i8* %55, i32 1)
%57 = load i8*, i8** %3
%58 = call i8* @insert(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i8* %58, i8** %3
br label %76
59: ; preds = %45
%60 = load i8*, i8** %3
%61 = call i32 @delete(i8* %60, i32 1)
%62 = load i8*, i8** %3
%63 = call i8* @insert(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i8* %63, i8** %3
br label %76
64: ; preds = %45
%65 = load i8*, i8** %3
%66 = call i32 @delete(i8* %65, i32 1)
%67 = load i8*, i8** %3
%68 = call i8* @insert(i8* %67, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
store i8* %68, i8** %3
br label %76
69: ; preds = %45
%70 = load i8*, i8** %3
%71 = call i32 @delete(i8* %70, i32 1)
%72 = load i8*, i8** %3
%73 = call i8* @insert(i8* %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store i8* %73, i8** %3
br label %76
74: ; preds = %45
%75 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
br label %76
76: ; preds = %74, %69, %64, %59, %54, %49
br label %77
77: ; preds = %76, %39, %21
%78 = load i8*, i8** %3
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 40
br i1 %81, label %82, label %85
82: ; preds = %77
%83 = load i8*, i8** %3
%84 = call i8* @skipParens(i8* %83)
store i8* %84, i8** %2
br label %96
85: ; preds = %77
br label %86
86: ; preds = %91, %85
%87 = load i8*, i8** %3
%88 = load i8, i8* %87
%89 = call i64 @isdigit(i8 signext %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %86
%92 = load i8*, i8** %3
%93 = getelementptr inbounds i8, i8* %92, i32 1
store i8* %93, i8** %3
br label %86
94: ; preds = %86
%95 = load i8*, i8** %3
store i8* %95, i8** %2
br label %96
96: ; preds = %94, %82, %16, %7
%97 = load i8*, i8** %2
ret i8* %97
}

LLVM IR (-O2):
@.str = [3 x i8] c"fp\00"
@.str.1 = [3 x i8] c"30\00"
@.str.2 = [3 x i8] c"sp\00"
@.str.3 = [3 x i8] c"14\00"
@.str.4 = [3 x i8] c"0+\00"
@.str.5 = [3 x i8] c"8+\00"
@.str.6 = [4 x i8] c"16+\00"
@.str.7 = [4 x i8] c"24+\00"
@.str.8 = [19 x i8] c"THIS CANNOT HAPPEN\00"
define i8* @rewrite_sparc_reg(i8* %0) {
%2 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @delete(i8* %0, i32 2)
%6 = tail call i8* @insert(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %59
7: ; preds = %1
%8 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @delete(i8* %0, i32 2)
%12 = tail call i8* @insert(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %59
13: ; preds = %7
%14 = load i8, i8* %0
%15 = tail call i64 @is_sparc_r(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %44, label %17
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %0, i64 1
%19 = load i8, i8* %18
%20 = and i8 %19, -8
%21 = icmp eq i8 %20, 48
%22 = icmp eq i8 %19, 40
%23 = or i1 %22, %21
br i1 %23, label %24, label %44
24: ; preds = %17
%25 = load i8, i8* %0
%26 = sext i8 %25 to i32
switch i32 %26, label %42 [
i32 114, label %27
i32 103, label %30
i32 111, label %33
i32 108, label %36
i32 105, label %39
]
27: ; preds = %24
%28 = tail call i32 @delete(i8* %0, i32 1)
%29 = tail call i8* @insert(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %44
30: ; preds = %24
%31 = tail call i32 @delete(i8* %0, i32 1)
%32 = tail call i8* @insert(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %44
33: ; preds = %24
%34 = tail call i32 @delete(i8* %0, i32 1)
%35 = tail call i8* @insert(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %44
36: ; preds = %24
%37 = tail call i32 @delete(i8* %0, i32 1)
%38 = tail call i8* @insert(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %44
39: ; preds = %24
%40 = tail call i32 @delete(i8* %0, i32 1)
%41 = tail call i8* @insert(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %44
42: ; preds = %24
%43 = tail call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
br label %44
44: ; preds = %17, %27, %30, %33, %36, %39, %42, %13
%45 = phi i8* [ %0, %42 ], [ %41, %39 ], [ %38, %36 ], [ %35, %33 ], [ %32, %30 ], [ %29, %27 ], [ %0, %13 ], [ %0, %17 ]
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 40
br i1 %47, label %51, label %48
48: ; preds = %44
%49 = tail call i64 @isdigit(i8 signext %46)
%50 = icmp eq i64 %49, 0
br i1 %50, label %59, label %53
51: ; preds = %44
%52 = tail call i8* @skipParens(i8* %45)
br label %59
53: ; preds = %48, %53
%54 = phi i8* [ %55, %53 ], [ %45, %48 ]
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = load i8, i8* %55
%57 = tail call i64 @isdigit(i8 signext %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %53
59: ; preds = %53, %48, %51, %10, %4
%60 = phi i8* [ %52, %51 ], [ %12, %10 ], [ %6, %4 ], [ %45, %48 ], [ %55, %53 ]
ret i8* %60
}