#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 *, ...);
int /*<<< orphan*/ welcome();
int main() {
  float a, b, c;
  char choice;
  welcome();
  for (;;) {
    do {
      printf("\nEnter choice of operation (q to quit) -\n");
      printf("1. Addition\n");
      printf("2. Subtraction\n");
      printf("3. Multiplication\n");
      printf("4. Division\n");
      printf("Operation: ");
      scanf("%c", &choice);
    } while (choice < '1' || choice > '4' && choice != 'q');
    if (choice == 'q')
      break;
    printf("\nEnter first number: ");
    scanf("%f", &a);
    printf("Enter second number: ");
    scanf("%f", &b);
    switch (choice) {
    case '1':
      c = a + b;
      printf("\na + b = %f", c);
      break;
    case '2':
      c = a - b;
      printf("\na - b = %f", c);
      break;
    case '3':
      c = a * b;
      printf("\na * b = %f", c);
      break;
    case '4':
      c = a / b;
      printf("\na / b = %f", c);
      break;
    default:
      printf("\nPlease enter a valid choice");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <welcome@plt>
jmp    114b <main+0x1b>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedd(%rip),%rdi
lea    -0x11(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movsbl -0x11(%rbp),%ecx
mov    $0x1,%al
cmp    $0x31,%ecx
mov    %al,-0x12(%rbp)
jl     11e8 <main+0xb8>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x34,%ecx
mov    %al,-0x13(%rbp)
jle    11e2 <main+0xb2>
movsbl -0x11(%rbp),%eax
cmp    $0x71,%eax
setne  %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    114b <main+0x1b>
movsbl -0x11(%rbp),%eax
cmp    $0x71,%eax
jne    1205 <main+0xd5>
jmp    1335 <main+0x205>
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xeb3(%rip),%rdi
mov    %rdi,-0x30(%rbp)
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x21(%rbp),%al
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x21(%rbp),%al
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
movsbl -0x11(%rbp),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     1322 <main+0x1f2>
mov    -0x20(%rbp),%rax
lea    0xd93(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe1d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1330 <main+0x200>
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdfe(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1330 <main+0x200>
movss  -0x8(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xddf(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1330 <main+0x200>
movss  -0x8(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc0(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1330 <main+0x200>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1146 <main+0x16>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1050 <welcome@plt>
lea    0xf71(%rip),%r12
lea    0xf79(%rip),%r14
lea    0xf84(%rip),%r13
lea    0xe9f(%rip),%r15
jmp    1191 <main+0x51>
movss  0x14(%rsp),%xmm0
addss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xec1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe84(%rip),%rbx
lea    0xf(%rsp),%rbp
lea    0xef4(%rip),%rdi
call   1030 <puts@plt>
lea    0xf11(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movzbl 0xf(%rsp),%eax
cmp    $0x31,%al
jl     119d <main+0x5d>
cmp    $0x35,%al
jb     11f5 <main+0xb5>
cmp    $0x71,%al
jne    119d <main+0x5d>
cmp    $0x71,%al
je     12cb <main+0x18b>
mov    %r12,%rbx
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe57(%rip),%r12
mov    %r12,%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe0a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movsbl 0xf(%rsp),%eax
add    $0xffffffcf,%eax
cmp    $0x3,%eax
ja     127d <main+0x13d>
lea    0xdab(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
mov    %rbx,%r12
jmp    *%rax
movss  0x14(%rsp),%xmm0
subss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xddf(%rip),%rdi
jmp    118a <main+0x4a>
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%r12
jmp    1191 <main+0x51>
movss  0x14(%rsp),%xmm0
mulss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdb9(%rip),%rdi
jmp    118a <main+0x4a>
movss  0x14(%rsp),%xmm0
divss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xda9(%rip),%rdi
jmp    118a <main+0x4a>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"\0AEnter choice of operation (q to quit) -\0A\00"
@.str.1 = [13 x i8] c"1. Addition\0A\00"
@.str.2 = [16 x i8] c"2. Subtraction\0A\00"
@.str.3 = [19 x i8] c"3. Multiplication\0A\00"
@.str.4 = [13 x i8] c"4. Division\0A\00"
@.str.5 = [12 x i8] c"Operation: \00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [22 x i8] c"\0AEnter first number: \00"
@.str.8 = [3 x i8] c"%f\00"
@.str.9 = [22 x i8] c"Enter second number: \00"
@.str.10 = [12 x i8] c"\0Aa + b = %f\00"
@.str.11 = [12 x i8] c"\0Aa - b = %f\00"
@.str.12 = [12 x i8] c"\0Aa * b = %f\00"
@.str.13 = [12 x i8] c"\0Aa / b = %f\00"
@.str.14 = [29 x i8] c"\0APlease enter a valid choice\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca i8
store i32 0, i32* %1
%6 = call i32 (...) @welcome()
br label %7
7: ; preds = %74, %0
br label %8
8: ; preds = %30, %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %5)
br label %16
16: ; preds = %8
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp slt i32 %18, 49
br i1 %19, label %30, label %20
20: ; preds = %16
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp sgt i32 %22, 52
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 113
br label %28
28: ; preds = %24, %20
%29 = phi i1 [ false, %20 ], [ %27, %24 ]
br label %30
30: ; preds = %28, %16
%31 = phi i1 [ true, %16 ], [ %29, %28 ]
br i1 %31, label %8, label %32
32: ; preds = %30
%33 = load i8, i8* %5
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 113
br i1 %35, label %36, label %37
36: ; preds = %32
br label %75
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%39 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), float* %2)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%41 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), float* %3)
%42 = load i8, i8* %5
%43 = sext i8 %42 to i32
switch i32 %43, label %72 [
i32 49, label %44
i32 50, label %51
i32 51, label %58
i32 52, label %65
]
44: ; preds = %37
%45 = load float, float* %2
%46 = load float, float* %3
%47 = fadd float %45, %46
store float %47, float* %4
%48 = load float, float* %4
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), double %49)
br label %74
51: ; preds = %37
%52 = load float, float* %2
%53 = load float, float* %3
%54 = fsub float %52, %53
store float %54, float* %4
%55 = load float, float* %4
%56 = fpext float %55 to double
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), double %56)
br label %74
58: ; preds = %37
%59 = load float, float* %2
%60 = load float, float* %3
%61 = fmul float %59, %60
store float %61, float* %4
%62 = load float, float* %4
%63 = fpext float %62 to double
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), double %63)
br label %74
65: ; preds = %37
%66 = load float, float* %2
%67 = load float, float* %3
%68 = fdiv float %66, %67
store float %68, float* %4
%69 = load float, float* %4
%70 = fpext float %69 to double
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), double %70)
br label %74
72: ; preds = %37
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.14, i64 0, i64 0))
br label %74
74: ; preds = %72, %65, %58, %51, %44
br label %7
75: ; preds = %36
ret i32 0
}

