#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;
  printf("Enter two numbers and operator in format\n");
  printf(" num1 operator num2\n");
  scanf("%f %c %f", &num1, &op, &num2);
  if (op == '*') {
    result = num1 * num2;
  } else if (op == '+') {
    result = num1 + num2;
  } else if (op == '-') {
    result = num1 - num2;
  } else if (op == '/') {
    if (num2) {
      result = num1 / num2;
    } else {
      printf("Division by 0!\n");
      return 0;
    }
  } else {
    printf("Invalid operator!\n");
    return 0;
  }
  printf("%f %c %f = %f\n", num1, op, num2, result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeed(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x5(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x2a,%eax
jne    1184 <main+0x64>
movss  -0xc(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    124b <main+0x12b>
movsbl -0x5(%rbp),%eax
cmp    $0x2b,%eax
jne    11a5 <main+0x85>
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1246 <main+0x126>
movsbl -0x5(%rbp),%eax
cmp    $0x2d,%eax
jne    11c6 <main+0xa6>
movss  -0xc(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1241 <main+0x121>
movsbl -0x5(%rbp),%eax
cmp    $0x2f,%eax
jne    1222 <main+0x102>
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11ef <main+0xcf>
jp     11ef <main+0xcf>
jmp    1203 <main+0xe3>
movss  -0xc(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    121d <main+0xfd>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127f <main+0x15f>
jmp    123c <main+0x11c>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127f <main+0x15f>
jmp    1241 <main+0x121>
jmp    1246 <main+0x126>
jmp    124b <main+0x12b>
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    0xdfa(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xef5(%rip),%rdi
call   1030 <puts@plt>
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
lea    0xec5(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0xf(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1050 <scanf@plt>
movzbl 0xf(%rsp),%esi
lea    -0x2a(%rsi),%eax
cmp    $0x5,%al
ja     11b0 <main+0x80>
movzbl %al,%eax
lea    0xe83(%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    11f0 <main+0xc0>
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
movaps %xmm0,%xmm2
addss  %xmm1,%xmm2
jmp    11f0 <main+0xc0>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
jmp    120a <main+0xda>
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
movaps %xmm0,%xmm2
subss  %xmm1,%xmm2
jmp    11f0 <main+0xc0>
movss  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    11e3 <main+0xb3>
jnp    1211 <main+0xe1>
movss  0x14(%rsp),%xmm0
movaps %xmm0,%xmm2
divss  %xmm1,%xmm2
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
cvtss2sd %xmm2,%xmm2
lea    0xe1e(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
jmp    120a <main+0xda>

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

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