#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 */
unsigned int apply_masking_mode(unsigned int);
int /*<<< orphan*/ assert(int);
unsigned int error(char *, char const *);
unsigned int eval_register(char const *, int *);
unsigned int arithmetic_op(const char *text, const char *ip, unsigned int ret) {
  int len;
  unsigned int lval = eval_register(ip, &len);
  if (lval == -1u)
    return -1u;
  ret |= (lval << 9);
  ip += len;
  if (*ip++ != ',')
    return error("Expected second operand in \"%s\"", text);
  lval = eval_register(ip, &len);
  if (lval == -1u)
    return -1u;
  assert(lval <= 7);
  ret |= (lval << 3);
  ip += len;
  if ((ret & 0700) != 0700) {
    if (*ip++ != ',')
      return error("Expected third operand in \"%s\"", text);
    lval = eval_register(ip, &len);
    if (lval == -1u)
      return -1u;
    assert(lval <= 7);
    ret |= lval;
    ip += len;
    if (*ip++ != '\0')
      return error("Expected only three operands in \"%s\"", text);
  } else {
    if (*ip++ != '\0')
      return error("Expected only two operands in \"%s\"", text);
  }
  return apply_masking_mode(ret);
}


x86 assembly (clang, -O0):
<arithmetic_op>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <eval_register@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1179 <arithmetic_op+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    132f <arithmetic_op+0x1ef>
mov    -0x24(%rbp),%eax
shl    $0x9,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     11c9 <arithmetic_op+0x89>
mov    -0x10(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1040 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    132f <arithmetic_op+0x1ef>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <eval_register@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11ef <arithmetic_op+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    132f <arithmetic_op+0x1ef>
cmpl   $0x7,-0x24(%rbp)
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x24(%rbp),%eax
shl    $0x3,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x1c0,%eax
cmp    $0x1c0,%eax
je     12ec <arithmetic_op+0x1ac>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     1263 <arithmetic_op+0x123>
mov    -0x10(%rbp),%rsi
lea    0xdca(%rip),%rdi
call   1040 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    132f <arithmetic_op+0x1ef>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <eval_register@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1289 <arithmetic_op+0x149>
movl   $0xffffffff,-0x4(%rbp)
jmp    132f <arithmetic_op+0x1ef>
cmpl   $0x7,-0x24(%rbp)
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x24(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12e7 <arithmetic_op+0x1a7>
mov    -0x10(%rbp),%rsi
lea    0xd65(%rip),%rdi
call   1040 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    132f <arithmetic_op+0x1ef>
jmp    1324 <arithmetic_op+0x1e4>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
je     131f <arithmetic_op+0x1df>
mov    -0x10(%rbp),%rsi
lea    0xd52(%rip),%rdi
call   1040 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    132f <arithmetic_op+0x1ef>
jmp    1324 <arithmetic_op+0x1e4>
mov    -0x1c(%rbp),%edi
call   1050 <apply_masking_mode@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arithmetic_op>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r13d
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0xc(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <eval_register@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     1258 <arithmetic_op+0x118>
mov    %eax,%ebx
movslq 0xc(%rsp),%rax
cmpb   $0x2c,0x0(%rbp,%rax,1)
jne    11e5 <arithmetic_op+0xa5>
mov    %r15,0x10(%rsp)
lea    (%rax,%rbp,1),%r15
add    $0x1,%r15
lea    0xc(%rsp),%rsi
mov    %r15,%rdi
call   1060 <eval_register@plt>
cmp    $0xffffffff,%eax
je     1258 <arithmetic_op+0x118>
mov    %eax,%r12d
shl    $0x9,%ebx
or     %r13d,%ebx
xor    %edi,%edi
cmp    $0x8,%eax
setb   %dil
call   1030 <assert@plt>
shl    $0x3,%r12d
or     %ebx,%r12d
movslq 0xc(%rsp),%rax
add    %rax,%r15
mov    %r12d,%eax
not    %eax
test   $0x1c0,%eax
jne    11f6 <arithmetic_op+0xb6>
cmpb   $0x0,(%r15)
je     124d <arithmetic_op+0x10d>
lea    0xe81(%rip),%rdi
jmp    123e <arithmetic_op+0xfe>
lea    0xe14(%rip),%rdi
mov    %r15,%rsi
call   1040 <error@plt>
jmp    1255 <arithmetic_op+0x115>
cmpb   $0x2c,(%r15)
jne    1237 <arithmetic_op+0xf7>
add    $0x1,%r15
lea    0xc(%rsp),%rsi
mov    %r15,%rdi
call   1060 <eval_register@plt>
cmp    $0xffffffff,%eax
je     1258 <arithmetic_op+0x118>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0x8,%eax
setb   %dil
call   1030 <assert@plt>
movslq 0xc(%rsp),%rax
cmpb   $0x0,(%r15,%rax,1)
je     124a <arithmetic_op+0x10a>
lea    0xe0a(%rip),%rdi
jmp    123e <arithmetic_op+0xfe>
lea    0xde2(%rip),%rdi
mov    0x10(%rsp),%rsi
call   1040 <error@plt>
jmp    1255 <arithmetic_op+0x115>
or     %ebx,%r12d
mov    %r12d,%edi
call   1050 <apply_masking_mode@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Expected second operand in \22%s\22\00"
@.str.1 = [31 x i8] c"Expected third operand in \22%s\22\00"
@.str.2 = [37 x i8] c"Expected only three operands in \22%s\22\00"
@.str.3 = [35 x i8] c"Expected only two operands in \22%s\22\00"
define i32 @arithmetic_op(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = call i32 @eval_register(i8* %10, i32* %8)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %103
15: ; preds = %3
%16 = load i32, i32* %9
%17 = shl i32 %16, 9
%18 = load i32, i32* %7
%19 = or i32 %18, %17
store i32 %19, i32* %7
%20 = load i32, i32* %8
%21 = load i8*, i8** %6
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %21, i64 %22
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
%26 = load i8, i8* %24
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 44
br i1 %28, label %29, label %32
29: ; preds = %15
%30 = load i8*, i8** %5
%31 = call i32 @error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %30)
store i32 %31, i32* %4
br label %103
32: ; preds = %15
%33 = load i8*, i8** %6
%34 = call i32 @eval_register(i8* %33, i32* %8)
store i32 %34, i32* %9
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 -1, i32* %4
br label %103
38: ; preds = %32
%39 = load i32, i32* %9
%40 = icmp ule i32 %39, 7
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load i32, i32* %9
%44 = shl i32 %43, 3
%45 = load i32, i32* %7
%46 = or i32 %45, %44
store i32 %46, i32* %7
%47 = load i32, i32* %8
%48 = load i8*, i8** %6
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8* %50, i8** %6
%51 = load i32, i32* %7
%52 = and i32 %51, 448
%53 = icmp ne i32 %52, 448
br i1 %53, label %54, label %90
54: ; preds = %38
%55 = load i8*, i8** %6
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %6
%57 = load i8, i8* %55
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 44
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = load i8*, i8** %5
%62 = call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %61)
store i32 %62, i32* %4
br label %103
63: ; preds = %54
%64 = load i8*, i8** %6
%65 = call i32 @eval_register(i8* %64, i32* %8)
store i32 %65, i32* %9
%66 = load i32, i32* %9
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %69
68: ; preds = %63
store i32 -1, i32* %4
br label %103
69: ; preds = %63
%70 = load i32, i32* %9
%71 = icmp ule i32 %70, 7
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
%74 = load i32, i32* %9
%75 = load i32, i32* %7
%76 = or i32 %75, %74
store i32 %76, i32* %7
%77 = load i32, i32* %8
%78 = load i8*, i8** %6
%79 = sext i32 %77 to i64
%80 = getelementptr inbounds i8, i8* %78, i64 %79
store i8* %80, i8** %6
%81 = load i8*, i8** %6
%82 = getelementptr inbounds i8, i8* %81, i32 1
store i8* %82, i8** %6
%83 = load i8, i8* %81
%84 = sext i8 %83 to i32
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %69
%87 = load i8*, i8** %5
%88 = call i32 @error(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %87)
store i32 %88, i32* %4
br label %103
89: ; preds = %69
br label %100
90: ; preds = %38
%91 = load i8*, i8** %6
%92 = getelementptr inbounds i8, i8* %91, i32 1
store i8* %92, i8** %6
%93 = load i8, i8* %91
%94 = sext i8 %93 to i32
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %90
%97 = load i8*, i8** %5
%98 = call i32 @error(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %97)
store i32 %98, i32* %4
br label %103
99: ; preds = %90
br label %100
100: ; preds = %99, %89
%101 = load i32, i32* %7
%102 = call i32 @apply_masking_mode(i32 %101)
store i32 %102, i32* %4
br label %103
103: ; preds = %100, %96, %86, %68, %60, %37, %29, %14
%104 = load i32, i32* %4
ret i32 %104
}

LLVM IR (-O2):
@.str = [32 x i8] c"Expected second operand in \22%s\22\00"
@.str.1 = [31 x i8] c"Expected third operand in \22%s\22\00"
@.str.2 = [37 x i8] c"Expected only three operands in \22%s\22\00"
@.str.3 = [35 x i8] c"Expected only two operands in \22%s\22\00"
define i32 @arithmetic_op(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 @eval_register(i8* %1, i32* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %62, label %8
8: ; preds = %3
%9 = shl i32 %6, 9
%10 = or i32 %9, %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %13
%16 = icmp eq i8 %15, 44
br i1 %16, label %19, label %17
17: ; preds = %8
%18 = call i32 @error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %62
19: ; preds = %8
%20 = call i32 @eval_register(i8* %14, i32* %4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %62, label %22
22: ; preds = %19
%23 = icmp ult i32 %20, 8
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = shl i32 %20, 3
%27 = or i32 %10, %26
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %14, i64 %29
%31 = and i32 %27, 448
%32 = icmp eq i32 %31, 448
br i1 %32, label %54, label %33
33: ; preds = %22
%34 = getelementptr inbounds i8, i8* %30, i64 1
%35 = load i8, i8* %30
%36 = icmp eq i8 %35, 44
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %62
39: ; preds = %33
%40 = call i32 @eval_register(i8* %34, i32* %4)
%41 = icmp eq i32 %40, -1
br i1 %41, label %62, label %42
42: ; preds = %39
%43 = icmp ult i32 %40, 8
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = or i32 %40, %27
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %34, i64 %48
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 0
br i1 %51, label %59, label %52
52: ; preds = %42
%53 = call i32 @error(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %62
54: ; preds = %22
%55 = load i8, i8* %30
%56 = icmp eq i8 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = call i32 @error(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %62
59: ; preds = %54, %42
%60 = phi i32 [ %46, %42 ], [ %27, %54 ]
%61 = call i32 @apply_masking_mode(i32 %60)
br label %62
62: ; preds = %39, %19, %3, %59, %57, %52, %37, %17
%63 = phi i32 [ %18, %17 ], [ %38, %37 ], [ %53, %52 ], [ %61, %59 ], [ %58, %57 ], [ -1, %3 ], [ -1, %19 ], [ -1, %39 ]
ret i32 %63
}