#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 ExprEval(char *, int *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, int, int,
                           int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int evalExpr(char *str, int debug, int isTest, int erc, int eval, int testOk,
             int testFail, int testCount) {
  int rc = 1;
  int val = 0;
  if (isTest) {
    testCount++;
    rc = ExprEval(str, &val, debug);
    if (rc == erc && val == eval) {
      testOk++;
    } else {
      testFail++;
      fprintf(stderr,
              "Test failed : %s\neval = %d\n val = %d\nerc = %d\n rc = %d\n",
              str, eval, val, erc, rc);
    }
    return 2;
  }
  if (rc = ExprEval(str, &val, debug)) {
    printf("Error: expression evaluation failed, code [%d]\n", rc);
    return 1;
  } else {
    printf("Value: %d\n", val);
    return 0;
  }
}


x86 assembly (clang, -O0):
<evalExpr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11ec <evalExpr+0xbc>
mov    0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x2c(%rbp),%rsi
call   1050 <ExprEval@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11ad <evalExpr+0x7d>
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    11ad <evalExpr+0x7d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e0 <evalExpr+0xb0>
mov    0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,0x10(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x28(%rbp),%eax
lea    0xe28(%rip),%rsi
mov    %eax,(%rsp)
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1239 <evalExpr+0x109>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x2c(%rbp),%rsi
call   1050 <ExprEval@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     1223 <evalExpr+0xf3>
mov    -0x28(%rbp),%esi
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <evalExpr+0x109>
mov    -0x2c(%rbp),%esi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evalExpr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %esi,%edx
mov    %rdi,%rbx
movl   $0x0,0x14(%rsp)
lea    0x14(%rsp),%rsi
call   1050 <ExprEval@plt>
test   %ebp,%ebp
je     1194 <evalExpr+0x64>
mov    0x14(%rsp),%r8d
mov    $0x2,%ebp
cmp    %r15d,%eax
jne    1171 <evalExpr+0x41>
cmp    %r14d,%r8d
je     11bf <evalExpr+0x8f>
mov    0x2e68(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,(%rsp)
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    %r15d,%r9d
call   1040 <fprintf@plt>
jmp    11bf <evalExpr+0x8f>
test   %eax,%eax
je     11ad <evalExpr+0x7d>
lea    0xe99(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%ebp
jmp    11bf <evalExpr+0x8f>
mov    0x14(%rsp),%esi
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"Test failed : %s\0Aeval = %d\0A val = %d\0Aerc = %d\0A rc = %d\0A\00"
@.str.1 = [48 x i8] c"Error: expression evaluation failed, code [%d]\0A\00"
@.str.2 = [11 x i8] c"Value: %d\0A\00"
define i32 @evalExpr(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i8* %0, i8** %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i32 1, i32* %18
store i32 0, i32* %19
%20 = load i32, i32* %12
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %49
22: ; preds = %8
%23 = load i32, i32* %17
%24 = add nsw i32 %23, 1
store i32 %24, i32* %17
%25 = load i8*, i8** %10
%26 = load i32, i32* %11
%27 = call i32 @ExprEval(i8* %25, i32* %19, i32 %26)
store i32 %27, i32* %18
%28 = load i32, i32* %18
%29 = load i32, i32* %13
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %38
31: ; preds = %22
%32 = load i32, i32* %19
%33 = load i32, i32* %14
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i32, i32* %15
%37 = add nsw i32 %36, 1
store i32 %37, i32* %15
br label %48
38: ; preds = %31, %22
%39 = load i32, i32* %16
%40 = add nsw i32 %39, 1
store i32 %40, i32* %16
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %10
%43 = load i32, i32* %14
%44 = load i32, i32* %19
%45 = load i32, i32* %13
%46 = load i32, i32* %18
%47 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %42, i32 %43, i32 %44, i32 %45, i32 %46)
br label %48
48: ; preds = %38, %35
store i32 2, i32* %9
br label %60
49: ; preds = %8
%50 = load i8*, i8** %10
%51 = load i32, i32* %11
%52 = call i32 @ExprEval(i8* %50, i32* %19, i32 %51)
store i32 %52, i32* %18
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i32, i32* %18
%56 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %55)
store i32 1, i32* %9
br label %60
57: ; preds = %49
%58 = load i32, i32* %19
%59 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %58)
store i32 0, i32* %9
br label %60
60: ; preds = %57, %54, %48
%61 = load i32, i32* %9
ret i32 %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [56 x i8] c"Test failed : %s\0Aeval = %d\0A val = %d\0Aerc = %d\0A rc = %d\0A\00"
@.str.1 = [48 x i8] c"Error: expression evaluation failed, code [%d]\0A\00"
@.str.2 = [11 x i8] c"Value: %d\0A\00"
define i32 @evalExpr(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%11 = icmp eq i32 %2, 0
%12 = call i32 @ExprEval(i8* %0, i32* %9, i32 %1)
br i1 %11, label %21, label %13
13: ; preds = %8
%14 = icmp eq i32 %12, %3
%15 = load i32, i32* %9
%16 = icmp eq i32 %15, %4
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %28, label %18
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %4, i32 %15, i32 %3, i32 %12)
br label %28
21: ; preds = %8
%22 = icmp eq i32 %12, 0
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %28
25: ; preds = %21
%26 = load i32, i32* %9
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %18, %13, %25, %23
%29 = phi i32 [ 1, %23 ], [ 0, %25 ], [ 2, %13 ], [ 2, %18 ]
ret i32 %29
}