#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 *, float *, char *);
int main(void) {
  double accumulator = 0;
  float operand;
  char operator;
  printf("Begin calculations\n");
  do {
    scanf("%f %c", &operand, &operator);
    switch (operator) {
    case '+':
      accumulator += operand;
      break;
    case '-':
      accumulator -= operand;
      break;
    case '*':
      accumulator *= operand;
      break;
    case '/':
      if (operand)
        accumulator /= operand;
      else
        printf("Division by zero.\n");
      break;
    case 'S':
      accumulator = operand;
      break;
    case 'E':
      break;
    default:
      printf("Unknown operator.\n");
      break;
    }
    printf("= %.3f\n", accumulator);
  } while ('E' != operator);
  printf("End calculations\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    0xf6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf70(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x15(%rbp),%rdx
call   1040 <scanf@plt>
movsbl -0x15(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x29,%eax
ja     1232 <main+0x112>
mov    -0x20(%rbp),%rax
lea    0xe86(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1240 <main+0x120>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1240 <main+0x120>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1240 <main+0x120>
movss  -0x14(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11eb <main+0xcb>
jp     11eb <main+0xcb>
jmp    1207 <main+0xe7>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1215 <main+0xf5>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <main+0x120>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1240 <main+0x120>
jmp    1240 <main+0x120>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xe9c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsbl -0x15(%rbp),%ecx
mov    $0x45,%eax
cmp    %ecx,%eax
jne    1145 <main+0x25>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%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    0xf75(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xf52(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xb(%rsp),%r13
lea    0xf85(%rip),%r12
lea    0xf40(%rip),%rbx
lea    0xe8b(%rip),%rbp
jmp    11ab <main+0x7b>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
cmpb   $0x45,0xb(%rsp)
je     1267 <main+0x137>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <scanf@plt>
movsbl 0xb(%rsp),%eax
add    $0xffffffd6,%eax
cmp    $0x29,%eax
ja     1208 <main+0xd8>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
jmp    1190 <main+0x60>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
jmp    1190 <main+0x60>
mov    %r12,%rdi
jmp    125d <main+0x12d>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
jmp    1190 <main+0x60>
movss  0xc(%rsp),%xmm0
ucomiss 0xdc7(%rip),%xmm0
jne    123d <main+0x10d>
jnp    1256 <main+0x126>
cvtss2sd %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
jmp    1190 <main+0x60>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x60>
lea    0xe5f(%rip),%rdi
call   1030 <puts@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 = [6 x i8] c"%f %c\00"
@.str.2 = [19 x i8] c"Division by zero.\0A\00"
@.str.3 = [19 x i8] c"Unknown operator.\0A\00"
@.str.4 = [8 x i8] c"= %.3f\0A\00"
@.str.5 = [18 x i8] c"End calculations\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca float
%4 = alloca i8
store i32 0, i32* %1
store double 0.000000e+00, double* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %45, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %3, i8* %4)
%8 = load i8, i8* %4
%9 = sext i8 %8 to i32
switch i32 %9, label %40 [
i32 43, label %10
i32 45, label %15
i32 42, label %20
i32 47, label %25
i32 83, label %36
i32 69, label %39
]
10: ; preds = %6
%11 = load float, float* %3
%12 = fpext float %11 to double
%13 = load double, double* %2
%14 = fadd double %13, %12
store double %14, double* %2
br label %42
15: ; preds = %6
%16 = load float, float* %3
%17 = fpext float %16 to double
%18 = load double, double* %2
%19 = fsub double %18, %17
store double %19, double* %2
br label %42
20: ; preds = %6
%21 = load float, float* %3
%22 = fpext float %21 to double
%23 = load double, double* %2
%24 = fmul double %23, %22
store double %24, double* %2
br label %42
25: ; preds = %6
%26 = load float, float* %3
%27 = fcmp une float %26, 0.000000e+00
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load float, float* %3
%30 = fpext float %29 to double
%31 = load double, double* %2
%32 = fdiv double %31, %30
store double %32, double* %2
br label %35
33: ; preds = %25
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
br label %42
36: ; preds = %6
%37 = load float, float* %3
%38 = fpext float %37 to double
store double %38, double* %2
br label %42
39: ; preds = %6
br label %42
40: ; preds = %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %39, %36, %35, %20, %15, %10
%43 = load double, double* %2
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %43)
br label %45
45: ; preds = %42
%46 = load i8, i8* %4
%47 = sext i8 %46 to i32
%48 = icmp ne i32 69, %47
br i1 %48, label %6, label %49
49: ; preds = %45
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%f %c\00"
@.str.4 = [8 x i8] c"= %.3f\0A\00"
@str = [19 x i8] c"Begin calculations\00"
@str.6 = [17 x i8] c"End calculations\00"
@str.7 = [18 x i8] c"Division by zero.\00"
@str.8 = [18 x i8] c"Unknown operator.\00"
define i32 @main() {
%1 = alloca float
%2 = alloca i8
%3 = bitcast float* %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 = %35, %0
%6 = phi double [ 0.000000e+00, %0 ], [ %36, %35 ]
%7 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %1, i8* %2)
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
switch i32 %9, label %33 [
i32 43, label %10
i32 45, label %14
i32 42, label %18
i32 47, label %22
i32 83, label %30
i32 69, label %35
]
10: ; preds = %5
%11 = load float, float* %1
%12 = fpext float %11 to double
%13 = fadd double %6, %12
br label %35
14: ; preds = %5
%15 = load float, float* %1
%16 = fpext float %15 to double
%17 = fsub double %6, %16
br label %35
18: ; preds = %5
%19 = load float, float* %1
%20 = fpext float %19 to double
%21 = fmul double %6, %20
br label %35
22: ; preds = %5
%23 = load float, float* %1
%24 = fcmp une float %23, 0.000000e+00
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = fpext float %23 to double
%27 = fdiv double %6, %26
br label %35
28: ; preds = %22
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
br label %35
30: ; preds = %5
%31 = load float, float* %1
%32 = fpext float %31 to double
br label %35
33: ; preds = %5
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
br label %35
35: ; preds = %25, %28, %33, %5, %30, %18, %14, %10
%36 = phi double [ %6, %33 ], [ %6, %5 ], [ %32, %30 ], [ %27, %25 ], [ %6, %28 ], [ %21, %18 ], [ %17, %14 ], [ %13, %10 ]
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double %36)
%38 = load i8, i8* %2
%39 = icmp eq i8 %38, 69
br i1 %39, label %40, label %5
40: ; preds = %35
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
ret i32 0
}