#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*/ duergarkavalrachni(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ femalesteeder(int);
int /*<<< orphan*/ giantlizard(int /*<<< orphan*/);
int /*<<< orphan*/ kuotoa(int);
int /*<<< orphan*/ malesteeder(int /*<<< orphan*/);
int /*<<< orphan*/ niceprint(char *);
int /*<<< orphan*/ printf(char *, int, ...);
void traders(unsigned d4) {
  int numtraders;
  numtraders = d(4) + d(4);
  niceprint(
      "The party encounters traders plying their trade in the tunnels of the "
      "Underdark, traveling from settlement to settlement.\n\n");
  switch (d4) {
  case 1:
    deepgnome(numtraders);
    if (d(6) < 4) {
      niceprint("The traders have beasts of burden with them to help "
                "carry their wares.\n\n");
      giantlizard((numtraders / 2) + 1);
    }
    break;
  case 2:
    drow(numtraders);
    if (d(6) < 4) {
      giantlizard((numtraders / 2) + 1);
    }
    niceprint(
        "If the drow traders see the adventurers and have the opportunity "
        "to report it, increase the drow pursuit level by 1.\n\n");
    break;
  case 3:
    duergar(numtraders);
    if (d(6) < 4) {
      malesteeder((numtraders / 2) + 1);
      if (d(6) < 4) {
        duergarkavalrachni(1);
        femalesteeder(1);
        numtraders++;
      }
    }
    break;
  case 4:
    kuotoa(numtraders);
    break;
  default:
    printf("Impossible trader encounter of %d\n", d4);
    exit(EXIT_FAILURE);
  }
  niceprint(
      "The trader's carry the following which they are willing to sell up "
      "to 20% of either to the party:\n\n");
  printf("Goods worth %d gp plus %d day(s) of provisions\n",
         10 * (d(4) + d(4) + d(4) + d(4) + d(4)), 10 * numtraders);
}


