#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*/ EXIT_FAILURE;
int d(int);
int /*<<< orphan*/ deepgnome(int);
int /*<<< orphan*/ drow(int);
int /*<<< orphan*/ duergar(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ indefinitemadness();
int /*<<< orphan*/ magictablea();
int /*<<< orphan*/ magictableb();
int /*<<< orphan*/ niceprint(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stonegiant(int);
void madcreature(unsigned d4) {
  int d20;
  niceprint("The party encounters a creature driven insane by the influence "
            "of the demon lords. If cured of its madness, the creature behaves "
            "in accordance with its alignment.\n\n");
  switch (d4) {
  case 1:
    deepgnome(1);
    break;
  case 2:
    drow(1);
    break;
  case 3:
    duergar(1);
    break;
  case 4:
    stonegiant(1);
    break;
  default:
    printf("Impossible mad creature encounter of %d\n", d4);
    exit(EXIT_FAILURE);
  }
  indefinitemadness();
  d20 = d(20);
  if (d20 < 11)
    return;
  printf("The mad creature has something of interest:\n\n");
  if (d20 < 14)
    printf("A 10gp gem\n");
  else if (d20 < 16)
    printf("A gold ring worth 25gp\n");
  else if (d20 < 18)
    printf("An obsidian statue of Lolth worth 100gp\n");
  else if (d20 < 20)
    magictablea();
  else
    magictableb();
}


x86 assembly (clang, -O0):
<madcreature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe4e(%rip),%rdi
call   10b0 <niceprint@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     122c <madcreature+0x7c>
mov    -0x10(%rbp),%rax
lea    0xe19(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x1,%edi
call   1090 <deepgnome@plt>
jmp    124b <madcreature+0x9b>
mov    $0x1,%edi
call   1040 <drow@plt>
jmp    124b <madcreature+0x9b>
mov    $0x1,%edi
call   1060 <duergar@plt>
jmp    124b <madcreature+0x9b>
mov    $0x1,%edi
call   10a0 <stonegiant@plt>
jmp    124b <madcreature+0x9b>
mov    -0x4(%rbp),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   1070 <indefinitemadness@plt>
mov    $0x14,%edi
call   1030 <d@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xb,-0x8(%rbp)
jge    126e <madcreature+0xbe>
jmp    12ff <madcreature+0x14f>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0xe,-0x8(%rbp)
jge    1299 <madcreature+0xe9>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ff <madcreature+0x14f>
cmpl   $0x10,-0x8(%rbp)
jge    12b6 <madcreature+0x106>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12fa <madcreature+0x14a>
cmpl   $0x12,-0x8(%rbp)
jge    12d3 <madcreature+0x123>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f5 <madcreature+0x145>
cmpl   $0x14,-0x8(%rbp)
jge    12e9 <madcreature+0x139>
mov    $0x0,%al
call   1080 <magictablea@plt>
jmp    12f0 <madcreature+0x140>
mov    $0x0,%al
call   10d0 <magictableb@plt>
jmp    12f5 <madcreature+0x145>
jmp    12fa <madcreature+0x14a>
jmp    12ff <madcreature+0x14f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<madcreature>:
push   %rbx
mov    %edi,%ebx
lea    0xe46(%rip),%rdi
call   10c0 <niceprint@plt>
lea    -0x1(%rbx),%eax
cmp    $0x3,%eax
ja     1288 <madcreature+0xc8>
lea    0xe1e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x1,%edi
call   10a0 <deepgnome@plt>
jmp    1219 <madcreature+0x59>
mov    $0x1,%edi
call   1070 <duergar@plt>
jmp    1219 <madcreature+0x59>
mov    $0x1,%edi
call   1050 <drow@plt>
jmp    1219 <madcreature+0x59>
mov    $0x1,%edi
call   10b0 <stonegiant@plt>
xor    %eax,%eax
call   1080 <indefinitemadness@plt>
mov    $0x14,%edi
call   1040 <d@plt>
cmp    $0xb,%eax
jge    1231 <madcreature+0x71>
pop    %rbx
ret
mov    %eax,%ebx
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
cmp    $0xd,%ebx
ja     1251 <madcreature+0x91>
lea    0xeff(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
cmp    $0xf,%ebx
ja     1263 <madcreature+0xa3>
lea    0xed6(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
cmp    $0x11,%ebx
ja     1275 <madcreature+0xb5>
lea    0xe9c(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
xor    %eax,%eax
cmp    $0x13,%ebx
ja     1282 <madcreature+0xc2>
pop    %rbx
jmp    1090 <magictablea@plt>
pop    %rbx
jmp    10e0 <magictableb@plt>
lea    0xe26(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [165 x i8] c"The party encounters a creature driven insane by the influence of the demon lords. If cured of its madness, the creature behaves in accordance with its alignment.\0A\0A\00"
@.str.1 = [41 x i8] c"Impossible mad creature encounter of %d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [46 x i8] c"The mad creature has something of interest:\0A\0A\00"
@.str.3 = [12 x i8] c"A 10gp gem\0A\00"
@.str.4 = [24 x i8] c"A gold ring worth 25gp\0A\00"
@.str.5 = [41 x i8] c"An obsidian statue of Lolth worth 100gp\0A\00"
define void @madcreature(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @niceprint(i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* %2
switch i32 %5, label %14 [
i32 1, label %6
i32 2, label %8
i32 3, label %10
i32 4, label %12
]
6: ; preds = %1
%7 = call i32 @deepgnome(i32 1)
br label %19
8: ; preds = %1
%9 = call i32 @drow(i32 1)
br label %19
10: ; preds = %1
%11 = call i32 @duergar(i32 1)
br label %19
12: ; preds = %1
%13 = call i32 @stonegiant(i32 1)
br label %19
14: ; preds = %1
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %12, %10, %8, %6
%20 = call i32 (...) @indefinitemadness()
%21 = call i32 @d(i32 20)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 11
br i1 %23, label %24, label %25
24: ; preds = %19
br label %51
25: ; preds = %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 14
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %51
31: ; preds = %25
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 16
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %50
36: ; preds = %31
%37 = load i32, i32* %3
%38 = icmp slt i32 %37, 18
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
br label %49
41: ; preds = %36
%42 = load i32, i32* %3
%43 = icmp slt i32 %42, 20
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 (...) @magictablea()
br label %48
46: ; preds = %41
%47 = call i32 (...) @magictableb()
br label %48
48: ; preds = %46, %44
br label %49
49: ; preds = %48, %39
br label %50
50: ; preds = %49, %34
br label %51
51: ; preds = %24, %50, %29
ret void
}

LLVM IR (-O2):
@.str = [165 x i8] c"The party encounters a creature driven insane by the influence of the demon lords. If cured of its madness, the creature behaves in accordance with its alignment.\0A\0A\00"
@.str.1 = [41 x i8] c"Impossible mad creature encounter of %d\0A\00"
@EXIT_FAILURE = global i32 0
@str = [45 x i8] c"The mad creature has something of interest:\0A\00"
@str.6 = [40 x i8] c"An obsidian statue of Lolth worth 100gp\00"
@str.7 = [23 x i8] c"A gold ring worth 25gp\00"
@str.8 = [11 x i8] c"A 10gp gem\00"
define void @madcreature(i32 %0) {
%2 = tail call i32 @niceprint(i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0))
switch i32 %0, label %11 [
i32 1, label %3
i32 2, label %5
i32 3, label %7
i32 4, label %9
]
3: ; preds = %1
%4 = tail call i32 @deepgnome(i32 1)
br label %15
5: ; preds = %1
%6 = tail call i32 @drow(i32 1)
br label %15
7: ; preds = %1
%8 = tail call i32 @duergar(i32 1)
br label %15
9: ; preds = %1
%10 = tail call i32 @stonegiant(i32 1)
br label %15
11: ; preds = %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %9, %7, %5, %3
%16 = tail call i32 (...) @indefinitemadness()
%17 = tail call i32 @d(i32 20)
%18 = icmp slt i32 %17, 11
br i1 %18, label %38, label %19
19: ; preds = %15
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%21 = icmp ult i32 %17, 14
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.8, i64 0, i64 0))
br label %38
24: ; preds = %19
%25 = icmp ult i32 %17, 16
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
br label %38
28: ; preds = %24
%29 = icmp ult i32 %17, 18
br i1 %29, label %30, label %32
30: ; preds = %28
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.6, i64 0, i64 0))
br label %38
32: ; preds = %28
%33 = icmp ult i32 %17, 20
br i1 %33, label %34, label %36
34: ; preds = %32
%35 = tail call i32 (...) @magictablea()
br label %38
36: ; preds = %32
%37 = tail call i32 (...) @magictableb()
br label %38
38: ; preds = %22, %30, %36, %34, %26, %15
ret void
}