#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 getkey();
int /*<<< orphan*/ write(int, char *, int);
char getMenuChoice() {
  char choice = 0;
  write(1, "Choose 1, 2, 3, or 4\n\n", 22);
  write(1, "1. Free Draw\n", 13);
  write(1, "2. Draw Rectangle\n", 18);
  write(1, "3. Draw Circle\n", 15);
  write(1, "4. Exit\n", 8);
  while (choice == 0) {
    choice = getkey();
  }
  return (choice);
}


x86 assembly (clang, -O0):
<getMenuChoice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x1(%rbp)
mov    $0x1,%edi
lea    0xec8(%rip),%rsi
mov    $0x16,%edx
call   1030 <write@plt>
mov    $0x1,%edi
lea    0xec9(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
mov    $0x1,%edi
lea    0xec1(%rip),%rsi
mov    $0x12,%edx
call   1030 <write@plt>
mov    $0x1,%edi
lea    0xebe(%rip),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
mov    $0x1,%edi
lea    0xeb8(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
movsbl -0x1(%rbp),%eax
cmp    $0x0,%eax
jne    11b6 <getMenuChoice+0x96>
mov    $0x0,%al
call   1040 <getkey@plt>
mov    %al,-0x1(%rbp)
jmp    119a <getMenuChoice+0x7a>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMenuChoice>:
push   %rax
lea    0xed8(%rip),%rsi
mov    $0x1,%edi
mov    $0x16,%edx
call   1030 <write@plt>
lea    0xed9(%rip),%rsi
mov    $0x1,%edi
mov    $0xd,%edx
call   1030 <write@plt>
lea    0xed1(%rip),%rsi
mov    $0x1,%edi
mov    $0x12,%edx
call   1030 <write@plt>
lea    0xece(%rip),%rsi
mov    $0x1,%edi
mov    $0xf,%edx
call   1030 <write@plt>
lea    0xec8(%rip),%rsi
mov    $0x1,%edi
mov    $0x8,%edx
call   1030 <write@plt>
nop
xor    %eax,%eax
call   1040 <getkey@plt>
test   %al,%al
je     1190 <getMenuChoice+0x70>
pop    %rcx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Choose 1, 2, 3, or 4\0A\0A\00"
@.str.1 = [14 x i8] c"1. Free Draw\0A\00"
@.str.2 = [19 x i8] c"2. Draw Rectangle\0A\00"
@.str.3 = [16 x i8] c"3. Draw Circle\0A\00"
@.str.4 = [9 x i8] c"4. Exit\0A\00"
define signext i8 @getMenuChoice() {
%1 = alloca i8
store i8 0, i8* %1
%2 = call i32 @write(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 22)
%3 = call i32 @write(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 13)
%4 = call i32 @write(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 18)
%5 = call i32 @write(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 15)
%6 = call i32 @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
br label %7
7: ; preds = %11, %0
%8 = load i8, i8* %1
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call signext i8 (...) @getkey()
store i8 %12, i8* %1
br label %7
13: ; preds = %7
%14 = load i8, i8* %1
ret i8 %14
}

LLVM IR (-O2):
@.str = [23 x i8] c"Choose 1, 2, 3, or 4\0A\0A\00"
@.str.1 = [14 x i8] c"1. Free Draw\0A\00"
@.str.2 = [19 x i8] c"2. Draw Rectangle\0A\00"
@.str.3 = [16 x i8] c"3. Draw Circle\0A\00"
@.str.4 = [9 x i8] c"4. Exit\0A\00"
define signext i8 @getMenuChoice() {
%1 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 22)
%2 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 13)
%3 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 18)
%4 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 15)
%5 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
br label %6
6: ; preds = %0, %6
%7 = tail call signext i8 (...) @getkey()
%8 = icmp eq i8 %7, 0
br i1 %8, label %6, label %9
9: ; preds = %6
ret i8 %7
}