#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 */
struct ev_input {
  int dummy;
};
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
char ev_getc(struct ev_input *);
char ev_peekc(struct ev_input *);
int /*<<< orphan*/ eval_term(struct ev_input *);
int64_t eval_expr(struct ev_input *e) {
  int64_t v0, v1;
  char op = '+';
  if (ev_peekc(e) == '+' || ev_peekc(e) == '-') {
    op = ev_getc(e);
  }
  v0 = eval_term(e);
  if (op == '-')
    v0 = -v0;
  while (ev_peekc(e) == '+' || ev_peekc(e) == '-') {
    op = ev_getc(e);
    v1 = eval_term(e);
    if (op == '-')
      v0 = v0 - v1;
    else
      v0 = v0 + v1;
  }
  return v0;
}


x86 assembly (clang, -O0):
<eval_expr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x2b,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ev_peekc@plt>
movsbl %al,%eax
cmp    $0x2b,%eax
je     116a <eval_expr+0x3a>
mov    -0x8(%rbp),%rdi
call   1040 <ev_peekc@plt>
movsbl %al,%eax
cmp    $0x2d,%eax
jne    1176 <eval_expr+0x46>
mov    -0x8(%rbp),%rdi
call   1030 <ev_getc@plt>
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <eval_term@plt>
mov    %eax,-0xc(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x2d,%eax
jne    1197 <eval_expr+0x67>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    119c <eval_expr+0x6c>
mov    -0x8(%rbp),%rdi
call   1040 <ev_peekc@plt>
movsbl %al,%ecx
mov    $0x1,%al
cmp    $0x2b,%ecx
mov    %al,-0x12(%rbp)
je     11cb <eval_expr+0x9b>
mov    -0x8(%rbp),%rdi
call   1040 <ev_peekc@plt>
movsbl %al,%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    11db <eval_expr+0xab>
jmp    121c <eval_expr+0xec>
mov    -0x8(%rbp),%rdi
call   1030 <ev_getc@plt>
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <eval_term@plt>
mov    %eax,-0x10(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x2d,%eax
jne    120e <eval_expr+0xde>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1217 <eval_expr+0xe7>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    119c <eval_expr+0x6c>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_expr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbp
call   1040 <ev_peekc@plt>
cmp    $0x2b,%al
je     114f <eval_expr+0x1f>
mov    %rbp,%rdi
call   1040 <ev_peekc@plt>
cmp    $0x2d,%al
jne    1172 <eval_expr+0x42>
mov    %rbp,%rdi
call   1030 <ev_getc@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1050 <eval_term@plt>
mov    %eax,%r15d
neg    %r15d
cmp    $0x2d,%r14b
cmovne %eax,%r15d
jmp    119f <eval_expr+0x6f>
mov    %rbp,%rdi
call   1050 <eval_term@plt>
mov    %eax,%r15d
jmp    119f <eval_expr+0x6f>
nop
mov    %rbp,%rdi
call   1030 <ev_getc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <eval_term@plt>
mov    %eax,%ecx
neg    %ecx
cmp    $0x2d,%bl
cmovne %eax,%ecx
add    %ecx,%r15d
mov    %rbp,%rdi
call   1040 <ev_peekc@plt>
cmp    $0x2b,%al
je     1180 <eval_expr+0x50>
mov    %rbp,%rdi
call   1040 <ev_peekc@plt>
cmp    $0x2d,%al
je     1180 <eval_expr+0x50>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ev_input = type { i32 }
define i32 @eval_expr(%struct.ev_input* %0) {
%2 = alloca %struct.ev_input*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store %struct.ev_input* %0, %struct.ev_input** %2
store i8 43, i8* %5
%6 = load %struct.ev_input*, %struct.ev_input** %2
%7 = call signext i8 @ev_peekc(%struct.ev_input* %6)
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 43
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = load %struct.ev_input*, %struct.ev_input** %2
%12 = call signext i8 @ev_peekc(%struct.ev_input* %11)
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 45
br i1 %14, label %15, label %18
15: ; preds = %10, %1
%16 = load %struct.ev_input*, %struct.ev_input** %2
%17 = call signext i8 @ev_getc(%struct.ev_input* %16)
store i8 %17, i8* %5
br label %18
18: ; preds = %15, %10
%19 = load %struct.ev_input*, %struct.ev_input** %2
%20 = call i32 @eval_term(%struct.ev_input* %19)
store i32 %20, i32* %3
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 45
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %3
%26 = sub nsw i32 0, %25
store i32 %26, i32* %3
br label %27
27: ; preds = %24, %18
br label %28
28: ; preds = %56, %27
%29 = load %struct.ev_input*, %struct.ev_input** %2
%30 = call signext i8 @ev_peekc(%struct.ev_input* %29)
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 43
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load %struct.ev_input*, %struct.ev_input** %2
%35 = call signext i8 @ev_peekc(%struct.ev_input* %34)
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 45
br label %38
38: ; preds = %33, %28
%39 = phi i1 [ true, %28 ], [ %37, %33 ]
br i1 %39, label %40, label %57
40: ; preds = %38
%41 = load %struct.ev_input*, %struct.ev_input** %2
%42 = call signext i8 @ev_getc(%struct.ev_input* %41)
store i8 %42, i8* %5
%43 = load %struct.ev_input*, %struct.ev_input** %2
%44 = call i32 @eval_term(%struct.ev_input* %43)
store i32 %44, i32* %4
%45 = load i8, i8* %5
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 45
br i1 %47, label %48, label %52
48: ; preds = %40
%49 = load i32, i32* %3
%50 = load i32, i32* %4
%51 = sub nsw i32 %49, %50
store i32 %51, i32* %3
br label %56
52: ; preds = %40
%53 = load i32, i32* %3
%54 = load i32, i32* %4
%55 = add nsw i32 %53, %54
store i32 %55, i32* %3
br label %56
56: ; preds = %52, %48
br label %28
57: ; preds = %38
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.ev_input = type { i32 }
define i32 @eval_expr(%struct.ev_input* %0) {
%2 = tail call signext i8 @ev_peekc(%struct.ev_input* %0)
%3 = icmp eq i8 %2, 43
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call signext i8 @ev_peekc(%struct.ev_input* %0)
%6 = icmp eq i8 %5, 45
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @eval_term(%struct.ev_input* %0)
br label %15
9: ; preds = %1, %4
%10 = tail call signext i8 @ev_getc(%struct.ev_input* %0)
%11 = icmp eq i8 %10, 45
%12 = tail call i32 @eval_term(%struct.ev_input* %0)
%13 = sub nsw i32 0, %12
%14 = select i1 %11, i32 %13, i32 %12
br label %15
15: ; preds = %9, %7
%16 = phi i32 [ %14, %9 ], [ %8, %7 ]
br label %17
17: ; preds = %15, %24
%18 = phi i32 [ %30, %24 ], [ %16, %15 ]
%19 = tail call signext i8 @ev_peekc(%struct.ev_input* %0)
%20 = icmp eq i8 %19, 43
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = tail call signext i8 @ev_peekc(%struct.ev_input* %0)
%23 = icmp eq i8 %22, 45
br i1 %23, label %24, label %31
24: ; preds = %17, %21
%25 = tail call signext i8 @ev_getc(%struct.ev_input* %0)
%26 = tail call i32 @eval_term(%struct.ev_input* %0)
%27 = icmp eq i8 %25, 45
%28 = sub i32 0, %26
%29 = select i1 %27, i32 %28, i32 %26
%30 = add i32 %29, %18
br label %17
31: ; preds = %21
ret i32 %18
}