#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*/ error(char *, int);
scalar_t__ is_ppc_reg(char *);
scalar_t__ isalnum(char);
scalar_t__ isalpha(int);
scalar_t__ isdigit(char);
char *skipParens(char *);
char *rewrite_ppc_imm(char *arg, int argind) {
  int c = *arg;
  if (isdigit(c) || (c == '-' && isdigit(arg[1]))) {
    while (isdigit(*++arg))
      ;
  } else if (isalpha(c) || (c == '_')) {
    while (isalnum(*arg) || (*arg == '_'))
      ++arg;
    if (*arg == '(') {
      if (is_ppc_reg(arg + 1))
        return arg;
      arg = skipParens(arg);
    }
  } else if (*arg == '(') {
    arg = skipParens(arg);
  } else {
    error("unrecognised operand, position %d", argind);
  }
  return arg;
}


x86 assembly (clang, -O0):
<rewrite_ppc_imm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movsbl %al,%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11af <rewrite_ppc_imm+0x4f>
cmpl   $0x2d,-0x18(%rbp)
jne    11e0 <rewrite_ppc_imm+0x80>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e0 <rewrite_ppc_imm+0x80>
jmp    11b4 <rewrite_ppc_imm+0x54>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11db <rewrite_ppc_imm+0x7b>
jmp    11b4 <rewrite_ppc_imm+0x54>
jmp    12d1 <rewrite_ppc_imm+0x171>
mov    -0x18(%rbp),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%rax
jne    11fc <rewrite_ppc_imm+0x9c>
cmpl   $0x5f,-0x18(%rbp)
jne    1296 <rewrite_ppc_imm+0x136>
jmp    1201 <rewrite_ppc_imm+0xa1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
jne    122f <rewrite_ppc_imm+0xcf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    123f <rewrite_ppc_imm+0xdf>
jmp    1250 <rewrite_ppc_imm+0xf0>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1201 <rewrite_ppc_imm+0xa1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    1291 <rewrite_ppc_imm+0x131>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1040 <is_ppc_reg@plt>
cmp    $0x0,%rax
je     1284 <rewrite_ppc_imm+0x124>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d9 <rewrite_ppc_imm+0x179>
mov    -0x10(%rbp),%rdi
call   1080 <skipParens@plt>
mov    %rax,-0x10(%rbp)
jmp    12cc <rewrite_ppc_imm+0x16c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    12b8 <rewrite_ppc_imm+0x158>
mov    -0x10(%rbp),%rdi
call   1080 <skipParens@plt>
mov    %rax,-0x10(%rbp)
jmp    12c7 <rewrite_ppc_imm+0x167>
mov    -0x14(%rbp),%esi
lea    0xd3e(%rip),%rdi
call   1070 <error@plt>
jmp    12cc <rewrite_ppc_imm+0x16c>
jmp    12d1 <rewrite_ppc_imm+0x171>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewrite_ppc_imm>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
movsbl (%rdi),%ebp
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     119a <rewrite_ppc_imm+0x3a>
nopl   0x0(%rax)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1180 <rewrite_ppc_imm+0x20>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x2d,%bpl
jne    11ae <rewrite_ppc_imm+0x4e>
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1180 <rewrite_ppc_imm+0x20>
mov    %ebp,%edi
call   1060 <isalpha@plt>
cmp    $0x5f,%bpl
je     11e4 <rewrite_ppc_imm+0x84>
test   %rax,%rax
jne    11e4 <rewrite_ppc_imm+0x84>
cmpb   $0x28,(%rbx)
je     120a <rewrite_ppc_imm+0xaa>
lea    0xe34(%rip),%rdi
mov    %r14d,%esi
call   1070 <error@plt>
jmp    1192 <rewrite_ppc_imm+0x32>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1050 <isalnum@plt>
test   %rax,%rax
jne    11e0 <rewrite_ppc_imm+0x80>
movzbl (%rbx),%eax
cmp    $0x5f,%al
je     11e0 <rewrite_ppc_imm+0x80>
cmp    $0x28,%al
jne    1192 <rewrite_ppc_imm+0x32>
lea    0x1(%rbx),%rdi
call   1040 <is_ppc_reg@plt>
test   %rax,%rax
jne    1192 <rewrite_ppc_imm+0x32>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <skipParens@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"unrecognised operand, position %d\00"
define i8* @rewrite_ppc_imm(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = trunc i32 %10 to i8
%12 = call i64 @isdigit(i8 signext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 45
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = call i64 @isdigit(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %17, %2
br label %24
24: ; preds = %30, %23
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
%27 = load i8, i8* %26
%28 = call i64 @isdigit(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
br label %24
31: ; preds = %24
br label %84
32: ; preds = %17, %14
%33 = load i32, i32* %6
%34 = call i64 @isalpha(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i32, i32* %6
%38 = icmp eq i32 %37, 95
br i1 %38, label %39, label %71
39: ; preds = %36, %32
br label %40
40: ; preds = %52, %39
%41 = load i8*, i8** %4
%42 = load i8, i8* %41
%43 = call i64 @isalnum(i8 signext %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = load i8*, i8** %4
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 95
br label %50
50: ; preds = %45, %40
%51 = phi i1 [ true, %40 ], [ %49, %45 ]
br i1 %51, label %52, label %55
52: ; preds = %50
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %4
br label %40
55: ; preds = %50
%56 = load i8*, i8** %4
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 40
br i1 %59, label %60, label %70
60: ; preds = %55
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = call i64 @is_ppc_reg(i8* %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = load i8*, i8** %4
store i8* %66, i8** %3
br label %86
67: ; preds = %60
%68 = load i8*, i8** %4
%69 = call i8* @skipParens(i8* %68)
store i8* %69, i8** %4
br label %70
70: ; preds = %67, %55
br label %83
71: ; preds = %36
%72 = load i8*, i8** %4
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 40
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load i8*, i8** %4
%78 = call i8* @skipParens(i8* %77)
store i8* %78, i8** %4
br label %82
79: ; preds = %71
%80 = load i32, i32* %5
%81 = call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %79, %76
br label %83
83: ; preds = %82, %70
br label %84
84: ; preds = %83, %31
%85 = load i8*, i8** %4
store i8* %85, i8** %3
br label %86
86: ; preds = %84, %65
%87 = load i8*, i8** %3
ret i8* %87
}

LLVM IR (-O2):
@.str = [34 x i8] c"unrecognised operand, position %d\00"
define i8* @rewrite_ppc_imm(i8* %0, i32 %1) {
%3 = load i8, i8* %0
%4 = sext i8 %3 to i32
%5 = tail call i64 @isdigit(i8 signext %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = icmp eq i8 %3, 45
br i1 %8, label %9, label %21
9: ; preds = %7
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = tail call i64 @isdigit(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %9, %2
br label %15
15: ; preds = %14, %15
%16 = phi i8* [ %17, %15 ], [ %0, %14 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = tail call i64 @isdigit(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %48, label %15
21: ; preds = %9, %7
%22 = tail call i64 @isalpha(i32 %4)
%23 = icmp ne i64 %22, 0
%24 = icmp eq i8 %3, 95
%25 = or i1 %24, %23
br i1 %25, label %26, label %41
26: ; preds = %21, %33
%27 = phi i8* [ %34, %33 ], [ %0, %21 ]
%28 = load i8, i8* %27
%29 = tail call i64 @isalnum(i8 signext %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load i8, i8* %27
switch i8 %32, label %48 [
i8 95, label %33
i8 40, label %35
]
33: ; preds = %31, %26
%34 = getelementptr inbounds i8, i8* %27, i64 1
br label %26
35: ; preds = %31
%36 = getelementptr inbounds i8, i8* %27, i64 1
%37 = tail call i64 @is_ppc_reg(i8* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = tail call i8* @skipParens(i8* %27)
br label %48
41: ; preds = %21
%42 = load i8, i8* %0
%43 = icmp eq i8 %42, 40
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i8* @skipParens(i8* %0)
br label %48
46: ; preds = %41
%47 = tail call i32 @error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %48
48: ; preds = %15, %31, %44, %46, %39, %35
%49 = phi i8* [ %27, %35 ], [ %40, %39 ], [ %45, %44 ], [ %0, %46 ], [ %27, %31 ], [ %17, %15 ]
ret i8* %49
}