#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main(void) {
  float num = 0.0f, total = 0.0f;
  char ch;
  printf("Enter an expression: ");
  scanf("%f", &total);
  while ((ch = getchar()) != '\n') {
    switch (ch) {
    case '+':
      scanf("%f", &num);
      total += num;
      break;
    case '-':
      scanf("%f", &num);
      total -= num;
      break;
    case '*':
      scanf("%f", &num);
      total *= num;
      break;
    case '/':
      scanf("%f", &num);
      total /= num;
      break;
    default:
      continue;
    }
  }
  printf("Value of expression: %.2f\n", total);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     124f <main+0x11f>
movsbl -0xd(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     1245 <main+0x115>
mov    -0x18(%rbp),%rax
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe7a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    124a <main+0x11a>
lea    0xe56(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    124a <main+0x11a>
lea    0xe2e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0x8(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    124a <main+0x11a>
lea    0xe0a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    124a <main+0x11a>
jmp    116d <main+0x3d>
jmp    116d <main+0x3d>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    1197 <main+0x67>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xead(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe62(%rip),%rbx
lea    0xe89(%rip),%r14
lea    0xc(%rsp),%r15
jmp    11d8 <main+0xa8>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movss  0x8(%rsp),%xmm0
divss  0xc(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
je     1173 <main+0x43>
movsbl %al,%eax
add    $0xffffffd6,%eax
cmp    $0x5,%eax
ja     11cd <main+0x9d>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movss  0xc(%rsp),%xmm0
mulss  0x8(%rsp),%xmm0
jmp    11c7 <main+0x97>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movss  0xc(%rsp),%xmm0
addss  0x8(%rsp),%xmm0
jmp    11c7 <main+0x97>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
jmp    11c7 <main+0x97>

LLVM IR (-O0):
@.str = [22 x i8] c"Enter an expression: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [27 x i8] c"Value of expression: %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca i8
store i32 0, i32* %1
store float 0.000000e+00, float* %2
store float 0.000000e+00, float* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
br label %7
7: ; preds = %35, %34, %0
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %4
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %36
11: ; preds = %7
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
switch i32 %13, label %34 [
i32 43, label %14
i32 45, label %19
i32 42, label %24
i32 47, label %29
]
14: ; preds = %11
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%16 = load float, float* %2
%17 = load float, float* %3
%18 = fadd float %17, %16
store float %18, float* %3
br label %35
19: ; preds = %11
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%21 = load float, float* %2
%22 = load float, float* %3
%23 = fsub float %22, %21
store float %23, float* %3
br label %35
24: ; preds = %11
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%26 = load float, float* %2
%27 = load float, float* %3
%28 = fmul float %27, %26
store float %28, float* %3
br label %35
29: ; preds = %11
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%31 = load float, float* %2
%32 = load float, float* %3
%33 = fdiv float %32, %31
store float %33, float* %3
br label %35
34: ; preds = %11
br label %7
35: ; preds = %29, %24, %19, %14
br label %7
36: ; preds = %7
%37 = load float, float* %3
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter an expression: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [27 x i8] c"Value of expression: %.2f\0A\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = bitcast float* %1 to i8*
store float 0.000000e+00, float* %1
%4 = bitcast float* %2 to i8*
store float 0.000000e+00, float* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%7 = call signext i8 (...) @getchar()
%8 = icmp eq i8 %7, 10
br i1 %8, label %35, label %9
9: ; preds = %0, %32
%10 = phi i8 [ %33, %32 ], [ %7, %0 ]
%11 = sext i8 %10 to i32
switch i32 %11, label %32 [
i32 43, label %12
i32 45, label %17
i32 42, label %22
i32 47, label %27
]
12: ; preds = %9
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%14 = load float, float* %1
%15 = load float, float* %2
%16 = fadd float %14, %15
store float %16, float* %2
br label %32
17: ; preds = %9
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%19 = load float, float* %1
%20 = load float, float* %2
%21 = fsub float %20, %19
store float %21, float* %2
br label %32
22: ; preds = %9
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%24 = load float, float* %1
%25 = load float, float* %2
%26 = fmul float %24, %25
store float %26, float* %2
br label %32
27: ; preds = %9
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%29 = load float, float* %1
%30 = load float, float* %2
%31 = fdiv float %30, %29
store float %31, float* %2
br label %32
32: ; preds = %12, %17, %22, %27, %9
%33 = call signext i8 (...) @getchar()
%34 = icmp eq i8 %33, 10
br i1 %34, label %35, label %9
35: ; preds = %32, %0
%36 = load float, float* %2
%37 = fpext float %36 to double
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %37)
ret i32 0
}