#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 atoi(char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ strcmp(char *, char *);
int main(void) {
  char input[256];
  int answer;
  int state = 0;
  while (1) {
    gets(input);
    if (state == 0) {
      answer = atoi(input);
      state = 3;
    }
    if (state == 1) {
      answer += atoi(input);
      state = 3;
    }
    if (state == 2) {
      answer -= atoi(input);
      state = 3;
    }
    if (state == 3) {
      if (strcmp(input, "+") == 0) {
        state = 1;
      }
      if (strcmp(input, "-") == 0) {
        state = 2;
      }
      if (strcmp(input, "=") == 0) {
        state = 3;
        break;
      }
    }
  }
  printf("%d\n", answer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <gets@plt>
cmpl   $0x0,-0x118(%rbp)
jne    1191 <main+0x51>
lea    -0x110(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x114(%rbp)
movl   $0x3,-0x118(%rbp)
cmpl   $0x1,-0x118(%rbp)
jne    11c0 <main+0x80>
lea    -0x110(%rbp),%rdi
call   1060 <atoi@plt>
add    -0x114(%rbp),%eax
mov    %eax,-0x114(%rbp)
movl   $0x3,-0x118(%rbp)
cmpl   $0x2,-0x118(%rbp)
jne    11f3 <main+0xb3>
lea    -0x110(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x114(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x114(%rbp)
movl   $0x3,-0x118(%rbp)
cmpl   $0x3,-0x118(%rbp)
jne    127f <main+0x13f>
lea    -0x110(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1227 <main+0xe7>
movl   $0x1,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    124e <main+0x10e>
movl   $0x2,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    127a <main+0x13a>
movl   $0x3,-0x118(%rbp)
jmp    1284 <main+0x144>
jmp    127f <main+0x13f>
jmp    115c <main+0x1c>
mov    -0x114(%rbp),%esi
lea    0xd75(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
xor    %r14d,%r14d
mov    %rsp,%rbx
lea    0xea4(%rip),%r15
mov    $0x2,%r13d
lea    0xe99(%rip),%r12
jmp    11bb <main+0x7b>
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <atoi@plt>
add    %eax,%ebp
mov    %rbx,%rdi
lea    0xe7c(%rip),%rsi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,1),%r14d
add    $0x1,%r14d
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
cmove  %r13d,%r14d
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ec <main+0xac>
mov    %rbx,%rdi
call   1050 <gets@plt>
cmp    $0x2,%r14d
je     11e0 <main+0xa0>
cmp    $0x1,%r14d
je     1170 <main+0x30>
test   %r14d,%r14d
jne    117a <main+0x3a>
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
jmp    117a <main+0x3a>
mov    %rbx,%rdi
call   1060 <atoi@plt>
sub    %eax,%ebp
jmp    117a <main+0x3a>
lea    0xe13(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"+\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
br label %5
5: ; preds = %0, %48
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %3
store i32 3, i32* %4
br label %13
13: ; preds = %10, %5
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%18 = call i32 @atoi(i8* %17)
%19 = load i32, i32* %3
%20 = add nsw i32 %19, %18
store i32 %20, i32* %3
store i32 3, i32* %4
br label %21
21: ; preds = %16, %13
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%26 = call i32 @atoi(i8* %25)
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, %26
store i32 %28, i32* %3
store i32 3, i32* %4
br label %29
29: ; preds = %24, %21
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 3
br i1 %31, label %32, label %48
32: ; preds = %29
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
store i32 1, i32* %4
br label %37
37: ; preds = %36, %32
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 2, i32* %4
br label %42
42: ; preds = %41, %37
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 3, i32* %4
br label %49
47: ; preds = %42
br label %48
48: ; preds = %47, %29
br label %5
49: ; preds = %46
%50 = load i32, i32* %3
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"+\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %15, %0
%4 = phi i32 [ undef, %0 ], [ %16, %15 ]
%5 = phi i32 [ 0, %0 ], [ %22, %15 ]
%6 = call i32 @gets(i8* %2)
switch i32 %5, label %15 [
i32 0, label %7
i32 1, label %9
i32 2, label %12
]
7: ; preds = %3
%8 = call i32 @atoi(i8* %2)
br label %15
9: ; preds = %3
%10 = call i32 @atoi(i8* %2)
%11 = add nsw i32 %10, %4
br label %15
12: ; preds = %3
%13 = call i32 @atoi(i8* %2)
%14 = sub nsw i32 %4, %13
br label %15
15: ; preds = %3, %7, %9, %12
%16 = phi i32 [ %14, %12 ], [ %8, %7 ], [ %11, %9 ], [ %4, %3 ]
%17 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i32 1, i32 3
%20 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i32 2, i32 %19
%23 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %3
25: ; preds = %15
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %16)
ret i32 0
}