#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 *, double *, char *, double *);
int main() {
  double first = 0.0, second = 0.0, result = 0.0;
  char operator= 0;
  printf("Welcome to simple calculator!\n");
  printf("Supported operations: +, -, *, /\n");
  scanf("%lf %c %lf", &first, &operator, & second);
  switch (operator) {
  case '+':
    result = first + second;
    break;
  case '-':
    result = first - second;
    break;
  case '*':
    result = first * second;
    break;
  case '/':
    result = first / second;
    break;
  default:
    printf("Unsupported operator: %c\n", operator);
    break;
  }
  printf("Result: %f\n", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
lea    0xec6(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x31(%rbp)
call   1030 <printf@plt>
mov    -0x31(%rbp),%al
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x21(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1040 <scanf@plt>
movsbl -0x21(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x5,%eax
ja     11fd <main+0xdd>
mov    -0x30(%rbp),%rax
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120f <main+0xef>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120f <main+0xef>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120f <main+0xef>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120f <main+0xef>
movsbl -0x21(%rbp),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xe63(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movb   $0x0,0x7(%rsp)
lea    0xef7(%rip),%rdi
call   1030 <puts@plt>
lea    0xf09(%rip),%rdi
call   1030 <puts@plt>
lea    0xeae(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x7(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1050 <scanf@plt>
movsbl 0x7(%rsp),%esi
lea    -0x2a(%rsi),%eax
cmp    $0x5,%eax
ja     11b7 <main+0x87>
lea    0xe6e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
jmp    11e5 <main+0xb5>
movsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
jmp    11e5 <main+0xb5>
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xorpd  %xmm0,%xmm0
jmp    11e5 <main+0xb5>
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
jmp    11e5 <main+0xb5>
movsd  0x10(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
lea    0xe51(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Welcome to simple calculator!\0A\00"
@.str.1 = [34 x i8] c"Supported operations: +, -, *, /\0A\00"
@.str.2 = [11 x i8] c"%lf %c %lf\00"
@.str.3 = [26 x i8] c"Unsupported operator: %c\0A\00"
@.str.4 = [12 x i8] c"Result: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i8
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store i8 0, i8* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double* %2, i8* %5, double* %3)
%9 = load i8, i8* %5
%10 = sext i8 %9 to i32
switch i32 %10, label %27 [
i32 43, label %11
i32 45, label %15
i32 42, label %19
i32 47, label %23
]
11: ; preds = %0
%12 = load double, double* %2
%13 = load double, double* %3
%14 = fadd double %12, %13
store double %14, double* %4
br label %31
15: ; preds = %0
%16 = load double, double* %2
%17 = load double, double* %3
%18 = fsub double %16, %17
store double %18, double* %4
br label %31
19: ; preds = %0
%20 = load double, double* %2
%21 = load double, double* %3
%22 = fmul double %20, %21
store double %22, double* %4
br label %31
23: ; preds = %0
%24 = load double, double* %2
%25 = load double, double* %3
%26 = fdiv double %24, %25
store double %26, double* %4
br label %31
27: ; preds = %0
%28 = load i8, i8* %5
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %27, %23, %19, %15, %11
%32 = load double, double* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double %32)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [11 x i8] c"%lf %c %lf\00"
@.str.3 = [26 x i8] c"Unsupported operator: %c\0A\00"
@.str.4 = [12 x i8] c"Result: %f\0A\00"
@str = [30 x i8] c"Welcome to simple calculator!\00"
@str.5 = [33 x i8] c"Supported operations: +, -, *, /\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca i8
%4 = bitcast double* %1 to i8*
store double 0.000000e+00, double* %1
%5 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
store i8 0, i8* %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.5, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double* %1, i8* %3, double* %2)
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
switch i32 %10, label %27 [
i32 43, label %11
i32 45, label %15
i32 42, label %19
i32 47, label %23
]
11: ; preds = %0
%12 = load double, double* %1
%13 = load double, double* %2
%14 = fadd double %12, %13
br label %29
15: ; preds = %0
%16 = load double, double* %1
%17 = load double, double* %2
%18 = fsub double %16, %17
br label %29
19: ; preds = %0
%20 = load double, double* %1
%21 = load double, double* %2
%22 = fmul double %20, %21
br label %29
23: ; preds = %0
%24 = load double, double* %1
%25 = load double, double* %2
%26 = fdiv double %24, %25
br label %29
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %10)
br label %29
29: ; preds = %27, %23, %19, %15, %11
%30 = phi double [ 0.000000e+00, %27 ], [ %26, %23 ], [ %22, %19 ], [ %18, %15 ], [ %14, %11 ]
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double %30)
ret i32 0
}