#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*/ creature_encounter();
int d(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ terrain_encounter();
void random_encounter(void) {
  unsigned d20;
  bool open = false;
  d20 = d(20);
  if (d20 < 14) {
    printf("No encounter\n");
    return;
  }
  switch (d(3)) {
  case 1:
    printf("An encounter occurs in a narrow passageway (single file)\n");
    break;
  case 2:
    printf("An encounter occurs in a standard passageway (two abreast)\n");
    break;
  case 3:
    printf("An encounter occurs in a large open area\n");
    open = true;
    break;
  default:
    printf("Impossible encounter conditions of %d\n", d20);
    exit(EXIT_FAILURE);
  }
  switch (d(2)) {
  case 1:
    switch (d(6)) {
    case 1:
      printf("The area is warm and damp, lit by bioluminescent green moss "
             "(Orum, OotA p.23)\n");
      break;
    case 2:
      printf("The area is lit by %s\n",
             (open) ? "tall, tube-shaped, bioluminescent mushrooms emitting "
                      "dim light (Nightlight, OotA, p.23)"
                    : "phosphorescen moss and lichens");
      break;
    default:
      printf("The area is dimly lit by %s\n",
             (d(5) == 1) ? "faerzress" : "phosphorescent moss and lichens");
    }
    break;
  case 2:
    printf("The area is in darkness\n");
    break;
  default:
    printf("Impossible lighting conditions of %d\n", d20);
    exit(EXIT_FAILURE);
  }
  (void)putchar('\n');
  if (d20 < 16 || d20 > 17) {
    terrain_encounter();
  }
  if (d20 > 15) {
    creature_encounter();
  }
}


x86 assembly (clang, -O0):
<random_encounter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x14,%edi
call   1040 <d@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xe,-0x4(%rbp)
jae    1199 <random_encounter+0x39>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    136d <random_encounter+0x20d>
mov    $0x3,%edi
call   1040 <d@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
sub    $0x1,%eax
je     11d8 <random_encounter+0x78>
jmp    11b6 <random_encounter+0x56>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
je     11eb <random_encounter+0x8b>
jmp    11c7 <random_encounter+0x67>
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
je     11fe <random_encounter+0x9e>
jmp    1218 <random_encounter+0xb8>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1237 <random_encounter+0xd7>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1237 <random_encounter+0xd7>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    1237 <random_encounter+0xd7>
mov    -0x4(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    $0x2,%edi
call   1040 <d@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
sub    $0x1,%eax
je     1265 <random_encounter+0x105>
jmp    1254 <random_encounter+0xf4>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     1305 <random_encounter+0x1a5>
jmp    1318 <random_encounter+0x1b8>
mov    $0x6,%edi
call   1040 <d@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0x1,%eax
je     1293 <random_encounter+0x133>
jmp    1282 <random_encounter+0x122>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     12a6 <random_encounter+0x146>
jmp    12d1 <random_encounter+0x171>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1300 <random_encounter+0x1a0>
mov    -0x8(%rbp),%ecx
lea    0xee3(%rip),%rsi
lea    0xe84(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1300 <random_encounter+0x1a0>
mov    $0x5,%edi
call   1040 <d@plt>
mov    %eax,%ecx
lea    0xef5(%rip),%rsi
lea    0xee4(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1337 <random_encounter+0x1d7>
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1337 <random_encounter+0x1d7>
mov    -0x4(%rbp),%esi
lea    0xef0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x10,-0x4(%rbp)
jb     1355 <random_encounter+0x1f5>
cmpl   $0x11,-0x4(%rbp)
jbe    135c <random_encounter+0x1fc>
mov    $0x0,%al
call   1050 <terrain_encounter@plt>
cmpl   $0xf,-0x4(%rbp)
jbe    136d <random_encounter+0x20d>
mov    $0x0,%al
call   1080 <creature_encounter@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_encounter>:
push   %r14
push   %rbx
push   %rax
mov    $0x14,%edi
call   1050 <d@plt>
cmp    $0xd,%eax
ja     1196 <random_encounter+0x26>
lea    0x109b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>
mov    %eax,%r14d
mov    $0x3,%edi
call   1050 <d@plt>
add    $0xffffffff,%eax
cmp    $0x3,%eax
jae    1282 <random_encounter+0x112>
movslq %eax,%rbx
lea    0x107b(%rip),%rax
movslq (%rax,%rbx,4),%rdi
add    %rax,%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
call   1050 <d@plt>
cmp    $0x2,%eax
je     11fa <random_encounter+0x8a>
cmp    $0x1,%eax
jne    128b <random_encounter+0x11b>
mov    $0x6,%edi
call   1050 <d@plt>
cmp    $0x2,%eax
je     1208 <random_encounter+0x98>
cmp    $0x1,%eax
jne    121f <random_encounter+0xaf>
lea    0xf6b(%rip),%rdi
jmp    1201 <random_encounter+0x91>
lea    0xf4a(%rip),%rdi
call   1040 <puts@plt>
jmp    124c <random_encounter+0xdc>
lea    0x1031(%rip),%rax
movslq (%rax,%rbx,4),%rsi
add    %rax,%rsi
lea    0xe0a(%rip),%rdi
jmp    1245 <random_encounter+0xd5>
mov    $0x5,%edi
call   1050 <d@plt>
cmp    $0x1,%eax
lea    0xe9f(%rip),%rax
lea    0xea2(%rip),%rsi
cmove  %rax,%rsi
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x12(%r14),%eax
cmp    $0xfffffffd,%eax
ja     126c <random_encounter+0xfc>
xor    %eax,%eax
call   1060 <terrain_encounter@plt>
cmp    $0x10,%r14d
jb     127a <random_encounter+0x10a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <creature_encounter@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd77(%rip),%rdi
jmp    1292 <random_encounter+0x122>
lea    0xe6a(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"No encounter\0A\00"
@.str.1 = [58 x i8] c"An encounter occurs in a narrow passageway (single file)\0A\00"
@.str.2 = [60 x i8] c"An encounter occurs in a standard passageway (two abreast)\0A\00"
@.str.3 = [42 x i8] c"An encounter occurs in a large open area\0A\00"
@.str.4 = [39 x i8] c"Impossible encounter conditions of %d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [79 x i8] c"The area is warm and damp, lit by bioluminescent green moss (Orum, OotA p.23)\0A\00"
@.str.6 = [23 x i8] c"The area is lit by %s\0A\00"
@.str.7 = [88 x i8] c"tall, tube-shaped, bioluminescent mushrooms emitting dim light (Nightlight, OotA, p.23)\00"
@.str.8 = [31 x i8] c"phosphorescen moss and lichens\00"
@.str.9 = [29 x i8] c"The area is dimly lit by %s\0A\00"
@.str.10 = [10 x i8] c"faerzress\00"
@.str.11 = [32 x i8] c"phosphorescent moss and lichens\00"
@.str.12 = [25 x i8] c"The area is in darkness\0A\00"
@.str.13 = [38 x i8] c"Impossible lighting conditions of %d\0A\00"
define void @random_encounter() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
%3 = call i32 @d(i32 20)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp ult i32 %4, 14
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %61
8: ; preds = %0
%9 = call i32 @d(i32 3)
switch i32 %9, label %16 [
i32 1, label %10
i32 2, label %12
i32 3, label %14
]
10: ; preds = %8
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
br label %21
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
br label %21
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
br label %21
16: ; preds = %8
%17 = load i32, i32* %1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %14, %12, %10
%22 = call i32 @d(i32 2)
switch i32 %22, label %42 [
i32 1, label %23
i32 2, label %40
]
23: ; preds = %21
%24 = call i32 @d(i32 6)
switch i32 %24, label %33 [
i32 1, label %25
i32 2, label %27
]
25: ; preds = %23
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.5, i64 0, i64 0))
br label %39
27: ; preds = %23
%28 = load i32, i32* %2
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %31)
br label %39
33: ; preds = %23
%34 = call i32 @d(i32 5)
%35 = icmp eq i32 %34, 1
%36 = zext i1 %35 to i64
%37 = select i1 %35, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %33, %27, %25
br label %47
40: ; preds = %21
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0))
br label %47
42: ; preds = %21
%43 = load i32, i32* %1
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.13, i64 0, i64 0), i32 %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %40, %39
%48 = call i32 @putchar(i8 signext 10)
%49 = load i32, i32* %1
%50 = icmp ult i32 %49, 16
br i1 %50, label %54, label %51
51: ; preds = %47
%52 = load i32, i32* %1
%53 = icmp ugt i32 %52, 17
br i1 %53, label %54, label %56
54: ; preds = %51, %47
%55 = call i32 (...) @terrain_encounter()
br label %56
56: ; preds = %54, %51
%57 = load i32, i32* %1
%58 = icmp ugt i32 %57, 15
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 (...) @creature_encounter()
br label %61
61: ; preds = %6, %59, %56
ret void
}

