#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 *, float *);
int main(void) {
  float value1, value2;
  char operator;
  printf("Type in your expression.\n");
  scanf("%f %c %f", &value1, &operator, & value2);
  if (operator== '+') {
    printf("%.2f\n", value1 + value2);
  } else if (operator== '-') {
    printf("%.2f\n", value1 - value2);
  } else if (operator== '*') {
    printf("%.2f\n", value1 * value2);
  } else if (operator== '/') {
    if (value2 == 0.0f) {
      printf("Division by zero\n");
    } else {
      printf("%.2f\n", value1 / value2);
    }
  } else {
    printf("Unknown operator");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xd(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   1040 <scanf@plt>
movsbl -0xd(%rbp),%eax
cmp    $0x2b,%eax
jne    1183 <main+0x63>
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xeac(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1254 <main+0x134>
movsbl -0xd(%rbp),%eax
cmp    $0x2d,%eax
jne    11b1 <main+0x91>
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe7e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    124f <main+0x12f>
movsbl -0xd(%rbp),%eax
cmp    $0x2a,%eax
jne    11df <main+0xbf>
movss  -0x8(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe50(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    124a <main+0x12a>
movsbl -0xd(%rbp),%eax
cmp    $0x2f,%eax
jne    1237 <main+0x117>
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1216 <main+0xf6>
jp     1216 <main+0xf6>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1232 <main+0x112>
movss  -0x8(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf8(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1245 <main+0x125>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124a <main+0x12a>
jmp    124f <main+0x12f>
jmp    1254 <main+0x134>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xed1(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0xf(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1050 <scanf@plt>
mov    0xf(%rsp),%al
add    $0xd6,%al
cmp    $0x5,%al
ja     1194 <main+0x64>
movzbl %al,%eax
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  0x14(%rsp),%xmm0
mulss  0x10(%rsp),%xmm0
jmp    11b0 <main+0x80>
movss  0x14(%rsp),%xmm0
addss  0x10(%rsp),%xmm0
jmp    11b0 <main+0x80>
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c2 <main+0x92>
movss  0x14(%rsp),%xmm0
subss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe66(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
movss  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11e7 <main+0xb7>
jp     11e7 <main+0xb7>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
jmp    11c2 <main+0x92>
movss  0x14(%rsp),%xmm1
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
jmp    11b4 <main+0x84>

LLVM IR (-O0):
@.str = [26 x i8] c"Type in your expression.\0A\00"
@.str.1 = [9 x i8] c"%f %c %f\00"
@.str.2 = [6 x i8] c"%.2f\0A\00"
@.str.3 = [18 x i8] c"Division by zero\0A\00"
@.str.4 = [17 x i8] c"Unknown operator\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca i8
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), float* %2, i8* %4, float* %3)
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 43
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load float, float* %2
%12 = load float, float* %3
%13 = fadd float %11, %12
%14 = fpext float %13 to double
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %14)
br label %57
16: ; preds = %0
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 45
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load float, float* %2
%22 = load float, float* %3
%23 = fsub float %21, %22
%24 = fpext float %23 to double
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %24)
br label %56
26: ; preds = %16
%27 = load i8, i8* %4
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 42
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load float, float* %2
%32 = load float, float* %3
%33 = fmul float %31, %32
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %34)
br label %55
36: ; preds = %26
%37 = load i8, i8* %4
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 47
br i1 %39, label %40, label %52
40: ; preds = %36
%41 = load float, float* %3
%42 = fcmp oeq float %41, 0.000000e+00
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %51
45: ; preds = %40
%46 = load float, float* %2
%47 = load float, float* %3
%48 = fdiv float %46, %47
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %49)
br label %51
51: ; preds = %45, %43
br label %54
52: ; preds = %36
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %51
br label %55
55: ; preds = %54, %30
br label %56
56: ; preds = %55, %20
br label %57
57: ; preds = %56, %10
ret i32 0
}

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