x86 assembly (clang, -O0):
<traders>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x4,%edi
mov    %edi,-0x18(%rbp)
call   1030 <d@plt>
mov    -0x18(%rbp),%edi
mov    %eax,-0x14(%rbp)
call   1030 <d@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
lea    0xe1c(%rip),%rdi
call   10b0 <niceprint@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     131b <traders+0x15b>
mov    -0x10(%rbp),%rax
lea    0xde7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%edi
call   10a0 <deepgnome@plt>
mov    $0x6,%edi
call   1030 <d@plt>
cmp    $0x4,%eax
jge    125e <traders+0x9e>
lea    0xe48(%rip),%rdi
call   10b0 <niceprint@plt>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
call   1050 <giantlizard@plt>
jmp    133a <traders+0x17a>
mov    -0x8(%rbp),%edi
call   1040 <drow@plt>
mov    $0x6,%edi
call   1030 <d@plt>
cmp    $0x4,%eax
jge    1293 <traders+0xd3>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
call   1050 <giantlizard@plt>
lea    0xe3b(%rip),%rdi
call   10b0 <niceprint@plt>
jmp    133a <traders+0x17a>
mov    -0x8(%rbp),%edi
call   1070 <duergar@plt>
mov    $0x6,%edi
call   1030 <d@plt>
cmp    $0x4,%eax
jge    1309 <traders+0x149>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
call   1090 <malesteeder@plt>
mov    $0x6,%edi
call   1030 <d@plt>
cmp    $0x4,%eax
jge    1304 <traders+0x144>
mov    $0x1,%edi
call   1080 <duergarkavalrachni@plt>
mov    $0x1,%edi
call   10c0 <femalesteeder@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1309 <traders+0x149>
jmp    133a <traders+0x17a>
mov    -0x8(%rbp),%edi
call   10e0 <kuotoa@plt>
jmp    133a <traders+0x17a>
mov    -0x4(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xe2e(%rip),%rdi
call   10b0 <niceprint@plt>
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,-0x28(%rbp)
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
imul   $0xa,%eax,%esi
imul   $0xa,-0x8(%rbp),%edx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<traders>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%ebp
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%r14d
lea    0xe2a(%rip),%rdi
call   10b0 <niceprint@plt>
lea    -0x1(%rbx),%eax
cmp    $0x3,%eax
ja     1348 <traders+0x188>
add    %ebp,%r14d
lea    0xdff(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %r14d,%edi
call   10a0 <deepgnome@plt>
mov    $0x6,%edi
call   1030 <d@plt>
cmp    $0x3,%eax
jg     12dc <traders+0x11c>
lea    0xe60(%rip),%rdi
call   10b0 <niceprint@plt>
mov    %r14d,%edi
shr    $0x1f,%edi
add    %r14d,%edi
sar    %edi
add    $0x1,%edi
call   1050 <giantlizard@plt>
jmp    12dc <traders+0x11c>
mov    %r14d,%edi
call   1070 <duergar@plt>
mov    $0x6,%edi
call   1030 <d@plt>
cmp    $0x3,%eax
jg     12dc <traders+0x11c>
mov    %r14d,%edi
shr    $0x1f,%edi
add    %r14d,%edi
sar    %edi
add    $0x1,%edi
call   1090 <malesteeder@plt>
mov    $0x6,%edi
call   1030 <d@plt>
cmp    $0x3,%eax
jg     12dc <traders+0x11c>
mov    $0x1,%edi
call   1080 <duergarkavalrachni@plt>
mov    $0x1,%edi
call   10c0 <femalesteeder@plt>
add    $0x1,%r14d
jmp    12dc <traders+0x11c>
mov    %r14d,%edi
call   1040 <drow@plt>
mov    $0x6,%edi
call   1030 <d@plt>
cmp    $0x3,%eax
jg     12c6 <traders+0x106>
mov    %r14d,%edi
shr    $0x1f,%edi
add    %r14d,%edi
sar    %edi
add    $0x1,%edi
call   1050 <giantlizard@plt>
lea    0xe08(%rip),%rdi
call   10b0 <niceprint@plt>
jmp    12dc <traders+0x11c>
mov    %r14d,%edi
call   10e0 <kuotoa@plt>
lea    0xe8c(%rip),%rdi
call   10b0 <niceprint@plt>
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%ebx
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%ebp
add    %ebx,%ebp
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,%ebp
add    %ebx,%ebp
mov    $0x4,%edi
call   1030 <d@plt>
add    %ebp,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%esi
add    %r14d,%r14d
lea    (%r14,%r14,4),%edx
lea    0xe96(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <printf@plt>
lea    0xdfd(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [124 x i8] c"The party encounters traders plying their trade in the tunnels of the Underdark, traveling from settlement to settlement.\0A\0A\00"
@.str.1 = [73 x i8] c"The traders have beasts of burden with them to help carry their wares.\0A\0A\00"
@.str.2 = [119 x i8] c"If the drow traders see the adventurers and have the opportunity to report it, increase the drow pursuit level by 1.\0A\0A\00"
@.str.3 = [35 x i8] c"Impossible trader encounter of %d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [100 x i8] c"The trader's carry the following which they are willing to sell up to 20% of either to the party:\0A\0A\00"
@.str.5 = [48 x i8] c"Goods worth %d gp plus %d day(s) of provisions\0A\00"
define void @traders(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @d(i32 4)
%5 = call i32 @d(i32 4)
%6 = add nsw i32 %4, %5
store i32 %6, i32* %3
%7 = call i32 @niceprint(i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %2
switch i32 %8, label %55 [
i32 1, label %9
i32 2, label %21
i32 3, label %33
i32 4, label %52
]
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @deepgnome(i32 %10)
%12 = call i32 @d(i32 6)
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = call i32 @niceprint(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 2
%18 = add nsw i32 %17, 1
%19 = call i32 @giantlizard(i32 %18)
br label %20
20: ; preds = %14, %9
br label %60
21: ; preds = %1
%22 = load i32, i32* %3
%23 = call i32 @drow(i32 %22)
%24 = call i32 @d(i32 6)
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i32, i32* %3
%28 = sdiv i32 %27, 2
%29 = add nsw i32 %28, 1
%30 = call i32 @giantlizard(i32 %29)
br label %31
31: ; preds = %26, %21
%32 = call i32 @niceprint(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.2, i64 0, i64 0))
br label %60
33: ; preds = %1
%34 = load i32, i32* %3
%35 = call i32 @duergar(i32 %34)
%36 = call i32 @d(i32 6)
%37 = icmp slt i32 %36, 4
br i1 %37, label %38, label %51
38: ; preds = %33
%39 = load i32, i32* %3
%40 = sdiv i32 %39, 2
%41 = add nsw i32 %40, 1
%42 = call i32 @malesteeder(i32 %41)
%43 = call i32 @d(i32 6)
%44 = icmp slt i32 %43, 4
br i1 %44, label %45, label %50
45: ; preds = %38
%46 = call i32 @duergarkavalrachni(i32 1)
%47 = call i32 @femalesteeder(i32 1)
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
br label %50
50: ; preds = %45, %38
br label %51
51: ; preds = %50, %33
br label %60
52: ; preds = %1
%53 = load i32, i32* %3
%54 = call i32 @kuotoa(i32 %53)
br label %60
55: ; preds = %1
%56 = load i32, i32* %2
%57 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %52, %51, %31, %20
%61 = call i32 @niceprint(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @d(i32 4)
%63 = call i32 @d(i32 4)
%64 = add nsw i32 %62, %63
%65 = call i32 @d(i32 4)
%66 = add nsw i32 %64, %65
%67 = call i32 @d(i32 4)
%68 = add nsw i32 %66, %67
%69 = call i32 @d(i32 4)
%70 = add nsw i32 %68, %69
%71 = mul nsw i32 10, %70
%72 = load i32, i32* %3
%73 = mul nsw i32 10, %72
%74 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 %71, i32 %73)
ret void
}

LLVM IR (-O2):
@.str = [124 x i8] c"The party encounters traders plying their trade in the tunnels of the Underdark, traveling from settlement to settlement.\0A\0A\00"
@.str.1 = [73 x i8] c"The traders have beasts of burden with them to help carry their wares.\0A\0A\00"
@.str.2 = [119 x i8] c"If the drow traders see the adventurers and have the opportunity to report it, increase the drow pursuit level by 1.\0A\0A\00"
@.str.3 = [35 x i8] c"Impossible trader encounter of %d\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [100 x i8] c"The trader's carry the following which they are willing to sell up to 20% of either to the party:\0A\0A\00"
@.str.5 = [48 x i8] c"Goods worth %d gp plus %d day(s) of provisions\0A\00"
define void @traders(i32 %0) {
%2 = tail call i32 @d(i32 4)
%3 = tail call i32 @d(i32 4)
%4 = add nsw i32 %3, %2
%5 = tail call i32 @niceprint(i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str, i64 0, i64 0))
switch i32 %0, label %41 [
i32 1, label %6
i32 2, label %15
i32 3, label %25
i32 4, label %39
]
6: ; preds = %1
%7 = tail call i32 @deepgnome(i32 %4)
%8 = tail call i32 @d(i32 6)
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %45
10: ; preds = %6
%11 = tail call i32 @niceprint(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0))
%12 = sdiv i32 %4, 2
%13 = add nsw i32 %12, 1
%14 = tail call i32 @giantlizard(i32 %13)
br label %45
15: ; preds = %1
%16 = tail call i32 @drow(i32 %4)
%17 = tail call i32 @d(i32 6)
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = sdiv i32 %4, 2
%21 = add nsw i32 %20, 1
%22 = tail call i32 @giantlizard(i32 %21)
br label %23
23: ; preds = %19, %15
%24 = tail call i32 @niceprint(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.2, i64 0, i64 0))
br label %45
25: ; preds = %1
%26 = tail call i32 @duergar(i32 %4)
%27 = tail call i32 @d(i32 6)
%28 = icmp slt i32 %27, 4
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = sdiv i32 %4, 2
%31 = add nsw i32 %30, 1
%32 = tail call i32 @malesteeder(i32 %31)
%33 = tail call i32 @d(i32 6)
%34 = icmp slt i32 %33, 4
br i1 %34, label %35, label %45
35: ; preds = %29
%36 = tail call i32 @duergarkavalrachni(i32 1)
%37 = tail call i32 @femalesteeder(i32 1)
%38 = add nsw i32 %4, 1
br label %45
39: ; preds = %1
%40 = tail call i32 @kuotoa(i32 %4)
br label %45
41: ; preds = %1
%42 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @exit(i32 %43)
unreachable
45: ; preds = %25, %35, %29, %6, %10, %39, %23
%46 = phi i32 [ %4, %39 ], [ %38, %35 ], [ %4, %29 ], [ %4, %25 ], [ %4, %23 ], [ %4, %10 ], [ %4, %6 ]
%47 = tail call i32 @niceprint(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.4, i64 0, i64 0))
%48 = tail call i32 @d(i32 4)
%49 = tail call i32 @d(i32 4)
%50 = add nsw i32 %49, %48
%51 = tail call i32 @d(i32 4)
%52 = add nsw i32 %50, %51
%53 = tail call i32 @d(i32 4)
%54 = add nsw i32 %52, %53
%55 = tail call i32 @d(i32 4)
%56 = add nsw i32 %54, %55
%57 = mul nsw i32 %56, 10
%58 = mul nsw i32 %46, 10
%59 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 %57, i32 %58)
ret void
}