#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *, char *);
int main(void) {
  double accumulator;
  double number;
  char operator;
  bool isCalculating;
  accumulator = 0.0;
  isCalculating = true;
  printf("Begin Calculations\n");
  while (isCalculating) {
    scanf("%lf %c", &number, &operator);
    switch (operator) {
    case '+':
      accumulator += number;
      break;
    case '-':
      accumulator -= number;
      break;
    case '*':
      accumulator *= number;
      break;
    case '/':
      if (number == 0)
        printf("ERROR: Division by 0 is not allowed!");
      else
        accumulator /= number;
      break;
    case 'S':
      accumulator = number;
      break;
    case 'E':
      isCalculating = false;
      break;
    default:
      printf("ERROR: Unknown operator!\n");
      break;
    }
    printf("= %f\n", accumulator);
  }
  printf("End of Calculations");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
lea    0xf63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
je     1258 <main+0x138>
lea    0xf5f(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x19(%rbp),%rdx
call   1040 <scanf@plt>
movsbl -0x19(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x29,%eax
ja     1232 <main+0x112>
mov    -0x28(%rbp),%rax
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1240 <main+0x120>
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1240 <main+0x120>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1240 <main+0x120>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ff <main+0xdf>
jp     11ff <main+0xdf>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <main+0xf2>
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1240 <main+0x120>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1240 <main+0x120>
movl   $0x0,-0x20(%rbp)
jmp    1240 <main+0x120>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xeb6(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    114c <main+0x2c>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xfb1(%rip),%rdi
call   1030 <puts@plt>
lea    0xf5f(%rip),%r14
lea    0x10(%rsp),%r15
lea    0x7(%rsp),%r13
lea    0xfa7(%rip),%r12
lea    0xf73(%rip),%rbx
lea    0xe98(%rip),%rbp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    11a0 <main+0x70>
movsd  0x10(%rsp),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <scanf@plt>
movsbl 0x7(%rsp),%eax
add    $0xffffffd6,%eax
cmp    $0x29,%eax
ja     11e1 <main+0xb1>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
movsd  0x8(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
jmp    1190 <main+0x60>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
jmp    1190 <main+0x60>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1219 <main+0xe9>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
jmp    1190 <main+0x60>
movsd  0x10(%rsp),%xmm0
ucomisd 0xdf9(%rip),%xmm0
jne    1224 <main+0xf4>
jp     1224 <main+0xf4>
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
jmp    1190 <main+0x60>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    1190 <main+0x60>
lea    0xe9e(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Begin Calculations\0A\00"
@.str.1 = [7 x i8] c"%lf %c\00"
@.str.2 = [37 x i8] c"ERROR: Division by 0 is not allowed!\00"
@.str.3 = [26 x i8] c"ERROR: Unknown operator!\0A\00"
@.str.4 = [6 x i8] c"= %f\0A\00"
@.str.5 = [20 x i8] c"End of Calculations\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store i32 1, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %41, %0
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %44
10: ; preds = %7
%11 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double* %3, i8* %4)
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
switch i32 %13, label %39 [
i32 43, label %14
i32 45, label %18
i32 42, label %22
i32 47, label %26
i32 83, label %36
i32 69, label %38
]
14: ; preds = %10
%15 = load double, double* %3
%16 = load double, double* %2
%17 = fadd double %16, %15
store double %17, double* %2
br label %41
18: ; preds = %10
%19 = load double, double* %3
%20 = load double, double* %2
%21 = fsub double %20, %19
store double %21, double* %2
br label %41
22: ; preds = %10
%23 = load double, double* %3
%24 = load double, double* %2
%25 = fmul double %24, %23
store double %25, double* %2
br label %41
26: ; preds = %10
%27 = load double, double* %3
%28 = fcmp oeq double %27, 0.000000e+00
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %35
31: ; preds = %26
%32 = load double, double* %3
%33 = load double, double* %2
%34 = fdiv double %33, %32
store double %34, double* %2
br label %35
35: ; preds = %31, %29
br label %41
36: ; preds = %10
%37 = load double, double* %3
store double %37, double* %2
br label %41
38: ; preds = %10
store i32 0, i32* %5
br label %41
39: ; preds = %10
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %38, %36, %35, %22, %18, %14
%42 = load double, double* %2
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %42)
br label %7
44: ; preds = %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%lf %c\00"
@.str.2 = [37 x i8] c"ERROR: Division by 0 is not allowed!\00"
@.str.4 = [6 x i8] c"= %f\0A\00"
@.str.5 = [20 x i8] c"End of Calculations\00"
@str = [19 x i8] c"Begin Calculations\00"
@str.6 = [25 x i8] c"ERROR: Unknown operator!\00"
define i32 @main() {
%1 = alloca double
%2 = alloca i8
%3 = bitcast double* %1 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %30, %0
%6 = phi double [ 0.000000e+00, %0 ], [ %31, %30 ]
%7 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double* %1, i8* %2)
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
switch i32 %9, label %28 [
i32 43, label %10
i32 45, label %13
i32 42, label %16
i32 47, label %19
i32 83, label %26
i32 69, label %33
]
10: ; preds = %5
%11 = load double, double* %1
%12 = fadd double %6, %11
br label %30
13: ; preds = %5
%14 = load double, double* %1
%15 = fsub double %6, %14
br label %30
16: ; preds = %5
%17 = load double, double* %1
%18 = fmul double %6, %17
br label %30
19: ; preds = %5
%20 = load double, double* %1
%21 = fcmp oeq double %20, 0.000000e+00
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %30
24: ; preds = %19
%25 = fdiv double %6, %20
br label %30
26: ; preds = %5
%27 = load double, double* %1
br label %30
28: ; preds = %5
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
br label %30
30: ; preds = %22, %24, %28, %26, %16, %13, %10
%31 = phi double [ %6, %28 ], [ %27, %26 ], [ %6, %22 ], [ %25, %24 ], [ %18, %16 ], [ %15, %13 ], [ %12, %10 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %31)
br label %5
33: ; preds = %5
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %6)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}