#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 */
char EOF;
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char getchar();
scalar_t__ isspace(char);
int /*<<< orphan*/ printf(char *, int);
int scanf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
int main(const int argc, const char *argv[]) {
  int x = 0;
  int y = 0;
  int result = 0;
  char c = '\0';
  char op[2] = {0};
  int isValid = 1;
  if (scanf("%d", &x) == 1) {
    while (1) {
      if (scanf(" %1[+-] %d", &op, &y) == 2) {
        switch (op[0]) {
        case '+':
          result = x + y;
          break;
        case '-':
          result = x - y;
          break;
        case '/':
          if (y == 0) {
            isValid = 0;
            break;
          }
          result = x / y;
          break;
        case '*':
          result = x * y;
          break;
        default:
          break;
        }
        if (!isValid)
          break;
        x = result;
        while ((c = getchar()) != EOF && isspace(c) && c != '\n')
          continue;
        if (c == '\n') {
          (void)printf("%d\n", result);
          break;
        } else {
          (void)ungetc(c, stdin);
        }
      } else {
        isValid = 0;
        break;
      }
    }
  } else {
    isValid = 0;
  }
  if (!isValid) {
    while ((c = getchar()) != '\n' && c != EOF)
      continue;
    (void)fprintf(stderr, "Error. Unsupported operation.\n");
  }
  (void)getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <memset@plt>
movl   $0x1,-0x24(%rbp)
lea    0xe63(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
cmp    $0x1,%eax
jne    133a <main+0x1ca>
jmp    11d6 <main+0x66>
lea    0xe3b(%rip),%rdi
lea    -0x1f(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1090 <scanf@plt>
cmp    $0x2,%eax
jne    1324 <main+0x1b4>
movsbl -0x1f(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x5,%eax
ja     126f <main+0xff>
mov    -0x30(%rbp),%rax
lea    0xdea(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1274 <main+0x104>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1274 <main+0x104>
cmpl   $0x0,-0x18(%rbp)
jne    1251 <main+0xe1>
movl   $0x0,-0x24(%rbp)
jmp    1274 <main+0x104>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x1c(%rbp)
jmp    1274 <main+0x104>
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1274 <main+0x104>
jmp    1274 <main+0x104>
cmpl   $0x0,-0x24(%rbp)
jne    1283 <main+0x113>
jmp    1335 <main+0x1c5>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%ecx
mov    0x2d43(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x31(%rbp)
je     12d5 <main+0x165>
movsbl -0x1d(%rbp),%edi
call   1050 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x31(%rbp)
je     12d5 <main+0x165>
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    12e5 <main+0x175>
jmp    12ea <main+0x17a>
jmp    1289 <main+0x119>
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
jne    130b <main+0x19b>
mov    -0x1c(%rbp),%esi
lea    0xd22(%rip),%rdi
call   1030 <printf@plt>
jmp    1335 <main+0x1c5>
mov    -0x1d(%rbp),%al
mov    0x2cd3(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1080 <ungetc@plt>
jmp    1330 <main+0x1c0>
movl   $0x0,-0x24(%rbp)
jmp    1335 <main+0x1c5>
jmp    11d6 <main+0x66>
jmp    1341 <main+0x1d1>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    13ab <main+0x23b>
jmp    1350 <main+0x1e0>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x32(%rbp)
je     1381 <main+0x211>
movsbl -0x1d(%rbp),%eax
mov    0x2c6a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    1391 <main+0x221>
jmp    1396 <main+0x226>
jmp    1350 <main+0x1e0>
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
lea    0xc81(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    0x2c0f(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movw   $0x0,0xe(%rsp)
lea    0xe94(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    12b7 <main+0x157>
lea    0xe70(%rip),%rdi
lea    0xe(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1080 <scanf@plt>
cmp    $0x2,%eax
jne    12b7 <main+0x157>
mov    0x2e17(%rip),%r14
lea    0x10(%rsp),%r12
lea    0xe2b(%rip),%r15
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
movsbl 0xe(%rsp),%eax
add    $0xffffffd6,%eax
cmp    $0x5,%eax
ja     1250 <main+0xf0>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    0x10(%rsp),%r13d
imul   0x14(%rsp),%r13d
jmp    1250 <main+0xf0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%r13d
add    0x14(%rsp),%r13d
jmp    1250 <main+0xf0>
nopl   0x0(%rax)
mov    0x14(%rsp),%r13d
sub    0x10(%rsp),%r13d
jmp    1250 <main+0xf0>
nopl   0x0(%rax)
mov    0x10(%rsp),%ecx
test   %ecx,%ecx
je     12b7 <main+0x157>
mov    0x14(%rsp),%eax
cltd
idiv   %ecx
mov    %eax,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,0x14(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
movsbl %al,%ebp
cmp    (%r14),%al
je     1283 <main+0x123>
mov    %ebp,%edi
call   1040 <isspace@plt>
cmp    $0xa,%bpl
je     1283 <main+0x123>
test   %rax,%rax
jne    1260 <main+0x100>
cmp    $0xa,%bl
je     1303 <main+0x1a3>
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <ungetc@plt>
lea    0xd79(%rip),%rdi
lea    0xe(%rsp),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <scanf@plt>
cmp    $0x2,%eax
je     11e0 <main+0x80>
mov    0x2d22(%rip),%rbx
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     12cf <main+0x16f>
cmp    (%rbx),%al
jne    12c0 <main+0x160>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    0xd48(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd19(%rip),%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
jmp    12e4 <main+0x184>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c" %1[+-] %d\00"
@EOF = global i8 0
@.str.2 = [4 x i8] c"%d\0A\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.3 = [31 x i8] c"Error. Unsupported operation.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca [2 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i8 0, i8* %9
%12 = bitcast [2 x i8]* %10 to i8*
store i32 1, i32* %11
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %82
15: ; preds = %2
br label %16
16: ; preds = %15, %80
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), [2 x i8]* %10, i32* %7)
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %79
19: ; preds = %16
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %43 [
i32 43, label %23
i32 45, label %27
i32 47, label %31
i32 42, label %39
]
23: ; preds = %19
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = add nsw i32 %24, %25
store i32 %26, i32* %8
br label %44
27: ; preds = %19
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = sub nsw i32 %28, %29
store i32 %30, i32* %8
br label %44
31: ; preds = %19
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 0, i32* %11
br label %44
35: ; preds = %31
%36 = load i32, i32* %6
%37 = load i32, i32* %7
%38 = sdiv i32 %36, %37
store i32 %38, i32* %8
br label %44
39: ; preds = %19
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = mul nsw i32 %40, %41
store i32 %42, i32* %8
br label %44
43: ; preds = %19
br label %44
44: ; preds = %43, %39, %35, %34, %27, %23
%45 = load i32, i32* %11
%46 = icmp ne i32 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %44
br label %81
48: ; preds = %44
%49 = load i32, i32* %8
store i32 %49, i32* %6
br label %50
50: ; preds = %66, %48
%51 = call signext i8 (...) @getchar()
store i8 %51, i8* %9
%52 = sext i8 %51 to i32
%53 = load i8, i8* @EOF
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %52, %54
br i1 %55, label %56, label %64
56: ; preds = %50
%57 = load i8, i8* %9
%58 = call i64 @isspace(i8 signext %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = load i8, i8* %9
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 10
br label %64
64: ; preds = %60, %56, %50
%65 = phi i1 [ false, %56 ], [ false, %50 ], [ %63, %60 ]
br i1 %65, label %66, label %67
66: ; preds = %64
br label %50
67: ; preds = %64
%68 = load i8, i8* %9
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 10
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = load i32, i32* %8
%73 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %72)
br label %81
74: ; preds = %67
%75 = load i8, i8* %9
%76 = load i32, i32* @stdin
%77 = call i32 @ungetc(i8 signext %75, i32 %76)
br label %78
78: ; preds = %74
br label %80
79: ; preds = %16
store i32 0, i32* %11
br label %81
80: ; preds = %78
br label %16
81: ; preds = %79, %71, %47
br label %83
82: ; preds = %2
store i32 0, i32* %11
br label %83
83: ; preds = %82, %81
%84 = load i32, i32* %11
%85 = icmp ne i32 %84, 0
br i1 %85, label %103, label %86
86: ; preds = %83
br label %87
87: ; preds = %99, %86
%88 = call signext i8 (...) @getchar()
store i8 %88, i8* %9
%89 = sext i8 %88 to i32
%90 = icmp ne i32 %89, 10
br i1 %90, label %91, label %97
91: ; preds = %87
%92 = load i8, i8* %9
%93 = sext i8 %92 to i32
%94 = load i8, i8* @EOF
%95 = sext i8 %94 to i32
%96 = icmp ne i32 %93, %95
br label %97
97: ; preds = %91, %87
%98 = phi i1 [ false, %87 ], [ %96, %91 ]
br i1 %98, label %99, label %100
99: ; preds = %97
br label %87
100: ; preds = %97
%101 = load i32, i32* @stderr
%102 = call i32 @fprintf(i32 %101, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %103
103: ; preds = %100, %83
%104 = call signext i8 (...) @getchar()
%105 = load i32, i32* @EXIT_SUCCESS
ret i32 %105
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c" %1[+-] %d\00"
@EOF = global i8 0
@.str.2 = [4 x i8] c"%d\0A\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.3 = [31 x i8] c"Error. Unsupported operation.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i16
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = bitcast i16* %5 to i8*
store i16 0, i16* %5
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %56
11: ; preds = %2
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i16* %5, i32* %4)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %56
14: ; preds = %11, %51
%15 = phi i32 [ %37, %51 ], [ 0, %11 ]
%16 = load i8, i8* %8
%17 = sext i8 %16 to i32
switch i32 %17, label %36 [
i32 43, label %18
i32 45, label %22
i32 47, label %26
i32 42, label %32
]
18: ; preds = %14
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = add nsw i32 %20, %19
br label %36
22: ; preds = %14
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = sub nsw i32 %23, %24
br label %36
26: ; preds = %14
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 0
br i1 %28, label %56, label %29
29: ; preds = %26
%30 = load i32, i32* %3
%31 = sdiv i32 %30, %27
br label %36
32: ; preds = %14
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = mul nsw i32 %34, %33
br label %36
36: ; preds = %14, %32, %29, %22, %18
%37 = phi i32 [ %21, %18 ], [ %25, %22 ], [ %31, %29 ], [ %35, %32 ], [ %15, %14 ]
store i32 %37, i32* %3
br label %38
38: ; preds = %42, %36
%39 = call signext i8 (...) @getchar()
%40 = load i8, i8* @EOF
%41 = icmp eq i8 %39, %40
br i1 %41, label %47, label %42
42: ; preds = %38
%43 = call i64 @isspace(i8 signext %39)
%44 = icmp ne i64 %43, 0
%45 = icmp ne i8 %39, 10
%46 = and i1 %45, %44
br i1 %46, label %38, label %47
47: ; preds = %38, %42
%48 = icmp eq i8 %39, 10
br i1 %48, label %49, label %51
49: ; preds = %47
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %66
51: ; preds = %47
%52 = load i32, i32* @stdin
%53 = call i32 @ungetc(i8 signext %39, i32 %52)
%54 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i16* %5, i32* %4)
%55 = icmp eq i32 %54, 2
br i1 %55, label %14, label %56
56: ; preds = %51, %26, %11, %2
br label %57
57: ; preds = %56, %57
%58 = call signext i8 (...) @getchar()
%59 = icmp ne i8 %58, 10
%60 = load i8, i8* @EOF
%61 = icmp ne i8 %58, %60
%62 = select i1 %59, i1 %61, i1 false
br i1 %62, label %57, label %63
63: ; preds = %57
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %66
66: ; preds = %49, %63
%67 = call signext i8 (...) @getchar()
%68 = load i32, i32* @EXIT_SUCCESS
ret i32 %68
}