#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 *, ...);
void calculator() {
  printf("calculator app\n");
  char again;
  char operation;
  double num1;
  double num2;
  double result;
  do {
    printf("+. Add\n");
    printf("-. Subtract\n");
    printf("*. Multiplication\n");
    printf("/. Divide\n");
    printf("Operation? ");
    scanf(" %c", &operation);
    printf("Number 1? ");
    scanf(" %lf", &num1);
    printf("Number 2? ");
    scanf(" %lf", &num2);
    if (operation == '+') {
      result = num1 + num2;
      printf("Result: %lf + %lf = %lf\n", num1, num2, result);
    } else if (operation == '-') {
      result = num1 - num2;
      printf("Result: %lf - %lf = %lf\n", num1, num2, result);
    } else if (operation == '*') {
      result = num1 * num2;
      printf("Result: %lf * %lf = %lf\n", num1, num2, result);
    } else if (operation == '/') {
      result = num1 / num2;
      printf("Result: %lf / %lf = %lf\n", num1, num2, result);
    }
    printf("Again? ");
    scanf(" %c", &again);
  } while (again == 'y' || again == 'Y');
}


x86 assembly (clang, -O0):
<calculator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x2(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9b(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x2(%rbp),%eax
cmp    $0x2b,%eax
jne    120c <calculator+0xec>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
lea    0xe6e(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    12d0 <calculator+0x1b0>
movsbl -0x2(%rbp),%eax
cmp    $0x2d,%eax
jne    124a <calculator+0x12a>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
lea    0xe49(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    12cb <calculator+0x1ab>
movsbl -0x2(%rbp),%eax
cmp    $0x2a,%eax
jne    1288 <calculator+0x168>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
lea    0xe24(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    12c6 <calculator+0x1a6>
movsbl -0x2(%rbp),%eax
cmp    $0x2f,%eax
jne    12c1 <calculator+0x1a1>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
lea    0xdff(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    12c6 <calculator+0x1a6>
jmp    12cb <calculator+0x1ab>
jmp    12d0 <calculator+0x1b0>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd6a(%rip),%rdi
lea    -0x1(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x1(%rbp),%ecx
mov    $0x1,%al
cmp    $0x79,%ecx
mov    %al,-0x21(%rbp)
je     130f <calculator+0x1ef>
movsbl -0x1(%rbp),%eax
cmp    $0x59,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1136 <calculator+0x16>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculator>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xf6a(%rip),%rdi
call   1030 <puts@plt>
lea    0xed3(%rip),%rbp
lea    0xedb(%rip),%r12
lea    0x8(%rsp),%r14
lea    0xf43(%rip),%r15
lea    0x7(%rsp),%r13
lea    0xe90(%rip),%rbx
jmp    11c8 <calculator+0x98>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
lea    0xef3(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movzbl 0x7(%rsp),%eax
and    $0xdf,%al
cmp    $0x59,%al
jne    12d0 <calculator+0x1a0>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
lea    0xef0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
lea    0x6(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movzbl 0x6(%rsp),%eax
add    $0xd6,%al
cmp    $0x5,%al
ja     11a2 <calculator+0x72>
movzbl %al,%eax
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm1,%xmm2
lea    0xdf2(%rip),%rdi
jmp    119b <calculator+0x6b>
nopl   0x0(%rax,%rax,1)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
lea    0xd98(%rip),%rdi
jmp    119b <calculator+0x6b>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
lea    0xd91(%rip),%rdi
jmp    119b <calculator+0x6b>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"calculator app\0A\00"
@.str.1 = [8 x i8] c"+. Add\0A\00"
@.str.2 = [13 x i8] c"-. Subtract\0A\00"
@.str.3 = [19 x i8] c"*. Multiplication\0A\00"
@.str.4 = [11 x i8] c"/. Divide\0A\00"
@.str.5 = [12 x i8] c"Operation? \00"
@.str.6 = [4 x i8] c" %c\00"
@.str.7 = [11 x i8] c"Number 1? \00"
@.str.8 = [5 x i8] c" %lf\00"
@.str.9 = [11 x i8] c"Number 2? \00"
@.str.10 = [25 x i8] c"Result: %lf + %lf = %lf\0A\00"
@.str.11 = [25 x i8] c"Result: %lf - %lf = %lf\0A\00"
@.str.12 = [25 x i8] c"Result: %lf * %lf = %lf\0A\00"
@.str.13 = [25 x i8] c"Result: %lf / %lf = %lf\0A\00"
@.str.14 = [8 x i8] c"Again? \00"
define void @calculator() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %79, %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), double* %3)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), double* %4)
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 43
br i1 %20, label %21, label %29
21: ; preds = %7
%22 = load double, double* %3
%23 = load double, double* %4
%24 = fadd double %22, %23
store double %24, double* %5
%25 = load double, double* %3
%26 = load double, double* %4
%27 = load double, double* %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), double %25, double %26, double %27)
br label %68
29: ; preds = %7
%30 = load i8, i8* %2
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 45
br i1 %32, label %33, label %41
33: ; preds = %29
%34 = load double, double* %3
%35 = load double, double* %4
%36 = fsub double %34, %35
store double %36, double* %5
%37 = load double, double* %3
%38 = load double, double* %4
%39 = load double, double* %5
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), double %37, double %38, double %39)
br label %67
41: ; preds = %29
%42 = load i8, i8* %2
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 42
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load double, double* %3
%47 = load double, double* %4
%48 = fmul double %46, %47
store double %48, double* %5
%49 = load double, double* %3
%50 = load double, double* %4
%51 = load double, double* %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), double %49, double %50, double %51)
br label %66
53: ; preds = %41
%54 = load i8, i8* %2
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 47
br i1 %56, label %57, label %65
57: ; preds = %53
%58 = load double, double* %3
%59 = load double, double* %4
%60 = fdiv double %58, %59
store double %60, double* %5
%61 = load double, double* %3
%62 = load double, double* %4
%63 = load double, double* %5
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), double %61, double %62, double %63)
br label %65
65: ; preds = %57, %53
br label %66
66: ; preds = %65, %45
br label %67
67: ; preds = %66, %33
br label %68
68: ; preds = %67, %21
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
%70 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %1)
br label %71
71: ; preds = %68
%72 = load i8, i8* %1
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 121
br i1 %74, label %79, label %75
75: ; preds = %71
%76 = load i8, i8* %1
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 89
br label %79
79: ; preds = %75, %71
%80 = phi i1 [ true, %71 ], [ %78, %75 ]
br i1 %80, label %7, label %81
81: ; preds = %79
ret void
}

