#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 */
char getchar();
int /*<<< orphan*/ printf(char *);
int get_choice(void) {
  int ch, error = 0;
  printf("Enter the operation of your choice:\n");
  printf("a. add\t\ts. subtract\n");
  printf("m. multiply\td. divide\n");
  printf("q. quit\n");
  do {
    ch = getchar();
    while (getchar() != '\n')
      continue;
    switch (ch) {
    case 'a':
      return 1;
    case 's':
      return 2;
    case 'm':
      return 3;
    case 'd':
      return 4;
    case 'q':
      return 0;
    default:
      printf("Please respond with a, s, m, d, or q\n");
      error = 1;
    }
  } while (error);
  return -1;
}


x86 assembly (clang, -O0):
<get_choice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xf16(%rip),%rdi
call   1030 <printf@plt>
lea    0xf2f(%rip),%rdi
call   1030 <printf@plt>
lea    0xf38(%rip),%rdi
call   1030 <printf@plt>
lea    0xf43(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1184 <get_choice+0x64>
jmp    116c <get_choice+0x4c>
mov    -0x8(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x12,%eax
ja     11e9 <get_choice+0xc9>
mov    -0x18(%rbp),%rax
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x4(%rbp)
jmp    1212 <get_choice+0xf2>
movl   $0x2,-0x4(%rbp)
jmp    1212 <get_choice+0xf2>
movl   $0x3,-0x4(%rbp)
jmp    1212 <get_choice+0xf2>
movl   $0x4,-0x4(%rbp)
jmp    1212 <get_choice+0xf2>
movl   $0x0,-0x4(%rbp)
jmp    1212 <get_choice+0xf2>
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0xc(%rbp)
jmp    1201 <get_choice+0xe1>
cmpl   $0x0,-0xc(%rbp)
jne    115f <get_choice+0x3f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_choice>:
push   %r15
push   %r14
push   %rbx
lea    0xf20(%rip),%rdi
call   1030 <puts@plt>
lea    0xf38(%rip),%rdi
call   1030 <puts@plt>
lea    0xf40(%rip),%rdi
call   1030 <puts@plt>
lea    0xf4a(%rip),%rdi
lea    0xf4b(%rip),%r14
lea    0xea2(%rip),%r15
xchg   %ax,%ax
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    1170 <get_choice+0x50>
movsbl %bl,%eax
add    $0xffffff9f,%eax
mov    %r14,%rdi
cmp    $0x12,%eax
ja     1160 <get_choice+0x40>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
mov    %r14,%rdi
jmp    *%rax
mov    $0x1,%eax
jmp    11b3 <get_choice+0x93>
mov    $0x4,%eax
jmp    11b3 <get_choice+0x93>
mov    $0x3,%eax
jmp    11b3 <get_choice+0x93>
xor    %eax,%eax
jmp    11b3 <get_choice+0x93>
mov    $0x2,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Enter the operation of your choice:\0A\00"
@.str.1 = [21 x i8] c"a. add\09\09s. subtract\0A\00"
@.str.2 = [23 x i8] c"m. multiply\09d. divide\0A\00"
@.str.3 = [9 x i8] c"q. quit\0A\00"
@.str.4 = [38 x i8] c"Please respond with a, s, m, d, or q\0A\00"
define i32 @get_choice() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %8
8: ; preds = %26, %0
%9 = call signext i8 (...) @getchar()
%10 = sext i8 %9 to i32
store i32 %10, i32* %2
br label %11
11: ; preds = %15, %8
%12 = call signext i8 (...) @getchar()
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %11
br label %11
16: ; preds = %11
%17 = load i32, i32* %2
switch i32 %17, label %23 [
i32 97, label %18
i32 115, label %19
i32 109, label %20
i32 100, label %21
i32 113, label %22
]
18: ; preds = %16
store i32 1, i32* %1
br label %30
19: ; preds = %16
store i32 2, i32* %1
br label %30
20: ; preds = %16
store i32 3, i32* %1
br label %30
21: ; preds = %16
store i32 4, i32* %1
br label %30
22: ; preds = %16
store i32 0, i32* %1
br label %30
23: ; preds = %16
%24 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %25
25: ; preds = %23
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = icmp ne i32 %27, 0
br i1 %28, label %8, label %29
29: ; preds = %26
store i32 -1, i32* %1
br label %30
30: ; preds = %29, %22, %21, %20, %19, %18
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@str = [36 x i8] c"Enter the operation of your choice:\00"
@str.5 = [20 x i8] c"a. add\09\09s. subtract\00"
@str.6 = [22 x i8] c"m. multiply\09d. divide\00"
@str.7 = [8 x i8] c"q. quit\00"
@str.8 = [37 x i8] c"Please respond with a, s, m, d, or q\00"
define i32 @get_choice() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
br label %4
4: ; preds = %11, %0
%5 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.7, i64 0, i64 0), %0 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @str.8, i64 0, i64 0), %11 ]
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
%7 = tail call signext i8 (...) @getchar()
br label %8
8: ; preds = %8, %4
%9 = tail call signext i8 (...) @getchar()
%10 = icmp eq i8 %9, 10
br i1 %10, label %11, label %8
11: ; preds = %8
%12 = sext i8 %7 to i32
switch i32 %12, label %4 [
i32 97, label %17
i32 115, label %13
i32 109, label %14
i32 100, label %15
i32 113, label %16
]
13: ; preds = %11
br label %17
14: ; preds = %11
br label %17
15: ; preds = %11
br label %17
16: ; preds = %11
br label %17
17: ; preds = %11, %16, %15, %14, %13
%18 = phi i32 [ 2, %13 ], [ 3, %14 ], [ 4, %15 ], [ 0, %16 ], [ 1, %11 ]
ret i32 %18
}