LLVM IR (-O2):
@.str.4 = [39 x i8] c"Impossible encounter conditions of %d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [23 x i8] c"The area is lit by %s\0A\00"
@.str.7 = [88 x i8] c"tall, tube-shaped, bioluminescent mushrooms emitting dim light (Nightlight, OotA, p.23)\00"
@.str.8 = [31 x i8] c"phosphorescen moss and lichens\00"
@.str.9 = [29 x i8] c"The area is dimly lit by %s\0A\00"
@.str.10 = [10 x i8] c"faerzress\00"
@.str.11 = [32 x i8] c"phosphorescent moss and lichens\00"
@.str.13 = [38 x i8] c"Impossible lighting conditions of %d\0A\00"
@str = [41 x i8] c"An encounter occurs in a large open area\00"
@str.14 = [24 x i8] c"The area is in darkness\00"
@str.15 = [78 x i8] c"The area is warm and damp, lit by bioluminescent green moss (Orum, OotA p.23)\00"
@str.16 = [59 x i8] c"An encounter occurs in a standard passageway (two abreast)\00"
@str.17 = [57 x i8] c"An encounter occurs in a narrow passageway (single file)\00"
@str.18 = [13 x i8] c"No encounter\00"
@reltable.random_encounter = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([57 x i8]* @str.17 to i64), i64 ptrtoint ([3 x i32]* @reltable.random_encounter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([59 x i8]* @str.16 to i64), i64 ptrtoint ([3 x i32]* @reltable.random_encounter to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([41 x i8]* @str to i64), i64 ptrtoint ([3 x i32]* @reltable.random_encounter to i64)) to i32)]
@reltable.random_encounter.20 = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @.str.8 to i64), i64 ptrtoint ([3 x i32]* @reltable.random_encounter.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @.str.8 to i64), i64 ptrtoint ([3 x i32]* @reltable.random_encounter.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([88 x i8]* @.str.7 to i64), i64 ptrtoint ([3 x i32]* @reltable.random_encounter.20 to i64)) to i32)]
define void @random_encounter() {
%1 = tail call i32 @d(i32 20)
%2 = icmp ult i32 %1, 14
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.18, i64 0, i64 0))
br label %48
5: ; preds = %0
%6 = tail call i32 @d(i32 3)
%7 = add i32 %6, -1
%8 = icmp ult i32 %7, 3
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %1)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %5
%14 = sext i32 %7 to i64
%15 = shl i64 %14, 2
%16 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.random_encounter to i8*), i64 %15)
%17 = sext i32 %7 to i64
%18 = shl i64 %17, 2
%19 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.random_encounter.20 to i8*), i64 %18)
%20 = tail call i32 @puts(i8* dereferenceable(1) %16)
%21 = tail call i32 @d(i32 2)
switch i32 %21, label %35 [
i32 1, label %22
i32 2, label %33
]
22: ; preds = %13
%23 = tail call i32 @d(i32 6)
switch i32 %23, label %28 [
i32 1, label %24
i32 2, label %26
]
24: ; preds = %22
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.15, i64 0, i64 0))
br label %39
26: ; preds = %22
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %19)
br label %39
28: ; preds = %22
%29 = tail call i32 @d(i32 5)
%30 = icmp eq i32 %29, 1
%31 = select i1 %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %31)
br label %39
33: ; preds = %13
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
br label %39
35: ; preds = %13
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.13, i64 0, i64 0), i32 %1)
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %24, %26, %28, %33
%40 = tail call i32 @putchar(i8 signext 10)
%41 = add i32 %1, -18
%42 = icmp ult i32 %41, -2
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = tail call i32 (...) @terrain_encounter()
%45 = icmp ugt i32 %1, 15
br i1 %45, label %46, label %48
46: ; preds = %39, %43
%47 = tail call i32 (...) @creature_encounter()
br label %48
48: ; preds = %43, %46, %3
ret void
}