#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() {
  char op;
  float num1, num2, result = 0;
  printf("num1 operator num2\n");
  scanf("%f %c %f", &num1, &op, &num2);
  switch (op) {
  case '+':
    result = num1 + num2;
    break;
  case '-':
    result = num1 - num2;
    break;
  case '*':
    result = num1 * num2;
    break;
  case '/':
    if (num2 == 0) {
      printf("Division with 0\n");
    } else {
      result = num1 / num2;
    }
    break;
  default:
    printf("Unknown operator %c\n", op);
    break;
  }
  if (result)
    printf("%.2f %c %.2f = %f", num1, op, num2, result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xedb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x5(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     1200 <main+0xe0>
mov    -0x20(%rbp),%rax
lea    0xe83(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1212 <main+0xf2>
movss  -0xc(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1212 <main+0xf2>
movss  -0xc(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1212 <main+0xf2>
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11ec <main+0xcc>
jp     11ec <main+0xcc>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fb <main+0xdb>
movss  -0xc(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1212 <main+0xf2>
movsbl -0x5(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movss  -0x14(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    122e <main+0x10e>
jp     122e <main+0x10e>
jmp    125b <main+0x13b>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsbl -0x5(%rbp),%esi
movss  -0x10(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0x14(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xe07(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xf0d(%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>
movsbl 0xf(%rsp),%esi
lea    -0x2a(%rsi),%eax
cmp    $0x5,%eax
ja     11a2 <main+0x72>
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
movaps %xmm0,%xmm2
mulss  %xmm1,%xmm2
jmp    11f2 <main+0xc2>
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
movaps %xmm0,%xmm2
addss  %xmm1,%xmm2
jmp    11f2 <main+0xc2>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1216 <main+0xe6>
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
movaps %xmm0,%xmm2
subss  %xmm1,%xmm2
jmp    11f2 <main+0xc2>
movss  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    11e5 <main+0xb5>
jp     11e5 <main+0xb5>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
jmp    1216 <main+0xe6>
movss  0x14(%rsp),%xmm0
movaps %xmm0,%xmm2
divss  %xmm1,%xmm2
xorps  %xmm3,%xmm3
ucomiss %xmm3,%xmm2
jne    11fc <main+0xcc>
jnp    1216 <main+0xe6>
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
cvtss2sd %xmm2,%xmm2
lea    0xe27(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

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

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