LLVM IR (-O2):
@.str.5 = [12 x i8] c"Operation? \00"
@.str.6 = [4 x i8] c" %c\00"
@.str.7 = [11 x i8] c"Number 1? \00"
@.str.8 = [5 x i8] c" %lf\00"
@.str.9 = [11 x i8] c"Number 2? \00"
@.str.10 = [25 x i8] c"Result: %lf + %lf = %lf\0A\00"
@.str.11 = [25 x i8] c"Result: %lf - %lf = %lf\0A\00"
@.str.12 = [25 x i8] c"Result: %lf * %lf = %lf\0A\00"
@.str.13 = [25 x i8] c"Result: %lf / %lf = %lf\0A\00"
@.str.14 = [8 x i8] c"Again? \00"
@str = [15 x i8] c"calculator app\00"
@str.15 = [7 x i8] c"+. Add\00"
@str.16 = [12 x i8] c"-. Subtract\00"
@str.17 = [18 x i8] c"*. Multiplication\00"
@str.18 = [10 x i8] c"/. Divide\00"
define void @calculator() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca double
%4 = alloca double
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%6 = bitcast double* %3 to i8*
%7 = bitcast double* %4 to i8*
br label %8
8: ; preds = %40, %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.15, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.16, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.17, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.18, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), double* %3)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), double* %4)
%19 = load i8, i8* %2
switch i8 %19, label %40 [
i8 43, label %20
i8 45, label %25
i8 42, label %30
i8 47, label %35
]
20: ; preds = %8
%21 = load double, double* %3
%22 = load double, double* %4
%23 = fadd double %21, %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), double %21, double %22, double %23)
br label %40
25: ; preds = %8
%26 = load double, double* %3
%27 = load double, double* %4
%28 = fsub double %26, %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), double %26, double %27, double %28)
br label %40
30: ; preds = %8
%31 = load double, double* %3
%32 = load double, double* %4
%33 = fmul double %31, %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), double %31, double %32, double %33)
br label %40
35: ; preds = %8
%36 = load double, double* %3
%37 = load double, double* %4
%38 = fdiv double %36, %37
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), double %36, double %37, double %38)
br label %40
40: ; preds = %8, %25, %35, %30, %20
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
%42 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %1)
%43 = load i8, i8* %1
%44 = and i8 %43, -33
%45 = icmp eq i8 %44, 89
br i1 %45, label %8, label %46
46: ; preds = %40
ret void
}