#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 /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int sscanf(char *, char *, int *, char *, int *);
int process_rhs(char *curr, int *variables) {
  int index1;
  int const_val;
  char op;
  if (sscanf(curr, "V%d%c%d", &index1, &op, &const_val) != 3) {
    puts("Right side of equation must be a variable, an operator, and a "
         "constant!");
    exit(0);
  }
  if (index1 > 20) {
    puts("index out of bounds!");
    exit(0);
  }
  int val1 = variables[index1];
  if (op == '+') {
    return val1 + const_val;
  } else if (op == '-') {
    return val1 - const_val;
  } else if (op == '*') {
    return val1 * const_val;
  } else if (op == '/') {
    return val1 / const_val;
  } else {
    puts("unknown operator");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<process_rhs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x21(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
je     1178 <process_rhs+0x48>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>
cmpl   $0x14,-0x1c(%rbp)
jle    1195 <process_rhs+0x65>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x2b,%eax
jne    11be <process_rhs+0x8e>
mov    -0x28(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <process_rhs+0xf4>
movsbl -0x21(%rbp),%eax
cmp    $0x2d,%eax
jne    11d9 <process_rhs+0xa9>
mov    -0x28(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <process_rhs+0xf4>
movsbl -0x21(%rbp),%eax
cmp    $0x2a,%eax
jne    11f5 <process_rhs+0xc5>
mov    -0x28(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <process_rhs+0xf4>
movsbl -0x21(%rbp),%eax
cmp    $0x2f,%eax
jne    1211 <process_rhs+0xe1>
mov    -0x28(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,-0x4(%rbp)
jmp    1224 <process_rhs+0xf4>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_rhs>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xed9(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x7(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    11a3 <process_rhs+0x73>
movslq 0xc(%rsp),%rax
cmp    $0x15,%rax
jge    11ac <process_rhs+0x7c>
mov    0x7(%rsp),%cl
add    $0xd6,%cl
cmp    $0x5,%cl
ja     11b5 <process_rhs+0x85>
mov    (%rbx,%rax,4),%eax
movzbl %cl,%ecx
lea    0xe84(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
imul   0x8(%rsp),%eax
jmp    119d <process_rhs+0x6d>
sub    0x8(%rsp),%eax
jmp    119d <process_rhs+0x6d>
cltd
idivl  0x8(%rsp)
jmp    119d <process_rhs+0x6d>
add    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe76(%rip),%rdi
jmp    11bc <process_rhs+0x8c>
lea    0xeb5(%rip),%rdi
jmp    11bc <process_rhs+0x8c>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"V%d%c%d\00"
@.str.1 = [72 x i8] c"Right side of equation must be a variable, an operator, and a constant!\00"
@.str.2 = [21 x i8] c"index out of bounds!\00"
@.str.3 = [17 x i8] c"unknown operator\00"
define i32 @process_rhs(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%10 = load i8*, i8** %4
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %6, i8* %8, i32* %7)
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @puts(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 20
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %16
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
store i32 %27, i32* %9
%28 = load i8, i8* %8
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 43
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = load i32, i32* %9
%33 = load i32, i32* %7
%34 = add nsw i32 %32, %33
store i32 %34, i32* %3
br label %62
35: ; preds = %22
%36 = load i8, i8* %8
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 45
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i32, i32* %9
%41 = load i32, i32* %7
%42 = sub nsw i32 %40, %41
store i32 %42, i32* %3
br label %62
43: ; preds = %35
%44 = load i8, i8* %8
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 42
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load i32, i32* %9
%49 = load i32, i32* %7
%50 = mul nsw i32 %48, %49
store i32 %50, i32* %3
br label %62
51: ; preds = %43
%52 = load i8, i8* %8
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 47
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = load i32, i32* %9
%57 = load i32, i32* %7
%58 = sdiv i32 %56, %57
store i32 %58, i32* %3
br label %62
59: ; preds = %51
%60 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%61 = call i32 @exit(i32 0)
unreachable
62: ; preds = %55, %47, %39, %31
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [8 x i8] c"V%d%c%d\00"
@.str.1 = [72 x i8] c"Right side of equation must be a variable, an operator, and a constant!\00"
@.str.2 = [21 x i8] c"index out of bounds!\00"
@.str.3 = [17 x i8] c"unknown operator\00"
define i32 @process_rhs(i8* nocapture %0, i32* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %3, i8* %5, i32* %4)
%9 = icmp eq i32 %8, 3
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 20
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %13
%20 = sext i32 %14 to i64
%21 = getelementptr inbounds i32, i32* %1, i64 %20
%22 = load i32, i32* %21
%23 = load i8, i8* %5
switch i8 %23, label %36 [
i8 43, label %24
i8 45, label %27
i8 42, label %30
i8 47, label %33
]
24: ; preds = %19
%25 = load i32, i32* %4
%26 = add nsw i32 %25, %22
br label %39
27: ; preds = %19
%28 = load i32, i32* %4
%29 = sub nsw i32 %22, %28
br label %39
30: ; preds = %19
%31 = load i32, i32* %4
%32 = mul nsw i32 %31, %22
br label %39
33: ; preds = %19
%34 = load i32, i32* %4
%35 = sdiv i32 %22, %34
br label %39
36: ; preds = %19
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %33, %30, %27, %24
%40 = phi i32 [ %26, %24 ], [ %29, %27 ], [ %32, %30 ], [ %35, %33 ]
ret i32 %40
}