#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 dialogue(char *, char **, int);
int /*<<< orphan*/ printf(char *);
int main() {
  char *choices[] = {"Chocolate", "Lollipop", "Licorice"};
  int choice = dialogue("Welcome to the candy store! What may I get for you?",
                        choices, 3);
  switch (choice) {
  case 1:
    printf("Mmm, chocolate!");
    break;
  case 2:
    printf("I'm not much of a fan of those.");
    break;
  case 3:
    printf("My favorite!");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2cda(%rip),%rax
mov    %rax,-0x10(%rbp)
movaps 0x2cbf(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
lea    0xed0(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1040 <dialogue@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     1193 <main+0x73>
jmp    1171 <main+0x51>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     11a4 <main+0x84>
jmp    1182 <main+0x62>
mov    -0x28(%rbp),%eax
sub    $0x3,%eax
je     11b5 <main+0x95>
jmp    11c1 <main+0xa1>
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
jmp    11c1 <main+0xa1>
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
jmp    11c1 <main+0xa1>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0x2ce5(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2cc9(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeda(%rip),%rdi
mov    %rsp,%rsi
mov    $0x3,%edx
call   1040 <dialogue@plt>
add    $0xffffffff,%eax
cmp    $0x2,%eax
ja     116c <main+0x4c>
cltq
lea    0xf30(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Chocolate\00"
@.str.1 = [9 x i8] c"Lollipop\00"
@.str.2 = [9 x i8] c"Licorice\00"
@__const.main.choices = [3 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [52 x i8] c"Welcome to the candy store! What may I get for you?\00"
@.str.4 = [16 x i8] c"Mmm, chocolate!\00"
@.str.5 = [32 x i8] c"I'm not much of a fan of those.\00"
@.str.6 = [13 x i8] c"My favorite!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i8*]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [3 x i8*]* %2 to i8*
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%6 = call i32 @dialogue(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8** %5, i32 3)
store i32 %6, i32* %3
%7 = load i32, i32* %3
switch i32 %7, label %14 [
i32 1, label %8
i32 2, label %10
i32 3, label %12
]
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %14
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %14
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %14
14: ; preds = %0, %12, %10, %8
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"Chocolate\00"
@.str.1 = [9 x i8] c"Lollipop\00"
@.str.2 = [9 x i8] c"Licorice\00"
@__const.main.choices = [3 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [52 x i8] c"Welcome to the candy store! What may I get for you?\00"
@.str.4 = [16 x i8] c"Mmm, chocolate!\00"
@.str.5 = [32 x i8] c"I'm not much of a fan of those.\00"
@.str.6 = [13 x i8] c"My favorite!\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.4 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.5 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.6 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = alloca [3 x i8*]
%2 = bitcast [3 x i8*]* %1 to i8*
%3 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 0
%4 = call i32 @dialogue(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8** %3, i32 3)
%5 = add i32 %4, -1
%6 = icmp ult i32 %5, 3
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = sext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %9)
%11 = call i32 @printf(i8* dereferenceable(1) %10)
br label %12
12: ; preds = %0, %7
ret i32 0
}