#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 */
double operation(char, double, double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *, double *);
int main(void) {
  printf("Commands for REPL calculator:\n");
  printf(" [] = number -> Set given number to current value.\n");
  printf(" [] + number -> Add given number to current value\n");
  printf("                and set result to current value.\n");
  printf(" [] - number -> Substract number from current value\n");
  printf("                and set result to current value.\n");
  printf(" [] * number -> Mulltiplly number and current value\n");
  printf("                and set result to current value.\n\n");
  double current = 0, n;
  char op;
  while (true) {
    printf("[%.4f] ", current);
    scanf("\n%c%lf", &op, &n);
    current = operation(op, current, n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xf92(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xf8c(%rip),%rdi
lea    -0x19(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <scanf@plt>
mov    -0x19(%rbp),%al
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsbl %al,%edi
call   1040 <operation@plt>
movsd  %xmm0,-0x10(%rbp)
jmp    11b7 <main+0x87>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
lea    0xf50(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xf0d(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xf5e(%rip),%rdi
call   1030 <puts@plt>
lea    0xf86(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
lea    0xe4c(%rip),%r14
lea    0xe4d(%rip),%r15
lea    0x7(%rsp),%r12
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <scanf@plt>
movsbl 0x7(%rsp),%edi
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
call   1050 <operation@plt>
jmp    11d0 <main+0x90>

LLVM IR (-O0):
@.str = [31 x i8] c"Commands for REPL calculator:\0A\00"
@.str.1 = [52 x i8] c" [] = number -> Set given number to current value.\0A\00"
@.str.2 = [51 x i8] c" [] + number -> Add given number to current value\0A\00"
@.str.3 = [50 x i8] c" and set result to current value.\0A\00"
@.str.4 = [53 x i8] c" [] - number -> Substract number from current value\0A\00"
@.str.5 = [53 x i8] c" [] * number -> Mulltiplly number and current value\0A\00"
@.str.6 = [51 x i8] c" and set result to current value.\0A\0A\00"
@.str.7 = [8 x i8] c"[%.4f] \00"
@.str.8 = [7 x i8] c"\0A%c%lf\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i8
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0))
store double 0.000000e+00, double* %2
br label %13
13: ; preds = %0, %13
%14 = load double, double* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), double %14)
%16 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %4, double* %3)
%17 = load i8, i8* %4
%18 = load double, double* %2
%19 = load double, double* %3
%20 = call double @operation(i8 signext %17, double %18, double %19)
store double %20, double* %2
br label %13
}

LLVM IR (-O2):
@.str.7 = [8 x i8] c"[%.4f] \00"
@.str.8 = [7 x i8] c"\0A%c%lf\00"
@str = [30 x i8] c"Commands for REPL calculator:\00"
@str.9 = [51 x i8] c" [] = number -> Set given number to current value.\00"
@str.10 = [50 x i8] c" [] + number -> Add given number to current value\00"
@str.12 = [52 x i8] c" [] - number -> Substract number from current value\00"
@str.13 = [49 x i8] c" and set result to current value.\00"
@str.14 = [52 x i8] c" [] * number -> Mulltiplly number and current value\00"
@str.15 = [50 x i8] c" and set result to current value.\0A\00"
define i32 @main() {
%1 = alloca double
%2 = alloca i8
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.9, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.10, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.13, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.12, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.13, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.14, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.15, i64 0, i64 0))
%11 = bitcast double* %1 to i8*
br label %12
12: ; preds = %12, %0
%13 = phi double [ 0.000000e+00, %0 ], [ %18, %12 ]
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), double %13)
%15 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %2, double* %1)
%16 = load i8, i8* %2
%17 = load double, double* %1
%18 = call double @operation(i8 signext %16, double %13, double %17)
br label %12
}