#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 d(int);
int /*<<< orphan*/ duergar(int, int /*<<< orphan*/);
int /*<<< orphan*/ niceprint(char *);
int /*<<< orphan*/ putchar(char);
void madduergar() {
  niceprint("The characters encounter a duergar afflicted with a form of "
            "indefinite madness.");
  (void)putchar('\n');
  switch (d(5)) {
  case 1:
    niceprint("The duergar is a merchant desperate to sell his wares, "
              "convinced that his life depends upon it.");
    break;
  case 2:
    niceprint("The duergar is a street sweaper who hounds the characters while "
              "accusing them of being spies "
              "and working for the drow.");
    break;
  case 3:
    niceprint("The duergar is a cloaked guard who thinks he's Deepking Horgar "
              "Steelshadow V. He tries to draft "
              "the party to help him slay Themberchaud, convinced that the "
              "dragon is possessed by a demon lord.");
    break;
  case 4:
    niceprint("The duergar is a merchant who accuses the characters of theft "
              "and calls out for a duergar patrol "
              "to arrest them.");
    break;
  case 5:
    niceprint("The duergar is a weaponsmith convinced that one of the "
              "characters is a long-lost member of her "
              "clan and who insists on giving the party food and shelter.");
    break;
  }
  (void)putchar('\n');
  duergar(1, 0);
}


x86 assembly (clang, -O0):
<madduergar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec5(%rip),%rdi
call   1060 <niceprint@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x5,%edi
call   1040 <d@plt>
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x8(%rbp)
sub    $0x4,%eax
ja     11de <madduergar+0x9e>
mov    -0x8(%rbp),%rax
lea    0xe7b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xecf(%rip),%rdi
call   1060 <niceprint@plt>
jmp    11de <madduergar+0x9e>
lea    0xf1e(%rip),%rdi
call   1060 <niceprint@plt>
jmp    11de <madduergar+0x9e>
lea    0xf84(%rip),%rdi
call   1060 <niceprint@plt>
jmp    11de <madduergar+0x9e>
lea    0x1034(%rip),%rdi
call   1060 <niceprint@plt>
jmp    11de <madduergar+0x9e>
lea    0x1094(%rip),%rdi
call   1060 <niceprint@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <duergar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<madduergar>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1060 <niceprint@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x5,%edi
call   1040 <d@plt>
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     117e <madduergar+0x3e>
cltq
lea    0x1182(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1060 <niceprint@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
xor    %esi,%esi
pop    %rax
jmp    1050 <duergar@plt>

LLVM IR (-O0):
@.str = [80 x i8] c"The characters encounter a duergar afflicted with a form of indefinite madness.\00"
@.str.1 = [96 x i8] c"The duergar is a merchant desperate to sell his wares, convinced that his life depends upon it.\00"
@.str.2 = [119 x i8] c"The duergar is a street sweaper who hounds the characters while accusing them of being spies and working for the drow.\00"
@.str.3 = [193 x i8] c"The duergar is a cloaked guard who thinks he's Deepking Horgar Steelshadow V. He tries to draft the party to help him slay Themberchaud, convinced that the dragon is possessed by a demon lord.\00"
@.str.4 = [113 x i8] c"The duergar is a merchant who accuses the characters of theft and calls out for a duergar patrol to arrest them.\00"
@.str.5 = [154 x i8] c"The duergar is a weaponsmith convinced that one of the characters is a long-lost member of her clan and who insists on giving the party food and shelter.\00"
define void @madduergar() {
%1 = call i32 @niceprint(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
%2 = call i32 @putchar(i8 signext 10)
%3 = call i32 @d(i32 5)
switch i32 %3, label %14 [
i32 1, label %4
i32 2, label %6
i32 3, label %8
i32 4, label %10
i32 5, label %12
]
4: ; preds = %0
%5 = call i32 @niceprint(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.1, i64 0, i64 0))
br label %14
6: ; preds = %0
%7 = call i32 @niceprint(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.2, i64 0, i64 0))
br label %14
8: ; preds = %0
%9 = call i32 @niceprint(i8* getelementptr inbounds ([193 x i8], [193 x i8]* @.str.3, i64 0, i64 0))
br label %14
10: ; preds = %0
%11 = call i32 @niceprint(i8* getelementptr inbounds ([113 x i8], [113 x i8]* @.str.4, i64 0, i64 0))
br label %14
12: ; preds = %0
%13 = call i32 @niceprint(i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.5, i64 0, i64 0))
br label %14
14: ; preds = %0, %12, %10, %8, %6, %4
%15 = call i32 @putchar(i8 signext 10)
%16 = call i32 @duergar(i32 1, i32 0)
ret void
}

LLVM IR (-O2):
@.str = [80 x i8] c"The characters encounter a duergar afflicted with a form of indefinite madness.\00"
@.str.1 = [96 x i8] c"The duergar is a merchant desperate to sell his wares, convinced that his life depends upon it.\00"
@.str.2 = [119 x i8] c"The duergar is a street sweaper who hounds the characters while accusing them of being spies and working for the drow.\00"
@.str.3 = [193 x i8] c"The duergar is a cloaked guard who thinks he's Deepking Horgar Steelshadow V. He tries to draft the party to help him slay Themberchaud, convinced that the dragon is possessed by a demon lord.\00"
@.str.4 = [113 x i8] c"The duergar is a merchant who accuses the characters of theft and calls out for a duergar patrol to arrest them.\00"
@.str.5 = [154 x i8] c"The duergar is a weaponsmith convinced that one of the characters is a long-lost member of her clan and who insists on giving the party food and shelter.\00"
@reltable.madduergar = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([96 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.madduergar to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([119 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.madduergar to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([193 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.madduergar to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([113 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.madduergar to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([154 x i8]* @.str.5 to i64), i64 ptrtoint ([5 x i32]* @reltable.madduergar to i64)) to i32)]
define void @madduergar() {
%1 = tail call i32 @niceprint(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @putchar(i8 signext 10)
%3 = tail call i32 @d(i32 5)
%4 = add i32 %3, -1
%5 = icmp ult i32 %4, 5
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = sext i32 %4 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.madduergar to i8*), i64 %8)
%10 = tail call i32 @niceprint(i8* %9)
br label %11
11: ; preds = %0, %6
%12 = tail call i32 @putchar(i8 signext 10)
%13 = tail call i32 @duergar(i32 1, i32 0)
ret void
}