LLVM IR (-O2):
@.str.5 = [12 x i8] c"Operation: \00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [22 x i8] c"\0AEnter first number: \00"
@.str.8 = [3 x i8] c"%f\00"
@.str.9 = [22 x i8] c"Enter second number: \00"
@.str.10 = [12 x i8] c"\0Aa + b = %f\00"
@.str.11 = [12 x i8] c"\0Aa - b = %f\00"
@.str.12 = [12 x i8] c"\0Aa * b = %f\00"
@.str.13 = [12 x i8] c"\0Aa / b = %f\00"
@.str.14 = [29 x i8] c"\0APlease enter a valid choice\00"
@str = [41 x i8] c"\0AEnter choice of operation (q to quit) -\00"
@str.15 = [12 x i8] c"1. Addition\00"
@str.16 = [15 x i8] c"2. Subtraction\00"
@str.17 = [18 x i8] c"3. Multiplication\00"
@str.18 = [12 x i8] c"4. Division\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca i8
%4 = bitcast float* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = tail call i32 (...) @welcome()
br label %7
7: ; preds = %21, %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.15, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 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 ([12 x i8], [12 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 ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %3)
%15 = load i8, i8* %3
%16 = icmp slt i8 %15, 49
br i1 %16, label %21, label %17
17: ; preds = %7
%18 = icmp ugt i8 %15, 52
%19 = icmp ne i8 %15, 113
%20 = and i1 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17, %7, %55, %49, %43, %37, %31
br label %7
22: ; preds = %17
%23 = icmp eq i8 %15, 113
br i1 %23, label %57, label %24
24: ; preds = %22
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), float* %1)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), float* %2)
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
switch i32 %30, label %55 [
i32 49, label %31
i32 50, label %37
i32 51, label %43
i32 52, label %49
]
31: ; preds = %24
%32 = load float, float* %1
%33 = load float, float* %2
%34 = fadd float %32, %33
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), double %35)
br label %21
37: ; preds = %24
%38 = load float, float* %1
%39 = load float, float* %2
%40 = fsub float %38, %39
%41 = fpext float %40 to double
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), double %41)
br label %21
43: ; preds = %24
%44 = load float, float* %1
%45 = load float, float* %2
%46 = fmul float %44, %45
%47 = fpext float %46 to double
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), double %47)
br label %21
49: ; preds = %24
%50 = load float, float* %1
%51 = load float, float* %2
%52 = fdiv float %50, %51
%53 = fpext float %52 to double
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), double %53)
br label %21
55: ; preds = %24
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.14, i64 0, i64 0))
br label %21
57: ; preds = %22
ret i32 0
}