#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 /*<<< orphan*/ ambush(int);
int /*<<< orphan*/ carrioncrawler(int);
int d(int);
int /*<<< orphan*/ domesticcrawler();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ firebeetle(int /*<<< orphan*/);
int /*<<< orphan*/ fungi(int);
int /*<<< orphan*/ madcreature(int);
int /*<<< orphan*/ niceprint(char *);
int /*<<< orphan*/ ochrejelly(int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ raiders(int);
int /*<<< orphan*/ rocktopus(int);
int /*<<< orphan*/ scouts(int);
int /*<<< orphan*/ slaves(int);
int /*<<< orphan*/ society(int);
int /*<<< orphan*/ sporeservants(int);
int /*<<< orphan*/ traders(int);
void creature_encounter(void) {
  unsigned d20;
  d20 = d(20);
  switch (d20) {
  case 1:
  case 2:
    ambush(d(20));
    break;
  case 3:
    if (d(4) == 1)
      domesticcrawler();
    else
      carrioncrawler(1);
    break;
  case 4:
  case 5:
    slaves(d(4));
    break;
  case 6:
  case 7:
    fungi(d(6));
    break;
  case 8:
  case 9:
    firebeetle(d(6) + d(6) + d(6));
    niceprint("Characters in need of light sources can harvest the glowing "
              "glands fo slain beetles.\n\n");
    break;
  case 10:
  case 11:
    rocktopus(1);
    break;
  case 12:
    madcreature(d(4));
    break;
  case 13:
    ochrejelly(1);
    niceprint("The ooze follows the characters, attacking when they stop "
              "to take their next rest. Characters in the back of the marching "
              "order who have a passive Wisdom (Perception) score of 14 or "
              "higher spot the ooze following them.\n\n");
    break;
  case 14:
  case 15:
    raiders(d(6));
    break;
  case 16:
    scouts(d(6));
    break;
  case 17:
    society(d(10));
    break;
  case 18:
    sporeservants(d(10));
    break;
  case 19:
  case 20:
    traders(d(4));
    break;
  default:
    printf("Impossible creature encounter of %d\n", d20);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<creature_encounter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x14,%edi
call   1060 <d@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x13,%eax
ja     13c2 <creature_encounter+0x1a2>
mov    -0x10(%rbp),%rax
lea    0xdab(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x14,%edi
call   1060 <d@plt>
mov    %eax,%edi
call   1090 <ambush@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x4,%edi
call   1060 <d@plt>
cmp    $0x1,%eax
jne    1293 <creature_encounter+0x73>
mov    $0x0,%al
call   10b0 <domesticcrawler@plt>
jmp    129d <creature_encounter+0x7d>
mov    $0x1,%edi
call   1050 <carrioncrawler@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x4,%edi
call   1060 <d@plt>
mov    %eax,%edi
call   10a0 <slaves@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x6,%edi
call   1060 <d@plt>
mov    %eax,%edi
call   10c0 <fungi@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x6,%edi
call   1060 <d@plt>
mov    %eax,-0x18(%rbp)
mov    $0x6,%edi
call   1060 <d@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    $0x6,%edi
call   1060 <d@plt>
mov    -0x14(%rbp),%edi
add    %eax,%edi
call   1120 <firebeetle@plt>
lea    0xd46(%rip),%rdi
call   1100 <niceprint@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x1,%edi
call   1110 <rocktopus@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x4,%edi
call   1060 <d@plt>
mov    %eax,%edi
call   1070 <madcreature@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x1,%edi
call   1040 <ochrejelly@plt>
lea    0xd5d(%rip),%rdi
call   1100 <niceprint@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x6,%edi
call   1060 <d@plt>
mov    %eax,%edi
call   1030 <raiders@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x6,%edi
call   1060 <d@plt>
mov    %eax,%edi
call   10d0 <scouts@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0xa,%edi
call   1060 <d@plt>
mov    %eax,%edi
call   10e0 <society@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0xa,%edi
call   1060 <d@plt>
mov    %eax,%edi
call   1140 <sporeservants@plt>
jmp    13df <creature_encounter+0x1bf>
mov    $0x4,%edi
call   1060 <d@plt>
mov    %eax,%edi
call   10f0 <traders@plt>
jmp    13df <creature_encounter+0x1bf>
mov    -0x4(%rbp),%esi
lea    0xdb8(%rip),%rdi
call   1080 <printf@plt>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<creature_encounter>:
push   %rbx
mov    $0x14,%edi
call   1060 <d@plt>
lea    -0x1(%rax),%ecx
cmp    $0x13,%ecx
ja     1365 <creature_encounter+0x145>
lea    0xdc2(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    $0x14,%edi
call   1060 <d@plt>
mov    %eax,%edi
pop    %rbx
jmp    1090 <ambush@plt>
mov    $0x4,%edi
call   1060 <d@plt>
mov    %eax,%edi
pop    %rbx
jmp    10a0 <slaves@plt>
mov    $0x6,%edi
call   1060 <d@plt>
mov    %eax,%edi
pop    %rbx
jmp    10c0 <fungi@plt>
mov    $0x6,%edi
call   1060 <d@plt>
mov    %eax,%ebx
mov    $0x6,%edi
call   1060 <d@plt>
add    %eax,%ebx
mov    $0x6,%edi
call   1060 <d@plt>
add    %eax,%ebx
mov    %ebx,%edi
call   1120 <firebeetle@plt>
lea    0xda1(%rip),%rdi
pop    %rbx
jmp    1100 <niceprint@plt>
mov    $0x1,%edi
pop    %rbx
jmp    1110 <rocktopus@plt>
mov    $0x6,%edi
call   1060 <d@plt>
mov    %eax,%edi
pop    %rbx
jmp    1030 <raiders@plt>
mov    $0x4,%edi
call   1060 <d@plt>
mov    %eax,%edi
pop    %rbx
jmp    10f0 <traders@plt>
mov    $0x4,%edi
call   1060 <d@plt>
cmp    $0x1,%eax
jne    135a <creature_encounter+0x13a>
xor    %eax,%eax
pop    %rbx
jmp    10b0 <domesticcrawler@plt>
mov    $0x4,%edi
call   1060 <d@plt>
mov    %eax,%edi
pop    %rbx
jmp    1070 <madcreature@plt>
mov    $0x1,%edi
call   1040 <ochrejelly@plt>
lea    0xd89(%rip),%rdi
pop    %rbx
jmp    1100 <niceprint@plt>
mov    $0x6,%edi
call   1060 <d@plt>
mov    %eax,%edi
pop    %rbx
jmp    10d0 <scouts@plt>
mov    $0xa,%edi
call   1060 <d@plt>
mov    %eax,%edi
pop    %rbx
jmp    10e0 <society@plt>
mov    $0xa,%edi
call   1060 <d@plt>
mov    %eax,%edi
pop    %rbx
jmp    1140 <sporeservants@plt>
mov    $0x1,%edi
pop    %rbx
jmp    1050 <carrioncrawler@plt>
lea    0xe18(%rip),%rdi
mov    %eax,%esi
call   1080 <printf@plt>
mov    0x2c66(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>

LLVM IR (-O0):
@.str = [87 x i8] c"Characters in need of light sources can harvest the glowing glands fo slain beetles.\0A\0A\00"
@.str.1 = [221 x i8] c"The ooze follows the characters, attacking when they stop to take their next rest. Characters in the back of the marching order who have a passive Wisdom (Perception) score of 14 or higher spot the ooze following them.\0A\0A\00"
@.str.2 = [37 x i8] c"Impossible creature encounter of %d\0A\00"
@EXIT_FAILURE = global i32 0
define void @creature_encounter() {
%1 = alloca i32
%2 = call i32 @d(i32 20)
store i32 %2, i32* %1
%3 = load i32, i32* %1
switch i32 %3, label %52 [
i32 1, label %4
i32 2, label %4
i32 3, label %7
i32 4, label %15
i32 5, label %15
i32 6, label %18
i32 7, label %18
i32 8, label %21
i32 9, label %21
i32 10, label %29
i32 11, label %29
i32 12, label %31
i32 13, label %34
i32 14, label %37
i32 15, label %37
i32 16, label %40
i32 17, label %43
i32 18, label %46
i32 19, label %49
i32 20, label %49
]
4: ; preds = %0, %0
%5 = call i32 @d(i32 20)
%6 = call i32 @ambush(i32 %5)
br label %57
7: ; preds = %0
%8 = call i32 @d(i32 4)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 (...) @domesticcrawler()
br label %14
12: ; preds = %7
%13 = call i32 @carrioncrawler(i32 1)
br label %14
14: ; preds = %12, %10
br label %57
15: ; preds = %0, %0
%16 = call i32 @d(i32 4)
%17 = call i32 @slaves(i32 %16)
br label %57
18: ; preds = %0, %0
%19 = call i32 @d(i32 6)
%20 = call i32 @fungi(i32 %19)
br label %57
21: ; preds = %0, %0
%22 = call i32 @d(i32 6)
%23 = call i32 @d(i32 6)
%24 = add nsw i32 %22, %23
%25 = call i32 @d(i32 6)
%26 = add nsw i32 %24, %25
%27 = call i32 @firebeetle(i32 %26)
%28 = call i32 @niceprint(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
br label %57
29: ; preds = %0, %0
%30 = call i32 @rocktopus(i32 1)
br label %57
31: ; preds = %0
%32 = call i32 @d(i32 4)
%33 = call i32 @madcreature(i32 %32)
br label %57
34: ; preds = %0
%35 = call i32 @ochrejelly(i32 1)
%36 = call i32 @niceprint(i8* getelementptr inbounds ([221 x i8], [221 x i8]* @.str.1, i64 0, i64 0))
br label %57
37: ; preds = %0, %0
%38 = call i32 @d(i32 6)
%39 = call i32 @raiders(i32 %38)
br label %57
40: ; preds = %0
%41 = call i32 @d(i32 6)
%42 = call i32 @scouts(i32 %41)
br label %57
43: ; preds = %0
%44 = call i32 @d(i32 10)
%45 = call i32 @society(i32 %44)
br label %57
46: ; preds = %0
%47 = call i32 @d(i32 10)
%48 = call i32 @sporeservants(i32 %47)
br label %57
49: ; preds = %0, %0
%50 = call i32 @d(i32 4)
%51 = call i32 @traders(i32 %50)
br label %57
52: ; preds = %0
%53 = load i32, i32* %1
%54 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %53)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %49, %46, %43, %40, %37, %34, %31, %29, %21, %18, %15, %14, %4
ret void
}

LLVM IR (-O2):
@.str = [87 x i8] c"Characters in need of light sources can harvest the glowing glands fo slain beetles.\0A\0A\00"
@.str.1 = [221 x i8] c"The ooze follows the characters, attacking when they stop to take their next rest. Characters in the back of the marching order who have a passive Wisdom (Perception) score of 14 or higher spot the ooze following them.\0A\0A\00"
@.str.2 = [37 x i8] c"Impossible creature encounter of %d\0A\00"
@EXIT_FAILURE = global i32 0
define void @creature_encounter() {
%1 = tail call i32 @d(i32 20)
switch i32 %1, label %49 [
i32 1, label %2
i32 2, label %2
i32 3, label %5
i32 4, label %12
i32 5, label %12
i32 6, label %15
i32 7, label %15
i32 8, label %18
i32 9, label %18
i32 10, label %26
i32 11, label %26
i32 12, label %28
i32 13, label %31
i32 14, label %34
i32 15, label %34
i32 16, label %37
i32 17, label %40
i32 18, label %43
i32 19, label %46
i32 20, label %46
]
2: ; preds = %0, %0
%3 = tail call i32 @d(i32 20)
%4 = tail call i32 @ambush(i32 %3)
br label %53
5: ; preds = %0
%6 = tail call i32 @d(i32 4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (...) @domesticcrawler()
br label %53
10: ; preds = %5
%11 = tail call i32 @carrioncrawler(i32 1)
br label %53
12: ; preds = %0, %0
%13 = tail call i32 @d(i32 4)
%14 = tail call i32 @slaves(i32 %13)
br label %53
15: ; preds = %0, %0
%16 = tail call i32 @d(i32 6)
%17 = tail call i32 @fungi(i32 %16)
br label %53
18: ; preds = %0, %0
%19 = tail call i32 @d(i32 6)
%20 = tail call i32 @d(i32 6)
%21 = add nsw i32 %20, %19
%22 = tail call i32 @d(i32 6)
%23 = add nsw i32 %21, %22
%24 = tail call i32 @firebeetle(i32 %23)
%25 = tail call i32 @niceprint(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
br label %53
26: ; preds = %0, %0
%27 = tail call i32 @rocktopus(i32 1)
br label %53
28: ; preds = %0
%29 = tail call i32 @d(i32 4)
%30 = tail call i32 @madcreature(i32 %29)
br label %53
31: ; preds = %0
%32 = tail call i32 @ochrejelly(i32 1)
%33 = tail call i32 @niceprint(i8* getelementptr inbounds ([221 x i8], [221 x i8]* @.str.1, i64 0, i64 0))
br label %53
34: ; preds = %0, %0
%35 = tail call i32 @d(i32 6)
%36 = tail call i32 @raiders(i32 %35)
br label %53
37: ; preds = %0
%38 = tail call i32 @d(i32 6)
%39 = tail call i32 @scouts(i32 %38)
br label %53
40: ; preds = %0
%41 = tail call i32 @d(i32 10)
%42 = tail call i32 @society(i32 %41)
br label %53
43: ; preds = %0
%44 = tail call i32 @d(i32 10)
%45 = tail call i32 @sporeservants(i32 %44)
br label %53
46: ; preds = %0, %0
%47 = tail call i32 @d(i32 4)
%48 = tail call i32 @traders(i32 %47)
br label %53
49: ; preds = %0
%50 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%51 = load i32, i32* @EXIT_FAILURE
%52 = tail call i32 @exit(i32 %51)
unreachable
53: ; preds = %8, %10, %46, %43, %40, %37, %34, %31, %28, %26, %18, %15, %12, %2
ret void
}